1
1
module JuliaInterpreter
2
2
3
3
using Base. Meta
4
- import Base: + , convert, isless
4
+ import Base: + , - , convert, isless
5
5
using Core: CodeInfo, SSAValue, SlotNumber, TypeMapEntry, SimpleVector, LineInfoNode, GotoNode, Slot,
6
6
GeneratedFunctionStub, MethodInstance, NewvarNode, TypeName
7
7
@@ -24,6 +24,7 @@ struct JuliaProgramCounter
24
24
next_stmt:: Int
25
25
end
26
26
+ (x:: JuliaProgramCounter , y:: Integer ) = JuliaProgramCounter (x. next_stmt+ y)
27
+ - (x:: JuliaProgramCounter , y:: Integer ) = JuliaProgramCounter (x. next_stmt- y)
27
28
convert (:: Type{Int} , pc:: JuliaProgramCounter ) = pc. next_stmt
28
29
isless (x:: JuliaProgramCounter , y:: Integer ) = isless (x. next_stmt, y)
29
30
@@ -367,31 +368,17 @@ one that does not require special top-level handling (see [`JuliaInterpreter.spl
367
368
function prepare_thunk (mod:: Module , thunk:: Expr , recursive= false )
368
369
if isexpr (thunk, :thunk )
369
370
framecode = JuliaFrameCode (mod, thunk. args[1 ])
370
- elseif isexpr (thunk, :error )
371
+ elseif isexpr (thunk, :error ) || isexpr (thunk, :incomplete )
371
372
error (" lowering returned an error, " , thunk)
372
373
elseif recursive
373
- error (" expected thunk expression, got " , thunk. head)
374
+ thunk = Meta. lower (mod, Expr (:block , nothing , thunk))
375
+ framecode = JuliaFrameCode (mod, thunk. args[1 ])
374
376
else
375
377
return prepare_thunk (mod, Meta. lower (mod, thunk), true )
376
378
end
377
379
return prepare_locals (framecode, [])
378
380
end
379
-
380
- function prepare_thunk ((mod, ex):: Tuple{Module,Expr} )
381
- lwr = Meta. lower (mod, ex)
382
- if isexpr (lwr, :thunk )
383
- return prepare_thunk (mod, lwr)
384
- # elseif isexpr(lwr, :toplevel)
385
- # return split_expressions!(frames, docexprs, lex, mod, lwr; extract_docexprs=extract_docexprs, filename=filename)
386
- # elseif isa(lwr, Expr) && (lwr.head == :export || lwr.head == :using || lwr.head == :import)
387
- # @show lwr
388
- # push!(modexs, (mod, ex, lwr))
389
- # elseif isa(lwr, Symbol) || isa(lwr, Nothing)
390
- else
391
- @show mod ex lwr
392
- error (" lowering did not produce a :thunk Expr" )
393
- end
394
- end
381
+ prepare_thunk ((mod, ex):: Tuple{Module,Expr} ) = prepare_thunk (mod, ex)
395
382
396
383
"""
397
384
modexs, docexprs = split_expressions(mod::Module, expr::Expr; extract_docexprs=false)
@@ -497,11 +484,12 @@ function split_expressions!(modexs, docexprs, lex::Expr, mod::Module, ex::Expr;
497
484
end
498
485
else
499
486
if isempty (lex. args)
500
- push! (lex. args, isexpr (ex, :macrocall ) ? ex. args[2 ] : LineNumberNode (0 , Symbol (filename)))
487
+ push! (modexs, (mod, copy (ex)))
488
+ else
489
+ push! (lex. args, ex)
490
+ push! (modexs, (mod, copy (lex)))
491
+ empty! (lex. args)
501
492
end
502
- push! (lex. args, ex)
503
- push! (modexs, (mod, copy (lex)))
504
- empty! (lex. args)
505
493
end
506
494
return modexs, docexprs
507
495
end
0 commit comments