rpn 		() { # 2-cell (no stack) compose data in Reverse-Polish
			# needs bases, aq, ad, i.e. osimplay
if test "$1" = "h" ; then  echo -e  "\n\t\t\t\t

Chuck Moore does a lot of what amounts to bitwise hand-assembly in the
MASM sources for colorForth. He does a lot of inner-interpreter tokens or
something with MASM arithmetic expressions, with huge gobs of parens. Most
disturbing to see the inventor of Forth resorting to that. Also
problematic for my - unmasm - script that converts MASM to osimplay is
that the precedence of MASM expressions operators differs from Bash for
bitshifts, which get used constantly for such things.

This is a red flashing example of why people should do hand-coded assembly
with shell scripts. Until they get thier Forth booted, that is. Chuck's
expressions happen to be mostly RPN without an RPN calculator. All the
left-parens are at the left end. This is not algebra, this is
Forth-in-MASM_expressions. So here. New osimplay word, rpn. Plays nice
with osimplay - aq - and - ad - as - , - in good Forthy style, or - bases
- if you echo (= or .) stuff. A version of rpn is now in osimplay, and
could be cheaply added to a shell, even a throwback like ash, as a
builtin. rash? Fash?

I have a true stack in Bash laying around somewhere. I'm not going bother.
It needs eval, as I recall, and that's to be avoided where possible. The
few times Chuck doesn't go strictly left-to-right I can still resort to
$((expr)).

Here's Chuck's MASM...

       dd (((24o shl 4+3)shl 4+5)shl 7+140o)shl 12 ; LOAD

Here's the osimplay with rpn ...
						(cell is already 4)

	rpn 024 4 up 3 + 4 up 5 + 7 up 0140 + 12 up , # LOAD

I don't have a runnable check of MASM, but I am assuming )shl 7+104o)
breaks at the +. Not too often do you want to leftshift a quad by 118.
Along with the above you get shell interpretation of variables and whatnot
for free.




\n\n"
                                        else ################
        HL


local b t i start=yes
set -f
for i									; do
	if test "$start"		 ; then
		b=$i	start=
	fi
	case $i in
		+)			b=$((b+t))	;;
		-)			b=$((b-t))	 ;;
		"<<"|up*|left*)		b=$((b<<t))	 ;;
		">>"|down*|right*)	b=$((b>>t))	 ;;
		"&"|AND)		b=$((b&t))	 ;;
		"|"|OR)			b=$((b|t))	 ;;
		"^"|XOR)		b=$((b^t))	 ;;
		"*")			b=$((b*t))	 ;;
		=|.)			bases $b	 ;;
		,)		if test "$cell" = 2   ; then
					ad $b
				else
					aq $b
				fi
					start="re"	 ;;
		*)			let t=$i	;;   # numeric
	esac
done
fi
}



echo "

Rick Hohensee
Aug 2003



" > /dev/null

