Advertisement
deadmarshal

Forth

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