blob: 8cfadeba868ddf046b44587484132f7a14019249 (
plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
\ *****************************************************************************
\ * Copyright (c) 2004, 2007 IBM Corporation
\ * All rights reserved.
\ * This program and the accompanying materials
\ * are made available under the terms of the BSD License
\ * which accompanies this distribution, and is available at
\ * http://www.opensource.org/licenses/bsd-license.php
\ *
\ * Contributors:
\ * IBM Corporation - initial implementation
\ ****************************************************************************/
: ?offset16 ( -- true|false )
fcode-offset 16 =
;
: ?arch64 ( -- true|false )
cell 8 =
;
: ?bigendian ( -- true|false )
deadbeef fcode-num !
fcode-num ?arch64 IF 4 + THEN
c@ de =
;
: reset-fcode-end ( -- )
false fcode-end !
;
: get-ip ( -- n )
ip @
;
: set-ip ( n -- )
ip !
;
: next-ip ( -- )
get-ip 1+ set-ip
;
: jump-n-ip ( n -- )
get-ip + set-ip
;
: read-byte ( -- n )
get-ip fcode-rb@
;
: ?compile-mode ( -- on|off )
state @
;
: save-evaluator-state
get-ip eva-debug? IF ." saved ip " dup . cr THEN
fcode-end @ eva-debug? IF ." saved fcode-end " dup . cr THEN
fcode-offset eva-debug? IF ." saved fcode-offset " dup . cr THEN
\ local fcodes are currently NOT saved!
fcode-spread eva-debug? IF ." saved fcode-spread " dup . cr THEN
['] fcode@ behavior eva-debug? IF ." saved fcode@ " dup . cr THEN
;
: restore-evaluator-state
eva-debug? IF ." restored fcode@ " dup . cr THEN to fcode@
eva-debug? IF ." restored fcode-spread " dup . cr THEN to fcode-spread
\ local fcodes are currently NOT restored!
eva-debug? IF ." restored fcode-offset " dup . cr THEN to fcode-offset
eva-debug? IF ." restored fcode-end " dup . cr THEN fcode-end !
eva-debug? IF ." restored ip " dup . cr THEN set-ip
;
: token-table-index ( fcode# -- addr )
cells token-table +
;
: join-immediate ( xt immediate? addr -- xt+immediate? addr )
-rot + swap
;
: split-immediate ( xt+immediate? -- xt immediate? )
dup 1 and 2dup - rot drop swap
;
: literal, ( n -- )
postpone literal
;
: fc-string,
postpone sliteral
dup c, bounds ?do i c@ c, loop
;
: set-token ( xt immediate? fcode# -- )
token-table-index join-immediate !
;
: get-token ( fcode# -- xt immediate? )
token-table-index @ split-immediate
;
-1 VALUE break-fcode-addr
: exec ( FCode# -- )
eva-debug? IF
dup
get-ip 8 u.r ." : "
." [" 3 u.r ." ] "
THEN
get-ip break-fcode-addr = IF
TRUE fcode-end ! drop EXIT
THEN
get-token 0= IF \ imm == 0 == false
?compile-mode IF
compile,
ELSE
eva-debug? IF dup xt>name type space THEN
execute
THEN
ELSE \ immediate
eva-debug? IF dup xt>name type space THEN
execute
THEN
eva-debug? IF .s cr THEN
;
( ---------------------------------------------------- )
0 ?bigendian INCLUDE? big.fs
0 ?bigendian NOT INCLUDE? little.fs
( ---------------------------------------------------- )
: read-fcode# ( -- FCode# )
read-byte
dup 01 0F between IF drop read-fcode-num16 THEN
;
: read-header ( adr -- )
next-ip read-byte drop
next-ip read-fcode-num16 drop
next-ip read-fcode-num32 drop
;
: read-fcode-string ( -- str len )
read-byte \ get string length ( -- len )
next-ip get-ip \ get string addr ( -- len str )
swap \ type needs the parameters swapped ( -- str len )
dup 1- jump-n-ip \ jump to the end of the string in FCode
;
: evaluate-fcode ( -- )
fcode@ exec \ read start code
BEGIN
next-ip fcode@ exec
fcode-end @
UNTIL
;
: step-fcode ( -- )
break-fcode-addr >r -1 to break-fcode-addr
fcode@ exec next-ip
r> to break-fcode-addr
;
( ---------------------------------------------------- )
|