PageRenderTime 37ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/samples/Forth/tools.fth

https://gitlab.com/Blueprint-Marketing/linguist
Forth | 133 lines | 85 code | 45 blank | 3 comment | 6 complexity | 1f1b7257ba0a6fa3fc79a2163f087676 MD5 | raw file
  1. \ -*- forth -*- Copyright 2004, 2013 Lars Brinkhoff
  2. ( Tools words. )
  3. : .s ( -- )
  4. [char] < emit depth (.) ." > "
  5. 'SP @ >r r@ depth 1- cells +
  6. begin
  7. dup r@ <>
  8. while
  9. dup @ .
  10. /cell -
  11. repeat r> 2drop ;
  12. : ? @ . ;
  13. : c? c@ . ;
  14. : dump bounds do i ? /cell +loop cr ;
  15. : cdump bounds do i c? loop cr ;
  16. : again postpone branch , ; immediate
  17. : see-find ( caddr -- end xt )
  18. >r here lastxt @
  19. begin
  20. dup 0= abort" Undefined word"
  21. dup r@ word= if r> drop exit then
  22. nip dup >nextxt
  23. again ;
  24. : cabs ( char -- |char| ) dup 127 > if 256 swap - then ;
  25. : xt. ( xt -- )
  26. ( >name ) count cabs type ;
  27. : xt? ( xt -- flag )
  28. >r lastxt @ begin
  29. ?dup
  30. while
  31. dup r@ = if r> 2drop -1 exit then
  32. >nextxt
  33. repeat r> drop 0 ;
  34. : disassemble ( x -- )
  35. dup xt? if
  36. ( >name ) count
  37. dup 127 > if ." postpone " then
  38. cabs type
  39. else
  40. .
  41. then ;
  42. : .addr dup . ;
  43. : see-line ( addr -- )
  44. cr ." ( " .addr ." ) " @ disassemble ;
  45. : see-word ( end xt -- )
  46. >r ." : " r@ xt.
  47. r@ >body do i see-line /cell +loop
  48. ." ;" r> c@ 127 > if ." immediate" then ;
  49. : see bl word see-find see-word cr ;
  50. : #body bl word see-find >body - ;
  51. : type-word ( end xt -- flag )
  52. xt. space drop 0 ;
  53. : traverse-dictionary ( in.. xt -- out.. )
  54. \ xt execution: ( in.. end xt2 -- in.. 0 | in.. end xt2 -- out.. true )
  55. >r here lastxt @ begin
  56. ?dup
  57. while
  58. r> 2dup >r >r execute
  59. if r> r> 2drop exit then
  60. r> dup >nextxt
  61. repeat r> 2drop ;
  62. : words ( -- )
  63. ['] type-word traverse-dictionary cr ;
  64. \ ----------------------------------------------------------------------
  65. ( Tools extension words. )
  66. \ ;code
  67. \ assembler
  68. \ in kernel: bye
  69. \ code
  70. \ cs-pick
  71. \ cs-roll
  72. \ editor
  73. : forget ' dup >nextxt lastxt ! 'here ! reveal ;
  74. \ Kernel: state
  75. \ [else]
  76. \ [if]
  77. \ [then]
  78. \ ----------------------------------------------------------------------
  79. ( Forth2012 tools extension words. )
  80. \ TODO: n>r
  81. \ TODO: nr>
  82. \ TODO: synonym
  83. : [undefined] bl-word find nip 0= ; immediate
  84. : [defined] postpone [undefined] invert ; immediate
  85. \ ----------------------------------------------------------------------
  86. : @+ ( addr -- addr+/cell x ) dup cell+ swap @ ;
  87. : !+ ( x addr -- addr+/cell ) tuck ! cell+ ;
  88. : -rot swap >r swap r> ;