compiler-mode implemented
[watForth.git] / forth.forth
1 \ This program is free software: you can redistribute it and/or modify
2 \ it under the terms of the GNU General Public License as published by
3 \ the Free Software Foundation, either version 3 of the License, or
4 \ (at your option) any later version.
5 \
6 \ This program is distributed in the hope that it will be useful,
7 \ but WITHOUT ANY WARRANTY; without even the implied warranty of
8 \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 \ GNU General Public License for more details.
10 \
11 \ You should have received a copy of the GNU General Public License
12 \ along with this program. If not, see <http://www.gnu.org/licenses/>.
13 16500 execute WORD 16500 29 execute
14 word DEFINE 29 29 execute
15 \ word EXECUTE 12 define
16 word RINIT 3 define
17 word NOOP 13 define
18 word MODE 14336 define
19 word EXECUTE-MODE 16680 define
20 word EXECUTE-NUM 16720 define
21 word INTERPRET 16400 define
22 word KEY 5 define
23 word WORD-START 20 define
24 word WORD-PUT 19 define
25 word WORD-END 23 define
26 word STRING-START 39 define
27 word STRING-PUT 40 define
28 word STRING-END 41 define
29 word NUMBER 22 define
30 word FIND 21 define
31 word FIND-DOES 44 define
32 word DEFINE-DOES 45 define
33 word QUIT 16384 define
34 word BYE 25 define
35 word WORDS 27 define
36 word !CHANNEL 35 define
37 word !HERE 36 define
38 word HERE 28 define
39
40 word ; 1 define
41 word JZ: 14 define
42 word JNZ: 15 define
43 word J-1: 24 define
44 word JMP: 18 define
45 word , 33 define
46 word + 7 define
47 word - 34 define
48 word =? 37 define
49 word WS? 17 define
50 word . 9 define
51 word .S 38 define
52 word @ 10 define
53 word @+ 42 define
54 word ! 11 define
55 word !+ 43 define
56 word LIT 2 define
57 word DUP 6 define
58 word 2DUP 30 define
59 word DROP 16 define
60 word 2DROP 32 define
61 word SWAP 26 define
62 word ROT 31 define
63
64 word ' here define
65 word word find , word find find , word ; find ,
66
67 word : here define
68 ' word , ' here , ' define , ' ; ,
69 ' : dup define-does
70
71 : IWRITE-MODE ' dup , ' JNZ: , here 12 + , ' 2drop , ' ; ,
72 ' 2dup , ' find , ' dup , ' JZ: , here 16 + , ' , , ' 2drop , ' ; ,
73 ' drop , ' LIT , ' LIT , ' , , ' EXECUTE-NUM , ' , , ' ; ,
74
75 : i ' LIT , ' MODE , ' LIT , ' IWRITE-MODE , ' ! , ' ; ,
76
77 \i
78 \: e LIT MODE LIT EXECUTE-MODE ! ;
79 \: :> word find here define-does ;
80 \' :> \dup \define-does
81 \: FINISH-" DROP STRING-END ;
82 \: " STRING-START \: KLOOP KEY 34 =? JNZ: FINISH-" STRING-PUT JMP: KLOOP
83 \:> " " swap lit lit , , lit lit , , ;
84 \: IF JZ: \here \8 \+ \, ; word 2drop ;
85 \:> IF \: DOIF LIT JZ: , HERE DUP , ;
86 \: ELSE ;
87 \:> ELSE \: DOELSE LIT JMP: , HERE DUP , SWAP HERE ! ;
88 \: THEN ;
89 \:> THEN \: DOTHEN HERE ! ;
90 \: COMPILE-MODE dup
91 \doif 2dup find dup
92 \doif dup find-does dup
93 \doif swap drop rot 2drop execute ;
94 \dothen drop , 2drop ;
95 \dothen drop lit lit , execute-num , ;
96 \dothen 2drop ;
97 \: c LIT MODE LIT COMPILE-MODE ! ;
98 \: DO"
99 \e
100
101 " watForth-32 Interactive CLI:
102 " .s