Documentation
¶
Index ¶
- Constants
- Variables
- type Array
- 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 Null
- type Object
- func Args(args ...Object) Object
- func Assert(args ...Object) Object
- func Bool(args ...Object) Object
- func Exit(args ...Object) Object
- func Find(args ...Object) Object
- func First(args ...Object) Object
- func Input(args ...Object) Object
- func Int(args ...Object) Object
- func Join(args ...Object) Object
- func Last(args ...Object) Object
- func Len(args ...Object) Object
- func Lower(args ...Object) Object
- func Pop(args ...Object) Object
- func Print(args ...Object) Object
- func Push(args ...Object) Object
- func Read(args ...Object) Object
- func Rest(args ...Object) Object
- func Split(args ...Object) Object
- func Str(args ...Object) Object
- func TypeOf(args ...Object) Object
- func Upper(args ...Object) Object
- func Write(args ...Object) Object
- type Return
- 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" )
Variables ¶
var ( Arguments []string StandardInput io.Reader StandardOutput io.Writer ExitFunction func(int) )
var Builtins = map[string]*Builtin{ "len": &Builtin{Name: "len", Fn: Len}, "input": &Builtin{Name: "input", Fn: Input}, "print": &Builtin{Name: "print", Fn: Print}, "first": &Builtin{Name: "first", Fn: First}, "last": &Builtin{Name: "last", Fn: Last}, "rest": &Builtin{Name: "rest", Fn: Rest}, "push": &Builtin{Name: "push", Fn: Push}, "pop": &Builtin{Name: "pop", Fn: Pop}, "exit": &Builtin{Name: "exit", Fn: Exit}, "assert": &Builtin{Name: "assert", Fn: Assert}, "bool": &Builtin{Name: "bool", Fn: Bool}, "int": &Builtin{Name: "int", Fn: Int}, "str": &Builtin{Name: "str", Fn: Str}, "typeof": &Builtin{Name: "typeof", Fn: TypeOf}, "args": &Builtin{Name: "args", Fn: Args}, "lower": &Builtin{Name: "lower", Fn: Lower}, "upper": &Builtin{Name: "upper", Fn: Upper}, "join": &Builtin{Name: "join", Fn: Join}, "split": &Builtin{Name: "split", Fn: Split}, "find": &Builtin{Name: "find", Fn: Find}, "read": &Builtin{Name: "read", Fn: Read}, "write": &Builtin{Name: "write", Fn: Write}, }
Builtins ...
var BuiltinsIndex []*Builtin
BuiltinsIndex ...
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) 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)
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 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.
Source Files
¶
- builtin_args.go
- builtin_assert.go
- builtin_bool.go
- builtin_exit.go
- builtin_find.go
- builtin_first.go
- builtin_input.go
- builtin_int.go
- builtin_join.go
- builtin_last.go
- builtin_len.go
- builtin_lower.go
- builtin_pop.go
- builtin_print.go
- builtin_push.go
- builtin_read.go
- builtin_rest.go
- builtin_split.go
- builtin_str.go
- builtin_typeof.go
- builtin_upper.go
- builtin_write.go
- builtins.go
- environment.go
- object.go
- state.go