object

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package object contains our core-definitions for objects.

Index

Constants

View Source
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

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

func (ao *Array) Inspect() string

Inspect returns a string-representation of the given object.

func (*Array) JSON added in v0.9.3

func (ao *Array) JSON(indent bool) string

JSON returns a json-friendly string

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.

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) 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) 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) JSON added in v0.9.3

func (b *Boolean) JSON(indent bool) string

JSON returns a json-friendly string

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.

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

func (b *Builtin) Inspect() string

Inspect returns a string-representation of the given object.

func (*Builtin) JSON added in v0.9.3

func (b *Builtin) JSON(indent bool) string

JSON returns a json-friendly string

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.

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 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) HashKey added in v0.1.0

func (s *DocString) HashKey() HashKey

HashKey returns a hash key for the given object.

func (*DocString) Inspect added in v0.1.0

func (s *DocString) Inspect() string

Inspect returns an empty string; a docstring should only be printable when it's part of a block

func (*DocString) JSON added in v0.9.3

func (s *DocString) JSON(indent bool) string

JSON returns a json-friendly string

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.

func (*DocString) Type added in v0.1.0

func (s *DocString) Type() Type

Type returns the type of this object.

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

func (*Environment) Set

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

Set stores the value of a variable, by name.

func (*Environment) SetLet

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

SetLet sets the value of a constant by name.

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

func (e *Error) Inspect() string

Inspect returns a string-representation of the given object.

func (*Error) JSON added in v0.9.3

func (e *Error) JSON(indent bool) string

JSON returns a json-friendly string

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.

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

func (f *File) Inspect() string

Inspect returns a string-representation of the given object.

func (*File) JSON added in v0.9.3

func (f *File) JSON(indent bool) string

JSON returns a json-friendly string

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.

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) 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) 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) JSON added in v0.9.3

func (f *Float) JSON(indent bool) string

JSON returns a json-friendly string

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.

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

func (f *Function) Inspect() string

Inspect returns a string-representation of the given object.

func (*Function) JSON added in v0.9.3

func (f *Function) JSON(indent bool) string

JSON returns a json-friendly string

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.

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

func (h *Hash) Inspect() string

Inspect returns a string-representation of the given object.

func (*Hash) JSON added in v0.9.3

func (h *Hash) JSON(indent bool) string

JSON returns a json-friendly string

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.

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) 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) 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) JSON added in v0.9.3

func (i *Integer) JSON(indent bool) string

JSON returns a json-friendly string

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.

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 Module

type Module struct {
	Name  string
	Attrs Object
}

Module is the module type used to represent a collection of vars

func (*Module) Bool

func (m *Module) Bool() bool

func (*Module) Compare

func (m *Module) Compare(other Object) int

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

func (m *Module) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Module) JSON added in v0.9.3

func (m *Module) JSON(indent bool) string

JSON returns a json-friendly string

func (*Module) String

func (m *Module) String() string

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.

func (*Module) Type

func (m *Module) Type() Type

Type returns the type of the object

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

func (n *Null) Inspect() string

Inspect returns a string-representation of the given object.

func (*Null) JSON added in v0.9.3

func (n *Null) JSON(indent bool) string

JSON returns a json-friendly string

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.

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

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

func (*ReturnValue) Type

func (r *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) 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) 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) JSON added in v0.9.3

func (s *String) JSON(indent bool) string

JSON returns a json-friendly string

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.

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