Skip to content

Commit

Permalink
Fix #10
Browse files Browse the repository at this point in the history
  • Loading branch information
Keno committed Nov 19, 2017
1 parent fe52dfd commit cc05800
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/ASTInterpreter2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function DebuggerFramework.locinfo(frame::JuliaStackFrame)
end

function lookup_var_if_var(frame, x)
if isa(x, Union{SSAValue, GlobalRef, SlotNumber}) || isexpr(x, :static_parameter) || isexpr(x, :the_exception)
if isa(x, Union{SSAValue, GlobalRef, SlotNumber}) || isexpr(x, :static_parameter) || isexpr(x, :the_exception) || isexpr(x, :boundscheck)
return lookup_var(frame, x)
end
x
Expand Down Expand Up @@ -183,6 +183,10 @@ function DebuggerFramework.eval_code(state, frame::JuliaStackFrame, command)
eval_res
end

function maybe_quote(x)
(isa(x, Expr) || isa(x, Symbol)) ? QuoteNode(x) : x
end

function DebuggerFramework.print_next_state(io::IO, state, frame::JuliaStackFrame)
print(io, "About to run: ")
expr = pc_expr(frame, frame.pc)
Expand All @@ -191,7 +195,7 @@ function DebuggerFramework.print_next_state(io::IO, state, frame::JuliaStackFram
expr = expr.args[2]
end
if isexpr(expr, :call) || isexpr(expr, :return)
expr.args = map(var->lookup_var_if_var(frame, var), expr.args)
expr.args = map(var->maybe_quote(lookup_var_if_var(frame, var)), expr.args)
end
if isa(expr, Expr)
for (i, arg) in enumerate(expr.args)
Expand Down
6 changes: 5 additions & 1 deletion src/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ lookup_var(frame, ref::GlobalRef) = getfield(ref.mod, ref.name)
lookup_var(frame, slot::SlotNumber) = get(frame.locals[slot.id])
function lookup_var(frame, e::Expr)
isexpr(e, :the_exception) && return get(frame.last_exception[])
isexpr(e, :boundscheck) && return true
isexpr(e, :static_parameter) || error()
frame.sparams[e.args[1]]
end
Expand Down Expand Up @@ -86,6 +87,9 @@ function _step_expr(frame, pc)
rhs = (isexpr(node.args[2], :call) || isexpr(node.args[2], :foreigncall)) ? evaluate_call(frame, node.args[2]) :
lookup_var_if_var(frame, node.args[2])
end
if isa(rhs, QuoteNode)
rhs = rhs.value
end
do_assignment!(frame, lhs, rhs)
# Special case hack for readability.
# ret = rhs
Expand Down Expand Up @@ -214,4 +218,4 @@ function next_line!(frame, stack = nothing)
end
end
maybe_next_call!(frame, pc)
end
end
3 changes: 2 additions & 1 deletion test/evaling.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using DebuggerFramework
using ASTInterpreter2

# Simple evaling of function argument
Expand All @@ -20,4 +21,4 @@ res = DebuggerFramework.eval_code(nothing, frame, "x")
@assert res == 1

res = DebuggerFramework.eval_code(nothing, frame, "T")
@assert res == Int
@assert res == Int
12 changes: 11 additions & 1 deletion test/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,14 @@ function foo(n)
end


step_through(enter_call_expr(:($(foo)(20))))
step_through(enter_call_expr(:($(foo)(20))))

# Make sure that Symbols don't get an extra QuoteNode
function foo_sym()
x = :ok
typeof(x)
end

@assert step_through(enter_call_expr(:($(foo_sym)()))) == Symbol


0 comments on commit cc05800

Please sign in to comment.