implement support for setting indexed values

This commit is contained in:
Alex Zenla
2025-07-26 17:01:24 -07:00
parent 48e19a8068
commit 3dcac2f9e6
26 changed files with 201 additions and 44 deletions

View File

@ -228,6 +228,12 @@ class AstIrEmitter(
index = visit(node.index)
)
override fun visitIndexedSetAssignment(node: IndexedSetAssignment): IrCodeElement = IrIndex(
data = visit(node.target),
index = visit(node.index),
value = visit(node.value),
)
override fun visitInfixOperation(node: InfixOperation): IrCodeElement {
val op = when (node.op) {
InfixOperator.Plus -> IrInfixOp.Add
@ -288,7 +294,7 @@ class AstIrEmitter(
override fun visitReturn(node: Return): IrCodeElement =
IrReturn(from = self, value = node.value.visit(this))
override fun visitSetAssignment(node: SetAssignment): IrCodeElement {
override fun visitSymbolSetAssignment(node: SymbolSetAssignment): IrCodeElement {
val symbol = lookupLocalVariable(node.symbol) ?:
throw CompileError("Unable to find local variable target '${node.symbol.id}'", node)
return IrStore(symbol, node.value.visit(this))

View File

@ -248,9 +248,16 @@ class IrStubOpEmitter(val irDefinition: IrDefinition, val code: CodeBuilder) : I
}
override fun visitIrIndex(ir: IrIndex) {
if (ir.value != null) {
visit(ir.value!!)
}
visit(ir.index)
visit(ir.data)
code.emit(Opcode.Index)
if (ir.value != null) {
code.emit(Opcode.IndexSet)
} else {
code.emit(Opcode.Index)
}
}
override fun visitIrListSize(ir: IrListSize) {