Documentation ¶
Index ¶
Constants ¶
const ( // INTEGER_OBJ is the Integer object type. INTEGER_OBJ = "INTEGER" // BOOLEAN_OBJ is the Boolean object type. BOOLEAN_OBJ = "BOOLEAN" // STRING_OBJ is the String object type. STRING_OBJ = "STRING" // NULL_OBJ is the Null object type. NULL_OBJ = "NULL" // RETURN_VALUE_OBJ is the Return value object type. RETURN_VALUE_OBJ = "RETURN_VALUE" // ERROR_OBJ is the Error object type. ERROR_OBJ = "ERROR" // FUNCTION_OBJ is the Function object type. FUNCTION_OBJ = "FUNCTION" // BUILTIN_OBJ is the Builtin object type. BUILTIN_OBJ = "BUILTIN" // ARRAY_OBJ is the Array object type. ARRAY_OBJ = "ARRAY" // HASH_OBJ is the Hash object type. HASH_OBJ = "HASH" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Array ¶
type Array struct {
Elements []Object
}
Array is the array literal type that holds a slice of Object(s).
type Boolean ¶
type Boolean struct {
Value bool
}
Boolean is the boolean type and used to represent boolean literals and holds an internal bool value.
type Builtin ¶
type Builtin struct {
Fn BuiltinFunction
}
Builtin is the builtin object type that simply holds a reference to a BuiltinFunction type that takes zero or more objects as arguments and returns an object.
type BuiltinFunction ¶
BuiltinFunction represents the builtin function type. It's the type definition of a callable Go function.
type Environment ¶
type Environment struct {
// contains filtered or unexported fields
}
Environment is what we use to keep track of value by associating them with a name. Technically, it's an object that holds a mapping of names to bound objets.
func NewEnclosedEnvironment ¶
func NewEnclosedEnvironment(outer *Environment) *Environment
NewEnclosedEnvironment returns a new Environment with the outer set to the current environment (enclosing environment).
func NewEnvironment ¶
func NewEnvironment() *Environment
NewEnvironment constructs a new Environment object to hold bindings of identifiers to their names.
type Error ¶
type Error struct {
Message string
}
Error is the error type and used to hold a message denoting the details of error encountered. This object is tracked through the evaluator and when encountered stops evaulation of the program or body of a function. In a production-ready interpreter we'd want to attach a stack trace to such error objects, add the line and column numbers of its origin.
type Function ¶
type Function struct { Parameters []*ast.Identifier Body *ast.BlockStatement Env *Environment }
Function is the function type that holds the function's formal parameters, body and an environment to support closures.
type Hash ¶
Hash is a hash map and holds a map of HashKey to HashPair(s).
type HashKey ¶
type HashKey struct { Type ObjectType Value uint64 }
HashKey represents a hash key object and holds the Type of Object hashed and its hash value in Value.
type Hashable ¶
type Hashable interface {
HashKey() HashKey
}
Hashable is the interface for all hashable objects which must implement the HashKey() method which returns a HashKey result.
type Integer ¶
type Integer struct {
Value int64
}
Integer is the integer type used to represent integer literals and holds an internal int64 value. Whenever we encounter an integer literal in the source code we first turn it into an ast.IntegerLiteral and then, when evaluating that AST node, we turn it into an object.Integer, saving the value inside our struct and passing around a reference to this struct.
type Null ¶
type Null struct{}
Null is the null type and used to represent the absence of a value.
type Object ¶
type Object interface { Type() ObjectType Inspect() string }
Object represents a value and implementations are expected to implement `Type()` and `Inspect()` functions. The reason Object being an interface instead of struct is that every value needs a different internal representation and it’s easier to define two different struct types than trying to fit booleans and integers into the same struct field.
type ReturnValue ¶
type ReturnValue struct {
Value Object
}
ReturnValue is the return value type and used to hold the value of another object. This is used for `return` statements and this object is tracked through the evaluator and when encountered stops evaluation of the program, or body of a function.
func (*ReturnValue) Inspect ¶
func (rv *ReturnValue) Inspect() string
Inspect returns a stringified version of the object for debugging.
func (*ReturnValue) Type ¶
func (rv *ReturnValue) Type() ObjectType
Type returns the type of the object.