@@ -151,13 +151,12 @@ extension Execution {
151
151
)
152
152
return pc. next ( )
153
153
}
154
-
154
+
155
155
mutating func returnCall( sp: inout Sp , pc: Pc , md: inout Md , ms: inout Ms , immediate: Instruction . ReturnCallOperand ) throws -> ( Pc , CodeSlot ) {
156
156
var pc = pc
157
157
( pc, sp) = try tailInvoke (
158
158
function: immediate. callee,
159
159
callerInstance: currentInstance ( sp: sp) ,
160
- spAddend: 0 ,
161
160
sp: sp, pc: pc, md: & md, ms: & ms
162
161
)
163
162
return pc. next ( )
@@ -172,13 +171,38 @@ extension Execution {
172
171
( pc, sp) = try tailInvoke (
173
172
function: function,
174
173
callerInstance: callerInstance,
175
- spAddend: 0 ,
176
174
sp: sp, pc: pc, md: & md, ms: & ms
177
175
)
178
176
return pc. next ( )
179
177
}
180
178
181
179
mutating func resizeFrameHeader( sp: inout Sp , immediate: Instruction . ResizeFrameHeaderOperand ) throws {
180
+ // The params/results space are resized by `delta` slots and the rest of the
181
+ // frame is copied to the new location. See the following diagram for the
182
+ // layout of the frame before and after the resize operation:
183
+ //
184
+ //
185
+ // |--------BEFORE-------| |--------AFTER--------|
186
+ // | Params | Results | | Params | Results |
187
+ // | ... | ... | | ... | ... |
188
+ // Old Header ->|---------------------|\ | ... | ... | -+
189
+ // | Sp | \ | ... | ... | | delta
190
+ // |---------------------| \|---------------------|<- New Header -+ -+
191
+ // | Pc | | Sp | |
192
+ // |---------------------| |---------------------| |
193
+ // | Current Func | C | Pc | |
194
+ // Old Sp ->|---------------------| O |---------------------| |
195
+ // | Locals | P | Current Func | |
196
+ // | ... | Y |---------------------|<- New Sp |
197
+ // |---------------------| | Locals | | sizeToCopy
198
+ // | Consts | | ... | |
199
+ // | ... | |---------------------| |
200
+ // |---------------------| | Consts | |
201
+ // | Value Stack | | ... | |
202
+ // | ... | |---------------------| |
203
+ // |---------------------|\ | Value Stack | |
204
+ // \ | ... | |
205
+ // \|---------------------| -+
182
206
let newSp = sp. advanced ( by: Int ( immediate. delta) )
183
207
try checkStackBoundary ( newSp)
184
208
let oldFrameHeader = sp. advanced ( by: - FrameHeaderLayout. numberOfSavingSlots)
0 commit comments