Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TRUE is -1, which is CELL sized number with all bits set to 1.
- It is printed as -1 because . interprets numbers as signed,
- for unsigned see u.
- The STATE variable holds the current compilation state flag of Forth,
- which is TRUE for compilation and FALSE otherwise.
- In the REPL, Forth interprets, in colon definitions
- like : blah blah ; Forth compiles addresses of words appearing
- in the definition.
- You can change the Forth state temporarily to do something using
- [ and ] words. [ changes the state to 'interpret' (FALSE),
- and ] changes state to 'compile' (TRUE).
- You can use this for example for conditional compilation
- like in C and it's macros:
- https://github.com/ams-hackers/gbforth/blob/main/src/rom.fs#L16
- You can change the STATE variable manually but that is not advised.
- Things like IF and [ are so-called immediate words, which means
- they are executed when encountered instead of their addresses being
- compiled. For IF, it keeps on reading until seeing a THEN word,
- and compiles the address of then in the place where
- IF address was saved, so doing this makes Forth jump to THEN
- if the condition before IF doesn't hold.
- It is basically calculating addresses and offesets.
- For learning defining words, first take a look at
- LFA,NFA,PFA,CFA terminology to understand a word structure,
- after knowing this, defining words becomes easier.
- https://www.bradrodriguez.com/papers/moving1.htm
- Forth Dimensions magazine has amazing Forth articles,
- especially about "defining words".
- There's an index pdf of authors here:
- https://github.com/BillRagsdale/Forth-Archive-Access/
- https://www.forth.org/fd/contents.html
- Forth ANS Standard 2012:
- https://forth-standard.org/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement