[Wasm] Use Wasm GC arrays instead of JS arrays
JS arrays was a workaround for lack of arrays in Firefox Wasm GC prototype Now with V8 as a test runner we can use proper arrays
This commit is contained in:
@@ -145,6 +145,11 @@ class WasmStructDeclaration(
|
||||
val fields: List<WasmStructFieldDeclaration>
|
||||
) : WasmTypeDeclaration(name)
|
||||
|
||||
class WasmArrayDeclaration(
|
||||
name: String,
|
||||
val field: WasmStructFieldDeclaration
|
||||
) : WasmTypeDeclaration(name)
|
||||
|
||||
class WasmStructFieldDeclaration(
|
||||
val name: String,
|
||||
val type: WasmType,
|
||||
|
||||
@@ -26,7 +26,7 @@ class WasmIrToBinary(outputStream: OutputStream, val module: WasmModule) {
|
||||
gcTypes.forEach {
|
||||
when (it) {
|
||||
is WasmStructDeclaration -> appendStructTypeDeclaration(it)
|
||||
else -> TODO("Support arrays")
|
||||
is WasmArrayDeclaration -> appendArrayTypeDeclaration(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,15 +197,24 @@ class WasmIrToBinary(outputStream: OutputStream, val module: WasmModule) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun appendFiledType(field: WasmStructFieldDeclaration) {
|
||||
appendType(field.type)
|
||||
b.writeVarUInt1(field.isMutable)
|
||||
}
|
||||
|
||||
private fun appendStructTypeDeclaration(type: WasmStructDeclaration) {
|
||||
b.writeVarInt7(-0x21)
|
||||
b.writeVarUInt32(type.fields.size)
|
||||
type.fields.forEach {
|
||||
appendType(it.type)
|
||||
b.writeVarUInt1(it.isMutable)
|
||||
appendFiledType(it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun appendArrayTypeDeclaration(type: WasmArrayDeclaration) {
|
||||
b.writeVarInt7(-0x22)
|
||||
appendFiledType(type.field)
|
||||
}
|
||||
|
||||
val WasmFunctionType.index: Int
|
||||
get() = module.functionTypes.indexOf(this)
|
||||
|
||||
|
||||
@@ -201,8 +201,9 @@ class WasmIrToText : SExpressionBuilder() {
|
||||
when (it) {
|
||||
is WasmStructDeclaration ->
|
||||
appendStructTypeDeclaration(it)
|
||||
else ->
|
||||
TODO("Support arrays")
|
||||
is WasmArrayDeclaration ->
|
||||
appendArrayTypeDeclaration(it)
|
||||
else -> error("Unexpected GC type: $it")
|
||||
}
|
||||
}
|
||||
importsInOrder.forEach {
|
||||
@@ -253,6 +254,16 @@ class WasmIrToText : SExpressionBuilder() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun appendArrayTypeDeclaration(type: WasmArrayDeclaration) {
|
||||
newLineList("type") {
|
||||
appendModuleFieldReference(type)
|
||||
sameLineList("array") {
|
||||
appendStructField(type.field)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun appendImportedFunction(function: WasmFunction.Imported) {
|
||||
newLineList("func") {
|
||||
appendModuleFieldReference(function)
|
||||
|
||||
Reference in New Issue
Block a user