Mirror of CollapseOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.8KB

  1. : H HERE @ ;
  2. : -^ SWAP - ;
  3. : +! SWAP OVER @ + SWAP ! ;
  4. : ALLOT HERE +! ;
  5. : C, H C! 1 ALLOT ;
  6. : COMPILE ' LITN ['] , , ; IMMEDIATE
  7. : BEGIN H ; IMMEDIATE
  8. : AGAIN COMPILE (bbr) H -^ C, ; IMMEDIATE
  9. : UNTIL COMPILE SKIP? COMPILE (bbr) H -^ C, ; IMMEDIATE
  10. : NOT 1 SWAP SKIP? EXIT 0 * ;
  11. : ( BEGIN LITS ) WORD SCMP NOT UNTIL ; IMMEDIATE
  12. ( Hello, hello, krkrkrkr... do you hear me?
  13. Ah, voice at last! Some lines above need comments
  14. BTW: Forth lines limited to 64 cols because of default
  15. input buffer size in Collapse OS
  16. COMPILE; Tough one. Get addr of caller word (example above
  17. (bbr)) and then call LITN on it.
  18. NOT: a bit convulted because we don't have IF yet )
  19. : IF ( -- a | a: br cell addr )
  20. COMPILE SKIP? ( if true, don't branch )
  21. COMPILE (fbr)
  22. H ( push a )
  23. 1 ALLOT ( br cell allot )
  24. ; IMMEDIATE
  25. : THEN ( a -- | a: br cell addr )
  26. DUP H -^ SWAP ( a-H a )
  27. C!
  28. ; IMMEDIATE
  29. : ELSE ( a1 -- a2 | a1: IF cell a2: ELSE cell )
  30. COMPILE (fbr)
  31. 1 ALLOT
  32. DUP H -^ SWAP ( a-H a )
  33. C!
  34. H 1 - ( push a. -1 for allot offset )
  35. ; IMMEDIATE
  36. : ? @ . ;
  37. : VARIABLE CREATE 2 ALLOT ;
  38. : CONSTANT CREATE H ! DOES> @ ;
  39. : = CMP NOT ;
  40. : < CMP 0 1 - = ;
  41. : > CMP 1 = ;
  42. : / /MOD SWAP DROP ;
  43. : MOD /MOD DROP ;
  44. ( In addition to pushing H this compiles 2 >R so that loop variables are sent
  45. to PS at runtime )
  46. : DO
  47. COMPILE SWAP COMPILE >R COMPILE >R
  48. H
  49. ; IMMEDIATE
  50. ( One could think that we should have a sub word to avoid all these COMPILE,
  51. but we can't because otherwise it messes with the RS )
  52. : LOOP
  53. COMPILE R> 1 LITN COMPILE + COMPILE DUP COMPILE >R
  54. COMPILE I' COMPILE = COMPILE SKIP? COMPILE (bbr)
  55. H -^ C,
  56. COMPILE R> COMPILE DROP COMPILE R> COMPILE DROP
  57. ; IMMEDIATE