mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 13:11:32 +00:00
implement support for setting indexed values
This commit is contained in:
@ -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())
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user