I'm new to FORTH and FlashForth and seeking clarification on the use of Execution Tokens (XT).
Specifically I want to use them for control of a state machine.
I have The Forth Programmers Handbook and am reviewing section 5.1 on Vectored Execution.
Below is some test code, but it seems not to compile or be interpreted due to circular references.
Is this to be expected ?
Is the only way around the problem, to use Execution Vector tables ?
I have had success using Execution Vector Tables.
Thank you.
defer StatePtr
' State1 is StatePtr
State1
cr ." State1" 5000 ms ['] State2 is StatePtr
;
State2
cr ." State2" 5000 ms ['] State3 is StatePtr
;
State3
cr ." State3" 5000 ms ['] State1 is StatePtr
;
\ : main
\ begin
\ StatePtr
\ again
\ ;
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In Forth you cannot have forward references because the compiler is a simple single pass compiler.
But you can use a VALUE for each state as a workaround.
flash 0 value State1 0 value State2 0 value State3
ram defer State
: S1 cr ." State1" 5000 ms State2 is State ; ' S1 to State1
: S2 cr ." State2" 5000 ms State3 is State ; ' S2 to State2
: S3 cr ." State3" 5000 ms State1 is State ; ' S3 to State3
: main
State1 is State
begin State again
;
Last edit: Mikael Nordman 2020-02-18
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here is a version that has less dictionary clutter.
flash 0 value State1 0 value State2 0 value State3
ram defer State
:noname cr ." State1" 5000 ms State2 is State ; to State1
:noname cr ." State2" 5000 ms State3 is State ; to State2
:noname cr ." State3" 5000 ms State1 is State ; to State3
: main
State1 is State
begin State again
;
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello, Simon here.
I'm new to FORTH and FlashForth and seeking clarification on the use of Execution Tokens (XT).
Specifically I want to use them for control of a state machine.
I have The Forth Programmers Handbook and am reviewing section 5.1 on Vectored Execution.
Below is some test code, but it seems not to compile or be interpreted due to circular references.
Is this to be expected ?
Is the only way around the problem, to use Execution Vector tables ?
I have had success using Execution Vector Tables.
Thank you.
State1
cr ." State1" 5000 ms
['] State2 is StatePtr
;
State2
cr ." State2" 5000 ms
['] State3 is StatePtr
;
State3
cr ." State3" 5000 ms
['] State1 is StatePtr
;
\ : main
\ begin
\ StatePtr
\ again
\ ;
In Forth you cannot have forward references because the compiler is a simple single pass compiler.
But you can use a VALUE for each state as a workaround.
Last edit: Mikael Nordman 2020-02-18
Here is a version that has less dictionary clutter.
Thank you for the version illustrating less dictionary clutter.
Initially I didn't understand is the use of :noname
A search of the Forth Programmers Handbook explains it's use. Section 4.2.4, Pg.139
What got me confused was that I couldn't recognise any mention of it's use in the help file,
"flash-forth-5-sheet-2014-05-17.pdf"