refactor objects
Some checks failed
Publish Image / publish (push) Waiting to run
Test / build (push) Waiting to run
Build / build (push) Has been cancelled

This commit is contained in:
2024-04-01 17:34:10 -04:00
parent 803f330e82
commit 99f7553d67
15 changed files with 101 additions and 94 deletions

View File

@@ -102,7 +102,7 @@ func (s *VMState) ExportedHash() *object.Hash {
if symbol.Scope == compiler.GlobalScope {
obj := s.Globals[symbol.Index]
s := object.String{Value: name}
pairs[s.HashKey()] = object.HashPair{Key: s, Value: obj}
pairs[s.Hash()] = object.HashPair{Key: s, Value: obj}
}
}
}
@@ -210,8 +210,8 @@ func (vm *VM) executeSetGlobal() error {
globalIndex := vm.currentFrame().ReadUint16()
ref := vm.pop()
if immutable, ok := ref.(object.Immutable); ok {
vm.state.Globals[globalIndex] = immutable.Clone()
if obj, ok := ref.(object.Copyable); ok {
vm.state.Globals[globalIndex] = obj.Copy()
} else {
vm.state.Globals[globalIndex] = ref
}
@@ -223,8 +223,8 @@ func (vm *VM) executeSetLocal() error {
localIndex := vm.currentFrame().ReadUint8()
ref := vm.pop()
if immutable, ok := ref.(object.Immutable); ok {
vm.stack[vm.currentFrame().basePointer+int(localIndex)] = immutable.Clone()
if obj, ok := ref.(object.Copyable); ok {
vm.stack[vm.currentFrame().basePointer+int(localIndex)] = obj.Copy()
} else {
vm.stack[vm.currentFrame().basePointer+int(localIndex)] = ref
}
@@ -241,12 +241,12 @@ func (vm *VM) buildHash(startIndex, endIndex int) (object.Object, error) {
pair := object.HashPair{Key: key, Value: value}
hashKey, ok := key.(object.Hashable)
hashKey, ok := key.(object.Hasher)
if !ok {
return nil, fmt.Errorf("unusable as hash key: %s", key.Type())
}
hashedPairs[hashKey.HashKey()] = pair
hashedPairs[hashKey.Hash()] = pair
}
return &object.Hash{Pairs: hashedPairs}, nil