object

package
v0.0.0-...-eb82b58 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2023 License: MIT Imports: 10 Imported by: 1

Documentation

Overview

Package object contains our core-definitions for objects.

Index

Constants

View Source
const (
	INTEGER_OBJ      = "INTEGER"
	FLOAT_OBJ        = "FLOAT"
	BOOLEAN_OBJ      = "BOOLEAN"
	NULL_OBJ         = "NULL"
	RETURN_VALUE_OBJ = "RETURN_VALUE"
	ERROR_OBJ        = "ERROR"
	FUNCTION_OBJ     = "FUNCTION"
	STRING_OBJ       = "STRING"
	BUILTIN_OBJ      = "BUILTIN"
	ARRAY_OBJ        = "ARRAY"
	HASH_OBJ         = "HASH"
	FILE_OBJ         = "FILE"
	REGEXP_OBJ       = "REGEXP"
)

pre-defined constant Type

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array struct {
	// Elements holds the individual members of the array we're wrapping.
	Elements []Object
	// contains filtered or unexported fields
}

Array wraps Object array and implements Object interface.

func (*Array) Inspect

func (ao *Array) Inspect() string

Inspect returns a string-representation of the given object.

func (*Array) InvokeMethod

func (ao *Array) InvokeMethod(method string, env Environment, args ...Object) Object

InvokeMethod invokes a method against the object. (Built-in methods only.)

func (*Array) Next

func (ao *Array) Next() (Object, Object, bool)

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.

It might also be helpful for embedded users.

func (*Array) Type

func (ao *Array) Type() Type

Type returns the type of this object.

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) HashKey

func (b *Boolean) HashKey() HashKey

HashKey returns a hash key for the given object.

func (*Boolean) Inspect

func (b *Boolean) Inspect() string

Inspect returns a string-representation of the given object.

func (*Boolean) InvokeMethod

func (b *Boolean) InvokeMethod(method string, env Environment, args ...Object) Object

InvokeMethod invokes 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.

It might also be helpful for embedded users.

func (*Boolean) Type

func (b *Boolean) Type() Type

Type returns the type of this object.

type Builtin

type Builtin struct {
	// Value holds the function we wrap.
	Fn BuiltinFunction
}

Builtin wraps func and implements Object interface.

func (*Builtin) Inspect

func (b *Builtin) Inspect() string

Inspect returns a string-representation of the given object.

func (*Builtin) InvokeMethod

func (b *Builtin) InvokeMethod(method string, env Environment, args ...Object) Object

InvokeMethod invokes 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.

It might also be helpful for embedded users.

func (*Builtin) Type

func (b *Builtin) Type() Type

Type returns the type of this object.

type BuiltinFunction

type BuiltinFunction func(env *Environment, args ...Object) Object

BuiltinFunction holds the type of a built-in function.

type Environment

type Environment struct {
	// contains filtered or unexported fields
}

Environment stores our functions, variables, constants, etc.

func NewEnclosedEnvironment

func NewEnclosedEnvironment(outer *Environment) *Environment

NewEnclosedEnvironment create new environment by outer parameter

func NewEnvironment

func NewEnvironment() *Environment

NewEnvironment creates new environment

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) 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.

func (*Environment) Set

func (e *Environment) Set(name string, val Object) Object

Set stores the value of a variable, by name.

func (*Environment) SetConst

func (e *Environment) SetConst(name string, val Object) Object

SetConst sets the value of a constant by name.

type Error

type Error struct {
	// Message contains the error-message we're wrapping
	Message string
}

Error wraps string and implements Object interface.

func (*Error) Inspect

func (e *Error) Inspect() string

Inspect returns a string-representation of the given object.

func (*Error) InvokeMethod

func (e *Error) InvokeMethod(method string, env Environment, args ...Object) Object

InvokeMethod invokes 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.

It might also be helpful for embedded users.

func (*Error) Type

func (e *Error) Type() Type

Type returns the type of this object.

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) Inspect

func (f *File) Inspect() string

Inspect returns a string-representation of the given object.

func (*File) InvokeMethod

func (f *File) InvokeMethod(method string, env Environment, args ...Object) Object

InvokeMethod invokes a method against the object. (Built-in methods only.)

func (*File) Open

func (f *File) Open(mode string) error

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.

It might also be helpful for embedded users.

func (*File) Type

func (f *File) Type() Type

Type returns the type of this object.

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) HashKey

func (f *Float) HashKey() HashKey

HashKey returns a hash key for the given object.

func (*Float) Inspect

func (f *Float) Inspect() string

Inspect returns a string-representation of the given object.

func (*Float) InvokeMethod

func (f *Float) InvokeMethod(method string, env Environment, args ...Object) Object

InvokeMethod invokes 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.

It might also be helpful for embedded users.

func (*Float) Type

func (f *Float) Type() Type

Type returns the type of this object.

type Function

type Function struct {
	Parameters []*ast.Identifier
	Body       *ast.BlockStatement
	Defaults   map[string]ast.Expression
	Env        *Environment
}

Function wraps ast.Identifier array, ast.BlockStatement and Environment and implements Object interface.

func (*Function) Inspect

func (f *Function) Inspect() string

Inspect returns a string-representation of the given object.

func (*Function) InvokeMethod

func (f *Function) InvokeMethod(method string, env Environment, args ...Object) Object

InvokeMethod invokes 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.

It might also be helpful for embedded users.

func (*Function) Type

func (f *Function) Type() Type

Type returns the type of this object.

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) Inspect

func (h *Hash) Inspect() string

Inspect returns a string-representation of the given object.

func (*Hash) InvokeMethod

func (h *Hash) InvokeMethod(method string, env Environment, args ...Object) Object

InvokeMethod invokes a method against the object. (Built-in methods only.)

func (*Hash) Next

func (h *Hash) Next() (Object, Object, bool)

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.

It might also be helpful for embedded users.

func (*Hash) Type

func (h *Hash) Type() Type

Type returns the type of this object.

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) HashKey

func (i *Integer) HashKey() HashKey

HashKey returns a hash key for the given object.

func (*Integer) Inspect

func (i *Integer) Inspect() string

Inspect returns a string-representation of the given object.

func (*Integer) InvokeMethod

func (i *Integer) InvokeMethod(method string, env Environment, args ...Object) Object

InvokeMethod invokes 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.

It might also be helpful for embedded users.

func (*Integer) Type

func (i *Integer) Type() Type

Type returns the type of this object.

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 Null

type Null struct{}

Null wraps nothing and implements our Object interface.

func (*Null) Inspect

func (n *Null) Inspect() string

Inspect returns a string-representation of the given object.

func (*Null) InvokeMethod

func (n *Null) InvokeMethod(method string, env Environment, args ...Object) Object

InvokeMethod invokes 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.

It might also be helpful for embedded users.

func (*Null) Type

func (n *Null) Type() Type

Type returns the type of this object.

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

	// InvokeMethod invokes a method against the object.
	// (Built-in methods only.)
	InvokeMethod(method string, env Environment, args ...Object) Object

	// 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{}
}

Object is the interface that all of our various object-types must implmenet.

type Regexp

type Regexp struct {
	// Value holds the string value this object wraps.
	Value string

	// Flags holds the flags for the object
	Flags string
}

Regexp wraps regular-expressions and implements the Object interface.

func (*Regexp) Inspect

func (r *Regexp) Inspect() string

Inspect returns a string-representation of the given object.

func (*Regexp) InvokeMethod

func (r *Regexp) InvokeMethod(method string, env Environment, args ...Object) Object

InvokeMethod invokes a method against the object. (Built-in methods only.)

func (*Regexp) ToInterface

func (r *Regexp) ToInterface() interface{}

ToInterface converts this object to a go-interface, which will allow it to be used naturally in our sprintf/printf primitives.

It might also be helpful for embedded users.

func (*Regexp) Type

func (r *Regexp) Type() Type

Type returns the type of this object.

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) Inspect

func (rv *ReturnValue) Inspect() string

Inspect returns a string-representation of the given object.

func (*ReturnValue) InvokeMethod

func (rv *ReturnValue) InvokeMethod(method string, env Environment, args ...Object) Object

InvokeMethod invokes a method against the object. (Built-in methods only.)

func (*ReturnValue) ToInterface

func (rv *ReturnValue) ToInterface() interface{}

ToInterface converts this object to a go-interface, which will allow it to be used naturally in our sprintf/printf primitives.

It might also be helpful for embedded users.

func (*ReturnValue) Type

func (rv *ReturnValue) Type() Type

Type returns the type of this object.

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) HashKey

func (s *String) HashKey() HashKey

HashKey returns a hash key for the given object.

func (*String) Inspect

func (s *String) Inspect() string

Inspect returns a string-representation of the given object.

func (*String) InvokeMethod

func (s *String) InvokeMethod(method string, env Environment, args ...Object) Object

InvokeMethod invokes a method against the object. (Built-in methods only.)

func (*String) Next

func (s *String) Next() (Object, Object, bool)

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.

It might also be helpful for embedded users.

func (*String) Type

func (s *String) Type() Type

Type returns the type of this object.

type Type

type Type string

Type describes the type of an object.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL