@@ -151,13 +151,12 @@ extension Execution {
151151 )
152152 return pc. next ( )
153153 }
154-
154+
155155 mutating func returnCall( sp: inout Sp , pc: Pc , md: inout Md , ms: inout Ms , immediate: Instruction . ReturnCallOperand ) throws -> ( Pc , CodeSlot ) {
156156 var pc = pc
157157 ( pc, sp) = try tailInvoke (
158158 function: immediate. callee,
159159 callerInstance: currentInstance ( sp: sp) ,
160- spAddend: 0 ,
161160 sp: sp, pc: pc, md: & md, ms: & ms
162161 )
163162 return pc. next ( )
@@ -172,13 +171,38 @@ extension Execution {
172171 ( pc, sp) = try tailInvoke (
173172 function: function,
174173 callerInstance: callerInstance,
175- spAddend: 0 ,
176174 sp: sp, pc: pc, md: & md, ms: & ms
177175 )
178176 return pc. next ( )
179177 }
180178
181179 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+ // \|---------------------| -+
182206 let newSp = sp. advanced ( by: Int ( immediate. delta) )
183207 try checkStackBoundary ( newSp)
184208 let oldFrameHeader = sp. advanced ( by: - FrameHeaderLayout. numberOfSavingSlots)
0 commit comments