object

package
v0.0.0-...-804c98d Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//INTEGER - Integer
	INTEGER = "INT_OBJ"
	//FLOAT - Float
	FLOAT = "FLT_OBJ"
	//STRING - String
	STRING = "STR_OBJ"
	//BOOLEAN - Boolean
	BOOLEAN = "BOOL_OBJ"
	//ARRAY - Array
	ARRAY = "ARR_OBJ"
	//MAP - Map
	MAP = "MAP_OBJ"
	//INDEX - Map or Array index
	INDEX = "IDX_OBJ"
	//NULL - Null value
	NULL = "NULL_OBJ"
	//RETURN - Return value of a block
	RETURN = "RETURN_OBJ"
	//FUNCTION - Function object
	FUNCTION = "FUNC_OBJ"
	//BUILTIN - Builtin function
	BUILTIN = "BUILTIN_OBJ"

	//ERROR - Error object
	ERROR = "ERROR_OBJ"

	//IDENT - Identifier
	IDENT = "IDENT_OBJ"

	//PRES - Program result
	PRES = "PROG_RES"

	//ENVIRONMENT - Environment
	ENVIRONMENT = "ENV_OBJ"
)

Variables

This section is empty.

Functions

func IsErr

func IsErr(o Object) bool

IsErr checks whether a result is Exception

func IsNull

func IsNull(o Object) bool

IsNull checks whether a result is Null

Types

type Array

type Array struct {
	Elements []Object
}

Array represents an array

func (*Array) Display

func (a *Array) Display()

Display implements Object for Array

func (*Array) Inspect

func (a *Array) Inspect() string

Inspect implements Object for Array

func (*Array) Type

func (a *Array) Type() string

Type implements Object for Array

type Boolean

type Boolean struct {
	Value bool
}

Boolean represents a bool

func (*Boolean) Display

func (b *Boolean) Display()

Display implements Object for Boolean

func (*Boolean) HashKey

func (b *Boolean) HashKey() HashKey

HashKey (boolean) implements Hashable for Boolean

func (*Boolean) Inspect

func (b *Boolean) Inspect() string

Inspect implements Object for Boolean

func (*Boolean) Type

func (b *Boolean) Type() string

Type implements Object for Boolean

type Builtin

type Builtin struct {
	Fn BuiltinFn
}

Builtin - a builtin interpreter function

func (*Builtin) Display

func (b *Builtin) Display()

Display implements Object for Builtin

func (*Builtin) Inspect

func (b *Builtin) Inspect() string

Inspect implements Object for Builtin

func (*Builtin) Type

func (b *Builtin) Type() string

Type implements Object for Builtin

type BuiltinFn

type BuiltinFn func(ctxt lexer.Context, args ...Object) Object

BuiltinFn is a function that is implemented within the interpreter itself

type Environment

type Environment struct {
	Data  map[string]Object
	Outer *Environment
}

Environment represents the execution environment

func NewEnclosedEnv

func NewEnclosedEnv(outer *Environment) *Environment

NewEnclosedEnv nests the provided environment inside a new one It mimics a new stack frame

func NewEnv

func NewEnv() *Environment

NewEnv - Returns a new fresh environment

func (*Environment) Display

func (env *Environment) Display()

Display implements Object for Environment

func (*Environment) Get

func (env *Environment) Get(ident string) (Object, bool)

Get recursively gets a variable from the environment and all its outer envs

func (*Environment) Inspect

func (env *Environment) Inspect() string

Inspect implements Object for Environment

func (*Environment) Set

func (env *Environment) Set(ident string, val Object) Object

Set adds a variable to the environment

func (*Environment) Type

func (env *Environment) Type() string

Type implements Object for Environment

type Exception

type Exception struct {
	Msg string
	Con lexer.Context
}

Exception - an error type to return

func (*Exception) Display

func (ex *Exception) Display()

Display implements Object for Exception

func (*Exception) Inspect

func (ex *Exception) Inspect() string

Inspect implements Object for Exception

func (*Exception) Type

func (ex *Exception) Type() string

Type implements Object for Exception

type Float

type Float struct {
	Value float64
}

Float represents a Float

func (*Float) Display

func (f *Float) Display()

Display implements Object for Float

func (*Float) Inspect

func (f *Float) Inspect() string

Inspect implements Object for Float

func (*Float) Type

func (f *Float) Type() string

Type implements Object for Float

type Function

type Function struct {
	Params []*ast.Identifier
	Body   *ast.BlockStatement
	Env    *Environment
}

Function represents a function in the environment

func (*Function) Display

func (f *Function) Display()

Display implements Object for Function

func (*Function) Inspect

func (f *Function) Inspect() string

Inspect implements Object for Function

func (*Function) Type

func (f *Function) Type() string

Type implements Object for Function

type HashKey

type HashKey struct {
	Type  string
	Value uint64
}

HashKey defines the key used in the Map

type Hashable

type Hashable interface {
	HashKey() HashKey
}

Hashable defines whether a type can be used as a key in a Map

type Index

type Index struct {
	Ident Object
	Index Object
}

Index represents an array or map index

func (*Index) Display

func (i *Index) Display()

Display implements Object for Index

func (*Index) Inspect

func (i *Index) Inspect() string

Inspect implements Object for Index

func (*Index) Type

func (i *Index) Type() string

Type implements Object for Index

type Integer

type Integer struct {
	Value int64
}

Integer represents an integer

func (*Integer) Display

func (i *Integer) Display()

Display implements Object for Int

func (*Integer) HashKey

func (i *Integer) HashKey() HashKey

HashKey (integer) implements Hashable for Integer

func (*Integer) Inspect

func (i *Integer) Inspect() string

Inspect implements Object for Int

func (*Integer) Type

func (i *Integer) Type() string

Type implements Object for Int

type Map

type Map struct {
	Elements map[HashKey]Object
}

Map represents a map in memory

func (*Map) Display

func (m *Map) Display()

Display implements Object for Map

func (*Map) Inspect

func (m *Map) Inspect() string

Inspect implements Object for Map

func (*Map) Type

func (m *Map) Type() string

Type implements Object for Map

type Null

type Null struct{}

Null represents a null value

func (*Null) Display

func (n *Null) Display()

Display implements Object for Null

func (*Null) Inspect

func (n *Null) Inspect() string

Inspect implements Object for Identifier

func (*Null) Type

func (n *Null) Type() string

Type implements Object for Identifier

type Object

type Object interface {
	Type() string
	Inspect() string
	Display()
}

Object represents any object returnable from an expression

type Return

type Return struct {
	Inner Object
}

Return - A wrapper type for a value returned by a return statement

func (*Return) Display

func (r *Return) Display()

Display implements Object for Return

func (*Return) Inspect

func (r *Return) Inspect() string

Inspect implements Object for Return

func (*Return) Type

func (r *Return) Type() string

Type implements Object for Return

type StmtResults

type StmtResults struct {
	Results []Object
}

StmtResults is the results returned by a program

func (*StmtResults) Display

func (pr *StmtResults) Display()

Display implements Object for StmtResults

func (*StmtResults) Inspect

func (pr *StmtResults) Inspect() string

Inspect implements Object for StmtResults

func (*StmtResults) Type

func (pr *StmtResults) Type() string

Type implements Object for StmtResults

type String

type String struct {
	Value string
}

String represents a string

func (*String) Display

func (s *String) Display()

Display implements Object for Float

func (*String) HashKey

func (s *String) HashKey() HashKey

HashKey implements Hashable for String

func (*String) Inspect

func (s *String) Inspect() string

Inspect implements Object for String

func (*String) Type

func (s *String) Type() string

Type implements Object for String

Jump to

Keyboard shortcuts

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