|
From: Kalus M. <mic...@on...> - 2008-07-16 17:16:18
|
Hi Bernard.
Am 15.07.2008 um 03:03 schrieb Bernard Mentink:
> And lastly, the FSM code is:
>
> : FSM: ( width -- ) CREATE , ]
> DOES> ( n adr -- )
> TUCK @ mystate @ * + CELLS CELL+ +
> ( adr') PERFORM ;
>
> I notice he enters into compile mode with the "]" word just before
> the
> DOES> word, is that necessary to do with the latest CREATE/DOES code?
In the meantime I studied Nobles Code (1). Hope I got it right what
he is doing there.
This is what the ] does:
He ceates a defining word called FSM: and during compiletime of FSM:
the ] is compiled into the definition. At runtime of FSM: the ] is
executed. Now this starts compilation of all the words following the
word defined by the defining word until the closing ; enters
execution again.
In Nobles example "3.2. A Better FSM" FSM: defines <Fixed.Pt#> and
thereafter compiles the list of execution tokens:
4 WIDE FSM: <Fixed.Pt#> ( action# -- )
\ other num - . \ state
DROP (00) (00) (02) \ 0
DROP (00) DROP (02) \ 1
DROP (02) DROP DROP ; \ 2
If you do not want to use that ]-trick, because it makes your program
code more mysterious, you archive the same result this way:
4 WIDE FSM: <Fixed.Pt#> ( action# -- )
\ other num - . \ state
' DROP , ' (00) , ' (00) , ' (02) , \ 0
' DROP , ' (00) , ' DROP , ' (02) , \ 1
' DROP , ' (02) , ' DROP , ' DROP , \ 2
This way it is more obvious what comes into the array.
So the use of ] has nothing to do with the CREATE/DOES Part of
creating a new defining word. ok?
Michael
(1) Finite State Machines in Forth; J. V. Noble
http://dec.bournemouth.ac.uk/forth/jfar/index.html
|