: ;  [ ] ;i ;EXIT IMMED? IMMEDIATE :NONAME STATE
:
The word : is the most used creation word in FORTH.
It defines a word <nom> called "colon" word in the form:
: NAME nomex1 nomex2 ... nomexn ; NAME \ execute NAME
Subsequent execution of NOM performs the execution sequence
words compiled in his "colon" definition.
After : NOM, the interpreter enters compile mode. All
non-immediate words are compiled in the definition, the numbers are compiled
in literal form. Only immediate words or placed in square brackets
(words [ and ]) are executed during compilation
to help control it. p>
A "colon" definition remains invalid, ie not inscribed in the
current vocabulary, as long as the interpreter did not execute ; (semi-colon).
;
Immediate execution word usually ending the compilation of a "colon" definition:
: NAME
nomex1 nomex2 ... nomexn ;
[ ( ---)
Enter interpretation state. [ is an immediate word.
: [
0 state !
; immediate
] ( ---)
Return to compilation. ] is an immediate word.
With FlashForth, the words [ and ] allow you to use
assembly code, subject to first compiling an assembler. Example:
\ Load constant $1234 to top of stack
: a-number ( -- 1234 )
dup \ Make space for new TOS value
[ R24 $34 ldi, ]
[ R25 $12 ldi, ]
;: ]
-1 state !
; immediate
;i
Specific Flash Forth
Immediate execution word completing the compilation of a "colon" definition but intended to be used through an interruption:
\ The interrupt routine
variable counter
: t3OverflowIsr ( ---)
1 counter +! \ increment counter
;i ATTENTION : the word t3OverflowIsr should not be
performed in interpretation, but only through an interruption.
EXIT ( ---)
Aborts the execution of a word and gives back to the calling word.
Typical use: : X ... test IF ... EXIT THEN ... ;
At run time, the word EXIT will have the same effect as the word ;
WARNING in FlashForth, do not run EXIT
in a FOR..NEXT loop.
IMMED? ( addr -- n )
Leave a nonzero value if addr contains a immediate flag.
IMMEDIATE ( ---)
Make the most recent definition an immediate word.
sets the compile-only lexicon bit in the name field of the new word just compiled. When the interpreter encounters a word with this bit set, it will not execute this word, but spit out an error message. This bit prevents structure words to be executed accidentally outside of a compound word.
NONAME: ( --- cfa-addr)
Define headerless forth code. cfa-addr is the code execution of a definition.
Exemple
:noname s" Saterday" ;
:noname s" Friday" ;
:noname s" Thursday" ;
:noname s" Wednesday" ;
:noname s" Tuesday" ;
:noname s" Monday" ;
:noname s" Sunday" ;
create (ENday) ( --- addr)
, , , , , , ,
:noname s" Samedi" ;
:noname s" Vendredi" ;
:noname s" Jeudi" ;
:noname s" Mercredi" ;
:noname s" Mardi" ;
:noname s" Lundi" ;
:noname s" Dimanche" ;
create (FRday) ( --- addr)
, , , , , , ,
defer (day)
: ENdays
['] (ENday) is (day) ;
: FRdays
['] (FRday) is (day) ;
3 value dayLength
: .day
(day)
swap cell *
+ @ execute
dayLength ?dup if
min
then
type
;
ENdays
0 .day \ display Sun
1 .day \ display Mon
2 .day \ display Tue
FRdays ok
0 .day \ display Dim
1 .day \ display Lun
2 .day \ display Mar
POSTPONE ( comp: -- <name> )
Skip leading space delimiters. Parse name delimited by a space. Find name. Append the compilation semantics of name to the current definition.
STATE ( --- flag)
Compilation state. State can only be changed by [ and ]