@@ -17,22 +17,45 @@ function finish!(frame)
1717 end
1818end
1919
20+ instantiate_type_in_env (arg, spsig, spvals) =
21+ ccall (:jl_instantiate_type_in_env , Any, (Any, Any, Ptr{Any}), arg, spsig, spvals)
22+
2023function evaluate_call (frame, call_expr)
21- # Don't go through eval since this may have unqouted, symbols and
22- # exprs
23- f = to_function (lookup_var (frame, call_expr. args[1 ]))
24- args = Array {Any} (length (call_expr. args)- 1 )
24+ args = Array {Any} (length (call_expr. args))
2525 for i = 1 : length (args)
26- arg = call_expr. args[i+ 1 ]
27- args[i] = isa (arg, Union{SSAValue, GlobalRef, Slot}) ? lookup_var (frame, arg) :
28- arg
26+ arg = call_expr. args[i]
27+ if isa (arg, QuoteNode)
28+ args[i] = arg. value
29+ elseif isa (arg, Union{SSAValue, GlobalRef, Slot})
30+ args[i] = lookup_var (frame, arg)
31+ elseif isexpr (arg, :& )
32+ args[i] = Expr (:& , lookup_var (frame, arg. args[1 ]))
33+ else
34+ args[i] = arg
35+ end
2936 end
30- if isa (f, CodeInfo)
31- ret = finish! (enter_call_expr (frame, call_expr))
37+ # Don't go through eval since this may have unqouted, symbols and
38+ # exprs
39+ if isexpr (call_expr, :foreigncall )
40+ args = map (args) do arg
41+ isa (arg, Symbol) ? QuoteNode (arg) : arg
42+ end
43+ if ! isempty (frame. sparams)
44+ args[2 ] = instantiate_type_in_env (args[2 ], frame. meth. sig, frame. sparams)
45+ args[3 ] = Core. svec (map (args[3 ]) do arg
46+ instantiate_type_in_env (arg, frame. meth. sig, frame. sparams)
47+ end ... )
48+ end
49+ ret = eval (frame. meth. module, Expr (:foreigncall , args... ))
3250 else
33- # Don't go through eval since this may have unqouted, symbols and
34- # exprs
35- ret = f (args... )
51+ f = to_function (args[1 ])
52+ if isa (f, CodeInfo)
53+ ret = finish! (enter_call_expr (frame, call_expr))
54+ else
55+ # Don't go through eval since this may have unqouted, symbols and
56+ # exprs
57+ ret = f (args[2 : end ]. .. )
58+ end
3659 end
3760 return ret
3861end
@@ -56,8 +79,13 @@ function _step_expr(frame, pc)
5679 if isa (node, Expr)
5780 if node. head == :(= )
5881 lhs = node. args[1 ]
59- rhs = isexpr (node. args[2 ], :call ) ? evaluate_call (frame, node. args[2 ]) :
60- lookup_var (frame, node. args[2 ])
82+ if isexpr (node. args[2 ], :new )
83+ new_expr = Expr (:new , map (x-> lookup_var_if_var (frame, x), node. args[2 ]. args)... )
84+ rhs = eval (frame. meth. module, new_expr)
85+ else
86+ rhs = (isexpr (node. args[2 ], :call ) || isexpr (node. args[2 ], :foreigncall )) ? evaluate_call (frame, node. args[2 ]) :
87+ lookup_var_if_var (frame, node. args[2 ])
88+ end
6189 do_assignment! (frame, lhs, rhs)
6290 # Special case hack for readability.
6391 # ret = rhs
@@ -66,19 +94,19 @@ function _step_expr(frame, pc)
6694 ret = node
6795 elseif node. head == :gotoifnot
6896 ret = node
69- arg = lookup_var (frame, node. args[1 ])
97+ arg = node. args[1 ]
98+ arg = isa (arg, Bool) ? arg : lookup_var (frame, arg)
7099 if ! isa (arg, Bool)
71100 throw (TypeError (frame. meth. name, " if" , Bool, node. args[1 ]))
72101 end
73102 if ! arg
74103 return JuliaProgramCounter (node. args[2 ])
75104 end
76- elseif node. head == :call
105+ elseif node. head == :call || node . head == :foreigncall
77106 evaluate_call (frame, node)
78107 elseif node. head == :static_typeof
79108 ret = Any
80- elseif node. head == :type_goto
81- ret = nothing
109+ elseif node. head == :type_goto || node. head == :inbounds
82110 elseif node. head == :enter
83111 push! (interp. exception_frames, node. args[1 ])
84112 ret = node
@@ -95,7 +123,7 @@ function _step_expr(frame, pc)
95123 ret = eval (node)
96124 end
97125 elseif isa (node, GotoNode)
98- return JuliaProgramCounter (node. args[ 1 ] )
126+ return JuliaProgramCounter (node. label )
99127 elseif isa (node, QuoteNode)
100128 ret = node. value
101129 else
@@ -154,20 +182,9 @@ isgotonode(node) = isa(node, GotoNode) || isexpr(node, :gotoifnot)
154182Determine whether we are calling a function for which the current function
155183is a wrapper (either because of optional arguments or becaue of keyword arguments).
156184"""
157- function iswrappercall (interp, expr)
158- ! isexpr (expr, :call ) && return false
159- r = determine_method_for_expr (interp, expr; enter_generated = false )
160- if r != = nothing
161- linfo, method, args, _ = r
162- ours, theirs = interp. linfo. def, method
163- # Check if this a method of the same function that shares a definition line/file.
164- # If so, we're likely in an automatically generated wrapper.
165- if ours. sig. parameters[1 ] == theirs. sig. parameters[1 ] &&
166- ours. line == theirs. line && ours. file == theirs. file
167- return true
168- end
169- end
170- return false
185+ function iswrappercall (expr)
186+ isexpr (expr, :(= )) && (expr = expr. args[2 ])
187+ isexpr (expr, :call ) && any (x-> x== SlotNumber (1 ), expr. args)
171188end
172189
173190pc_expr (frame, pc) = frame. code. code[pc. next_stmt]
@@ -181,7 +198,7 @@ function maybe_next_call!(frame, pc)
181198end
182199maybe_next_call! (frame) = maybe_next_call! (frame, frame. pc)
183200
184- function next_line! (frame; state = nothing )
201+ function next_line! (frame, stack = nothing )
185202 didchangeline = false
186203 fls = determine_line_and_file (frame, frame. pc. next_stmt)
187204 line = fls[1 ][2 ]
@@ -198,9 +215,13 @@ function next_line!(frame; state = nothing)
198215 pc == nothing && return nothing
199216 fls = determine_line_and_file (frame, pc. next_stmt)
200217 didchangeline = line != fls[1 ][2 ]
201- elseif iswrappercall (frame, pc_expr (frame, pc))
202- interp. did_wrappercall = true
203- frame = enter_call_expr (frame, pc_expr (frame, pc))
218+ elseif stack != = nothing && iswrappercall (pc_expr (frame, pc))
219+ stack[1 ] = JuliaStackFrame (frame, pc; wrapper = true )
220+ call_expr = pc_expr (frame, pc)
221+ isexpr (call_expr, :(= )) && (call_expr = call_expr. args[2 ])
222+ frame = enter_call_expr (Expr (:call , map (x-> lookup_var_if_var (frame, x), call_expr. args)... ))
223+ unshift! (stack, frame)
224+ pc = frame. pc
204225 elseif isa (pc_expr (frame, pc), LineNumberNode)
205226 line != pc_expr (frame, pc). line && break
206227 pc = _step_expr (frame, pc)
0 commit comments