Files
monkey/internal/builtins/hash.go
Charles Smith aebbe43999
Some checks failed
Build / build (push) Successful in 10m25s
Publish Image / publish (push) Failing after 39s
Test / build (push) Successful in 11m19s
Fix VM memory allocation optimizations by reducing what we allocate on the heap
2024-03-31 20:44:50 -04:00

23 lines
451 B
Go

package builtins
import (
"monkey/internal/object"
"monkey/internal/typing"
)
// HashOf ...
func HashOf(args ...object.Object) object.Object {
if err := typing.Check(
"hash", args,
typing.ExactArgs(1),
); err != nil {
return newError(err.Error())
}
if hash, ok := args[0].(object.Hashable); ok {
return object.Integer{Value: int64(hash.HashKey().Value)}
}
return newError("TypeError: hash() expected argument #1 to be hashable")
}