133
133
struct NOOPInstruction <: AbstractInstruction end
134
134
135
135
@inline result (t:: TapedFunction ) = t. binding_values[t. retval_binding_slot]
136
+ @inline function _arg (tf:: TapedFunction , i:: Int ; default= nothing )
137
+ length (tf. arg_binding_slots) < i && return default
138
+ tf. arg_binding_slots[i] > 0 && return tf. binding_values[tf. arg_binding_slots[i]]
139
+ return default
140
+ end
141
+ @inline function _arg! (tf:: TapedFunction , i:: Int , v)
142
+ length (tf. arg_binding_slots) >= i &&
143
+ tf. arg_binding_slots[i] > 0 && _update_var! (tf, tf. arg_binding_slots[i], v)
144
+ end
136
145
137
146
function (tf:: TapedFunction )(args... ; callback= nothing , continuation= false )
138
147
if ! continuation # reset counter and retval_binding_slot to run from the start
@@ -143,10 +152,10 @@ function (tf::TapedFunction)(args...; callback=nothing, continuation=false)
143
152
# set args
144
153
if tf. counter <= 1
145
154
# The first slot in `binding_values` is assumed to be `tf.func`.
146
- tf . arg_binding_slots[ 1 ] > 0 && _update_var ! (tf, tf . arg_binding_slots[ 1 ] , tf. func)
155
+ _arg ! (tf, 1 , tf. func)
147
156
for i in 1 : length (args) # the subsequent arg_binding_slots are arguments
148
157
slot = i + 1
149
- tf . arg_binding_slots[slot] > 0 && _update_var ! (tf, tf . arg_binding_slots[ slot] , args[i])
158
+ _arg ! (tf, slot, args[i])
150
159
end
151
160
end
152
161
@@ -314,7 +323,7 @@ function translate!(tape::RawTape, ir::Core.CodeInfo)
314
323
for (k, v) in bcache
315
324
isa (k, Core. SlotNumber) && (slots[k. id] = v)
316
325
end
317
- arg_binding_slots = fill (0 , maximum (keys (slots)))
326
+ arg_binding_slots = fill (0 , maximum (keys (slots); init = 0 ))
318
327
for (k, v) in slots
319
328
arg_binding_slots[k] = v
320
329
end
0 commit comments