From: Bernard M. <bme...@gm...> - 2008-07-16 21:32:27
|
Hi Michael, I implemented the "Elegant FSM" version of Julien's code Section 3.3 i.e: The FSM is then defined as 4 WIDE FSM: \ input: | other? | num? | minus? | dp? | \ state: --------------------------------------------- ( 0 ) DROP >0 EMIT >1 EMIT >1 EMIT >2 ( 1 ) DROP >1 EMIT >1 DROP >1 EMIT >2 ( 2 ) DROP >2 EMIT >2 DROP >2 DROP >2 ; That seems to me the most readable and flexible of all his examples. I have given Mathias the code for including in the Lib. Cheers, Bernard. On Thu, Jul 17, 2008 at 5:16 AM, Kalus Michael <mic...@on...> wrote: > 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 > > > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's > challenge > Build the coolest Linux based applications with Moblin SDK & win great > prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Amforth-devel mailing list > Amf...@li... > https://lists.sourceforge.net/lists/listinfo/amforth-devel > |