@@ -214,16 +214,18 @@ struct FrameHeaderLayout {
214214
215215struct StackLayout {
216216 let frameHeader : FrameHeaderLayout
217- let constantSlotSize : Int = 8
217+ let constantSlotSize : Int
218218 let numberOfLocals : Int
219219
220220 var stackRegBase : VReg {
221221 return VReg ( numberOfLocals + constantSlotSize)
222222 }
223223
224- init ( type: FunctionType , numberOfLocals: Int ) {
224+ init ( type: FunctionType , numberOfLocals: Int , codeSize : Int ) {
225225 self . frameHeader = FrameHeaderLayout ( type: type)
226226 self . numberOfLocals = numberOfLocals
227+ // The number of constant slots is determined by the code size
228+ self . constantSlotSize = max ( codeSize / 20 , 4 )
227229 }
228230
229231 func localReg( _ index: LocalIndex ) -> VReg {
@@ -780,6 +782,7 @@ struct InstructionTranslator<Context: TranslatorContext>: InstructionVisitor {
780782 type: FunctionType ,
781783 locals: [ WasmTypes . ValueType ] ,
782784 functionIndex: FunctionIndex ,
785+ codeSize: Int ,
783786 intercepting: Bool
784787 ) {
785788 self . allocator = allocator
@@ -788,7 +791,11 @@ struct InstructionTranslator<Context: TranslatorContext>: InstructionVisitor {
788791 self . module = module
789792 self . iseqBuilder = ISeqBuilder ( runtimeConfiguration: runtimeConfiguration)
790793 self . controlStack = ControlStack ( )
791- self . stackLayout = StackLayout ( type: type, numberOfLocals: locals. count)
794+ self . stackLayout = StackLayout (
795+ type: type,
796+ numberOfLocals: locals. count,
797+ codeSize: codeSize
798+ )
792799 self . valueStack = ValueStack ( stackLayout: stackLayout)
793800 self . locals = Locals ( types: type. parameters + locals)
794801 self . functionIndex = functionIndex
0 commit comments