Refactor Type to be an int
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:
Chuck Smith
2024-03-29 11:01:15 -04:00
parent f65d7bfb1c
commit 12d43c9835
58 changed files with 164 additions and 132 deletions

View File

@@ -3,24 +3,57 @@ package object
import "fmt"
// Type represents the type of an object
type ObjectType string
type Type int
const (
INTEGER_OBJ = "int"
BOOLEAN_OBJ = "bool"
NULL_OBJ = "null"
RETURN_VALUE_OBJ = "return"
ERROR_OBJ = "error"
FUNCTION_OBJ = "fn"
STRING_OBJ = "str"
BUILTIN_OBJ = "builtin"
ARRAY_OBJ = "array"
HASH_OBJ = "hash"
COMPILED_FUNCTION_OBJ = "COMPILED_FUNCTION"
CLOSURE_OBJ = "closure"
MODULE_OBJ = "module"
NullType = iota
IntegerType
StringType
BooleanType
ReturnType
ErrorType
FunctionType
CFunctionType
BuiltinType
ClosureType
ArrayType
HashType
ModuleType
)
func (t Type) String() string {
switch t {
case NullType:
return "null"
case IntegerType:
return "int"
case StringType:
return "str"
case BooleanType:
return "bool"
case ReturnType:
return "Return"
case ErrorType:
return "error"
case FunctionType:
return "fn"
case CFunctionType:
return "CFunction"
case BuiltinType:
return "Builtin"
case ClosureType:
return "Closure"
case ArrayType:
return "array"
case HashType:
return "hash"
case ModuleType:
return "module"
default:
return "???"
}
}
// Comparable is the interface for comparing two Object and their underlying
// values. It is the responsibility of the caller (left) to check for types.
// Returns `true` iif the types and values are identical, `false` otherwise.
@@ -45,7 +78,7 @@ type Immutable interface {
// `Type()` and `Inspect()` functions
type Object interface {
fmt.Stringer
Type() ObjectType
Type() Type
Bool() bool
Inspect() string
}