Re: [colorforth] new color
- Subject: Re: [colorforth] new color
- From: "Ray St. Marie" <ray.stmarie@xxxxxxxxx>
- Date: Sat, 4 Jun 2005 10:23:00 -0500
On 6/1/05, maslicke@xxxxxxxxxxx <maslicke@xxxxxxxxxxx> wrote:
> >Anyway, I get what you're doing now. With defer
> >in a word it's address pushed from the return
> >stack to the parameter stack so you can store
> >it in the jump table rather than execute it.
> >But here's what I don't get now. What keeps
> >"defer" from executing the second time when
> >the address is executed from the jump table?
>
> Here you have to know a little about how call/return work.
> Call pushes the address of the next instruction, therefore
> what ever instruction follows 'defer' is the address which
> is returned. Strings, arrays are implemented very similar.
> Look in block 48, to see that 'defer' goes by name
> of 'string' there. In the case of arrays the the
> call 'array' is aligned so the next address is divisable by
> 4.
>
> : string pop ;
> : array pop 2/ 2/ ; <-----|
|
Ray here: that array def | should have been :
: array string 2/ 2/ ;
( please be aware that Mark (and me too) comes to colorforth with
very little `real forth' experiance, so anything that we come up with
that resembles forth is a ( hehe ) historical accident, on forth's
part :). )
A discovered ambiguity in the general understanding of the environment
rears it's head.
The use of the word `string' in the definition `array' is an example
of what's known as a
colorforth `Return Stack Trick' or RST.
You'll see, thru-out the colorforth code, examples of pop being
defined as a word name that is supposed to have meaning for what ever
it is your trying to pop off the return stack.
In the `Ascii' code block 48 ( tipically), it uses pop, and calls it `string'.
Mark's accept code uses it as two different names several times just
in the first block.
<r>upper<g>pop<y>board<g>! ; / : upper pop [board] ! ;
<r>defer<g>pop ; / : defer pop ;
So whats this doing. Well, its poping off the return stack, the very
last call address, and putting it on the data stack.
In essence, setting the definition to return to, to be the previously
called word address, and leaving the poped address on the data stack
for such reasons as using that address as the location of data that
happens to be offset from that address.
In the case of Mark's `upper' definition, calling upper in a word
like, for instance `numbers'
<r>numbers<g>upper<hy>1b1a19 , 181e1d1c , 21201f , 0 , 0 , 0 ,
Let Mark define a word called `decimal' that at the end of its def,
`decimal' calls `numbers'.
Calling `decimal', we propose, sets the table called `board' with the
data needed to display the numbers portion of the decimal keyboard.
To do this, after doing a few set up tasks, Mark has `decimal' call `numbers'.
`numbers' puts it's address on the return stack and executes it's
first word, which is `upper'.
`upper' calls 'pop' and 'pop' puts the machine code to pop something
off the return stack on to the return stack.
`pop' returns to the 'upper' definition and finds the machine code to
pop something off the stack, so...
this machine code version of pop, pops off the return stack, the
address of 'numbers', and puts it on the data stack.
Then, `upper' calls a yellow variable 'board' which puts it's address
on the data stack, and the green ! stores into the address on top of
the stack, the value next on stack which happens to be `numbers'.
Calling `numbers' with the word `decimal' is just like having typed in
all the data following the word 'upper', and putting that data at the
end of the word 'decimal' and calling it 'board'.
Confused? ya me too :)
Mark has similar words for all the possible keyboards you may find in
the colorforth definition of accept. very clever,
Ray
--
Ray St. Marie
Rastm2ATusersDOTsourceforgeDOTnet
Ray.StMarieATgmailDOTcom and ATsbcglobalDOTnet
Ray_stmarieAThotmailDOTcom
Raystm2 and rastm2 in Internet Relay Chat (irc)
/connect irc.freenode.net Busness discussion: /join #biz
ColorForth: /join #c4th #c4th-ot Forth: /join #retro #forth #concatenative
Programming: /join #python #lisp #scheme #asm
---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: colorforth-help@xxxxxxxxxxxxxxxxxx
Main web page - http://www.colorforth.com