fixed mutability
Some checks failed
Build / build (push) Failing after 1m30s
Test / build (push) Failing after 12m1s

This commit is contained in:
Chuck Smith
2024-03-15 15:50:11 -04:00
parent 80f1a2d78c
commit 7463b3af39
7 changed files with 37 additions and 118 deletions

View File

@@ -157,22 +157,23 @@ func (vm *VM) Run() error {
vm.currentFrame().ip += 2
ref := vm.pop()
if mutable, ok := ref.(object.Mutable); ok {
vm.globals[globalIndex] = mutable.Clone()
if immutable, ok := ref.(object.Immutable); ok {
vm.globals[globalIndex] = immutable.Clone()
} else {
vm.globals[globalIndex] = ref
}
case code.OpAssign:
ident := vm.pop()
val := vm.pop()
case code.OpAssignGlobal:
globalIndex := code.ReadUint16(ins[ip+1:])
vm.currentFrame().ip += 2
vm.globals[globalIndex] = vm.pop()
obj, ok := ident.(object.Mutable)
if !ok {
return fmt.Errorf("cannot assign to %s", ident.Type())
}
case code.OpAssignLocal:
localIndex := code.ReadUint8(ins[ip+1:])
vm.currentFrame().ip += 1
obj.Set(val)
frame := vm.currentFrame()
vm.stack[frame.basePointer+int(localIndex)] = vm.pop()
case code.OpGetGlobal:
globalIndex := code.ReadUint16(ins[ip+1:])