object

package
v2.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TRUE  = Boolean{Value: true}
	FALSE = Boolean{Value: false}
)
View Source
var NULL = Null{}

Functions

func AssertTypes

func AssertTypes(obj Object, types ...Type) bool

Types

type Array

type Array struct {
	Elements []Object
}

Array is the array literal type that holds a slice of Object(s)

func (*Array) Add

func (a *Array) Add(other Object) (Object, error)

func (*Array) Append

func (a *Array) Append(obj Object)

func (*Array) Bool

func (a *Array) Bool() bool

func (*Array) Compare

func (a *Array) Compare(other Object) int

func (*Array) Copy

func (a *Array) Copy() *Array

func (*Array) Get

func (a *Array) Get(index Object) (Object, error)

func (*Array) Inspect

func (a *Array) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Array) Len

func (a *Array) Len() int

func (*Array) Less

func (a *Array) Less(i, j int) bool

func (*Array) Mul

func (a *Array) Mul(other Object) (Object, error)

func (*Array) PopLeft

func (a *Array) PopLeft() Object

func (*Array) PopRight

func (a *Array) PopRight() Object

func (*Array) Prepend

func (a *Array) Prepend(obj Object)

func (*Array) Reverse

func (a *Array) Reverse()

func (*Array) Set

func (a *Array) Set(index, other Object) error

func (*Array) String

func (a *Array) String() string

func (*Array) Swap

func (a *Array) Swap(i, j int)

func (*Array) Type

func (a *Array) Type() Type

Type returns the type of the object

type BinaryOpError

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

BinaryOpError is an binary operation error usually resulting from mismatched types

func NewBinaryOpError

func NewBinaryOpError(left, right Object, op string) BinaryOpError

NewBinaryOpError returns a new BinaryOpError

func (BinaryOpError) Error

func (e BinaryOpError) Error() string

type Boolean

type Boolean struct {
	Value bool
}

Boolean is the boolean type and used to represent boolean literals and holds an interval bool value

func NewBoolean

func NewBoolean(value bool) Boolean

func (Boolean) Bool

func (b Boolean) Bool() bool

func (Boolean) Compare

func (b Boolean) Compare(other Object) int

func (Boolean) Copy

func (b Boolean) Copy() Object

Copy implements the Copyable interface

func (Boolean) Hash

func (b Boolean) Hash() HashKey

Hash implements the Hasher interface

func (Boolean) Inspect

func (b Boolean) Inspect() string

Inspect returns a stringified version of the object for debugging

func (Boolean) Int

func (b Boolean) Int() int

func (Boolean) LogicalAnd

func (b Boolean) LogicalAnd(other Object) (Object, error)

func (Boolean) LogicalNot

func (b Boolean) LogicalNot() Object

func (Boolean) LogicalOr

func (b Boolean) LogicalOr(other Object) (Object, error)

func (Boolean) String

func (b Boolean) String() string

func (Boolean) Type

func (b Boolean) Type() Type

Type returns the type of the object

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.

func (Builtin) Bool

func (b Builtin) Bool() bool

func (Builtin) Inspect

func (b Builtin) Inspect() string

Inspect returns a stringified version of the object for debugging

func (Builtin) String

func (b Builtin) String() string

func (Builtin) Type

func (b Builtin) Type() Type

Type returns the type of the object

type BuiltinFunction

type BuiltinFunction func(ctx context.Context, args ...Object) Object

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

func (*Closure) Bool

func (c *Closure) Bool() bool

func (*Closure) Inspect

func (c *Closure) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Closure) String

func (c *Closure) String() string

func (*Closure) Type

func (c *Closure) Type() Type

Type returns the type of the object

type Comparable

type Comparable interface {
	Compare(other Object) int
}

Comparable is the interface for objects to implement suitable comparisons

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

func (cf *CompiledFunction) Bool() bool

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 Copyable

type Copyable interface {
	Copy() Object
}

Copyable is the interface for creating copies of objects

type DivisionByZeroError

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

DivisionByZeroError is an error returned when dividing by zero

func NewDivisionByZeroError

func NewDivisionByZeroError(left Object) DivisionByZeroError

NewDivisionByZeroError returns a new DivisionByZeroError

func (DivisionByZeroError) Error

func (e DivisionByZeroError) Error() string

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) 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 binding that starts with a capital letter. This is used by the module import system to wrap up the evaluated module into an object.

func (*Environment) Get

func (e *Environment) Get(name string) (Object, bool)

Get returns the object bound by name

func (*Environment) New

func (e *Environment) New() *Environment

New creates a new copy of the environment with the current environment as parent

func (*Environment) Set

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

Set stores the object with the given name

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 tracked through the evaluator and when encountered stops evaluation of the program or body of a function.

func (Error) Bool

func (e Error) Bool() bool

func (Error) Copy

func (e Error) Copy() Object

Copy implements the Copyable interface

func (Error) Inspect

func (e Error) Inspect() string

Inspect returns a stringified version of the object for debugging

func (Error) String

func (e Error) String() string

func (Error) Type

func (e Error) Type() Type

Type returns the type of the object

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.

func (Function) Bool

func (f Function) Bool() bool

func (Function) Inspect

func (f Function) Inspect() string

Inspect returns a stringified version of the object for debugging

func (Function) String

func (f Function) String() string

func (Function) Type

func (f Function) Type() Type

Type returns the type of the object

type Hash

type Hash struct {
	Pairs map[HashKey]HashPair
}

Hash is a hash map and holds a map of HashKey to HashPair(s)

func (*Hash) Add

func (h *Hash) Add(other Object) (Object, error)

func (*Hash) Bool

func (h *Hash) Bool() bool

func (*Hash) Compare

func (h *Hash) Compare(other Object) int

func (*Hash) Get

func (h *Hash) Get(index Object) (Object, error)

func (*Hash) Inspect

func (h *Hash) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Hash) Len

func (h *Hash) Len() int

func (*Hash) Set

func (h *Hash) Set(index, other Object) error

func (*Hash) String

func (h *Hash) String() string

func (*Hash) Type

func (h *Hash) Type() Type

Type returns the type of the object

type HashKey

type HashKey struct {
	Type  Type
	Value uint64
}

HashKey represents a hash key object and holds the Type of Object hashed and its hash value in Value

type HashPair

type HashPair struct {
	Key   Object
	Value Object
}

HashPair is an object that holds a key and value of type Object

type Hasher

type Hasher interface {
	Hash() HashKey
}

Hasher is the interface for objects to provide suitable hash keys

type Integer

type Integer struct {
	Value int64
}

Integer is the integer type used to represent integer literals and holds an internal int64 value

func (Integer) Add

func (i Integer) Add(other Object) (Object, error)

func (Integer) BitwiseAnd

func (i Integer) BitwiseAnd(other Object) (Object, error)

func (Integer) BitwiseNot

func (i Integer) BitwiseNot() Object

func (Integer) BitwiseOr

func (i Integer) BitwiseOr(other Object) (Object, error)

func (Integer) BitwiseXor

func (i Integer) BitwiseXor(other Object) (Object, error)

func (Integer) Bool

func (i Integer) Bool() bool

func (Integer) Compare

func (i Integer) Compare(other Object) int

func (Integer) Copy

func (i Integer) Copy() Object

Copy implements the Copyable interface

func (Integer) Div

func (i Integer) Div(other Object) (Object, error)

func (Integer) Hash

func (i Integer) Hash() HashKey

Hash implements the Hasher interface

func (Integer) Inspect

func (i Integer) Inspect() string

Inspect returns a stringified version of the object for debugging

func (Integer) LeftShift

func (i Integer) LeftShift(other Object) (Object, error)

func (Integer) LogicalNot

func (i Integer) LogicalNot() Object

func (Integer) Mod

func (i Integer) Mod(other Object) (Object, error)

func (Integer) Mul

func (i Integer) Mul(other Object) (Object, error)

func (Integer) Negate

func (i Integer) Negate() Object

func (Integer) RightShift

func (i Integer) RightShift(other Object) (Object, error)

func (Integer) String

func (i Integer) String() string

func (Integer) Sub

func (i Integer) Sub(other Object) (Object, error)

func (Integer) Type

func (i Integer) Type() Type

Type returns the type of the object

type Module

type Module struct {
	Name  string
	Attrs Object
}

Module is the module type used to represent a collection of variabels.

func (Module) Bool

func (m Module) Bool() bool

func (Module) Compare

func (m Module) Compare(other Object) int

func (Module) Get

func (m Module) Get(index Object) (Object, error)

func (Module) Inspect

func (m Module) Inspect() string

Inspect returns a stringified version of the object for debugging

func (Module) String

func (m Module) String() string

func (Module) Type

func (m Module) Type() Type

Type returns the type of the object

type Null

type Null struct{}

func (Null) Bool

func (n Null) Bool() bool

func (Null) Compare

func (n Null) Compare(other Object) int

func (Null) Inspect

func (n Null) Inspect() string

Inspect returns a stringified version of the object for debugging

func (Null) LogicalNot

func (n Null) LogicalNot() Object

func (Null) String

func (n Null) String() string

func (Null) Type

func (n Null) Type() Type

Type returns the type of the object

type Object

type Object interface {
	fmt.Stringer
	Type() Type
	Bool() bool
	Inspect() string
}

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 evaluator and when encountered stops evaluation of the program, or body of a function.

func (Return) Bool

func (r Return) Bool() bool

func (Return) Inspect

func (r Return) Inspect() string

Inspect returns a stringified version of the object for debugging

func (Return) String

func (r Return) String() string

func (Return) Type

func (r Return) Type() Type

Type returns the type of the object

type String

type String struct {
	Value string
}

String is the string type used to represent string literals and holds an internal string value

func (String) Add

func (s String) Add(other Object) (Object, error)

func (String) Bool

func (s String) Bool() bool

func (String) Compare

func (s String) Compare(other Object) int

func (String) Copy

func (s String) Copy() Object

Copy implements the Copyable interface

func (String) Get

func (s String) Get(index Object) (Object, error)

func (String) Hash

func (s String) Hash() HashKey

Hash implements the Hasher interface

func (String) Inspect

func (s String) Inspect() string

Inspect returns a stringified version of the object for debugging

func (String) Len

func (s String) Len() int

func (String) Mul

func (s String) Mul(other Object) (Object, error)

func (String) String

func (s String) String() string

func (String) Type

func (s String) Type() Type

Type returns the type of the object

type Type

type Type int

Type represents the type of an object

const (
	NullType Type = iota
	IntegerType
	StringType
	BooleanType
	ReturnType
	ErrorType
	FunctionType
	CFunctionType
	BuiltinType
	ClosureType
	ArrayType
	HashType
	ModuleType
)

func (Type) String

func (t Type) String() string

Jump to

Keyboard shortcuts

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