implement support for setting indexed values

This commit is contained in:
alex committed 2025-07-26 17:01:24 -07:00
1 parent 48e19a8068
commit 3dcac2f9e6
26 files changed
+201 -44

No files matched your search

@@ -15,6 +15,7 @@ val StandardOpHandlers: List<OpHandler> = listOf(
ListSizeOpHandler,
IndexOpHandler,
IndexSetOpHandler,
AndOpHandler,
OrOpHandler,
@@ -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
}
}
@@ -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())
}
}