@@ -143,6 +143,7 @@ class WasmBuilder {
143143
144144 val className = clazz.name.name
145145 val typeRef = IRTypes .ClassRef (className)
146+ val classInfo = ctx.getClassInfo(className)
146147
147148 // generate vtable type, this should be done for both abstract and concrete classes
148149 val vtable = ctx.calculateVtableType(className)
@@ -185,7 +186,7 @@ class WasmBuilder {
185186 WasmRefType (WasmHeapType .Type (vtableType.name)),
186187 isMutable = false
187188 )
188- val fields = clazz.fields .map(transformField)
189+ val fields = classInfo.allFieldDefs .map(transformField)
189190 val structType = WasmStructType (
190191 Names .WasmTypeName .WasmStructTypeName (clazz.name.name),
191192 vtableField +: WasmStructField .itables +: fields,
@@ -195,7 +196,7 @@ class WasmBuilder {
195196
196197 // Define the `new` function, unless the class is abstract
197198 if (! isAbstractClass)
198- genStructNewDefault(clazz , Some (gVtable), gItable)
199+ genStructNewDefault(classInfo , Some (gVtable), gItable)
199200
200201 structType
201202 }
@@ -269,15 +270,17 @@ class WasmBuilder {
269270 }
270271
271272 private def genStructNewDefault (
272- clazz : LinkedClass ,
273+ classInfo : WasmClassInfo ,
273274 vtable : Option [WasmGlobal ],
274275 itable : Option [WasmGlobal ]
275276 )(implicit ctx : WasmContext ): Unit = {
277+ val className = classInfo.name
278+
276279 val getVTable = vtable match {
277280 case None =>
278281 REF_NULL (
279282 WasmImmediate .HeapType (
280- WasmHeapType .Type (WasmTypeName .WasmVTableTypeName (clazz.name.name ))
283+ WasmHeapType .Type (WasmTypeName .WasmVTableTypeName (className ))
281284 )
282285 )
283286 case Some (v) => GLOBAL_GET (WasmImmediate .GlobalIdx (v.name))
@@ -288,19 +291,19 @@ class WasmBuilder {
288291 }
289292 val defaultFields =
290293 getVTable +: getITable +:
291- clazz.fields.collect { case f : IRTrees . FieldDef =>
294+ classInfo.allFieldDefs.map { f =>
292295 val ty = transformType(f.ftpe)
293296 Defaults .defaultValue(ty)
294297 }
295298
296- val className = WasmTypeName .WasmStructTypeName (clazz.name.name )
299+ val structName = WasmTypeName .WasmStructTypeName (className )
297300 val body =
298- defaultFields :+ STRUCT_NEW (WasmImmediate .TypeIdx (className ))
301+ defaultFields :+ STRUCT_NEW (WasmImmediate .TypeIdx (structName ))
299302 val sig =
300- WasmFunctionSignature (Nil , List (WasmRefType (WasmHeapType .Type (className ))))
303+ WasmFunctionSignature (Nil , List (WasmRefType (WasmHeapType .Type (structName ))))
301304 val newDefaultTypeName = ctx.addFunctionType(sig)
302305 val func = WasmFunction (
303- WasmFunctionName .newDefault(clazz.name.name ),
306+ WasmFunctionName .newDefault(className ),
304307 WasmFunctionType (newDefaultTypeName, sig),
305308 Nil ,
306309 WasmExpr (body)
@@ -467,17 +470,10 @@ class WasmBuilder {
467470 }
468471
469472 private def transformField (
470- field : IRTrees .AnyFieldDef
473+ field : IRTrees .FieldDef
471474 )(implicit ctx : WasmContext ): WasmStructField = {
472- val fieldName =
473- field match {
474- case f : IRTrees .FieldDef =>
475- Names .WasmFieldName (f.name.name)
476- // TODO
477- case js : IRTrees .JSFieldDef => ???
478- }
479475 WasmStructField (
480- fieldName ,
476+ Names . WasmFieldName (field.name.name) ,
481477 transformType(field.ftpe),
482478 // needs to be mutable even if it's flags.isMutable = false
483479 // because it's initialized by constructor
0 commit comments