reassign values
Some checks failed
Build / build (push) Failing after 1m46s
Test / build (push) Has been cancelled

This commit is contained in:
Chuck Smith
2024-03-15 15:24:48 -04:00
parent c818591f79
commit 2988719c9c
13 changed files with 327 additions and 17 deletions

View File

@@ -158,6 +158,17 @@ func (vm *VM) Run() error {
vm.globals[globalIndex] = vm.pop()
case code.OpAssign:
ident := vm.pop()
val := vm.pop()
obj, ok := ident.(object.Mutable)
if !ok {
return fmt.Errorf("cannot assign to %s", ident.Type())
}
obj.Set(val)
case code.OpGetGlobal:
globalIndex := code.ReadUint16(ins[ip+1:])
vm.currentFrame().ip += 2