-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathCompileTokensTest
53 lines (43 loc) · 1.49 KB
/
CompileTokensTest
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
S" GETCOMPATIBLE.F" INCLUDED
S" GETBYTECODE.F" INCLUDED
S" GETTOKENS.F" INCLUDED
S" GETSIMPLETOKENS.F" INCLUDED
S" GETCOMPILER.F" INCLUDED
S" SIMPLEWORDS.F" INCLUDED
: GET-FROM-PAD ( S: -- char )
PAD C@ PAD CHAR+ PAD 80 CHARS MOVE ;
' GET-FROM-PAD (IS) INPUT-TOKEN
T: .( ;T
: [HANDLE-TOKEN] HANDLE-TOKEN ; IMMEDIATE
: PUT-ONE ( S: addr token -- addr' )
OVER C! CHAR+ ;
: PUT" ( S: 'string"' addr -- addr' )
['] S" EXECUTE ROT 2DUP C! CHAR+ SWAP CHARS 2DUP + >R MOVE R> ;
CR .( should show ABCDE -> ) PAD LAST-TOKEN @ PUT-ONE DROP HANDLE-TOKEN ABCDE)
CR .( should show DEFGH -> )
PAD LAST-TOKEN @ PUT-ONE DROP : TARTRATE [HANDLE-TOKEN] DEFGH) ;
CR .( should show | 777 5 test| -> ) CHAR | EMIT
LAST-TOKEN @ PAD OVER PUT-ONE OVER PUT-ONE SWAP PUT-ONE DROP
3 HANDLE-TOKENS 777) 5) test) CHAR | EMIT
CREATE TOKEN-BUFFER 264 CHARS ALLOT
( G: silly example of word that conditionally stops tokencompiling )
: .(( ( S: -- )
INPUT-TOKEN DUP 3 = IF
DROP INPUT-TOKEN DUP EMIT [CHAR] E = IF
INPUT-TOKEN DUP EMIT [CHAR] N = IF
INPUT-TOKEN DUP EMIT [CHAR] D = IF
-1 STOP-READING !
THEN
ELSE
INPUT-TOKEN EMIT
THEN
ELSE
INPUT-TOKEN EMIT INPUT-TOKEN EMIT
THEN
ELSE
TOKEN-BUFFER 0 ROT TOKENS>STRINGN TYPE
THEN ;
T: .(( ;T
CR .( should show |TTTT END| -> ) CHAR | EMIT
LAST-TOKEN @ PAD OVER PUT-ONE PUT" TTTT " OVER PUT-ONE PUT" END" 2DROP
HANDLE-TOKENS-TIL-STOP CHAR | EMIT