forked from larsbrinkhoff/lbForth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore-ext.fth
105 lines (72 loc) · 2.71 KB
/
core-ext.fth
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
\ -*- forth -*- Copyright 2004, 2013 Lars Brinkhoff
: .( [char] ) parse type ; immediate
: 0<> if -1 else 0 then ;
: 0> 0 > ;
: 2r@ r> 2r> 2dup 2>r rot >r ;
: :noname s" " header, dodoes_code code, ] latestxt !csp
[ ' : >does @ ] literal does! ;
: (?do) r> 2r> 2dup > rot rot 2>r swap >r ;
: ?do leaves @ 0 leaves !
postpone 2>r postpone begin postpone (?do) postpone if ; compile-only
: string+ count + aligned ;
: (c") r> dup string+ >r ;
: string, dup c, ", ;
: ,c" parse" string, ;
: c" postpone (c") ,c" ; compile-only
: convert char+ 65535 >number drop ;
: case 0 ; compile-only
: of postpone over postpone = postpone if postpone drop ; compile-only
: endof postpone else swap 1+ ; compile-only
: endcase postpone drop 0 ?do postpone then loop ; compile-only
: erase 0 fill ;
variable span
: expect accept span ! ;
: true -1 ;
: false 0 ;
: hex 16 base ! ;
: pick ?dup if swap >r 1- recurse r> swap exit then dup ;
: roll ?dup if swap >r 1- recurse r> swap then ;
: query terminal-input refill drop ;
: value create , does> @ ;
: to ' >body ! ;
: to ' >body postpone literal postpone ! ; compile-only
: +to ' >body +! ;
: +to ' >body postpone literal postpone +! ; compile-only
: @+ ( addr -- a' x ) dup cell+ swap @ ;
create voc-link ' included-files ,
: current, current @ , ;
: context, context 9 cells move, ;
: latestxt, latestxt , ;
: voc-link, voc-link @ , ;
: vocs, voc-link begin @ ?dup while >body dup @ , cell+ repeat ;
: marker, current, context, latestxt, voc-link, vocs, ;
: here! dup dp ! ;
: current! @+ current ! ;
: context! dup context 9 cells cmove 9 cells + ;
: latestxt! @+ to latestxt ;
: voc-link! @+ voc-link ! ;
: voc! ( a1 a2 -- a1' a2' ) >body >r @+ r@ ! r> ;
: vocs! voc-link begin @ ?dup while voc! cell+ repeat ;
: marker! here! current! context! latestxt! voc-link! vocs! drop ;
: marker here marker, create , does> @ marker! ;
: tuck swap over ;
: (.r) ( n f u -- ) 0 <# #s rot sign #> rot over - spaces type ;
: u.r 0 rot (.r) ;
: .r swap s>d swap abs (.r) ;
: u> swap u< ;
: unused dictionary_end @ here - ;
: within over - under - u< ;
: [compile] ' compile, ; compile-only
\ ----------------------------------------------------------------------
( Forth2012 core extension words. )
: buffer: create allot ;
: alias ( xt "name" -- ) create , does> perform ;
: defer ['] abort alias ;
: defer! >body ! ;
: defer@ >body @ ;
: is ' defer! ;
: is postpone ['] postpone defer! ; compile-only
: action-of ' defer@ ;
: action-of postpone ['] postpone defer@ ; compile-only
: holds bounds swap begin 2dup < while 1- dup c@ hold repeat 2drop ;
\ TODO: s\"