object

package
v1.3.5 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// INTEGER is the Integer object type
	INTEGER = "int"

	// STRING is the String object type
	STRING = "str"

	// BOOLEAN is the Boolean object type
	BOOLEAN = "bool"

	// NULL is the Null object type
	NULL = "null"

	// RETURN is the Return object type
	RETURN = "return"

	// ERROR is the Error object type
	ERROR = "error"

	// FUNCTION is the Function object type
	FUNCTION = "fn"

	// COMPILED_FUNCTION is the CompiledFunction object type
	COMPILED_FUNCTION = "COMPILED_FUNCTION"

	// BUILTIN is the Builtin object type
	BUILTIN = "builtin"

	// CLOSURE is the Closure object type
	CLOSURE = "closure"

	// ARRAY is the Array object type
	ARRAY = "array"

	// HASH is the Hash object type
	HASH = "hash"

	// MODULE is the Module object type
	MODULE = "module"
)

Variables

View Source
var (
	Arguments      []string
	StandardInput  io.Reader
	StandardOutput io.Writer
	ExitFunction   func(int)
)

Functions

This section is empty.

Types

type Array

type Array struct {
	Elements []Object
}

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

func (*Array) Append added in v1.3.0

func (a *Array) Append(obj Object)

func (*Array) Bool added in v1.3.0

func (a *Array) Bool() bool

func (*Array) Compare added in v1.3.0

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

func (*Array) Copy added in v1.2.0

func (a *Array) Copy() *Array

func (*Array) Inspect

func (ao *Array) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Array) Len added in v1.2.0

func (a *Array) Len() int

func (*Array) Less added in v1.2.0

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

func (*Array) PopLeft added in v1.3.0

func (a *Array) PopLeft() Object

func (*Array) PopRight added in v1.3.0

func (a *Array) PopRight() Object

func (*Array) Prepend added in v1.3.0

func (a *Array) Prepend(obj Object)

func (*Array) Reverse added in v1.2.0

func (a *Array) Reverse()

func (*Array) String

func (ao *Array) String() string

func (*Array) Swap added in v1.2.0

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

func (*Array) Type

func (ao *Array) Type() Type

Type returns the type of the object

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 (*Boolean) Bool added in v1.3.0

func (b *Boolean) Bool() bool

func (*Boolean) Clone

func (b *Boolean) Clone() Object

Clone creates a new copy

func (*Boolean) Compare added in v1.3.0

func (b *Boolean) Compare(other Object) int

func (*Boolean) HashKey

func (b *Boolean) HashKey() HashKey

HashKey returns a HashKey object

func (*Boolean) Inspect

func (b *Boolean) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Boolean) Int added in v1.2.0

func (b *Boolean) Int() int

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 added in v1.3.0

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(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 added in v1.3.0

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 comparing two Object and their underlying values. It is the responsibility of the caller (left) to check for types. Returns `true` iif the types and values are identical, `false` otherwise.

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 added in v1.3.0

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

func (e *Environment) Clone() *Environment

Clone returns a new Environment with the parent set to the current environment (enclosing environment)

func (*Environment) ExportedHash added in v1.3.0

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 evaulated module into an object.

func (*Environment) Get

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

Get returns the object bound by name

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

func (*Error) Bool added in v1.3.0

func (e *Error) Bool() bool

func (*Error) Clone

func (e *Error) Clone() Object

Clone creates a new copy

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 added in v1.3.0

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) Bool added in v1.3.0

func (h *Hash) Bool() bool

func (*Hash) Compare added in v1.3.0

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

func (*Hash) Inspect

func (h *Hash) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Hash) Len added in v1.3.0

func (h *Hash) Len() int

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 Hashable

type Hashable interface {
	HashKey() HashKey
}

Hashable is the interface for all hashable objects which must implement the HashKey() method which reutrns a HashKey result.

type Immutable

type Immutable interface {
	Clone() Object
}

Immutable is the interface for all immutable objects which must implement the Clone() method used by binding names to values.

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) Bool added in v1.3.0

func (i *Integer) Bool() bool

func (*Integer) Clone

func (i *Integer) Clone() Object

Clone creates a new copy

func (*Integer) Compare added in v1.3.0

func (i *Integer) Compare(other Object) int

func (*Integer) HashKey

func (i *Integer) HashKey() HashKey

HashKey returns a HashKey object

func (*Integer) Inspect

func (i *Integer) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Integer) String

func (i *Integer) String() string

func (*Integer) Type

func (i *Integer) Type() Type

Type returns the type of the object

type Module added in v1.3.0

type Module struct {
	Name  string
	Attrs Object
}

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

func (*Module) Bool added in v1.3.0

func (m *Module) Bool() bool

func (*Module) Compare added in v1.3.0

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

func (*Module) Inspect added in v1.3.0

func (m *Module) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Module) String added in v1.3.0

func (m *Module) String() string

func (*Module) Type added in v1.3.0

func (m *Module) Type() Type

Type returns the type of the object

type Null

type Null struct{}

Null is the null type and used to represent the absence of a value

func (*Null) Bool added in v1.3.0

func (n *Null) Bool() bool

func (*Null) Compare added in v1.3.0

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

func (*Return) Bool added in v1.3.0

func (rv *Return) Bool() bool

func (*Return) Inspect

func (rv *Return) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Return) String

func (rv *Return) String() string

func (*Return) Type

func (rv *Return) Type() Type

Type returns the type of the object

type Sizeable added in v1.3.0

type Sizeable interface {
	Len() int
}

Sizeable is the interface for returning the size of an Object. Object(s) that have a valid size must implement this interface and the Len() method.

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) Bool added in v1.3.0

func (s *String) Bool() bool

func (*String) Clone

func (s *String) Clone() Object

Clone creates a new copy

func (*String) Compare added in v1.3.0

func (s *String) Compare(other Object) int

func (*String) HashKey

func (s *String) HashKey() HashKey

HashKey returns a HashKey object

func (*String) Inspect

func (s *String) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*String) Len added in v1.3.0

func (s *String) Len() int

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 string

Type represents the type of an object

Jump to

Keyboard shortcuts

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