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

@ -15,6 +15,7 @@ val StandardOpHandlers: List<OpHandler> = listOf(
ListSizeOpHandler,
IndexOpHandler,
IndexSetOpHandler,
AndOpHandler,
OrOpHandler,

View File

@ -0,0 +1,15 @@
package gay.pizza.pork.vm.ops
import gay.pizza.pork.bytecode.Op
import gay.pizza.pork.bytecode.Opcode
import gay.pizza.pork.vm.InternalMachine
import gay.pizza.pork.vm.OpHandler
object IndexSetOpHandler : OpHandler(Opcode.IndexSet) {
override fun handle(machine: InternalMachine, op: Op) {
val list = machine.pop<MutableList<Any>>()
val index = machine.pop<Number>().toInt()
val value = machine.pop<Any>()
list[index] = value
}
}

View File

@ -13,6 +13,6 @@ object ListMakeOpHandler : OpHandler(Opcode.ListMake) {
val item = machine.popAnyValue()
list.add(item)
}
machine.push(list.reversed())
machine.push(list.reversed().toMutableList())
}
}