reassign values
This commit is contained in:
11
vm/vm.go
11
vm/vm.go
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user