Skip to content

Commit f92487c

Browse files
authored
Merge pull request #107 from JuliaDebug/teh/fix_105
Handle :cfunction exprs. Fixes #105
2 parents 22c954c + fd01f86 commit f92487c

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/interpret.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,13 @@ Evaluate a `:foreigncall` (from a `ccall`) statement `callexpr` in the context o
145145
`stack` and `pc` are unused, but supplied for consistency with [`evaluate_call!`](@ref).
146146
"""
147147
function evaluate_foreigncall!(stack, frame::JuliaStackFrame, call_expr::Expr, pc)
148-
args = collect_args(frame, call_expr; isfc=true)
148+
head = call_expr.head
149+
args = collect_args(frame, call_expr; isfc = head==:foreigncall)
149150
for i = 2:length(args)
150151
arg = args[i]
151152
args[i] = isa(arg, Symbol) ? QuoteNode(arg) : arg
152153
end
154+
head == :cfunction && (args[2] = QuoteNode(args[2]))
153155
scope = frame.code.scope
154156
if !isempty(frame.sparams) && scope isa Method
155157
sig = scope.sig
@@ -158,7 +160,7 @@ function evaluate_foreigncall!(stack, frame::JuliaStackFrame, call_expr::Expr, p
158160
instantiate_type_in_env(arg, sig, frame.sparams)
159161
end...)
160162
end
161-
return Core.eval(moduleof(frame), Expr(:foreigncall, args...))
163+
return Core.eval(moduleof(frame), Expr(head, args...))
162164
end
163165

164166
function evaluate_call!(::Compiled, frame::JuliaStackFrame, call_expr::Expr, pc; #=unused=# exec!::Function=finish_and_return!)
@@ -318,7 +320,7 @@ function eval_rhs(stack, frame, node::Expr, pc)
318320
return check_isdefined(frame, node.args[1])
319321
elseif head == :call
320322
return evaluate_call!(stack, frame, node, pc)
321-
elseif head == :foreigncall
323+
elseif head == :foreigncall || head == :cfunction
322324
return evaluate_foreigncall!(stack, frame, node, pc)
323325
elseif head == :copyast
324326
val = (node.args[1]::QuoteNode).value

test/interpret.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ ex = quote
145145
end
146146
frame = JuliaInterpreter.prepare_thunk(Main, ex)
147147
@test JuliaInterpreter.finish_and_return!(JuliaStackFrame[], frame, true) == 1
148+
function cfcfun()
149+
cf = @cfunction(fcfun, Int, (Int, Int))
150+
ccall(cf, Int, (Int, Int), 1, 2)
151+
end
152+
@test @interpret(cfcfun()) == 1
148153

149154
# From Julia's test/ambiguous.jl. This tests whether we renumber :enter statements correctly.
150155
ambig(x, y) = 1

0 commit comments

Comments
 (0)