Skip to content

Commit

Permalink
Merge pull request #4 from JuliaDebug/teh/fix_3
Browse files Browse the repository at this point in the history
 Properly resolve the library symbol in :foreigncall (fixes #3)
  • Loading branch information
timholy committed Feb 7, 2019
2 parents 82b37e2 + dd5cc4c commit e9c1bc4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/JuliaInterpreter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 14 additions & 3 deletions src/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e9c1bc4

Please sign in to comment.