refactor objects
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user