Skip to content

Commit 101b254

Browse files
committed
Ensure prepare_thunk always returns a JuliaStackFrame
1 parent a4ae7bf commit 101b254

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

src/JuliaInterpreter.jl

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -367,31 +367,17 @@ one that does not require special top-level handling (see [`JuliaInterpreter.spl
367367
function prepare_thunk(mod::Module, thunk::Expr, recursive=false)
368368
if isexpr(thunk, :thunk)
369369
framecode = JuliaFrameCode(mod, thunk.args[1])
370-
elseif isexpr(thunk, :error)
370+
elseif isexpr(thunk, :error) || isexpr(thunk, :incomplete)
371371
error("lowering returned an error, ", thunk)
372372
elseif recursive
373-
error("expected thunk expression, got ", thunk.head)
373+
thunk = Meta.lower(mod, Expr(:block, nothing, thunk))
374+
framecode = JuliaFrameCode(mod, thunk.args[1])
374375
else
375376
return prepare_thunk(mod, Meta.lower(mod, thunk), true)
376377
end
377378
return prepare_locals(framecode, [])
378379
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
380+
prepare_thunk((mod, ex)::Tuple{Module,Expr}) = prepare_thunk(mod, ex)
395381

396382
"""
397383
modexs, docexprs = split_expressions(mod::Module, expr::Expr; extract_docexprs=false)

test/toplevel.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ end
1717
@test JuliaInterpreter.isdocexpr(ex.args[2])
1818
@test !JuliaInterpreter.isdocexpr(:(1+1))
1919

20+
@test isa(JuliaInterpreter.prepare_thunk(Main, :(export foo)), JuliaStackFrame)
21+
2022
@test !isdefined(Main, :JIInvisible)
2123
JuliaInterpreter.split_expressions(JIVisible, :(module JIInvisible f() = 1 end))
2224
@test !isdefined(Main, :JIInvisible)

0 commit comments

Comments
 (0)