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

@@ -61,8 +61,8 @@ func Eval(node ast.Node, env *object.Environment) object.Object {
}
if ident, ok := node.Left.(*ast.Identifier); ok {
if immutable, ok := value.(object.Immutable); ok {
env.Set(ident.Value, immutable.Clone())
if obj, ok := value.(object.Copyable); ok {
env.Set(ident.Value, obj.Copy())
} else {
env.Set(ident.Value, value)
}
@@ -105,8 +105,8 @@ func Eval(node ast.Node, env *object.Environment) object.Object {
if isError(key) {
return key
}
if hashKey, ok := key.(object.Hashable); ok {
hashed := hashKey.HashKey()
if hashKey, ok := key.(object.Hasher); ok {
hashed := hashKey.Hash()
hash.Pairs[hashed] = object.HashPair{Key: key, Value: value}
} else {
return newError("cannot index hash with %T", key)
@@ -630,12 +630,12 @@ func evalStringIndexExpression(str, index object.Object) object.Object {
func evalHashIndexExpression(hash, index object.Object) object.Object {
hashObject := hash.(*object.Hash)
key, ok := index.(object.Hashable)
key, ok := index.(object.Hasher)
if !ok {
return newError("unusable as hash key: %s", index.Type())
}
pair, ok := hashObject.Pairs[key.HashKey()]
pair, ok := hashObject.Pairs[key.Hash()]
if !ok {
return NULL
}
@@ -664,7 +664,7 @@ func evalHashLiteral(node *ast.HashLiteral, env *object.Environment) object.Obje
return key
}
hashKey, ok := key.(object.Hashable)
hashKey, ok := key.(object.Hasher)
if !ok {
return newError("unusable as hash key: %s", key.Type())
}
@@ -674,7 +674,7 @@ func evalHashLiteral(node *ast.HashLiteral, env *object.Environment) object.Obje
return value
}
hashed := hashKey.HashKey()
hashed := hashKey.Hash()
pairs[hashed] = object.HashPair{
Key: key,
Value: value,