object

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2020 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

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

	// FLOAT is the Float object type
	FLOAT = "float"

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

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

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

	// IMAGE is the Image object type
	IMAGE = "image"
)

Variables

This section is empty.

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

func (ar *Array) Append(obj Object)

func (*Array) Bool

func (ar *Array) Bool() bool

Bool implements the Object Bool method

func (*Array) Compare

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

Compare complies with Comparable interface

func (*Array) Copy

func (ar *Array) Copy() *Array

func (*Array) Inspect

func (ar *Array) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Array) Len

func (ar *Array) Len() int

Len complies with Sizeable interface

func (*Array) Less

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

func (*Array) PopLeft

func (ar *Array) PopLeft() Object

func (*Array) PopRight

func (ar *Array) PopRight() Object

func (*Array) Prepend

func (ar *Array) Prepend(obj Object)

func (*Array) Reverse

func (ar *Array) Reverse()

func (*Array) String

func (ar *Array) String() string

func (*Array) Swap

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

func (*Array) ToInterface

func (ar *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 (ar *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

func (b *Boolean) Bool() bool

Bool implements the Object Bool method

func (*Boolean) Clone

func (b *Boolean) Clone() Object

Clone creates a new copy

func (*Boolean) Compare

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

Compare complies with Comparable 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

Int converts the boolean value to int

func (*Boolean) String

func (b *Boolean) String() 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.

It might also be helpful for embedded users.

func (*Boolean) Type

func (b *Boolean) Type() Type

Type returns the type of the object

type Builtin

type Builtin struct {
	Name string
	Fn   BuiltinFunction
	Env  *Environment
}

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

Bool implements the Object Bool method

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) 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 the object

type BuiltinFunction

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

BuiltinFunction represents the builtin function type

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 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(ctx gg.GraphicContext, opts ...EnvironmentOption) *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) Get

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

Get returns the object bound by name

func (*Environment) GraphicContext added in v0.5.0

func (e *Environment) GraphicContext() gg.GraphicContext

GraphicContext returns the graphics context

func (*Environment) Set

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

Set stores the object with the given name

func (*Environment) SetGraphicContext added in v0.5.0

func (e *Environment) SetGraphicContext(ctx gg.GraphicContext)

SetGraphicContext sets the graphics context

func (*Environment) SnapshotFilename added in v0.5.0

func (e *Environment) SnapshotFilename() string

SnapshotFilename returns the snapshot filename

func (*Environment) SnapshotFolder added in v0.5.0

func (e *Environment) SnapshotFolder() string

SnapshotFolder returns the snapshot output folder

type EnvironmentOption added in v0.5.0

type EnvironmentOption func(*Environment)

EnvironmentOption defines a functional option for the environment creation

func WithOutputDir added in v0.5.0

func WithOutputDir(dir string) EnvironmentOption

WithOutputDir sets the snapshot output directory

func WithSnapshotPrefix added in v0.5.0

func WithSnapshotPrefix(prefix string) EnvironmentOption

WithSnapshotPrefix sets the snapshot filename prefix

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 NewError added in v0.4.1

func NewError(format string, a ...interface{}) *Error

NewError builds an error with a custom message Helper function used in all builtins.

func (*Error) Bool

func (e *Error) Bool() bool

Bool implements the Object Bool method

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) 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 the object

type Float

type Float struct {
	Value float64
}

Float is the float type used to represent float literals and holds an internal float64 value

func (*Float) Bool

func (f *Float) Bool() bool

Bool implements the Object Bool method

func (*Float) Clone

func (f *Float) Clone() Object

Clone creates a new copy

func (*Float) Compare

func (f *Float) Compare(other Object) int

Compare complies with Comparable interface

func (*Float) Inspect

func (f *Float) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Float) String

func (f *Float) String() 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.

It might also be helpful for embedded users.

func (*Float) Type

func (f *Float) 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

Bool implements the Object Bool method

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) 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 the object

type Image added in v0.4.1

type Image struct {
	Value image.Image
}

Image represents an image object

func (*Image) Bool added in v0.4.1

func (im *Image) Bool() bool

Bool implements the Object Bool method

func (*Image) Clone added in v0.4.1

func (im *Image) Clone() Object

Clone creates a new copy

func (*Image) Inspect added in v0.4.1

func (im *Image) Inspect() string

Inspect returns a stringified version of the object for debugging

func (*Image) String added in v0.4.1

func (im *Image) String() string

func (*Image) ToInterface added in v0.4.1

func (im *Image) 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 (*Image) Type added in v0.4.1

func (im *Image) Type() Type

Type returns the type of the object

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

func (i *Integer) Bool() bool

Bool implements the Object Bool method

func (*Integer) Clone

func (i *Integer) Clone() Object

Clone creates a new copy

func (*Integer) Compare

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

Compare complies with Comparable interface

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) 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 the object

type Null

type Null struct{}

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

func (*Null) Bool

func (n *Null) Bool() bool

Bool implements the Object Bool method

func (*Null) Compare

func (n *Null) Compare(other Object) int

Compare complies with Comparable interface

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) 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 the object

type Object

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

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

func (rv *Return) Bool() bool

Bool implements the Object Bool method

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

func (rv *Return) 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 (*Return) Type

func (rv *Return) Type() Type

Type returns the type of the object

type Sizeable

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

func (s *String) Bool() bool

Bool implements the Object Bool method

func (*String) Clone

func (s *String) Clone() Object

Clone creates a new copy (complies with Immutable interface)

func (*String) Compare

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

Compare complies with Comparable 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

Len complies with Sizeable interface

func (*String) String

func (s *String) String() string

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