Skip to content

Commit

Permalink
Fix stepping through more complicated wrappers. Fixes #12
Browse files Browse the repository at this point in the history
  • Loading branch information
Keno committed Nov 29, 2017
1 parent 9481073 commit bd4748f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ASTInterpreter2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ function prepare_locals(meth, code, argvals = (), generator = false)
locals[i] = Nullable{Any}()
end
JuliaStackFrame(meth, code, locals, ssavalues, sparams, Int[], Nullable{Any}(),
JuliaProgramCounter(2), Dict{Symbol,Int}(), false, generator,
JuliaProgramCounter(1), Dict{Symbol,Int}(), false, generator,
true)
end

Expand Down
24 changes: 18 additions & 6 deletions src/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,24 @@ function next_line!(frame, stack = nothing)
fls = determine_line_and_file(frame, pc.next_stmt)
didchangeline = line != fls[1][2]
elseif stack !== nothing && iswrappercall(pc_expr(frame, pc))
stack[1] = JuliaStackFrame(frame, pc; wrapper = true)
call_expr = pc_expr(frame, pc)
isexpr(call_expr, :(=)) && (call_expr = call_expr.args[2])
frame = enter_call_expr(Expr(:call, map(x->lookup_var_if_var(frame, x), call_expr.args)...))
unshift!(stack, frame)
pc = frame.pc
# With splatting it can happen that we do something like ssa = tuple(#self#), _apply(ssa), which
# confuses the logic here, just step into the first call that's not a builtin
while true
stack[1] = JuliaStackFrame(frame, pc; wrapper = true)
call_expr = pc_expr(frame, pc)
isexpr(call_expr, :(=)) && (call_expr = call_expr.args[2])
call_expr = Expr(:call, map(x->lookup_var_if_var(frame, x), call_expr.args)...)
new_frame = enter_call_expr(call_expr)
if new_frame !== nothing
unshift!(stack, new_frame)
frame = new_frame
pc = frame.pc
break
else
pc = _step_expr(frame, pc)
pc == nothing && return nothing
end
end
elseif isa(pc_expr(frame, pc), LineNumberNode)
line != pc_expr(frame, pc).line && break
pc = _step_expr(frame, pc)
Expand Down
11 changes: 11 additions & 0 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,14 @@ state = dummy_state(stack)
execute_command(state, state.stack[1], Val{:finish}(), "finish")
@test isempty(state.stack)
@test state.overall_result == 2 .* [1:10...]

# Issue #12
function complicated_keyword_stuff(args...; kw...)
args[1] == args[1]
(args..., kw...)
end
stack = @make_stack complicated_keyword_stuff(1)
state = dummy_state(stack)
execute_command(state, state.stack[1], Val{:n}(), "n")
execute_command(state, state.stack[1], Val{:finish}(), "finish")
@test isempty(state.stack)

0 comments on commit bd4748f

Please sign in to comment.