-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.ft
More file actions
43 lines (34 loc) · 1.51 KB
/
Copy pathcode.ft
File metadata and controls
43 lines (34 loc) · 1.51 KB
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
\ ## Parsing of 16 bit code words
\
\ Create words with binary machine code, parsing 16 bit unsigned integers
\ and adding them to the body, ended with the `NEXT` action.
\
\ Fetch a word from the input stream. If the word is found in the
\ current word list, execute it as code word parsing is run in immediate
\ mode. If it is not found, parse it as a number, and store it in the
\ target code space at the current data pointer.
: parse-code begin bl word dup c@ while
find ?dup if
drop execute
else
?number if
th,
else count type [char] ? emit cr then
then
repeat drop ;
\ Define a flag which we can use to check when parsing is done:
variable code-done
\ Parse words from the input stream until `code-done` is not zero.
: read-code false code-done ! begin
parse-code
code-done @ if exit then
refill
0= until ;
\ Start a new code word by first creating a dictionary header in the
\ target dictionary by fetching the next word as the code word name,
\ compiling the action needed for code words (used for ITC threading)
\ and then continue to read upcoming words as code words.
: code t: t,docode read-code ;
\ If we encounter `end-code` in the input stream, encode the `NEXT` action
\ to the target dictionary, and set `code-done` to true to stop parsing.
: end-code t,next true code-done ! ;