-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patheval.e
318 lines (295 loc) · 9.23 KB
/
eval.e
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
--
-- eval.e
--
include pmain.e
include builtins\VM\pProfile.e
include plist.e -- assembly and symbol table dump
include builtins\VM\pMemChk.e -- check_heap
--DEV mchk broke p -test... (also cmp [mchk],ebx crashes in pilasm.e)
-- (I have not used memory leak checking for a very long time,
-- I can live without, and it probably no longer works anyway)
global procedure Interpret()--bool mchk)
symtab[T_cmdlnflg] = 2 -- in command_line(), get stuff from symtab[T_fileset]
integer ebp4, -- saved ebp, /4 as it shd be dword-aligned, then fits in an integer
esp4, -- saved esp, ""
pst4 -- saved symtabptr, aka [ds+8] (via :%pGetSymPtr), ""
-- ntcb4 -- saved pGtcb.pNxtcb
object wasEBP = symtab[T_EBP] -- integer(0) = compiled, else
-- ({ebp4,esp4,pst4}) = interpreted
#ilASM{
-- set ebp4,esp4,pst4 (from ebp,esp,symtabptr)
[32]
mov eax,ebp
mov ecx,esp
call :%pGetSymPtr
shr eax,2
shr ecx,2
shr esi,2
mov [ebp4],eax
mov [esp4],ecx
mov [pst4],esi
[64]
mov rax,rbp
mov rcx,rsp
call :%pGetSymPtr
shr rax,2
shr rcx,2
shr rsi,2
mov [ebp4],rax
mov [esp4],rcx
mov [pst4],rsi
}
-- (note that esp4 is also used in builtins\VM\Stack.e\opAbort) [DEV]
symtab[T_EBP] = {ebp4,esp4,pst4}
-- added 28/5/15:
if not dumpil
and not listing
and not some_unresolved_rtnids then
rbldrqd = 1
end if
integer CSvaddr4 = floor(CSvaddr/4)
#ilASM{
[32]
mov eax,[with_js]
call :%pWithJS
-- cmp [mchk],0
-- je @f
-- call :%pNewGtcbChain
-- mov [ntcb4],eax -- temp save
-- @@:
mov esi,[symtab]
mov ecx,[CSvaddr4]
shl esi,2
shl ecx,2
call :%pSetSymPtr
push ecx
call :%pNewStack
mov ecx,[esp] -- (keep for diagnostics)
call ecx
pop ecx
-- cmp [mchk],0
-- je @f
-- call :%RunCleanup
-- @@:
call :%pGetSymPtr
mov edx,[esi+21*4] -- symtab[T_EBP=22]
mov eax,[ebx+edx*4] -- symtab[T_EBP][1] = ebp4
mov ecx,[ebx+edx*4+4] -- symtab[T_EBP][2] = esp4
mov esi,[ebx+edx*4+8] -- symtab[T_EBP][3] = pst4
shl eax,2
shl ecx,2
shl esi,2
mov ebp,eax -- restore ebp
mov esp,ecx -- restore esp
call :%pSetSymPtr
-- cmp [mchk],0
-- je @f
-- mov eax,[ntcb4]
-- call :%pRestoreGtcbChain
-- mov [ntcb4],edx
-- @@:
xor eax,eax
call :%pWithJS
[64]
mov rax,[with_js]
call :%pWithJS
-- cmp [mchk],0
-- je @f
-- call :%pNewGtcbChain
-- mov [ntcb4],rax -- temp save
-- @@:
mov rsi,[symtab]
mov rcx,[CSvaddr4]
shl rsi,2
shl rcx,2
call :%pSetSymPtr
push rcx
call :%pNewStack
mov rcx,[rsp] -- (keep for diagnostics)
call rcx
pop rcx
-- cmp [mchk],0
-- je @f
-- call :%RunCleanup
-- @@:
call :%pGetSymPtr
mov rdx,[rsi+168] -- symtab[T_EBP=22]
mov rax,[rbx+rdx*4] -- symtab[T_EBP][1] = ebp4
mov rcx,[rbx+rdx*4+8] -- symtab[T_EBP][2] = esp4
mov rsi,[rbx+rdx*4+16] -- symtab[T_EBP][3] = pst4
shl rax,2
shl rcx,2
shl rsi,2
mov rbp,rax -- restore ebp
mov rsp,rcx -- restore esp
call :%pSetSymPtr
-- cmp [mchk],0
-- je @f
-- mov rax,[ntcb4]
-- call :%pRestoreGtcbChain
-- mov [ntcb4],rdx
-- @@:
xor rax,rax
call :%pWithJS
[]
}
-- if mchk then
-- check_heap(ntcb4)
-- end if
--puts1("returned from call(CSvaddr)!\n")
symtab[T_EBP] = wasEBP
free(CSvaddr)
end procedure
bool first = true
global function eval(string code, sequence rset={}, iset={}, ival={})
if first then
first = false
tt_save_init()
end if
text = code & "\n" -- important!
fileno = 0
resetOptions()
mainpath = current_dir()
initFilePathSet()
tokinit()
syminit()
DSvaddr = 0
filenames = {{1,""}} --append(filenames,{pathno,file})
fileno = 1 --length(filenames)
allfiles = {""}
allpfiles = {""}
exptext = {0}--append(exptext,0)
expandedYet = {0}--append(expandedYet,0)
unresolved_routine_ids = {0}--append(unresolved_routine_ids,0)
ltl = length(text)
allfiles[1] = text
allpfiles[1] = text
exptext[1] = 0
expandedYet[1] = 0
unresolved_routine_ids[1] = 0
finalOptWarn = {optset[OptWarning]}
col = 0
-- bool mchk = MCHK and length(ptab)=0 and opLntpcalled=0
Compile()
currRtn = T_maintls
--end if
scopelevel = 1
--scopelevel += 1
-- with_js = 0
if with_js=1 then ?9/0 end if
profileon = false
if length(iset)!=length(ival) then
if length(ival) then ?9/0 end if
ival = vslice(iset,2)
iset = vslice(iset,1)
end if
-- ? = compile(code)
for i=1 to length(iset) do
string ii = iset[i]
tt_string(ii,-2)
tokno = 0
integer idx = InTable(InAny)
if idx=0 then
crash("%s (in iset[%d]) not found",{ii,i})
elsif symtab[idx][S_NTyp]!=S_GVar2 then
crash("%s (in iset[%d]) is not a gvar",{ii,i})
end if
-- printf(1,"iset[%d] (%s) is symtab[%d], flags:%08x\n",{i,ii,idx,symtab[idx][S_State]})
symtab[idx][S_value] = ival[i]
symtab[idx][S_State] = or_bits(symtab[idx][S_State],K_noclr)
-- integer k = get_var_idx(iset[i])
-- set_var(k,ival[i])
-- set_var(iset[i],ival[i])
end for
-- Interpret()
--?9/0
--/*
S_NTyp = 2, -- Const/GVar/TVar/Nspc/Type/Func/Proc
S_GVar2 = 2, -- global or static variable
S_State = 4, -- state flag. S_fwd/S_used/S_set etc
K_aod = #000040, -- assignment on declaration (avoid warnings/force cleanup)
K_noclr= #000200, -- do not clear on load (ie assignment on declaration occurred)
-- only used for GVars
K_lit = #004000, -- literal flag
S_lnc = #4200, -- K_lit+K_noclr
if sv[S_NTyp]<=S_GVar2 then
vno = sv[S_Slink] --DEV +gbase
if X64 then
offset = DSvaddr+vno*8+24
if c=isVar1 then
offset -= 1
elsif c=isVar4 then
offset -= 4
end if
offset -= CSvaddr+cout+3
else --32
offset = DSvaddr+vno*4+16
end if
--*/
sequence res = repeat(0,length(rset))
for i=1 to length(rset) do
string ri = rset[i]
tt_string(ri,-2)
integer rdx = InTable(InAny)
if rdx=0 then
crash("%s (in rset[%d]) not found",{ri,i})
elsif symtab[rdx][S_NTyp]!=S_GVar2 then
crash("%s (in rset[%d]) is not a gvar",{ri,i})
end if
-- printf(1,"rset[%d] (%s) is symtab[%d], flags:%08x\n",{i,ri,rdx,symtab[rdx][S_State]})
--?{"S_Tidx",symtab[rdx][S_Tidx],symtab[rdx]}
--?S_Tidx
-- ?{"rset",i,ri,rdx}
-- res[i] = get_var(rset[i])
rset[i] = rdx
end for
finalfixups2("","",0)
Interpret()
if safe_mode=0 then
safe_mode = 1
#ilASM{ call :%pSafeOff }
end if
--?9/0
--??
integer DSvaddr4 = floor(DSvaddr/4)
for i=1 to length(rset) do
integer sdx = rset[i],
-- vno = symtab[sdx][S_Slink]
vno = symtab[sdx][S_Slink]*machine_word()
object ri
-- atom addr = DSvaddr+vno*machine_word()+iff(machine_bits()=32?16:24)
#ilASM{
[32]
mov eax,[DSvaddr4]
mov ecx,[vno]
mov eax,[eax*4+ecx+16]
mov [ri],eax
--DEV it disney like dis... (under -c)
-- mov [eax*4+ecx+16],ebx
[64]
mov rax,[DSvaddr4]
mov rcx,[vno]
mov rax,[rax*4+rcx+24]
mov [ri],rax
-- mov [rax*4+rcx+24],rbx
[]
}
-- ?{"rset",i,sdx,symtab[sdx],peekns(addr)}
-- res[i] = get_var(rset[i])
-- res[i] = peekns(addr)
res[i] = ri
#ilASM{
[32]
mov [ri],ebx
[64]
mov [ri],rbx
[]
}
end for
free(DSvaddr)
--?{"errorcode",errorcode}
-- Warnings(1)
tt_init()
ResetResourceSectionDefaults()
return res
end function