Refactor Type to be an int
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user