object

package
v0.0.0-...-4b41b39 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package object contains types that represent in-memory objects while the interpreter is evaluating source code.

Index

Constants

View Source
const (
	// TypeArray is the type for an array value
	TypeArray = "Array"
)
View Source
const (
	// TypeBoolean is the type for a boolean value
	TypeBoolean = "Boolean"
)
View Source
const (
	// TypeCharacter is the type for a character value.
	TypeCharacter = "Character"
)
View Source
const (
	// TypeError is the type for an error value.
	TypeError = "error"
)
View Source
const (
	// TypeFunction is the type for a function value
	TypeFunction = "Function"
)
View Source
const (
	// TypeHash is the type returned by hash objects.
	TypeHash = "Hash"
)
View Source
const (
	// TypeNull is the type for null objects.
	TypeNull = "null"
)
View Source
const (
	// TypeNumber is the type for a numerical value
	TypeNumber = "Number"
)
View Source
const (
	// TypeReturnValue is the object type for `return` values.
	TypeReturnValue = "ReturnValue"
)
View Source
const (
	// TypeString is the type for a string value.
	TypeString = "String"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array struct {
	Elements []Object
}

The Array type represents an array of objects

func (*Array) Clone

func (ar *Array) Clone() Object

Clone returns a copy of the array as a new pointer.

func (*Array) String

func (ar *Array) String() string

func (*Array) Type

func (ar *Array) Type() Type

Type returns this object's type.

type Atomic

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

The Atomic type is a wrapper around Object that indicates the object is atomic. The value must be accessed via the getters/setters that use a mutex.

func MakeAtomic

func MakeAtomic(obj Object) *Atomic

MakeAtomic converts a given object into an atomic one

func (*Atomic) Clone

func (at *Atomic) Clone() Object

Clone creates a copy of the current object that can be used without modifying the original value

func (*Atomic) Set

func (at *Atomic) Set(obj Object)

Set sets the atomic value

func (*Atomic) String

func (at *Atomic) String() string

func (*Atomic) Type

func (at *Atomic) Type() Type

Type returns the type of the underlying object.

func (*Atomic) Value

func (at *Atomic) Value() Object

Value returns a copy of the atomic value.

type Boolean

type Boolean struct {
	Value bool
}

The Boolean type represents a true/false value in memory.

func (*Boolean) Clone

func (b *Boolean) Clone() Object

Clone creates a copy of the current object that can be used without modifying the original value

func (*Boolean) HashKey

func (b *Boolean) HashKey() HashKey

HashKey creates a unique identifier for this value for use in hashes.

func (*Boolean) String

func (b *Boolean) String() string

func (*Boolean) Type

func (b *Boolean) Type() Type

Type returns the type for this object.

type Builtin

type Builtin func(args ...Object) Object

The Builtin type represents a built-in function that can be called from the source code.

func (Builtin) Clone

func (bi Builtin) Clone() Object

Clone creates a copy of the current object that can be used without modifying the original value

func (Builtin) String

func (bi Builtin) String() string

func (Builtin) Type

func (bi Builtin) Type() Type

Type returns the object's type.

type Character

type Character struct {
	Value rune
}

The Character type represents a character value in memory.

func (*Character) Clone

func (c *Character) Clone() Object

Clone creates a copy of the current object that can be used without modifying the original value

func (*Character) HashKey

func (c *Character) HashKey() HashKey

HashKey creates a unique key for this value for use in hash maps.

func (*Character) String

func (c *Character) String() string

func (*Character) Type

func (c *Character) Type() Type

Type returns the type of the object.

type Constant

type Constant struct {
	Value Object
}

The Constant type is a wrapper around Object that indicates the object is immutable.

func (*Constant) Clone

func (c *Constant) Clone() Object

Clone creates a copy of the current object that can be used without modifying the original value

func (*Constant) String

func (c *Constant) String() string

func (*Constant) Type

func (c *Constant) Type() Type

Type returns the type of the underlying object.

type Function

type Function struct {
	Name       *ast.Identifier
	Parameters []*ast.Identifier
	Body       *ast.BlockStatement
	Async      bool
}

The Function type represents a function definition in memory that can be called/executed.

func (*Function) Clone

func (fn *Function) Clone() Object

Clone creates a copy of the current object that can be used without modifying the original value

func (*Function) String

func (fn *Function) String() string

func (*Function) Type

func (fn *Function) Type() Type

Type returns the type of the object.

type Hash

type Hash struct {
	Pairs map[HashKey]HashPair
}

The Hash type represents a hash stored in memory. Each key is uniquely generated based on the type used as the underlying key.

func (*Hash) Clone

func (h *Hash) Clone() Object

Clone creates a copy of the map.

func (*Hash) String

func (h *Hash) String() string

func (*Hash) Type

func (h *Hash) Type() Type

Type returns this object's type.

type HashKey

type HashKey struct {
	Type  Type
	Value float64
}

The HashKey type is used to store unique keys in a hash map

type HashPair

type HashPair struct {
	Key   Object
	Value Object
}

The HashPair type represents a key/value pair stored in a hash.

type Hashable

type Hashable interface {
	HashKey() HashKey
}

The Hashable interfaces defines a type that can be stored in a hash

type Null

type Null struct {
}

The Null type represents an unset object.

func (*Null) Clone

func (n *Null) Clone() Object

Clone returns null

func (*Null) String

func (n *Null) String() string

func (*Null) Type

func (n *Null) Type() Type

Type returns the object's type.

type Number

type Number struct {
	Value float64
}

The Number type represents a number stored in memory. All numbers are 64 bit floating point numbers.

func (*Number) Clone

func (num *Number) Clone() Object

Clone creates a copy of the current object that can be used without modifying the original value

func (*Number) HashKey

func (num *Number) HashKey() HashKey

HashKey creates a unique key for this value for use in hashes.

func (*Number) String

func (num *Number) String() string

func (*Number) Type

func (num *Number) Type() Type

Type returns the type of the object.

type Object

type Object interface {
	Type() Type
	String() string
	Clone() Object
}

The Object interface defines behavior for all objects.

func Error

func Error(msg string, args ...interface{}) Object

Error creates a new error in memory using the given token to note the line/column. Standard library style message formatting can be used to create a formatted error message.

type ReturnValue

type ReturnValue struct {
	Value Object
}

The ReturnValue type represents a return value in the source code. For example return 1

func (*ReturnValue) Clone

func (rv *ReturnValue) Clone() Object

Clone creates a copy of the current object that can be used without modifying the original value

func (*ReturnValue) String

func (rv *ReturnValue) String() string

func (*ReturnValue) Type

func (rv *ReturnValue) Type() Type

Type returns the type of the object.

type Scope

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

The Scope type contains all accessible objects for a certain scope. It allows for objects with the same name to be declared at different scopes and access them in order of current scope to last parent scope.

func NewScope

func NewScope() *Scope

NewScope creates a new instance of the Scope type.

func (*Scope) Get

func (s *Scope) Get(name string) Object

Get attempts to obtain an object from the scope using the given name. If it does not exist at the current scope, the parent is checked until the value is found.

func (*Scope) NewChildScope

func (s *Scope) NewChildScope() *Scope

NewChildScope creates a new scope using the called scope as the parent.

func (*Scope) Set

func (s *Scope) Set(name string, val Object) Object

Set attempts to set a value in the current scope using the given name.

type String

type String struct {
	Value string
}

The String type represents a string value in memory.

func (*String) Clone

func (str *String) Clone() Object

Clone creates a copy of the current object that can be used without modifying the original value

func (*String) HashKey

func (str *String) HashKey() HashKey

HashKey creates a unique key for this value for use in hash maps.

func (*String) String

func (str *String) String() string

func (*String) Type

func (str *String) Type() Type

Type returns the type of the object.

type Type

type Type string

The Type type contains an object's type.

Jump to

Keyboard shortcuts

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