PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/samples/Forth/core-ext.fth

https://bitbucket.org/liluo/linguist
Forth | 136 lines | 84 code | 51 blank | 1 comment | 4 complexity | 5fc21cdc65221129b6e08455db9e7d1d MD5 | raw file
  1. \ -*- forth -*- Copyright 2004, 2013 Lars Brinkhoff
  2. \ Kernel: #tib
  3. \ TODO: .r
  4. : .( ( "<string><paren>" -- )
  5. [char] ) parse type ; immediate
  6. : 0<> ( n -- flag ) 0 <> ;
  7. : 0> ( n -- flag ) 0 > ;
  8. \ Kernel: 2>r
  9. : 2r> ( -- x1 x2 ) ( R: x1 x2 -- ) r> r> r> rot >r swap ;
  10. : 2r@ ( -- x1 x2 ) ( R: x1 x2 -- x1 x2 ) 2r> 2dup 2>r ;
  11. : :noname align here 0 c, 15 allot lastxt dup @ , !
  12. [ ' enter >code @ ] literal , 0 , ] lastxt @ ;
  13. \ Kernel: <>
  14. \ : ?do ( n1 n2 -- ) ( R: -- loop-sys ) ( C: -- do-sys )
  15. \ here postpone 2>r unresolved branch here ;
  16. : again ( -- ) ( C: dest -- )
  17. postpone branch , ; immediate
  18. : string+ ( caddr -- addr )
  19. count + aligned ;
  20. : (c") ( -- caddr ) ( R: ret1 -- ret2 )
  21. r> dup string+ >r ;
  22. : c" ( "<string><quote>" -- caddr )
  23. postpone (c") [char] " parse dup c, string, ; immediate
  24. : case ( -- ) ( C: -- case-sys )
  25. 0 ;
  26. : compile, ( xt -- )
  27. , ;
  28. \ TODO: convert
  29. : endcase ( x -- ) ( C: case-sys -- )
  30. 0 do postpone then loop
  31. postpone drop ;
  32. : endof ( -- ) ( C: case-sys1 of-sys -- case-sys2 )
  33. postpone else swap 1+ ;
  34. \ TODO: erase
  35. \ TODO: expect
  36. : false ( -- 0 )
  37. 0 ;
  38. : hex ( -- )
  39. 16 base ! ;
  40. \ TODO: marker
  41. \ Kernel: nip
  42. : of ( x x -- | x y -- x ) ( C: -- of-sys )
  43. postpone over postpone = postpone if postpone drop ;
  44. \ Kernel: pad
  45. \ Kernel: parse
  46. : pick ( xn ... x0 n -- xn ... x0 xn )
  47. 2 + cells 'SP @ + @ ;
  48. : query ( -- )
  49. tib ''source ! #tib ''#source ! 0 'source-id !
  50. refill drop ;
  51. \ Kernel: refill
  52. \ Kernel: restore-input
  53. \ TODO: roll ( xn xn-1 ... x0 n -- xn-1 ... x0 xn ) ;
  54. \ Kernel: save-input
  55. \ Kernel: source-id
  56. \ TODO: span
  57. \ Kernel: tib
  58. : to ( x "word" -- )
  59. ' >body , ;
  60. : true ( -- -1 )
  61. -1 ;
  62. : tuck ( x y -- y x y )
  63. swap over ;
  64. \ TODO: u.r
  65. : u> ( x y -- flag )
  66. 2dup u< if 2drop false else <> then ;
  67. \ TODO: unused
  68. : value ( x "word" -- )
  69. create ,
  70. does> ( -- x )
  71. @ ;
  72. : within over - >r - r> u< ;
  73. \ TODO: [compile]
  74. \ Kernel: \
  75. \ ----------------------------------------------------------------------
  76. ( Forth2012 core extension words. )
  77. \ TODO: action-of
  78. \ TODO: buffer:
  79. : defer create ['] abort , does> @ execute ;
  80. : defer! ( xt2 xt1 -- ) >body ! ;
  81. : defer@ ( xt1 -- xt2 ) >body @ ;
  82. \ TODO: holds
  83. : is ( xt "word" -- ) ' defer! ;
  84. \ TODO: parse-name
  85. \ TODO: s\"