[ColorForth] One Color Color Forth
- Subject: [ColorForth] One Color Color Forth
- From: "Dirk Heise" <dheise@xxxxxxxxxxx>
- Date: Mon, 7 May 2001 21:50:37 +0200
Some thoughts about implementing a language
that resembles Color Forth in certain ways,
but without the color; maybe useful as a
medium that allows 1-to-1 translation into
the colorful implementation...
As i'm close to finishing my "traditional"
Forth compiler, i run into troubles coding the
interpreter and tokenizer loops. I'm meta-coding
Forth in C at the moment, so it looks like
compile(dup);
compile(lit);
compile(DP+7);
compile(bra);
...that kinda thing... Of course, coding the
control structures is the tricky part, i gotta
get the jump offsets right.
So, i'm breaking things up to tiny functions
that are coded much in the Color Forth sense,
like
: processtoken compilemode @ if compiletoken ; then
executetoken ;
Hope you can follow me. Of course i can't use ";"
this way - in a classical Forth, ";" switches
the mode! Duh!
So maybe i'll make it a Colorforth now. I really
start to like that idea. But wait... How many colors
will i need? What about running it on a device
with a monochrome display? I have an old
notebook with a monochrome display, and lots of
Palms are monochrome.
So there's this idea of Terry of "colorless ColorForth".
Ok, it's nagging to have to code a "color prefix
word" in front of each "real" word. So i though,
how many colors do i actually need, given that
a classical ":" is already kind of a prefix for
the color for "definition". Same goes for
variables with the word "variable"...
I think 2 colors are essential: Execute and Compile.
I already mentioned that i'd like an operator
for the infamous literals, so i need no color
for that.
I end up with 2 colors. When i now declare the
color "Execute" as the default behaviour of a
word, and to have the other color "compile",
i supply a "prefix operator" "c", a word looks
like this:
: 1+ 1 # c + ;
Lengthier words start to look ugly, like here:
: fib c dup c 0=
if c drop 1 # ; then
c dup 1 # c = if ; then
c dup 1 # c - c fib
c swap 2 # c - ;;
which should in theory compute a fibonacci number
recursively.
Of course, one sees, "c dup" occurs frequently,
so one could define a compiler word like
: cdup ' dup # c , ;
which would, in an indirectly threaded implementation,
compile a call to "dup".
Now, this doesn't change the look a great deal...
only a few spaces disappear.
But instead of prefixing "dup" with "c", we could
also append a ",". I like this, because "," was
always a very frequent idiom in compiler words.
Now "fib" will look like this:
: fib dup, 0=, if drop, 1 , ; then
dup, 1 , =, if ; then
dup, 1 , -, fib, swap, 2 , -, ;;
Note: I changed my literal operator from "#"
to "," here to have a more uniform look.
I don't plan to create any magic meaning for the
",", but instead define a special ":" that produces
the "fib," word automatically, before defining
the "fib" word.
So far my thoughts about a One Color Color Forth...
I think the "back end", the compiled code, is not
affected, there's only a slightly different
front end, so maybe this will also allow to switch
between colorless and colorful when editing.
Any comments?
Dirk
------------------------
To Unsubscribe from this list, send mail to Mdaemon@xxxxxxxxxxxxxxxxxx with:
unsubscribe ColorForth
as the first and only line within the message body
Problems - List-Admin@xxxxxxxxxxxxxxxxxx
Main ColorForth site - http://www.ultratechnology.com