object

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2020 License: MIT Imports: 8 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"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Boolean

type Boolean struct {
	Value bool
}

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

func (b *Builtin) Inspect() string

func (*Builtin) Type

func (b *Builtin) Type() ObjectType

type BuiltinFunction

type BuiltinFunction func(env *Environment, 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) Set

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

Set stores the object with the given name

type Error

type Error struct {
	Message string
}

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

func (f *Function) Inspect() string

func (*Function) Type

func (f *Function) Type() ObjectType

type List

type List struct {
	Elements []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) 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) 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) Inspect

func (n *Null) Inspect() string

func (*Null) Type

func (n *Null) Type() ObjectType

type Number

type Number struct {
	Value decimal.Decimal
}

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
}

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

func (rv *ReturnValue) Inspect() string

func (*ReturnValue) Type

func (rv *ReturnValue) Type() ObjectType

type String

type String struct {
	Value string
}

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
y or Y : Canonical URL