-
Notifications
You must be signed in to change notification settings - Fork 5
/
compiling-words.fs
56 lines (35 loc) · 1.32 KB
/
compiling-words.fs
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
\ Minimal Forth Workbench: compiling words uh 2015-10-15
primitive POSTPONE
primitive IMMEDIATE
primitive EXIT
: AHEAD POSTPONE FALSE POSTPONE IF ; IMMEDIATE
: ?EXIT POSTPONE IF POSTPONE EXIT POSTPONE THEN ; IMMEDIATE
\ : AGAIN POSTPONE FALSE POSTPONE UNTIL ; IMMEDIATE
primitive LITERAL
: ['] ' POSTPONE LITERAL ; IMMEDIATE
primitive PARSE
primitive SLITERAL
primitive TYPE
: ." 34 PARSE POSTPONE SLITERAL POSTPONE TYPE ; IMMEDIATE
: .( 41 PARSE TYPE ; IMMEDIATE
: S" 34 PARSE POSTPONE SLITERAL ; IMMEDIATE
primitive WORD
: CHAR ( "<spaces>name"-- char )
32 WORD CHAR+ C@ ;
: [CHAR] ( C: "<spaces>name" -- ) ( -- char )
CHAR POSTPONE LITERAL ; IMMEDIATE
primitive STATE
primitive >BODY
: TO ( x "<spaces>name" -- )
STATE @
IF POSTPONE ['] POSTPONE >BODY POSTPONE !
ELSE ' >BODY ! THEN ; IMMEDIATE
: IS ( x "<spaces>name" -- )
STATE @ IF POSTPONE TO ELSE ['] TO EXECUTE THEN ; IMMEDIATE
: CASE ( -- ) ( C: -- n ) 0 ; IMMEDIATE
: OF ( x1 x2 -- | x1 ) >R POSTPONE OVER POSTPONE = POSTPONE IF POSTPONE DROP R> ; IMMEDIATE
: ENDOF ( -- ) ( C: n1 -- n2 ) >R POSTPONE ELSE R> 1 + ; IMMEDIATE
: ENDCASE ( x1 -- ) ( C: n -- ) POSTPONE DROP >R BEGIN R@ WHILE POSTPONE THEN R> 1 - >R REPEAT R> DROP ; IMMEDIATE
primitive COMPILE,
primitive [
primitive ]