object

package
Version: v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2021 License: MIT Imports: 11 Imported by: 2

Documentation

Overview

Package object describes a named language entity such as a type, variable, function, or literal. All objects implement the Object interface.

Package object describes a named language entity such as a type, variable, function, or literal. All objects implement the Object interface.

Index

Constants

View Source
const (
	BOOLEAN_OBJ      = "BOOLEAN"
	BUILTIN_OBJ      = "BUILTIN"
	ERROR_OBJ        = "ERROR"
	FUNCTION_OBJ     = "FUNCTION"
	LIST_OBJ         = "LIST"
	MAP_OBJ          = "MAP"
	MODULE_OBJ       = "MODULE"
	NULL_OBJ         = "NULL"
	NUMBER_OBJ       = "NUMBER"
	PACKAGE_OBJ      = "PACKAGE"
	RETURN_VALUE_OBJ = "RETURN_VALUE"
	STRING_OBJ       = "STRING"

	NoMethodFound = "no method '%s' for %s found"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Boolean

type Boolean struct {
	Value bool
}

func (*Boolean) CallMethod added in v0.10.0

func (b *Boolean) CallMethod(method string, args []Object) Object

func (*Boolean) Inspect

func (b *Boolean) Inspect() string

func (*Boolean) MapKey

func (b *Boolean) MapKey() MapKey

func (*Boolean) Set

func (b *Boolean) Set(obj Object)

func (*Boolean) Type

func (b *Boolean) Type() ObjectType

type Builtin

type Builtin struct {
	Name string
	Fn   BuiltinFunction
}

func (*Builtin) CallMethod added in v0.10.0

func (b *Builtin) CallMethod(method string, args []Object) Object

func (*Builtin) Inspect

func (b *Builtin) Inspect() string

func (*Builtin) Type

func (b *Builtin) Type() ObjectType

type BuiltinFunction

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

type Environment

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

Environment is an object that holds a mapping of names to bound objects

func NewEnclosedEnvironment

func NewEnclosedEnvironment(outer *Environment) *Environment

NewEnclosedEnvironment constructs a new Environment, extending off a pre-existing environment.

func NewEnvironment

func NewEnvironment() *Environment

NewEnvironment constructs a new Environment object to hold bindings of identifiers to their names

func (*Environment) All

func (e *Environment) All() map[string]Object

All returns all stored identifiers.

func (*Environment) Delete added in v0.3.0

func (e *Environment) Delete(name string)

Delete removes the object with the given name

func (*Environment) Exported

func (e *Environment) Exported() *Map

func (*Environment) Get

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

Get returns the object bound by name

func (*Environment) GetDirectory added in v0.14.0

func (e *Environment) GetDirectory() string

func (*Environment) GetWriter added in v0.12.0

func (e *Environment) GetWriter() io.Writer

func (*Environment) Set

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

Set stores the object with the given name

func (*Environment) SetDirectory added in v0.14.0

func (e *Environment) SetDirectory(directory string)

func (*Environment) SetWriter added in v0.12.0

func (e *Environment) SetWriter(writer io.Writer)

type Error

type Error struct {
	Message string
}

func (*Error) CallMethod added in v0.10.0

func (e *Error) CallMethod(method string, args []Object) Object

func (*Error) Inspect

func (e *Error) Inspect() string

func (*Error) Set

func (e *Error) Set(obj Object)

func (*Error) Type

func (e *Error) Type() ObjectType

type Function

type Function struct {
	Parameters []*ast.IdentifierLiteral
	Body       *ast.BlockStatement
	Defaults   map[string]ast.Expression
	Env        *Environment
}

func (*Function) CallMethod added in v0.10.0

func (f *Function) CallMethod(method string, args []Object) Object

func (*Function) Inspect

func (f *Function) Inspect() string

func (*Function) Type

func (f *Function) Type() ObjectType

type List

type List struct {
	Elements []Object
}

func (*List) CallMethod added in v0.10.0

func (l *List) CallMethod(method string, args []Object) Object

func (*List) Inspect

func (l *List) Inspect() string

func (*List) Set

func (l *List) Set(obj Object)

func (*List) Type

func (l *List) Type() ObjectType

type Map

type Map struct {
	Pairs map[MapKey]MapPair
}

func (*Map) CallMethod added in v0.10.0

func (m *Map) CallMethod(method string, args []Object) Object

func (*Map) GetKeyType added in v0.6.0

func (m *Map) GetKeyType(key string) ObjectType

func (*Map) GetPair added in v0.6.0

func (m *Map) GetPair(key string) (MapPair, bool)

func (*Map) Inspect

func (m *Map) Inspect() string

func (*Map) Type

func (m *Map) Type() ObjectType

type MapKey

type MapKey struct {
	Type  ObjectType
	Value uint64
}

MapKey defines the key for maps that can be comparable and unique.

type MapPair

type MapPair struct {
	Key   Object
	Value Object
}

type Mappable

type Mappable interface {
	MapKey() MapKey
}

type Module

type Module struct {
	Name      string
	Functions []BuiltinFunction
}

func (*Module) CallMethod added in v0.10.0

func (m *Module) CallMethod(method string, args []Object) Object

func (*Module) Inspect

func (m *Module) Inspect() string

func (*Module) Type

func (m *Module) Type() ObjectType

type Mutable

type Mutable interface {
	Set(obj Object)
}

Mutable interface is implemented by all mutable objects.

type Null

type Null struct{}

func (*Null) CallMethod added in v0.10.0

func (n *Null) CallMethod(method string, args []Object) Object

func (*Null) Inspect

func (n *Null) Inspect() string

func (*Null) Type

func (n *Null) Type() ObjectType

type Number

type Number struct {
	Value decimal.Decimal
}

func (*Number) CallMethod added in v0.10.0

func (n *Number) CallMethod(method string, args []Object) Object

func (*Number) Inspect

func (n *Number) Inspect() string

func (*Number) MapKey

func (n *Number) MapKey() MapKey

func (*Number) Set

func (n *Number) Set(obj Object)

func (*Number) Type

func (n *Number) Type() ObjectType

type Object

type Object interface {
	Type() ObjectType
	Inspect() string
	CallMethod(method string, args []Object) Object
}

Object interface is implemented by all objects.

type ObjectType

type ObjectType string

type Package added in v0.4.0

type Package struct {
	Name       string
	Attributes Object
}

func (*Package) CallMethod added in v0.10.0

func (p *Package) CallMethod(method string, args []Object) Object

func (*Package) Inspect added in v0.4.0

func (m *Package) Inspect() string

func (*Package) Type added in v0.4.0

func (m *Package) Type() ObjectType

type ReturnValue

type ReturnValue struct {
	Value Object
}

func (*ReturnValue) CallMethod added in v0.10.0

func (rv *ReturnValue) CallMethod(method string, args []Object) Object

func (*ReturnValue) Inspect

func (rv *ReturnValue) Inspect() string

func (*ReturnValue) Type

func (rv *ReturnValue) Type() ObjectType

type String

type String struct {
	Value string
}

func (*String) CallMethod added in v0.10.0

func (s *String) CallMethod(method string, args []Object) Object

func (*String) Inspect

func (s *String) Inspect() string

func (*String) MapKey

func (s *String) MapKey() MapKey

func (*String) Set

func (s *String) Set(obj Object)

func (*String) Type

func (s *String) Type() ObjectType

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL