Documentation ¶
Index ¶
- Variables
- func AssertTypes(obj Object, types ...Type) bool
- type Array
- func (a *Array) Add(other Object) (Object, error)
- func (a *Array) Append(obj Object)
- func (a *Array) Bool() bool
- func (a *Array) Compare(other Object) int
- func (a *Array) Copy() *Array
- func (a *Array) Get(index Object) (Object, error)
- func (a *Array) Inspect() string
- func (a *Array) Len() int
- func (a *Array) Less(i, j int) bool
- func (a *Array) Mul(other Object) (Object, error)
- func (a *Array) PopLeft() Object
- func (a *Array) PopRight() Object
- func (a *Array) Prepend(obj Object)
- func (a *Array) Reverse()
- func (a *Array) Set(index, other Object) error
- func (a *Array) String() string
- func (a *Array) Swap(i, j int)
- func (a *Array) Type() Type
- type BinaryOpError
- type Boolean
- func (b Boolean) Bool() bool
- func (b Boolean) Compare(other Object) int
- func (b Boolean) Copy() Object
- func (b Boolean) Hash() HashKey
- func (b Boolean) Inspect() string
- func (b Boolean) Int() int
- func (b Boolean) LogicalAnd(other Object) (Object, error)
- func (b Boolean) LogicalNot() Object
- func (b Boolean) LogicalOr(other Object) (Object, error)
- func (b Boolean) String() string
- func (b Boolean) Type() Type
- type Builtin
- type BuiltinFunction
- type Closure
- type Comparable
- type CompiledFunction
- type Copyable
- type DivisionByZeroError
- type Environment
- type Error
- type Function
- type Hash
- func (h *Hash) Add(other Object) (Object, error)
- func (h *Hash) Bool() bool
- func (h *Hash) Compare(other Object) int
- func (h *Hash) Get(index Object) (Object, error)
- func (h *Hash) Inspect() string
- func (h *Hash) Len() int
- func (h *Hash) Set(index, other Object) error
- func (h *Hash) String() string
- func (h *Hash) Type() Type
- type HashKey
- type HashPair
- type Hasher
- type Integer
- func (i Integer) Add(other Object) (Object, error)
- func (i Integer) BitwiseAnd(other Object) (Object, error)
- func (i Integer) BitwiseNot() Object
- func (i Integer) BitwiseOr(other Object) (Object, error)
- func (i Integer) BitwiseXor(other Object) (Object, error)
- func (i Integer) Bool() bool
- func (i Integer) Compare(other Object) int
- func (i Integer) Copy() Object
- func (i Integer) Div(other Object) (Object, error)
- func (i Integer) Hash() HashKey
- func (i Integer) Inspect() string
- func (i Integer) LeftShift(other Object) (Object, error)
- func (i Integer) LogicalNot() Object
- func (i Integer) Mod(other Object) (Object, error)
- func (i Integer) Mul(other Object) (Object, error)
- func (i Integer) Negate() Object
- func (i Integer) RightShift(other Object) (Object, error)
- func (i Integer) String() string
- func (i Integer) Sub(other Object) (Object, error)
- func (i Integer) Type() Type
- type Module
- type Null
- type Object
- type Return
- type String
- func (s String) Add(other Object) (Object, error)
- func (s String) Bool() bool
- func (s String) Compare(other Object) int
- func (s String) Copy() Object
- func (s String) Get(index Object) (Object, error)
- func (s String) Hash() HashKey
- func (s String) Inspect() string
- func (s String) Len() int
- func (s String) Mul(other Object) (Object, error)
- func (s String) String() string
- func (s String) Type() Type
- type Type
Constants ¶
This section is empty.
Variables ¶
var ( TRUE = Boolean{Value: true} FALSE = Boolean{Value: false} )
var NULL = Null{}
Functions ¶
func AssertTypes ¶
Types ¶
type Array ¶
type Array struct {
Elements []Object
}
Array is the array literal type that holds a slice of Object(s)
type BinaryOpError ¶
type BinaryOpError struct {
// contains filtered or unexported fields
}
BinaryOpError is an binary operation error usually resulting from mismatched types
func NewBinaryOpError ¶
func NewBinaryOpError(left, right Object, op string) BinaryOpError
NewBinaryOpError returns a new BinaryOpError
func (BinaryOpError) Error ¶
func (e BinaryOpError) Error() string
type Boolean ¶
type Boolean struct {
Value bool
}
Boolean is the boolean type and used to represent boolean literals and holds an interval bool value
func NewBoolean ¶
func (Boolean) LogicalNot ¶
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 objects to implement suitable comparisons
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 ¶
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 Copyable ¶
type Copyable interface {
Copy() Object
}
Copyable is the interface for creating copies of objects
type DivisionByZeroError ¶
type DivisionByZeroError struct {
// contains filtered or unexported fields
}
DivisionByZeroError is an error returned when dividing by zero
func NewDivisionByZeroError ¶
func NewDivisionByZeroError(left Object) DivisionByZeroError
NewDivisionByZeroError returns a new DivisionByZeroError
func (DivisionByZeroError) Error ¶
func (e DivisionByZeroError) Error() string
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) ExportedHash ¶
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 evaluated module into an object.
func (*Environment) Get ¶
func (e *Environment) Get(name string) (Object, bool)
Get returns the object bound by name
func (*Environment) New ¶
func (e *Environment) New() *Environment
New creates a new copy of the environment with the current environment as parent
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 evaluation 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 Hasher ¶
type Hasher interface {
Hash() HashKey
}
Hasher is the interface for objects to provide suitable hash keys
type Integer ¶
type Integer struct {
Value int64
}
Integer is the integer type used to represent integer literals and holds an internal int64 value
func (Integer) BitwiseNot ¶
func (Integer) LogicalNot ¶
type Module ¶
Module is the module type used to represent a collection of variabels.
type Null ¶
type Null struct{}
func (Null) LogicalNot ¶
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 evaluator and when encountered stops evaluation of the program, or body of a function.