From adecda8c2de220925fb0ac6e489747227c99c6fa Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Thu, 7 Feb 2019 08:26:56 -0600 Subject: [PATCH 1/2] Fix naming These lines aren't currently used, but someday they might be. --- src/JuliaInterpreter.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/JuliaInterpreter.jl b/src/JuliaInterpreter.jl index e4767a92dac02..ac9e94290108b 100644 --- a/src/JuliaInterpreter.jl +++ b/src/JuliaInterpreter.jl @@ -424,11 +424,11 @@ end function renumber_ssa!(stmts::Vector{Any}, ssalookup) for (i, stmt) in enumerate(stmts) if isa(stmt, GotoNode) - new_code[i] = GotoNode(ssalookup[stmt.label]) + stmts[i] = GotoNode(ssalookup[stmt.label]) elseif isa(stmt, SSAValue) - new_code[i] = SSAValue(ssalookup[stmt.id]) + stmts[i] = SSAValue(ssalookup[stmt.id]) elseif isa(stmt, NewSSAValue) - new_code[i] = SSAValue(stmt.id) + stmts[i] = SSAValue(stmt.id) elseif isa(stmt, Expr) replace_ssa!(stmt, ssalookup) if stmt.head == :gotoifnot && isa(stmt.args[2], Int) From dd5cc4cf1086360e62d904f4a36d0921e545a766 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Thu, 7 Feb 2019 08:27:38 -0600 Subject: [PATCH 2/2] Properly resolve the library symbol in :foreigncall (fixes #3) --- src/interpret.jl | 17 ++++++++++++++--- test/interpret.jl | 4 ++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/interpret.jl b/src/interpret.jl index dccb061a72292..d883daebc4cab 100644 --- a/src/interpret.jl +++ b/src/interpret.jl @@ -106,11 +106,22 @@ end instantiate_type_in_env(arg, spsig, spvals) = ccall(:jl_instantiate_type_in_env, Any, (Any, Any, Ptr{Any}), arg, spsig, spvals) -function collect_args(frame, call_expr) +function resolvefc(expr) + (isa(expr, Symbol) || isa(expr, String) || isa(expr, QuoteNode)) && return expr + if isexpr(expr, :call) + a = expr.args[1] + (isa(a, QuoteNode) && a.value == Core.tuple) || error("unexpected ccall to ", expr) + return Expr(:call, GlobalRef(Core, :tuple), expr.args[2:end]...) + end + error("unexpected ccall to ", expr) +end + +function collect_args(frame, call_expr; isfc=false) args = frame.callargs resize!(args, length(call_expr.args)) mod = moduleof(frame) - for i = 1:length(args) + args[1] = isfc ? resolvefc(call_expr.args[1]) : @lookup(mod, frame, call_expr.args[1]) + for i = 2:length(args) args[i] = @lookup(mod, frame, call_expr.args[i]) end return args @@ -123,7 +134,7 @@ Evaluate a `:foreigncall` (from a `ccall`) statement `callexpr` in the context o `stack` and `pc` are unused, but supplied for consistency with [`evaluate_call!`](@ref). """ function evaluate_foreigncall!(stack, frame::JuliaStackFrame, call_expr::Expr, pc) - args = collect_args(frame, call_expr) + args = collect_args(frame, call_expr; isfc=true) for i = 1:length(args) arg = args[i] args[i] = isa(arg, Symbol) ? QuoteNode(arg) : arg diff --git a/test/interpret.jl b/test/interpret.jl index af78f1694aef5..0790daa409db7 100644 --- a/test/interpret.jl +++ b/test/interpret.jl @@ -29,3 +29,7 @@ end fkw(x::Int8; y=0, z="hello") = y @test @interpret(fkw(Int8(1); y=22, z="world")) == fkw(Int8(1); y=22, z="world") + +# issue #3 +@test @interpret(joinpath("/home/julia/base", "sysimg.jl")) == "/home/julia/base/sysimg.jl" +@test @interpret(10.0^4) == 10.0^4