@@ -22,6 +22,42 @@ object CoreWasmLib {
22
22
23
23
private implicit val noPos : Position = Position .NoPosition
24
24
25
+ /** Fields of the `typeData` struct definition.
26
+ *
27
+ * They are accessible as a public list because they must be repeated in every vtable type
28
+ * definition.
29
+ *
30
+ * @see
31
+ * [[VarGen.genFieldName.typeData ]], which contains documentation of what is in each field.
32
+ */
33
+ val typeDataStructFields : List [WasmStructField ] = {
34
+ import genFieldName .typeData ._
35
+ import WasmRefType .nullable
36
+ List (
37
+ WasmStructField (nameOffset, WasmInt32 , isMutable = false ),
38
+ WasmStructField (nameSize, WasmInt32 , isMutable = false ),
39
+ WasmStructField (nameStringIndex, WasmInt32 , isMutable = false ),
40
+ WasmStructField (kind, WasmInt32 , isMutable = false ),
41
+ WasmStructField (specialInstanceTypes, WasmInt32 , isMutable = false ),
42
+ WasmStructField (strictAncestors, nullable(genTypeName.typeDataArray), isMutable = false ),
43
+ WasmStructField (componentType, nullable(genTypeName.typeData), isMutable = false ),
44
+ WasmStructField (name, WasmRefType .anyref, isMutable = true ),
45
+ WasmStructField (classOfValue, nullable(genTypeName.ClassStruct ), isMutable = true ),
46
+ WasmStructField (arrayOf, nullable(genTypeName.ObjectVTable ), isMutable = true ),
47
+ WasmStructField (cloneFunction, nullable(genTypeName.cloneFunctionType), isMutable = false ),
48
+ WasmStructField (
49
+ isJSClassInstance,
50
+ nullable(genTypeName.isJSClassInstanceFuncType),
51
+ isMutable = false
52
+ ),
53
+ WasmStructField (
54
+ reflectiveProxies,
55
+ WasmRefType (genTypeName.reflectiveProxies),
56
+ isMutable = false
57
+ )
58
+ )
59
+ }
60
+
25
61
/** Generates definitions that must come *before* the code generated for regular classes.
26
62
*
27
63
* This notably includes the `typeData` definitions, since the vtable of `jl.Object` is a subtype
@@ -66,6 +102,19 @@ object CoreWasmLib {
66
102
}
67
103
68
104
private def genCoreTypesInRecType ()(implicit ctx : WasmContext ): Unit = {
105
+ ctx.mainRecType.addSubType(
106
+ genTypeName.cloneFunctionType,
107
+ WasmFunctionType (
108
+ List (WasmRefType (genTypeName.ObjectStruct )),
109
+ List (WasmRefType (genTypeName.ObjectStruct ))
110
+ )
111
+ )
112
+
113
+ ctx.mainRecType.addSubType(
114
+ genTypeName.isJSClassInstanceFuncType,
115
+ WasmFunctionType (List (WasmRefType .anyref), List (WasmInt32 ))
116
+ )
117
+
69
118
ctx.mainRecType.addSubType(
70
119
genTypeName.typeDataArray,
71
120
WasmArrayType (WasmFieldType (WasmRefType (genTypeName.typeData), isMutable = false ))
@@ -84,7 +133,7 @@ object CoreWasmLib {
84
133
genTypeName.typeData,
85
134
isFinal = false ,
86
135
None ,
87
- WasmStructType (ctx. typeDataStructFields)
136
+ WasmStructType (typeDataStructFields)
88
137
)
89
138
)
90
139
@@ -148,7 +197,7 @@ object CoreWasmLib {
148
197
149
198
private def genTags ()(implicit ctx : WasmContext ): Unit = {
150
199
val exceptionSig = WasmFunctionSignature (List (WasmRefType .externref), Nil )
151
- val typeName = ctx.addFunctionType (exceptionSig)
200
+ val typeName = ctx.moduleBuilder.signatureToTypeName (exceptionSig)
152
201
ctx.moduleBuilder.addImport(
153
202
WasmImport (
154
203
" __scalaJSHelpers" ,
@@ -287,7 +336,7 @@ object CoreWasmLib {
287
336
results : List [WasmType ]
288
337
): Unit = {
289
338
val sig = WasmFunctionSignature (params, results)
290
- val typeName = ctx.addFunctionType (sig)
339
+ val typeName = ctx.moduleBuilder.signatureToTypeName (sig)
291
340
ctx.moduleBuilder.addImport(
292
341
WasmImport (" __scalaJSHelpers" , name.name, WasmImportDesc .Func (name, typeName))
293
342
)
@@ -932,7 +981,7 @@ object CoreWasmLib {
932
981
instrs += REF_NULL (WasmHeapType .None ) // arrayOf
933
982
934
983
// clone
935
- instrs.switch(WasmRefType (ctx.cloneFunctionTypeName )) { () =>
984
+ instrs.switch(WasmRefType (genTypeName.cloneFunctionType )) { () =>
936
985
instrs += LOCAL_GET (typeDataParam)
937
986
instrs += STRUCT_GET (genTypeName.typeData, genFieldIdx.typeData.kindIdx)
938
987
}(
@@ -1104,7 +1153,7 @@ object CoreWasmLib {
1104
1153
instrs += BR_ON_NULL (isJSClassInstanceIsNull)
1105
1154
1106
1155
// Call the function
1107
- instrs += CALL_REF (ctx.isJSClassInstanceFuncTypeName )
1156
+ instrs += CALL_REF (genTypeName.isJSClassInstanceFuncType )
1108
1157
instrs += RETURN
1109
1158
}
1110
1159
instrs += DROP // drop `value` which was left on the stack
@@ -2073,7 +2122,7 @@ object CoreWasmLib {
2073
2122
val fb = newFunctionBuilder(genFunctionName.clone(baseRef))
2074
2123
val fromParam = fb.addParam(" from" , WasmRefType (genTypeName.ObjectStruct ))
2075
2124
fb.setResultType(WasmRefType (genTypeName.ObjectStruct ))
2076
- fb.setFunctionType(ctx.cloneFunctionTypeName )
2125
+ fb.setFunctionType(genTypeName.cloneFunctionType )
2077
2126
2078
2127
val instrs = fb
2079
2128
0 commit comments