Documentation
¶
Overview ¶
Package object defines the object system for the Monke programming language.
This package implements the runtime object system that represents values during the execution of a Monke program. It defines various types of objects such as integers, booleans, strings, arrays, hashes, functions, and built-ins.
Key components:
- Object interface: The base interface for all runtime values
- Various object types (Integer, Boolean, String, Array, Hash, Function, etc.)
- Environment: Stores variable bindings during execution
- Hashable interface: For objects that can be used as hash keys
- Optimized hash table implementation with key caching for better performance
The evaluator uses the object system to represent and manipulate values during program execution.
Index ¶
Constants ¶
const ( INTEGER_OBJ = "INTEGER" BOOLEAN_OBJ = "BOOLEAN" STRING_OBJ = "STRING" NULL_OBJ = "NULL" RETURN_VALUE_OBJ = "RETURN_VALUE" ERROR_OBJ = "ERROR" FUNCTION_OBJ = "FUNCTION" BUILTIN_OBJ = "BUILTIN" ARRAY_OBJ = "ARRAY" HASH_OBJ = "HASH" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Array ¶
type Array struct {
Elements []Object
}
Array represents a Monke array.
type Boolean ¶
type Boolean struct {
Value bool
}
Boolean represents a Monke boolean value.
type Builtin ¶
type Builtin struct {
Fn BuiltinFunction
}
Builtin represents a Monke builtin.
type BuiltinFunction ¶
BuiltinFunction represents a Monke builtin function.
type Environment ¶
type Environment struct {
// contains filtered or unexported fields
}
Environment represents a scope in a program.
func NewEnclosedEnvironment ¶
func NewEnclosedEnvironment(outer *Environment) *Environment
NewEnclosedEnvironment creates a new Environment with an empty store and the given outer environment. This is used to create a new scope (e.g., for function calls) that has access to variables in the outer scope through the outer environment.
func NewEnvironment ¶
func NewEnvironment() *Environment
NewEnvironment creates a new Environment with an empty store and no outer environment. This is typically used to create the global environment for a program.
type Error ¶
type Error struct {
Message string
}
Error represents a Monke error.
type Function ¶
type Function struct {
Parameters []*ast.Identifier
Body *ast.BlockStatement
Env *Environment
}
Function represents a Monke function.
type Hash ¶
Hash represents a Monke hash.
type Hashable ¶
type Hashable interface {
HashKey() HashKey
}
Hashable represents an object that can be used as a hash key.
type Integer ¶
type Integer struct {
Value int64
}
Integer represents a Monke integer value.
type Null ¶
type Null struct{}
Null represents a Monke null value.
type Object ¶
Object is the interface that wraps the basic operations of all Monke objects. All Monke objects implement this interface.
type ReturnValue ¶
type ReturnValue struct {
Value Object
}
ReturnValue represents a Monke return value.
func (*ReturnValue) Inspect ¶
func (rv *ReturnValue) Inspect() string
Inspect returns a string representation of the object.