Documentation ¶
Index ¶
- Constants
- Variables
- type Array
- func (a *Array) Append(obj Object)
- func (a *Array) Bool() bool
- func (ao *Array) Compare(other Object) int
- func (a *Array) Copy() *Array
- func (ao *Array) Inspect() string
- func (a *Array) Len() int
- func (a *Array) Less(i, j int) bool
- func (a *Array) PopLeft() Object
- func (a *Array) PopRight() Object
- func (a *Array) Prepend(obj Object)
- func (a *Array) Reverse()
- func (ao *Array) String() string
- func (a *Array) Swap(i, j int)
- func (ao *Array) Type() Type
- type Boolean
- type Builtin
- type BuiltinFunction
- type Closure
- type Comparable
- type CompiledFunction
- type Environment
- type Error
- type Function
- type Hash
- type HashKey
- type HashPair
- type Hashable
- type Immutable
- type Integer
- type Module
- type Null
- type Object
- type Return
- type Sizeable
- type String
- type Type
Constants ¶
const ( // INTEGER is the Integer object type INTEGER = "int" // STRING is the String object type STRING = "str" // BOOLEAN is the Boolean object type BOOLEAN = "bool" // NULL is the Null object type NULL = "null" // RETURN is the Return object type RETURN = "return" // ERROR is the Error object type ERROR = "error" // FUNCTION is the Function object type FUNCTION = "fn" // COMPILED_FUNCTION is the CompiledFunction object type COMPILED_FUNCTION = "COMPILED_FUNCTION" // BUILTIN is the Builtin object type BUILTIN = "builtin" // CLOSURE is the Closure object type CLOSURE = "closure" // ARRAY is the Array object type ARRAY = "array" // HASH is the Hash object type HASH = "hash" // MODULE is the Module object type MODULE = "module" )
Variables ¶
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 interval bool value
type Builtin ¶
type Builtin struct { Name string 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
type Closure ¶
type Closure struct { Fn *CompiledFunction Free []Object }
Closure is the closure object type that holds a reference to a compiled functions and its free variables
type Comparable ¶
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 CompiledFunction ¶
type CompiledFunction struct { Instructions code.Instructions NumLocals int NumParameters int }
CompiledFunction is the compiled function type that holds the function's compiled body as bytecode instructions
func (*CompiledFunction) Bool ¶ added in v1.3.0
func (cf *CompiledFunction) Bool() bool
func (*CompiledFunction) Inspect ¶
func (cf *CompiledFunction) Inspect() string
Inspect returns a stringified version of the object for debugging
func (*CompiledFunction) String ¶
func (cf *CompiledFunction) String() string
func (*CompiledFunction) Type ¶
func (cf *CompiledFunction) Type() Type
Type returns the type of the object
type Environment ¶
type Environment struct {
// contains filtered or unexported fields
}
Environment is an object that holds a mapping of names to bound objets
func NewEnvironment ¶
func NewEnvironment() *Environment
NewEnvironment constructs a new Environment object to hold bindings of identifiers to their names
func (*Environment) Clone ¶
func (e *Environment) Clone() *Environment
Clone returns a new Environment with the parent set to the current environment (enclosing environment)
func (*Environment) ExportedHash ¶ added in v1.3.0
func (e *Environment) ExportedHash() *Hash
ExportedHash returns a new Hash with the names and values of every publically exported binding in the environment. That is every binding that starts with a capital letter. This is used by the module import system to wrap up the evaulated module into an object.
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 trakced through the evaluator and when encountered stops evaulation of the program or body of a function.
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 ¶
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 reutrns a HashKey result.
type Immutable ¶
type Immutable interface {
Clone() Object
}
Immutable is the interface for all immutable objects which must implement the Clone() method used by binding names to values.
type Integer ¶
type Integer struct {
Value int64
}
Integer is the integer type used to represent integer literals and holds an internal int64 value
type Module ¶ added in v1.3.0
Module is the module type used to represent a collection of variabels.
type Null ¶
type Null struct{}
Null is the null type and used to represent the absence of a value
type Object ¶
Object represents a value and implementations are expected to implement `Type()` and `Inspect()` functions
type Return ¶
type Return struct {
Value Object
}
Return is the return type and used to hold the value of another object. This is used for `return` statements and this object is tracked through the evalulator and when encountered stops evaluation of the program, or body of a function.
type Sizeable ¶ added in v1.3.0
type Sizeable interface {
Len() 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.