[Wasm] Require location for buildStructSet and fix all usages

This commit is contained in:
Zalim Bashorov
2022-12-13 19:17:53 +01:00
parent e7dc443c18
commit 158a307334
2 changed files with 6 additions and 2 deletions
@@ -220,17 +220,20 @@ class BodyGenerator(
val field = expression.symbol.owner
val receiver = expression.receiver
val location = expression.getSourceLocation()
if (receiver != null) {
generateExpression(receiver)
generateExpression(expression.value)
body.buildStructSet(
struct = context.referenceGcType(field.parentAsClass.symbol),
fieldId = context.getStructFieldRef(field),
location
)
body.commentPreviousInstr { "name: ${field.name}, type: ${field.type.render()}" }
} else {
generateExpression(expression.value)
body.buildSetGlobal(context.referenceGlobalField(expression.symbol), expression.getSourceLocation())
body.buildSetGlobal(context.referenceGlobalField(expression.symbol), location)
body.commentPreviousInstr { "type: ${field.type.render()}" }
}
@@ -158,9 +158,10 @@ abstract class WasmExpressionBuilder {
buildInstr(WasmOp.STRUCT_NEW, location, WasmImmediate.GcType(struct))
}
fun buildStructSet(struct: WasmSymbol<WasmTypeDeclaration>, fieldId: WasmSymbol<Int>) {
fun buildStructSet(struct: WasmSymbol<WasmTypeDeclaration>, fieldId: WasmSymbol<Int>, location: SourceLocation) {
buildInstr(
WasmOp.STRUCT_SET,
location,
WasmImmediate.GcType(struct),
WasmImmediate.StructFieldIdx(fieldId)
)