Mirror of CollapseOS
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

74 lignes
1.9KB

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