Skip to content

Commit

Permalink
always use QuoteNode in eval_code (#469)
Browse files Browse the repository at this point in the history
* always use QuoteNode in eval_code

* fix tests on older Julia versions

* bump patch version
  • Loading branch information
simeonschaub authored Mar 14, 2021
1 parent 97e15b5 commit d802426
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "JuliaInterpreter"
uuid = "aa1ae85d-cabe-5617-a682-6adf51b2e16a"
version = "0.8.10"
version = "0.8.11"

[deps]
CodeTracking = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"
Expand Down
7 changes: 3 additions & 4 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,6 @@ function eval_code end

eval_code(frame::Frame, command::AbstractString) = eval_code(frame, Base.parse_input_line(command))
function eval_code(frame::Frame, expr)
maybe_quote(x) = (isa(x, Expr) || isa(x, Symbol)) ? QuoteNode(x) : x
code = frame.framecode
data = frame.framedata
isexpr(expr, :toplevel) && (expr = expr.args[end])
Expand All @@ -633,9 +632,9 @@ function eval_code(frame::Frame, expr)
defined_locals = findall(x -> x isa Some, data.locals)
res = gensym()
eval_expr = Expr(:let,
Expr(:block, map(x->Expr(:(=), x...), [(v.name, maybe_quote(v.value isa Core.Box ? v.value.contents : v.value)) for v in vars])...,
map(x->Expr(:(=), x...), [(Symbol("%$i"), maybe_quote(data.ssavalues[i])) for i in defined_ssa])...,
map(x->Expr(:(=), x...), [(Symbol("@_$i"), maybe_quote(data.locals[i].value)) for i in defined_locals])...),
Expr(:block, map(x->Expr(:(=), x...), [(v.name, QuoteNode(v.value isa Core.Box ? v.value.contents : v.value)) for v in vars])...,
map(x->Expr(:(=), x...), [(Symbol("%$i"), QuoteNode(data.ssavalues[i])) for i in defined_ssa])...,
map(x->Expr(:(=), x...), [(Symbol("@_$i"), QuoteNode(data.locals[i].value)) for i in defined_locals])...),
Expr(:block,
Expr(:(=), res, expr),
Expr(:tuple, res, Expr(:tuple, [v.name for v in vars]...))
Expand Down
6 changes: 6 additions & 0 deletions test/eval_code.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,9 @@ JuliaInterpreter.step_expr!(fr)
@test eval_code(fr, "output") == :sym
eval_code(fr, "output = :foo")
@test eval_code(fr, "output") == :foo

let f() = GlobalRef(Main, :doesnotexist)
fr = JuliaInterpreter.enter_call(f)
JuliaInterpreter.step_expr!(fr)
@test eval_code(fr, Symbol("%1")) == GlobalRef(Main, :doesnotexist)
end

0 comments on commit d802426

Please sign in to comment.