Skip to content

Commit 8f55669

Browse files
authored
Merge pull request #66 from JuliaDebug/teh/revise
Changes needed by Revise
2 parents 209fd47 + 1a7cbcc commit 8f55669

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

src/JuliaInterpreter.jl

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module JuliaInterpreter
22

33
using Base.Meta
4-
import Base: +, convert, isless
4+
import Base: +, -, convert, isless
55
using Core: CodeInfo, SSAValue, SlotNumber, TypeMapEntry, SimpleVector, LineInfoNode, GotoNode, Slot,
66
GeneratedFunctionStub, MethodInstance, NewvarNode, TypeName
77

@@ -24,6 +24,7 @@ struct JuliaProgramCounter
2424
next_stmt::Int
2525
end
2626
+(x::JuliaProgramCounter, y::Integer) = JuliaProgramCounter(x.next_stmt+y)
27+
-(x::JuliaProgramCounter, y::Integer) = JuliaProgramCounter(x.next_stmt-y)
2728
convert(::Type{Int}, pc::JuliaProgramCounter) = pc.next_stmt
2829
isless(x::JuliaProgramCounter, y::Integer) = isless(x.next_stmt, y)
2930

@@ -367,31 +368,17 @@ one that does not require special top-level handling (see [`JuliaInterpreter.spl
367368
function prepare_thunk(mod::Module, thunk::Expr, recursive=false)
368369
if isexpr(thunk, :thunk)
369370
framecode = JuliaFrameCode(mod, thunk.args[1])
370-
elseif isexpr(thunk, :error)
371+
elseif isexpr(thunk, :error) || isexpr(thunk, :incomplete)
371372
error("lowering returned an error, ", thunk)
372373
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])
374376
else
375377
return prepare_thunk(mod, Meta.lower(mod, thunk), true)
376378
end
377379
return prepare_locals(framecode, [])
378380
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)
395382

396383
"""
397384
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;
497484
end
498485
else
499486
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)
501492
end
502-
push!(lex.args, ex)
503-
push!(modexs, (mod, copy(lex)))
504-
empty!(lex.args)
505493
end
506494
return modexs, docexprs
507495
end

test/interpret.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ using JuliaInterpreter
22
using JuliaInterpreter: enter_call_expr
33
using Test, InteractiveUtils
44

5+
pc = JuliaInterpreter.JuliaProgramCounter(2)
6+
@test convert(Int, pc) == 2
7+
@test convert(Int, pc+1) == 3
8+
@test convert(Int, pc-1) == 1
9+
510
module Isolated end
611

712
function summer(A)

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)