1 |
/* |
2 |
* PearPC |
3 |
* forthtable.cc |
4 |
* |
5 |
* Copyright (C) 2003 Sebastian Biallas (sb@biallas.net) |
6 |
* |
7 |
* This program is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License version 2 as |
9 |
* published by the Free Software Foundation. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 |
*/ |
20 |
|
21 |
#include "forthtable.h" |
22 |
#include "forth.h" |
23 |
#include "fcode.h" |
24 |
|
25 |
struct forth_word { |
26 |
const char *name; |
27 |
uint32 fcode; |
28 |
FCodeFunction func; |
29 |
}; |
30 |
|
31 |
forth_word forth_word_table[] = { |
32 |
{"!", FCODE_ex, fcode_opc_ex}, |
33 |
{"#", FCODE_sharp, fcode_opc_sharp}, |
34 |
{"#>", FCODE_sharpgt, fcode_opc_sharpgt}, |
35 |
{"*", FCODE_mul, fcode_opc_mul}, |
36 |
{"+", FCODE_plus, fcode_opc_plus}, |
37 |
{"+!", FCODE_plusex, fcode_opc_plusex}, |
38 |
{",", FCODE_comma, fcode_opc_comma}, |
39 |
{"-", FCODE_minus, fcode_opc_minus}, |
40 |
{".", FCODE_dot, fcode_opc_dot}, |
41 |
{"/", FCODE_div, fcode_opc_div}, |
42 |
{"<", FCODE_lt, fcode_opc_lt}, |
43 |
{"<#", FCODE_ltsharp, fcode_opc_ltsharp}, |
44 |
{"<=", FCODE_ltequal, fcode_opc_ltequal}, |
45 |
{"<>", FCODE_ltgt, fcode_opc_ltgt}, |
46 |
{"=", FCODE_equal, fcode_opc_equal}, |
47 |
{">", FCODE_gt, fcode_opc_gt}, |
48 |
{">=", FCODE_gtequal, fcode_opc_gtequal}, |
49 |
{"@", FCODE_at, fcode_opc_at}, |
50 |
{"0", FCODE_0, fcode_opc_0}, |
51 |
{"0<", FCODE_0lt, fcode_opc_0lt}, |
52 |
{"0<=", FCODE_0ltequal, fcode_opc_0ltequal}, |
53 |
{"0<>", FCODE_0ltgt, fcode_opc_0ltgt}, |
54 |
{"0=", FCODE_0equal, fcode_opc_0equal}, |
55 |
{"0>", FCODE_0gt, fcode_opc_0gt}, |
56 |
{"0>=", FCODE_0gtequal, fcode_opc_0gtequal}, |
57 |
{"1", FCODE_1, fcode_opc_1}, |
58 |
{"-1", FCODE_minus1, fcode_opc_minus1}, |
59 |
{"2", FCODE_2, fcode_opc_2}, |
60 |
{"2!", FCODE_2ex, fcode_opc_2ex}, |
61 |
{"2*", FCODE_2mul, fcode_opc_2mul}, |
62 |
{"2/", FCODE_2div, fcode_opc_2div}, |
63 |
{"2@", FCODE_2at, fcode_opc_2at}, |
64 |
{"3", FCODE_3, fcode_opc_3}, |
65 |
{">>a", FCODE_gtgtA, fcode_opc_gtgtA}, |
66 |
{"abort", FCODE_ABORT, fcode_opc_ABORT}, |
67 |
{"abs", FCODE_ABS, fcode_opc_ABS}, |
68 |
{"alarm", FCODE_ALARM, fcode_opc_ALARM}, |
69 |
{"aligned", FCODE_ALIGNED, fcode_opc_ALIGNED}, |
70 |
{"alloc-mem", FCODE_ALLOC_MEM, fcode_opc_ALLOC_MEM}, |
71 |
{"and", FCODE_AND, fcode_opc_AND}, |
72 |
{"behavior", FCODE_BEHAVIOR, fcode_opc_BEHAVIOR}, |
73 |
{"bell", FCODE_BELL, fcode_opc_BELL}, |
74 |
{"between", FCODE_BETWEEN, fcode_opc_BETWEEN}, |
75 |
{"bl", FCODE_BL, fcode_opc_BL}, |
76 |
{"blink-screen", FCODE_BLINK_SCREEN, fcode_opc_BLINK_SCREEN}, |
77 |
{"bljoin", FCODE_BLJOIN, fcode_opc_BLJOIN}, |
78 |
{"body>", FCODE_BODYgt, fcode_opc_BODYgt}, |
79 |
{">body", FCODE_gtBODY, fcode_opc_gtBODY}, |
80 |
{"bounds", FCODE_BOUNDS, fcode_opc_BOUNDS}, |
81 |
{"bs", FCODE_BS, fcode_opc_BS}, |
82 |
{"bwjoin", FCODE_BWJOIN, fcode_opc_BWJOIN}, |
83 |
{"byte-load", FCODE_BYTE_LOAD, fcode_opc_BYTE_LOAD}, |
84 |
{"c!", FCODE_Cex, fcode_opc_Cex}, |
85 |
{"c,", FCODE_Ccomma, fcode_opc_Ccomma}, |
86 |
{"/c", FCODE_slashC, fcode_opc_slashC}, |
87 |
{"c@", FCODE_Cat, fcode_opc_Cat}, |
88 |
{"ca+", FCODE_CAplus, fcode_opc_CAplus}, |
89 |
{"$call-method", FCODE_dCALL_METHOD, fcode_opc_dCALL_METHOD}, |
90 |
{"call-package", FCODE_CALL_PACKAGE, fcode_opc_CALL_PACKAGE}, |
91 |
{"$call-parent", FCODE_dCALL_PARENT, fcode_opc_dCALL_PARENT}, |
92 |
{"catch", FCODE_CATCH, fcode_opc_CATCH}, |
93 |
{"cell+", FCODE_CELLplus, fcode_opc_CELLplus}, |
94 |
{"cells", FCODE_CELLS, fcode_opc_CELLS}, |
95 |
{"char+", FCODE_CHARplus, fcode_opc_CHARplus}, |
96 |
{"char-height", FCODE_CHAR_HEIGHT, fcode_opc_CHAR_HEIGHT}, |
97 |
{"chars", FCODE_CHARS, fcode_opc_CHARS}, |
98 |
{"char-width", FCODE_CHAR_WIDTH, fcode_opc_CHAR_WIDTH}, |
99 |
{"child", FCODE_CHILD, fcode_opc_CHILD}, |
100 |
{"close-package", FCODE_CLOSE_PACKAGE, fcode_opc_CLOSE_PACKAGE}, |
101 |
{"#column", FCODE_sharpCOLUMN, fcode_opc_sharpCOLUMN}, |
102 |
{"#columns", FCODE_sharpCOLUMNS, fcode_opc_sharpCOLUMNS}, |
103 |
{"comp", FCODE_COMP, fcode_opc_COMP}, |
104 |
{"compile,", FCODE_COMPILEcomma, fcode_opc_COMPILEcomma}, |
105 |
{"count", FCODE_COUNT, fcode_opc_COUNT}, |
106 |
{"cpeek", FCODE_CPEEK, fcode_opc_CPEEK}, |
107 |
{"cpoke", FCODE_CPOKE, fcode_opc_CPOKE}, |
108 |
{"cr", FCODE_CR, fcode_opc_CR}, |
109 |
{"(cr", FCODE_bracketCR, fcode_opc_bracketCR}, |
110 |
{"d+", FCODE_Dplus, fcode_opc_Dplus}, |
111 |
{"d-", FCODE_Dminus, fcode_opc_Dminus}, |
112 |
{"decode-int", FCODE_DECODE_INT, fcode_opc_DECODE_INT}, |
113 |
{"decode-phys", FCODE_DECODE_PHYS, fcode_opc_DECODE_PHYS}, |
114 |
{"decode-string", FCODE_DECODE_STRING, fcode_opc_DECODE_STRING}, |
115 |
{"default-font", FCODE_DEFAULT_FONT, fcode_opc_DEFAULT_FONT}, |
116 |
{"delete-chars", FCODE_DELETE_CHARS, fcode_opc_DELETE_CHARS}, |
117 |
{"delete-lines", FCODE_DELETE_LINES, fcode_opc_DELETE_LINES}, |
118 |
{"delete-property", FCODE_DELETE_PROPERTY, fcode_opc_DELETE_PROPERTY}, |
119 |
{"depth", FCODE_DEPTH, fcode_opc_DEPTH}, |
120 |
{"device-name", FCODE_DEVICE_NAME, fcode_opc_DEVICE_NAME}, |
121 |
{"device-type", FCODE_DEVICE_TYPE, fcode_opc_DEVICE_TYPE}, |
122 |
{"diagnostic-mode?", FCODE_DIAGNOSTIC_MODEq, fcode_opc_DIAGNOSTIC_MODEq}, |
123 |
{"digit", FCODE_DIGIT, fcode_opc_DIGIT}, |
124 |
{"draw-character", FCODE_DRAW_CHARACTER, fcode_opc_DRAW_CHARACTER}, |
125 |
{"draw-logo", FCODE_DRAW_LOGO, fcode_opc_DRAW_LOGO}, |
126 |
{"drop", FCODE_DROP, fcode_opc_DROP}, |
127 |
{"2drop", FCODE_2DROP, fcode_opc_2DROP}, |
128 |
{"dup", FCODE_DUP, fcode_opc_DUP}, |
129 |
{"2dup", FCODE_2DUP, fcode_opc_2DUP}, |
130 |
{"?dup", FCODE_qDUP, fcode_opc_qDUP}, |
131 |
{"emit", FCODE_EMIT, fcode_opc_EMIT}, |
132 |
{"encode+", FCODE_ENCODEplus, fcode_opc_ENCODEplus}, |
133 |
{"encode-bytes", FCODE_ENCODE_BYTES, fcode_opc_ENCODE_BYTES}, |
134 |
{"encode-int", FCODE_ENCODE_INT, fcode_opc_ENCODE_INT}, |
135 |
{"encode-phys", FCODE_ENCODE_PHYS, fcode_opc_ENCODE_PHYS}, |
136 |
{"encode-string", FCODE_ENCODE_STRING, fcode_opc_ENCODE_STRING}, |
137 |
{"end0", FCODE_END0, fcode_opc_END0}, |
138 |
{"end1", FCODE_END1, fcode_opc_END1}, |
139 |
{"erase-screen", FCODE_ERASE_SCREEN, fcode_opc_ERASE_SCREEN}, |
140 |
{"evaluate", FCODE_EVALUATE, fcode_opc_EVALUATE}, |
141 |
{"execute", FCODE_EXECUTE, fcode_opc_EXECUTE}, |
142 |
{"exit", FCODE_EXIT, fcode_opc_EXIT}, |
143 |
{"expect", FCODE_EXPECT, fcode_opc_EXPECT}, |
144 |
{"fb8-blink-screen", FCODE_FB8_BLINK_SCREEN, fcode_opc_FB8_BLINK_SCREEN}, |
145 |
{"fb8-delete-chars", FCODE_FB8_DELETE_CHARS, fcode_opc_FB8_DELETE_CHARS}, |
146 |
{"fb8-delete-lines", FCODE_FB8_DELETE_LINES, fcode_opc_FB8_DELETE_LINES}, |
147 |
{"fb8-draw-character", FCODE_FB8_DRAW_CHARACTER, fcode_opc_FB8_DRAW_CHARACTER}, |
148 |
{"fb8-draw-logo", FCODE_FB8_DRAW_LOGO, fcode_opc_FB8_DRAW_LOGO}, |
149 |
{"fb8-erase-screen", FCODE_FB8_ERASE_SCREEN, fcode_opc_FB8_ERASE_SCREEN}, |
150 |
{"fb8-insert-characters", FCODE_FB8_INSERT_CHARACTERS, fcode_opc_FB8_INSERT_CHARACTERS}, |
151 |
{"fb8-insert_lines", FCODE_FB8_INSERT_LINES, fcode_opc_FB8_INSERT_LINES}, |
152 |
{"fb8-install", FCODE_FB8_INSTALL, fcode_opc_FB8_INSTALL}, |
153 |
{"fb8-invert-screen", FCODE_FB8_INVERT_SCREEN, fcode_opc_FB8_INVERT_SCREEN}, |
154 |
{"fb8-reset-screen", FCODE_FB8_RESET_SCREEN, fcode_opc_FB8_RESET_SCREEN}, |
155 |
{"fb8-toggle-cursor", FCODE_FB8_TOGGLE_CURSOR, fcode_opc_FB8_TOGGLE_CURSOR}, |
156 |
{"fcode-revision", FCODE_FCODE_REVISION, fcode_opc_FCODE_REVISION}, |
157 |
{"ferror", FCODE_FERROR, fcode_opc_FERROR}, |
158 |
{"fill", FCODE_FILL, fcode_opc_FILL}, |
159 |
{"$find", FCODE_dFIND, fcode_opc_dFIND}, |
160 |
{"find-method", FCODE_FIND_METHOD, fcode_opc_FIND_METHOD}, |
161 |
{"find-package", FCODE_FIND_PACKAGE, fcode_opc_FIND_PACKAGE}, |
162 |
{"finish-device", FCODE_FINISH_DEVICE, fcode_opc_FINISH_DEVICE}, |
163 |
{">font", FCODE_gtFONT, fcode_opc_gtFONT}, |
164 |
{"fontbytes", FCODE_FONTBYTES, fcode_opc_FONTBYTES}, |
165 |
{"frame-buffer-adr", FCODE_FRAME_BUFFER_ADR, fcode_opc_FRAME_BUFFER_ADR}, |
166 |
{"free-mem", FCODE_FREE_MEM, fcode_opc_FREE_MEM}, |
167 |
{"free-virtual", FCODE_FREE_VIRTUAL, fcode_opc_FREE_VIRTUAL}, |
168 |
{"get-inherited_propertiy", FCODE_GET_INHERITED_PROPERTIY, fcode_opc_GET_INHERITED_PROPERTIY}, |
169 |
{"get-msecs", FCODE_GET_MSECS, fcode_opc_GET_MSECS}, |
170 |
{"get-my-property", FCODE_GET_MY_PROPERTY, fcode_opc_GET_MY_PROPERTY}, |
171 |
{"get-package_property", FCODE_GET_PACKAGE_PROPERTY, fcode_opc_GET_PACKAGE_PROPERTY}, |
172 |
{"get-token", FCODE_GET_TOKEN, fcode_opc_GET_TOKEN}, |
173 |
{"here", FCODE_HERE, fcode_opc_HERE}, |
174 |
{"hold", FCODE_HOLD, fcode_opc_HOLD}, |
175 |
{"i", FCODE_I, fcode_opc_I}, |
176 |
{"ihandle>phandle", FCODE_IHANDLEgtPHANDLE, fcode_opc_IHANDLEgtPHANDLE}, |
177 |
{"insert-characters", FCODE_INSERT_CHARACTERS, fcode_opc_INSERT_CHARACTERS}, |
178 |
{"insert-lines", FCODE_INSERT_LINES, fcode_opc_INSERT_LINES}, |
179 |
{"instance", FCODE_INSTANCE, fcode_opc_INSTANCE}, |
180 |
{"inverse?", FCODE_INVERSEq, fcode_opc_INVERSEq}, |
181 |
{"inverse-screen?", FCODE_INVERSE_SCREENq, fcode_opc_INVERSE_SCREENq}, |
182 |
{"invert", FCODE_INVERT, fcode_opc_INVERT}, |
183 |
{"invert-screen", FCODE_INVERT_SCREEN, fcode_opc_INVERT_SCREEN}, |
184 |
{"is-install", FCODE_IS_INSTALL, fcode_opc_IS_INSTALL}, |
185 |
{"is-remove", FCODE_IS_REMOVE, fcode_opc_IS_REMOVE}, |
186 |
{"is-selftest", FCODE_IS_SELFTEST, fcode_opc_IS_SELFTEST}, |
187 |
{"(is-user-word)", FCODE_bIS_USER_WORDd, fcode_opc_bIS_USER_WORDd}, |
188 |
{"j", FCODE_J, fcode_opc_J}, |
189 |
{"key", FCODE_KEY, fcode_opc_KEY}, |
190 |
{"key?", FCODE_KEYq, fcode_opc_KEYq}, |
191 |
{"l!", FCODE_Lex, fcode_opc_Lex}, |
192 |
{"l,", FCODE_Lcomma, fcode_opc_Lcomma}, |
193 |
{"l@", FCODE_Lat, fcode_opc_Lat}, |
194 |
{"/l", FCODE_divL, fcode_opc_divL}, |
195 |
{"/l*", FCODE_divLmul, fcode_opc_divLmul}, |
196 |
{"la+", FCODE_LAplus, fcode_opc_LAplus}, |
197 |
{"la1+", FCODE_LA1plus, fcode_opc_LA1plus}, |
198 |
{"lbflip", FCODE_LBFLIP, fcode_opc_LBFLIP}, |
199 |
{"lbflips", FCODE_LBFLIPS, fcode_opc_LBFLIPS}, |
200 |
{"lbsplit", FCODE_LBSPLIT, fcode_opc_LBSPLIT}, |
201 |
{"lcc", FCODE_LCC, fcode_opc_LCC}, |
202 |
{"left-parse-string", FCODE_LEFT_PARSE_STRING, fcode_opc_LEFT_PARSE_STRING}, |
203 |
{"#line", FCODE_sharpLINE, fcode_opc_sharpLINE}, |
204 |
{"#lines", FCODE_sharpLINES, fcode_opc_sharpLINES}, |
205 |
{"lpeek", FCODE_LPEEK, fcode_opc_LPEEK}, |
206 |
{"lpoke", FCODE_LPOKE, fcode_opc_LPOKE}, |
207 |
{"lshift", FCODE_LSHIFT, fcode_opc_LSHIFT}, |
208 |
{"lwflip", FCODE_LWFLIP, fcode_opc_LWFLIP}, |
209 |
{"lwflips", FCODE_LWFLIPS, fcode_opc_LWFLIPS}, |
210 |
{"lwsplit", FCODE_LWSPLIT, fcode_opc_LWSPLIT}, |
211 |
{"mac-address", FCODE_MAC_ADDRESS, fcode_opc_MAC_ADDRESS}, |
212 |
{"map-low", FCODE_MAP_LOW, fcode_opc_MAP_LOW}, |
213 |
{"mask", FCODE_MASK, fcode_opc_MASK}, |
214 |
{"max", FCODE_MAX, fcode_opc_MAX}, |
215 |
{"memory-test-suite", FCODE_MEMORY_TEST_SUITE, fcode_opc_MEMORY_TEST_SUITE}, |
216 |
{"min", FCODE_MIN, fcode_opc_MIN}, |
217 |
{"mod", FCODE_MOD, fcode_opc_MOD}, |
218 |
{"/mod", FCODE_divMOD, fcode_opc_divMOD}, |
219 |
{"model", FCODE_MODEL, fcode_opc_MODEL}, |
220 |
{"move", FCODE_MOVE, fcode_opc_MOVE}, |
221 |
{"ms", FCODE_MS, fcode_opc_MS}, |
222 |
{"my-address", FCODE_MY_ADDRESS, fcode_opc_MY_ADDRESS}, |
223 |
{"my-args", FCODE_MY_ARGS, fcode_opc_MY_ARGS}, |
224 |
{"my-parent", FCODE_MY_PARENT, fcode_opc_MY_PARENT}, |
225 |
{"my-self", FCODE_MY_SELF, fcode_opc_MY_SELF}, |
226 |
{"my-space", FCODE_MY_SPACE, fcode_opc_MY_SPACE}, |
227 |
{"my-unit", FCODE_MY_UNIT, fcode_opc_MY_UNIT}, |
228 |
{"/n", FCODE_slashN, fcode_opc_slashN}, |
229 |
{"na+", FCODE_NAplus, fcode_opc_NAplus}, |
230 |
{"named-token", FCODE_NAMED_TOKEN, fcode_opc_NAMED_TOKEN}, |
231 |
{"negate", FCODE_NEGATE, fcode_opc_NEGATE}, |
232 |
{"new-device", FCODE_NEW_DEVICE, fcode_opc_NEW_DEVICE}, |
233 |
{"next-property", FCODE_NEXT_PROPERTY, fcode_opc_NEXT_PROPERTY}, |
234 |
{"nip", FCODE_NIP, fcode_opc_NIP}, |
235 |
{"noop", FCODE_NOOP, fcode_opc_NOOP}, |
236 |
{"$number", FCODE_dNUMBER, fcode_opc_dNUMBER}, |
237 |
{"off", FCODE_OFF, fcode_opc_OFF}, |
238 |
{"offset16", FCODE_OFFSET16, fcode_opc_OFFSET16}, |
239 |
{"on", FCODE_ON, fcode_opc_ON}, |
240 |
{"open-package", FCODE_OPEN_PACKAGE, fcode_opc_OPEN_PACKAGE}, |
241 |
{"$open-package", FCODE_dOPEN_PACKAGE, fcode_opc_dOPEN_PACKAGE}, |
242 |
{"or", FCODE_OR, fcode_opc_OR}, |
243 |
{"#out", FCODE_sharpOUT, fcode_opc_sharpOUT}, |
244 |
{"over", FCODE_OVER, fcode_opc_OVER}, |
245 |
{"2over", FCODE_2OVER, fcode_opc_2OVER}, |
246 |
{"pack", FCODE_PACK, fcode_opc_PACK}, |
247 |
{"parse-2int", FCODE_PARSE_2INT, fcode_opc_PARSE_2INT}, |
248 |
{"peer", FCODE_PEER, fcode_opc_PEER}, |
249 |
{"pick", FCODE_PICK, fcode_opc_PICK}, |
250 |
{"property", FCODE_PROPERTY, fcode_opc_PROPERTY}, |
251 |
{"r>", FCODE_Rgt, fcode_opc_Rgt}, |
252 |
{"r@", FCODE_Rat, fcode_opc_Rat}, |
253 |
{".r", FCODE_dotR, fcode_opc_dotR}, |
254 |
{">r", FCODE_gtR, fcode_opc_gtR}, |
255 |
{"rb!", FCODE_RBex, fcode_opc_RBex}, |
256 |
{"rb@", FCODE_RBat, fcode_opc_RBat}, |
257 |
{"reg", FCODE_REG, fcode_opc_REG}, |
258 |
{"reset-screen", FCODE_RESET_SCREEN, fcode_opc_RESET_SCREEN}, |
259 |
{"rl!", FCODE_RLex, fcode_opc_RLex}, |
260 |
{"rl@", FCODE_RLat, fcode_opc_RLat}, |
261 |
{"roll", FCODE_ROLL, fcode_opc_ROLL}, |
262 |
{"rot", FCODE_ROT, fcode_opc_ROT}, |
263 |
{"-rot", FCODE_mROT, fcode_opc_mROT}, |
264 |
{"2rot", FCODE_2ROT, fcode_opc_2ROT}, |
265 |
{"rshift", FCODE_RSHIFT, fcode_opc_RSHIFT}, |
266 |
{"rw!", FCODE_RWex, fcode_opc_RWex}, |
267 |
{"rw@", FCODE_RWat, fcode_opc_RWat}, |
268 |
{"#s", FCODE_sharpS, fcode_opc_sharpS}, |
269 |
{".s", FCODE_dotS, fcode_opc_dotS}, |
270 |
{"sbus-intr>cpu", FCODE_SBUS_INTRgtCPU, fcode_opc_SBUS_INTRgtCPU}, |
271 |
{"screen-height", FCODE_SCREEN_HEIGHT, fcode_opc_SCREEN_HEIGHT}, |
272 |
{"screen-width", FCODE_SCREEN_WIDTH, fcode_opc_SCREEN_WIDTH}, |
273 |
{"set-args", FCODE_SET_ARGS, fcode_opc_SET_ARGS}, |
274 |
{"set-font", FCODE_SET_FONT, fcode_opc_SET_FONT}, |
275 |
{"sign", FCODE_SIGN, fcode_opc_SIGN}, |
276 |
{"start0", FCODE_START0, fcode_opc_START0}, |
277 |
{"start1", FCODE_START1, fcode_opc_START1}, |
278 |
{"start2", FCODE_START2, fcode_opc_START2}, |
279 |
{"start4", FCODE_START4, fcode_opc_START4}, |
280 |
{"state", FCODE_STATE, fcode_opc_STATE}, |
281 |
{"suspend-fcode", FCODE_SUSPEND_FCODE, fcode_opc_SUSPEND_FCODE}, |
282 |
{"swap", FCODE_SWAP, fcode_opc_SWAP}, |
283 |
{"2swap", FCODE_2SWAP, fcode_opc_2SWAP}, |
284 |
{"throw", FCODE_THROW, fcode_opc_THROW}, |
285 |
{"toggle-cursor", FCODE_TOGGLE_CURSOR, fcode_opc_TOGGLE_CURSOR}, |
286 |
{"tuck", FCODE_TUCK, fcode_opc_TUCK}, |
287 |
{"type", FCODE_TYPE, fcode_opc_TYPE}, |
288 |
{"u#", FCODE_Usharp, fcode_opc_Usharp}, |
289 |
{"u#>", FCODE_Usharpgt, fcode_opc_Usharpgt}, |
290 |
{"u#s", FCODE_UsharpS, fcode_opc_UsharpS}, |
291 |
{"u.", FCODE_Udot, fcode_opc_Udot}, |
292 |
{"u<", FCODE_Ult, fcode_opc_Ult}, |
293 |
{"u<=", FCODE_Ultequal, fcode_opc_Ultequal}, |
294 |
{"u>", FCODE_Ugt, fcode_opc_Ugt}, |
295 |
{"u>=", FCODE_Ugtequal, fcode_opc_Ugtequal}, |
296 |
{"u2/", FCODE_U2div, fcode_opc_U2div}, |
297 |
{"um*", FCODE_UMmul, fcode_opc_UMmul}, |
298 |
{"um/mod", FCODE_UMdivMOD, fcode_opc_UMdivMOD}, |
299 |
{"u/mod", FCODE_UdivMOD, fcode_opc_UdivMOD}, |
300 |
{"unloop", FCODE_UNLOOP, fcode_opc_UNLOOP}, |
301 |
{"upc", FCODE_UPC, fcode_opc_UPC}, |
302 |
{"u.r", FCODE_UdotR, fcode_opc_UdotR}, |
303 |
{"user-abort", FCODE_USER_ABORT, fcode_opc_USER_ABORT}, |
304 |
{"version1", FCODE_VERSION1, fcode_opc_VERSION1}, |
305 |
{"w!", FCODE_Wex, fcode_opc_Wex}, |
306 |
{"w,", FCODE_Wcomma, fcode_opc_Wcomma}, |
307 |
{"w@", FCODE_Wat, fcode_opc_Wat}, |
308 |
{"/w", FCODE_slashW, fcode_opc_slashW}, |
309 |
{"/w*", FCODE_slashWmul, fcode_opc_slashWmul}, |
310 |
{">w@", FCODE_ltWat, fcode_opc_ltWat}, |
311 |
{"wa+", FCODE_WAplus, fcode_opc_WAplus}, |
312 |
{"wa1+", FCODE_WA1plus, fcode_opc_WA1plus}, |
313 |
{"wbflip", FCODE_WBFLIP, fcode_opc_WBFLIP}, |
314 |
{"wbflips", FCODE_WBFLIPS, fcode_opc_WBFLIPS}, |
315 |
{"wbsplit", FCODE_WBSPLIT, fcode_opc_WBSPLIT}, |
316 |
{"window-left", FCODE_WINDOW_LEFT, fcode_opc_WINDOW_LEFT}, |
317 |
{"window-top", FCODE_WINDOW_TOP, fcode_opc_WINDOW_TOP}, |
318 |
{"within", FCODE_WITHIN, fcode_opc_WITHIN}, |
319 |
{"wljoin", FCODE_WLJOIN, fcode_opc_WLJOIN}, |
320 |
{"wpeek", FCODE_WPEEK, fcode_opc_WPEEK}, |
321 |
{"wpoke", FCODE_WPOKE, fcode_opc_WPOKE}, |
322 |
{"xor", FCODE_XOR, fcode_opc_XOR}, |
323 |
|
324 |
{"base", FCODE_BASE, fcode_opc_XOR}, |
325 |
}; |
326 |
|
327 |
forth_word forth_internal_word_table[] = { |
328 |
{"b(\")", FCODE_Bstring, fcode_opc_Bstring}, |
329 |
{"b(')", FCODE_Btick, fcode_opc_Btick}, |
330 |
{"b(:)", FCODE_Bcolon, fcode_opc_Bcolon}, |
331 |
{"b(;)", FCODE_Bsemincolon, fcode_opc_Bsemincolon}, |
332 |
{"bbranch", FCODE_BBRANCH, fcode_opc_BBRANCH}, |
333 |
{"b?branch", FCODE_BqBRANCH, fcode_opc_BqBRANCH}, |
334 |
{"b(buffer:)", FCODE_BBUFFERcol, fcode_opc_BBUFFERcol}, |
335 |
{"b(case)", FCODE_BCASE, fcode_opc_BCASE}, |
336 |
{"b(constant)", FCODE_BCONSTANT, fcode_opc_BCONSTANT}, |
337 |
{"b(create)", FCODE_BCREATE, fcode_opc_BCREATE}, |
338 |
{"b(defer)", FCODE_BDEFER, fcode_opc_BDEFER}, |
339 |
{"b(do)", FCODE_BDO, fcode_opc_BDO}, |
340 |
{"b(?do)", FCODE_BqDO, fcode_opc_BqDO}, |
341 |
{"b(endcase)", FCODE_BENDCASE, fcode_opc_BENDCASE}, |
342 |
{"b(endof)", FCODE_BENDOF, fcode_opc_BENDOF}, |
343 |
{"b(field)", FCODE_BFIELD, fcode_opc_BFIELD}, |
344 |
{"b(leave)", FCODE_BLEAVE, fcode_opc_BLEAVE}, |
345 |
{"b(lit)", FCODE_BLIT, fcode_opc_BLIT}, |
346 |
{"b(loop)", FCODE_BLOOP, fcode_opc_BLOOP}, |
347 |
{"b(+loop)", FCODE_BplusLOOP, fcode_opc_BplusLOOP}, |
348 |
{"b(<mark)", FCODE_BltMARK, fcode_opc_BltMARK}, |
349 |
{"b(of)", FCODE_BOF, fcode_opc_BOF}, |
350 |
{"b(>resolve)", FCODE_BgtRESOLVE, fcode_opc_BgtRESOLVE}, |
351 |
{"b(to)", FCODE_BTO, fcode_opc_BTO}, |
352 |
{"b(value)", FCODE_BVALUE, fcode_opc_BVALUE}, |
353 |
{"b(variable)", FCODE_BVARIABLE, fcode_opc_BVARIABLE}, |
354 |
{"external-token", FCODE_EXTERNAL_TOKEN, fcode_opc_EXTERNAL_TOKEN}, |
355 |
{"new-token", FCODE_NEW_TOKEN, fcode_opc_NEW_TOKEN}, |
356 |
}; |
357 |
|
358 |
static char *forth_aliases = "" |
359 |
" : << lshift ;" |
360 |
" : >> rshift ;" |
361 |
" : 1+ 1 + ;" |
362 |
" : 1- 1 - ;" |
363 |
" : 2+ 2 + ;" |
364 |
" : 2- 2 - ;" |
365 |
" : 3+ 3 + ;" |
366 |
" : 3- 3 - ;" |
367 |
" : accept span @ -rot expect span @ swap span ! ;" |
368 |
" : blank bl fill ;" |
369 |
" : /c* chars ;" |
370 |
" : ca1+ char+ ;" |
371 |
" : .d base @ swap 10 base ! . base ! ;" |
372 |
" : decimal 10 base ! ;" |
373 |
" : decode-bytes >r over r@ + swap r@ - rot r> ;" |
374 |
" : 3drop 2drop drop ;" |
375 |
" : 3dup 2 pick 2 pick 2 pick ;" |
376 |
" : eval evaluate ;" |
377 |
" : false 0 ;" |
378 |
" : .h base @ swap 16 base ! . base ! ;" |
379 |
" : hex 16 base ! ;" |
380 |
" : /n* cells ;" |
381 |
" : na1+ cell+ ;" |
382 |
" : not invert ;" |
383 |
" : space bl emit ;" |
384 |
" : spaces 0 max 0 ?do space loop ;" |
385 |
" : ;" |
386 |
" : ;" |
387 |
" : ;" |
388 |
" : ;" |
389 |
; |
390 |
|
391 |
/* |
392 |
* Initialize stuff |
393 |
*/ |
394 |
static char *forth_prepend = "" |
395 |
" 10 base !" |
396 |
" 1 to line#" |
397 |
" 0 span !" |
398 |
; |
399 |
|
400 |
void forth_build_vocabulary(Container &vocabulary, ForthVM &vm) |
401 |
{ |
402 |
for (uint i=0; i < sizeof forth_word_table/sizeof (forth_word); i++) { |
403 |
vocabulary.insert(new ForthWordBuildIn(forth_word_table[i].name, forth_word_table[i].fcode, forth_word_table[i].func)); |
404 |
} |
405 |
vocabulary.insert(new ForthWordString("\"", fwstString)); |
406 |
vocabulary.insert(new ForthWordString("s\"", fwstStringWithHex)); |
407 |
vocabulary.insert(new ForthWordString(".\"", fwstStringPrint)); |
408 |
vocabulary.insert(new ForthWordString(".(", fwstStringPrintBracket)); |
409 |
vocabulary.insert(new ForthWordTick("'")); |
410 |
vocabulary.insert(new ForthWordTick("[']")); |
411 |
|
412 |
vocabulary.insert(new ForthVar("base",0)); |
413 |
// , FCODE_BASE |
414 |
vocabulary.insert(new ForthVar("line#",0)); |
415 |
// , FCODE_LINEsharp |
416 |
vocabulary.insert(new ForthVar("span",0)); |
417 |
// , FCODE_SPAN |
418 |
} |
419 |
|
420 |
#include <cstdlib> |
421 |
void forth_disassemble(ForthVM &vm) |
422 |
{ |
423 |
String s; |
424 |
vm.mFCodeBuffer = &s; |
425 |
vm.mFCodeBufferIdx = 8; |
426 |
bool offset16 = true; |
427 |
while (1) { |
428 |
uint32 fcode = vm.getFCode(); |
429 |
switch (fcode) { |
430 |
case FCODE_Bstring: { |
431 |
byte len = vm.getFCodeByte(); |
432 |
printf("b(\") \""); |
433 |
for (int i=0; i<len; i++) { |
434 |
printf("%c", vm.getFCodeByte()); |
435 |
} |
436 |
printf("\" "); |
437 |
goto ok; |
438 |
} |
439 |
case FCODE_BLIT: { |
440 |
uint32 a = 0; |
441 |
a |= vm.getFCodeByte(); a<<=8; |
442 |
a |= vm.getFCodeByte(); a<<=8; |
443 |
a |= vm.getFCodeByte(); a<<=8; |
444 |
a |= vm.getFCodeByte(); |
445 |
printf("0x%08x ", a); |
446 |
goto ok; |
447 |
} |
448 |
} |
449 |
for (uint i=0; i < sizeof forth_word_table/sizeof (forth_word); i++) { |
450 |
if (forth_word_table[i].fcode == fcode) { |
451 |
printf("%s ", forth_word_table[i].name); |
452 |
goto ok; |
453 |
} |
454 |
} |
455 |
for (uint i=0; i < sizeof forth_internal_word_table/sizeof (forth_word); i++) { |
456 |
if (forth_internal_word_table[i].fcode == fcode) { |
457 |
printf("%s ", forth_internal_word_table[i].name); |
458 |
goto ok2; |
459 |
} |
460 |
} |
461 |
goto test; |
462 |
ok2: |
463 |
switch (fcode) { |
464 |
case FCODE_BqDO: |
465 |
case FCODE_BDO: |
466 |
case FCODE_BLOOP: |
467 |
case FCODE_BOF: |
468 |
case FCODE_BENDOF: |
469 |
case FCODE_BqBRANCH: |
470 |
case FCODE_BBRANCH: { |
471 |
if (offset16) { |
472 |
uint16 a = 0; |
473 |
a |= vm.getFCodeByte(); a<<=8; |
474 |
a |= vm.getFCodeByte(); |
475 |
printf("%04x ", a); |
476 |
} else { |
477 |
uint8 a = vm.getFCodeByte(); |
478 |
printf("%02x ", a); |
479 |
} |
480 |
break; |
481 |
} |
482 |
case FCODE_Btick: |
483 |
case FCODE_NEW_TOKEN: |
484 |
fcode = vm.getFCode(); |
485 |
printf("0x%x ", fcode); |
486 |
break; |
487 |
case FCODE_EXTERNAL_TOKEN: |
488 |
case FCODE_Bstring: { |
489 |
byte len = vm.getFCodeByte(); |
490 |
printf("\""); |
491 |
for (int i=0; i<len; i++) { |
492 |
printf("%c", vm.getFCodeByte()); |
493 |
} |
494 |
printf("\" "); |
495 |
if (fcode == FCODE_EXTERNAL_TOKEN) { |
496 |
fcode = vm.getFCode(); |
497 |
printf("0x%x ", fcode); |
498 |
} |
499 |
break; |
500 |
} |
501 |
} |
502 |
goto ok; |
503 |
test: |
504 |
if (fcode >= 0x800) { |
505 |
printf("user(0x%x) ", fcode); |
506 |
goto ok; |
507 |
} |
508 |
printf("%x unknown\n", fcode); |
509 |
exit(1); |
510 |
ok:; |
511 |
} |
512 |
} |