Repository navigation
Expand file tree
/
Copy pathprops.lua
More file actions
336 lines (297 loc) · 8.65 KB
/
Copy pathprops.lua
File metadata and controls
336 lines (297 loc) · 8.65 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
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
_PROPS = {
has_exts = false,
has_wclocks = false,
has_ints = false,
has_asyncs = false,
has_threads = false,
has_orgs = false,
has_news = false,
has_news_pool = false,
has_news_malloc = false,
has_ifcs = false,
has_clear = false,
has_pses = false,
has_ret = false,
}
local NO_fun = {
Finalize=true, Finally=true,
Host=true, Thread=true,
ParEver=true, ParOr=true, ParAnd=true,
AwaitS=true, AwaitExt=true, AwaitInt=true, AwaitN=true, AwaitT=true,
EmitInt=true, --EmitExt=true,
Pause=true,
}
local NO_fin = {
Finalize=true, Finally=true,
Host=true, Escape=true, Async=true, Thread=true,
ParEver=true, ParOr=true, ParAnd=true,
AwaitS=true, AwaitExt=true, AwaitInt=true, AwaitN=true, AwaitT=true,
EmitInt=true,
Pause=true,
}
local NO_async = {
Async=true, Thread=true,
ParEver=true, ParOr=true, ParAnd=true,
AwaitS=true, AwaitExt=true, AwaitInt=true, AwaitN=true, AwaitT=true,
EmitInt=true,
Pause=true,
Escape=true,
}
local NO_thread = {
Async=true, Thread=true,
ParEver=true, ParOr=true, ParAnd=true,
AwaitS=true, AwaitExt=true, AwaitInt=true, AwaitN=true, AwaitT=true,
EmitInt=true, EmitExt=true, EmitT=true,
Pause=true,
Escape=true,
}
local NO_constr = {
--Finalize=true, Finally=true,
Escape=true, Async=true, Thread=true,
ParEver=true, ParOr=true, ParAnd=true,
AwaitS=true, AwaitExt=true, AwaitInt=true, AwaitN=true, AwaitT=true,
EmitInt=true,
Pause=true,
}
-- Loop, SetBlock may need clear
-- if break/return are in parallel w/ something
-- or inside block that needs_clr
function NEEDS_CLR (top)
for n in _AST.iter() do
if n.tag == top.tag then
break
elseif n.tag == 'ParEver' or
n.tag == 'ParAnd' or
n.tag == 'ParOr' or
n.tag == 'Block' and n.needs_clr then
_PROPS.has_clear = true
top.needs_clr = true
break
end
end
end
function HAS_FINS ()
for n in _AST.iter() do
if n.tag == 'Block' or
n.tag == 'ParOr' or
n.tag == 'Loop' or
n.tag == 'SetBlock' then
n.needs_clr_fin = true
end
end
end
F = {
Node_pre = function (me)
if NO_fun[me.tag] then
ASR(not _AST.iter'Dcl_fun'(), me,
'not permitted inside `function´')
end
if NO_fin[me.tag] then
ASR(not _AST.iter'Finally'(), me,
'not permitted inside `finalize´')
end
if NO_async[me.tag] then
ASR(not _AST.iter'Async'(), me,
'not permitted inside `async´')
end
if NO_thread[me.tag] then
ASR(not _AST.iter'Thread'(), me,
'not permitted inside `thread´')
end
if NO_constr[me.tag] then
ASR(not _AST.iter'Dcl_constr'(), me,
'not permitted inside a constructor')
end
end,
Block_pre = function (me) -- _pre: break/return depends on it
if me.fins then
me.needs_clr = true
me.needs_clr_fin = true
_PROPS.has_clear = true
end
for _, var in ipairs(me.vars) do
if var.cls then
me.needs_clr = true
_PROPS.has_clear = true
break
end
end
if me.needs_clr then
HAS_FINS() -- TODO (-ROM): could avoid ors w/o fins
end
end,
Free = function (me)
_PROPS.has_news = true
_PROPS.has_clear = true
end,
New = function (me)
local max,_,_ = unpack(me)
_PROPS.has_news = true
if max or me.cls.max then
_PROPS.has_news_pool = true
if max then
local blk = me.blk
blk.pools = blk.pools or {}
blk.pools[me] = max
end
else
_PROPS.has_news_malloc = true
end
_PROPS.has_clear = true
me.blk.needs_clr = true
ASR(not _AST.iter'BlockI'(), me,
'not permitted inside an interface')
end,
Spawn = 'New',
ParOr = function (me)
me.needs_clr = true
_PROPS.has_clear = true
end,
Loop_pre = function (me)
me.brks = {}
end,
Break = function (me)
local loop = _AST.iter'Loop'()
ASR(loop, me, 'break without loop')
loop.brks[me] = true
loop.has_break = true
NEEDS_CLR(loop)
local fin = _AST.iter'Finally'()
ASR(not fin or fin.__depth<loop.__depth, me,
'not permitted inside `finalize´')
-- TODO: same for return
local async = _AST.iter(_AST.pred_async)()
if async then
local loop = _AST.iter'Loop'()
ASR(loop.__depth>async.__depth, me, '`break´ without loop')
end
end,
SetBlock_pre = function (me)
me.rets = {}
ASR(not _AST.iter'BlockI'(), me,
'not permitted inside an interface')
end,
Escape = function (me)
local blk = _AST.iter'SetBlock'()
blk.rets[me] = true
blk.has_escape = true
NEEDS_CLR(blk)
end,
Return = function (me)
ASR(_AST.iter'Dcl_fun'(), me,
'not permitted outside a function')
end,
Dcl_cls = function (me)
_PROPS.has_orgs = _PROPS.has_orgs or (me.id~='Main')
if me.is_ifc then
_PROPS.has_ifcs = true
end
end,
Dcl_ext = function (me)
_PROPS.has_exts = true
end,
Dcl_var = function (me)
if me.var.cls then
-- <class T with var U u; end>
ASR(not _AST.iter'BlockI'(), me,
'not permitted inside an interface')
end
end,
Async = function (me)
_PROPS.has_asyncs = true
end,
Thread = function (me)
_PROPS.has_threads = true
end,
Sync = function (me)
ASR(_AST.iter'Thread'(), me,'not permitted outside `thread´')
end,
Pause = function (me)
_PROPS.has_pses = true
end,
_loop1 = function (me)
for loop in _AST.iter'Loop' do
if loop.isEvery then
ASR(me.isEvery, me,
'`every´ cannot contain `await´')
end
end
end,
AwaitT = function (me)
_PROPS.has_wclocks = true
F._loop1(me)
end,
AwaitInt = function (me)
_PROPS.has_ints = true
F._loop1(me)
end,
AwaitExt = function (me)
F._loop1(me)
end,
AwaitN = function (me)
F._loop1(me)
end,
AwaitS = function (me)
for _, awt in ipairs(me) do
if awt.__ast_isexp then
F.AwaitInt(me)
elseif awt.tag=='Ext' then
F.AwaitExt(me)
else
F.AwaitT(me)
end
end
end,
EmitInt = function (me)
_PROPS.has_ints = true
end,
EmitExt = function (me)
local op, ext = unpack(me)
if ext.evt.pre == 'input' then
ASR( _AST.par(me,'Async') or op=='call',
me, 'invalid `'..op..'´')
-- no <emit I> on sync
end
if _AST.par(me,'Dcl_fun') then
ASR(op=='call', me, 'invalid `emit´')
end
end,
EmitT = function (me)
ASR(_AST.par(me,'Async'),
me,'not permitted outside `async´')
end,
SetExp = function (me)
local _, fr, to = unpack(me)
local thr = _AST.par(me, 'Thread')
if thr and (not to) then
ASR( thr.__depth <= _AST.iter'SetBlock'().__depth+1, me,
'invalid access from `thread´')
end
if _AST.iter'BlockI'() then
CLS().has_pre = true -- code for pre (before constr)
-- new, spawn, async, await
ASR(fr.tag ~= 'Ref',
me, 'not permitted inside an interface')
end
if to.tag=='Var' and to.var.id=='_ret' then
_PROPS.has_ret = true
end
end,
Var = function (me)
local thr = _AST.par(me, 'Thread')
if thr then
ASR(_AST.iter'VarList'() or -- param list
me.ret or -- var assigned on return
thr.__depth < me.var.blk.__depth, -- var is declared inside
me, 'invalid access from `thread´')
end
end,
Op1_cast = function (me)
local tp, _ = unpack(me)
local _tp = _TP.deref(tp)
if _tp and _ENV.clss[_tp] then
_PROPS.has_ifcs = true -- cast must check org->cls_id
end
end
}
_AST.visit(F)