restructure project
This commit is contained in:
60
internal/object/object.go
Normal file
60
internal/object/object.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package object
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Type represents the type of an object
|
||||
type ObjectType string
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
// 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.
|
||||
type Comparable interface {
|
||||
Compare(other Object) int
|
||||
}
|
||||
|
||||
// Sizeable is the interface for returning the size of an Object.
|
||||
// Object(s) that have a valid size must implement this interface and the
|
||||
// Len() method.
|
||||
type Sizeable interface {
|
||||
Len() int
|
||||
}
|
||||
|
||||
// Immutable is the interface for all immutable objects which must implement
|
||||
// the Clone() method used by binding names to values.
|
||||
type Immutable interface {
|
||||
Clone() Object
|
||||
}
|
||||
|
||||
// Object represents a value and implementations are expected to implement
|
||||
// `Type()` and `Inspect()` functions
|
||||
type Object interface {
|
||||
fmt.Stringer
|
||||
Type() ObjectType
|
||||
Bool() bool
|
||||
Inspect() string
|
||||
}
|
||||
|
||||
// Hashable is the interface for all hashable objects which must implement
|
||||
// the HashKey() method which returns a HashKey result.
|
||||
type Hashable interface {
|
||||
HashKey() HashKey
|
||||
}
|
||||
|
||||
// BuiltinFunction represents the builtin function type
|
||||
type BuiltinFunction func(args ...Object) Object
|
||||
Reference in New Issue
Block a user