Documentation ¶
Overview ¶
Package object contains our core-definitions for objects.
Index ¶
- Constants
- Variables
- type Array
- type Boolean
- type Builtin
- type BuiltinFunction
- type DocString
- type Environment
- type Error
- type File
- type Float
- type Function
- type Hash
- type HashKey
- type HashPair
- type Hashable
- type Integer
- type Iterable
- type Module
- func (m *Module) Bool() bool
- func (m *Module) Compare(other Object) int
- func (m *Module) GetMethod(method string) BuiltinFunction
- func (m *Module) Inspect() string
- func (m *Module) JSON(indent bool) string
- func (m *Module) String() string
- func (m *Module) ToInterface() interface{}
- func (m *Module) Type() Type
- type Null
- type Object
- type ReturnValue
- type String
- func (s *String) GetMethod(method string) BuiltinFunction
- func (s *String) HashKey() HashKey
- func (s *String) Inspect() string
- func (s *String) JSON(indent bool) string
- func (s *String) Next() (Object, Object, bool)
- func (s *String) Reset()
- func (s *String) ToInterface() interface{}
- func (s *String) Type() Type
- type Type
Constants ¶
const ( ARRAY_OBJ = "ARRAY" BOOLEAN_OBJ = "BOOLEAN" BUILTIN_OBJ = "BUILTIN" DOCSTRING_OBJ = "DOCSTRING" ERROR_OBJ = "ERROR" FILE_OBJ = "FILE" FLOAT_OBJ = "FLOAT" FUNCTION_OBJ = "FUNCTION" HASH_OBJ = "HASH" INTEGER_OBJ = "INTEGER" MODULE_OBJ = "MODULE" NULL_OBJ = "NULL" RETURN_VALUE_OBJ = "RETURN_VALUE" STRING_OBJ = "STRING" )
pre-defined constant Type
Variables ¶
var SystemTypesMap = map[Type]Object{ ARRAY_OBJ: &Array{}, BOOLEAN_OBJ: &Boolean{}, BUILTIN_OBJ: &Builtin{}, DOCSTRING_OBJ: &DocString{}, ERROR_OBJ: &Error{}, FILE_OBJ: &File{}, FLOAT_OBJ: &Float{}, FUNCTION_OBJ: &Function{}, HASH_OBJ: &Hash{}, INTEGER_OBJ: &Integer{}, MODULE_OBJ: &Module{}, NULL_OBJ: &Null{}, RETURN_VALUE_OBJ: &ReturnValue{}, STRING_OBJ: &String{}, }
SystemTypesMap map system types by type name
Functions ¶
This section is empty.
Types ¶
type Array ¶
type Array struct { Token token.Token // Elements holds the individual members of the array we're wrapping. Elements []Object // special arr when used for ... args IsCurrentArgs bool // contains filtered or unexported fields }
Array wraps Object array and implements Object interface.
func (*Array) GetMethod ¶ added in v0.1.0
func (ao *Array) GetMethod(method string) BuiltinFunction
GetMethod returns a method against the object. (Built-in methods only.)
func (*Array) Next ¶
Next implements the Iterable interface, and allows the contents of our array to be iterated over.
func (*Array) Reset ¶
func (ao *Array) Reset()
Reset implements the Iterable interface, and allows the contents of the array to be reset to allow re-iteration.
func (*Array) ToInterface ¶
func (ao *Array) ToInterface() interface{}
ToInterface converts this object to a go-interface, which will allow it to be used naturally in our sprintf/printf primitives.
type Boolean ¶
type Boolean struct { // Value holds the boolean value we wrap. Value bool }
Boolean wraps bool and implements Object and Hashable interface.
func (*Boolean) GetMethod ¶ added in v0.1.0
func (b *Boolean) GetMethod(method string) BuiltinFunction
GetMethod returns a method against the object. (Built-in methods only.)
func (*Boolean) ToInterface ¶
func (b *Boolean) ToInterface() interface{}
ToInterface converts this object to a go-interface, which will allow it to be used naturally in our sprintf/printf primitives.
type Builtin ¶
type Builtin struct { // Value holds the function we wrap. Fn BuiltinFunction }
Builtin wraps func and implements Object interface.
func (*Builtin) GetMethod ¶ added in v0.1.0
func (b *Builtin) GetMethod(method string) BuiltinFunction
GetMethod returns a method against the object. (Built-in methods only.)
func (*Builtin) ToInterface ¶
func (b *Builtin) ToInterface() interface{}
ToInterface converts this object to a go-interface, which will allow it to be used naturally in our sprintf/printf primitives.
type BuiltinFunction ¶
type BuiltinFunction func(env *Environment, args ...Object) Object
BuiltinFunction holds the type of a built-in function.
type DocString ¶ added in v0.1.0
type DocString struct { // Value holds the string value this object wraps. Value string }
DocString wraps string and implements Object and Hashable interfaces.
func (*DocString) GetMethod ¶ added in v0.1.0
func (s *DocString) GetMethod(method string) BuiltinFunction
GetMethod invokes a method against the object. (Built-in methods only.)
func (*DocString) Inspect ¶ added in v0.1.0
Inspect returns an empty string; a docstring should only be printable when it's part of a block
func (*DocString) ToInterface ¶ added in v0.1.0
func (s *DocString) ToInterface() interface{}
ToInterface converts this object to a go-interface, which will allow it to be used naturally in our sprintf/printf primitives.
type Environment ¶
type Environment struct { // Args used when creating this env. Used in ... CurrentArgs []Object // Spread elements from an array, used in .... SpreadElements []Object // contains filtered or unexported fields }
Environment stores our functions, variables, constants, etc.
func NewEnclosedEnvironment ¶
func NewEnclosedEnvironment(outer *Environment, args []Object) *Environment
NewEnclosedEnvironment create new environment by outer parameter
func NewTemporaryScope ¶
func NewTemporaryScope(outer *Environment, keys []string) *Environment
NewTemporaryScope creates a temporary scope where some values are ignored. This is used as a sneaky hack to allow `foreach` to access all global values as if they were local, but prevent the index/value keys from persisting.
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 top-level binding (not in a block). This is used by the module import system to wrap up the evaulated module into an object.
func (*Environment) Get ¶
func (e *Environment) Get(name string) (Object, bool)
Get returns the value of a given variable, by name.
func (*Environment) Names ¶
func (e *Environment) Names(prefix string) []string
Names returns the names of every known-value with the given prefix. This function is used by `invokeMethod` to get the methods associated with a particular class-type.
type Error ¶
type Error struct { // Message contains the error-message we're wrapping Message string // Optional exit code Code *int // If we're calling the error() builtin BuiltinCall bool // Any extra data Data string }
Error wraps string and implements Object interface.
func (*Error) GetMethod ¶ added in v0.1.0
func (e *Error) GetMethod(string) BuiltinFunction
GetMethod returns a method against the object. (Built-in methods only.)
func (*Error) ToInterface ¶
func (e *Error) ToInterface() interface{}
ToInterface converts this object to a go-interface, which will allow it to be used naturally in our sprintf/printf primitives.
type File ¶
type File struct { // The path this file object refers to. Filename string // Reader is a helper for file-reading. Reader *bufio.Reader // Writer is a helper for file-writing. Writer *bufio.Writer // Handle contains the filehandle we wrap. Handle *os.File }
File wraps a file.
func (*File) GetMethod ¶ added in v0.1.0
func (f *File) GetMethod(method string) BuiltinFunction
GetMethod returns a method against the object. (Built-in methods only.)
func (*File) Open ¶
Open opens the file - called only from the open-primitive where the Filename will have been filled in for us.
func (*File) ToInterface ¶
func (f *File) ToInterface() interface{}
ToInterface converts this object to a go-interface, which will allow it to be used naturally in our sprintf/printf primitives.
type Float ¶
type Float struct { // Value holds the float-value this object wraps. Value float64 }
Float wraps float64 and implements Object and Hashable interfaces.
func (*Float) GetMethod ¶ added in v0.1.0
func (f *Float) GetMethod(method string) BuiltinFunction
GetMethod returns a method against the object. (Built-in methods only.)
func (*Float) ToInterface ¶
func (f *Float) ToInterface() interface{}
ToInterface converts this object to a go-interface, which will allow it to be used naturally in our sprintf/printf primitives.
type Function ¶
type Function struct { Parameters []*ast.Identifier Body *ast.BlockStatement Defaults map[string]ast.Expression Env *Environment DocString *ast.DocStringLiteral Name string }
Function wraps ast.Identifier array, ast.BlockStatement and Environment and implements Object interface.
func (*Function) GetMethod ¶ added in v0.1.0
func (f *Function) GetMethod(method string) BuiltinFunction
GetMethod returns a method against the object. (Built-in methods only.)
func (*Function) ToInterface ¶
func (f *Function) ToInterface() interface{}
ToInterface converts this object to a go-interface, which will allow it to be used naturally in our sprintf/printf primitives.
type Hash ¶
type Hash struct { // Pairs holds the key/value pairs of the hash we wrap Pairs map[HashKey]HashPair // contains filtered or unexported fields }
Hash wrap map[HashKey]HashPair and implements Object interface.
func (*Hash) GetMethod ¶ added in v0.1.0
func (h *Hash) GetMethod(method string) BuiltinFunction
GetMethod returns a method against the object. (Built-in methods only.)
func (*Hash) Next ¶
Next implements the Iterable interface, and allows the contents of our array to be iterated over.
func (*Hash) Reset ¶
func (h *Hash) Reset()
Reset implements the Iterable interface, and allows the contents of the array to be reset to allow re-iteration.
func (*Hash) ToInterface ¶
func (h *Hash) ToInterface() interface{}
ToInterface converts this object to a go-interface, which will allow it to be used naturally in our sprintf/printf primitives.
type HashKey ¶
type HashKey struct { // Type holds the type of the object. Type Type // Value holds the actual hash-key value. Value uint64 }
HashKey is the structure used for hash-keys
type HashPair ¶
type HashPair struct { // Key holds our hash-key key. Key Object // Value holds our hash-key value. Value Object }
HashPair is a structure which is used to store hash-entries
type Hashable ¶
type Hashable interface { // HashKey returns a hash key for the given object. HashKey() HashKey }
Hashable type can be hashed
type Integer ¶
type Integer struct { // Value holds the integer value this object wraps Value int64 }
Integer wraps int64 and implements Object and Hashable interfaces.
func (*Integer) GetMethod ¶ added in v0.1.0
func (i *Integer) GetMethod(method string) BuiltinFunction
GetMethod returns a method against the object. (Built-in methods only.)
func (*Integer) ToInterface ¶
func (i *Integer) ToInterface() interface{}
ToInterface converts this object to a go-interface, which will allow it to be used naturally in our sprintf/printf primitives.
type Iterable ¶
type Iterable interface { // Reset the state of any previous iteration. Reset() // Get the next "thing" from the object being iterated // over. // The return values are the item which is to be returned // next, the index of that object, and finally a boolean // to say whether the function succeeded. // If the boolean value returned is false then that // means the iteration has completed and no further // items are available. Next() (Object, Object, bool) }
Iterable is an interface that some objects might support. If this interface is implemented then it will be possible to use the `foreach` function to iterate over the object. If the interface is not implemented then a run-time error will be generated instead.
type Module ¶
Module is the module type used to represent a collection of vars
func (*Module) GetMethod ¶ added in v0.1.0
func (m *Module) GetMethod(method string) BuiltinFunction
GetMethod invokes a method against the object. (Built-in methods only.)
func (*Module) ToInterface ¶
func (m *Module) ToInterface() interface{}
ToInterface converts this object to a go-interface, which will allow it to be used naturally in our sprintf/printf primitives.
type Null ¶
type Null struct{}
Null wraps nothing and implements our Object interface.
func (*Null) GetMethod ¶ added in v0.6.0
func (n *Null) GetMethod(string) BuiltinFunction
GetMethod returns a method against the object. (Built-in methods only.)
func (*Null) ToInterface ¶
func (n *Null) ToInterface() interface{}
ToInterface converts this object to a go-interface, which will allow it to be used naturally in our sprintf/printf primitives.
type Object ¶
type Object interface { // Type returns the type of this object. Type() Type // Inspect returns a string-representation of the given object. Inspect() string // GetMethod invokes a method against the object. // (Built-in methods only.) GetMethod(method string) BuiltinFunction // ToInterface converts the given object to a "native" golang value, // which is required to ensure that we can use the object in our // `sprintf` or `printf` primitives. ToInterface() interface{} // Return a JSON-friendly string JSON(indent bool) string }
Object is the interface that all of our various object-types must implmenet.
type ReturnValue ¶
type ReturnValue struct { // Value is the object that is to be returned Value Object }
ReturnValue wraps Object and implements Object interface.
func (*ReturnValue) GetMethod ¶ added in v0.1.0
func (r *ReturnValue) GetMethod(string) BuiltinFunction
GetMethod returns a method against the object. (Built-in methods only.)
func (*ReturnValue) Inspect ¶
func (r *ReturnValue) Inspect() string
Inspect returns a string-representation of the given object.
func (*ReturnValue) JSON ¶ added in v0.9.3
func (r *ReturnValue) JSON(indent bool) string
JSON returns a json-friendly string
func (*ReturnValue) ToInterface ¶
func (r *ReturnValue) ToInterface() interface{}
ToInterface converts this object to a go-interface, which will allow it to be used naturally in our sprintf/printf primitives.
type String ¶
type String struct { // Value holds the string value this object wraps. Value string // contains filtered or unexported fields }
String wraps string and implements Object and Hashable interfaces.
func (*String) GetMethod ¶ added in v0.1.0
func (s *String) GetMethod(method string) BuiltinFunction
GetMethod returns a method against the object. (Built-in methods only.)
func (*String) Next ¶
Next implements the Iterable interface, and allows the contents of our string to be iterated over.
func (*String) Reset ¶
func (s *String) Reset()
Reset implements the Iterable interface, and allows the contents of the string to be reset to allow re-iteration.
func (*String) ToInterface ¶
func (s *String) ToInterface() interface{}
ToInterface converts this object to a go-interface, which will allow it to be used naturally in our sprintf/printf primitives.