object

package
v0.0.0-...-43a95db Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// INTEGER_OBJ is the object type for integers
	INTEGER_OBJ = "INTEGER"
	// BOOLEAN_OBJ is the object type for booleans
	BOOLEAN_OBJ = "BOOLEAN"
	// NULL_OBJ is the object type for nulls
	NULL_OBJ = "NULL"
	// RETURN_VALUE_OBJ is the object type for return values
	RETURN_VALUE_OBJ = "RETURN_VALUE"
	// ERROR_OBJ is the object type for errors
	ERROR_OBJ = "ERROR"
	// FUNCTION_OBJ is the object type for functions
	FUNCTION_OBJ = "FUNCTION"
	// STRING_OBJ is the object type for strings
	STRING_OBJ = "STRING"
	// BUILTIN_OBJ is the object type for builtin functions
	BUILTIN_OBJ = "BUILTIN"
	// ARRAY_OBJ is the object type for arrays
	ARRAY_OBJ = "ARRAY"
	// HASH_OBJ is the object type for hashes
	HASH_OBJ = "HASH"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array struct {
	Elements []Object
}

Array is the object that holds arrays

func (*Array) Inspect

func (ao *Array) Inspect() string

Inspect returns a string representing the array

func (*Array) Type

func (ao *Array) Type() Type

Type returns the type string for the array

type Boolean

type Boolean struct {
	Value bool
}

Boolean is the object that holds booleans

func (*Boolean) Inspect

func (b *Boolean) Inspect() string

Inspect returns a formatted string with the value of the boolean

func (*Boolean) Type

func (b *Boolean) Type() Type

Type returns the type string for the boolean

type Builtin

type Builtin struct {
	Fn BuiltinFunction
}

Builtin is the object that holds builtin functions

func (*Builtin) Inspect

func (b *Builtin) Inspect() string

Inspect returns a string for the builtin function

func (*Builtin) Type

func (b *Builtin) Type() Type

Type returns the type string for the builtin function

type BuiltinFunction

type BuiltinFunction func(args ...Object) Object

BuiltinFunction is the type for functions defined by the interpreter

type Environment

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

Environment keeps track of identifiers and their values

func NewEnclosedEnvironment

func NewEnclosedEnvironment(outer *Environment) *Environment

NewEnclosedEnvironment creates a newly scoped environment with a reference to the outer env

func NewEnvironment

func NewEnvironment() *Environment

NewEnvironment creates a newly scoped environment

func (*Environment) Get

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

Get will return the value for an identifier if it exists

func (*Environment) Set

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

Set will save a new identifier and value to the environment

type Error

type Error struct {
	Message string
}

Error is the object that holds internal error messages

func (*Error) Inspect

func (e *Error) Inspect() string

Inspect returns a string with the message of the error

func (*Error) Type

func (e *Error) Type() Type

Type returns the type string for the error

type Function

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

Function is the object that holds the reference to an executable function

func (*Function) Inspect

func (f *Function) Inspect() string

Inspect returns a string representing the function

func (*Function) Type

func (f *Function) Type() Type

Type returns the type string for the function

type Hash

type Hash struct {
	Pairs map[string]Object
}

Hash is the object that holds hashes

func (*Hash) Inspect

func (h *Hash) Inspect() string

Inspect returns a string representing the hash

func (*Hash) Type

func (h *Hash) Type() Type

Type returns the type string for the hash

type Integer

type Integer struct {
	Value int64
}

Integer is the object that holds integers

func (*Integer) Inspect

func (i *Integer) Inspect() string

Inspect returns a formatted string with the value of the integer

func (*Integer) Type

func (i *Integer) Type() Type

Type returns the type string for the integer

type Null

type Null struct{}

Null is the object that holds nulls

func (*Null) Inspect

func (n *Null) Inspect() string

Inspect returns a string with the value of the null

func (*Null) Type

func (n *Null) Type() Type

Type returns the type string for the null

type Object

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

Object is a wrapper for values that we evaluate

type ReturnValue

type ReturnValue struct {
	Value Object
}

ReturnValue is the object that holds return values

func (*ReturnValue) Inspect

func (rv *ReturnValue) Inspect() string

Inspect returns a string with the value of the return value

func (*ReturnValue) Type

func (rv *ReturnValue) Type() Type

Type returns the type string for the return value

type String

type String struct {
	Value string
}

String is the object that holds strings

func (*String) Inspect

func (s *String) Inspect() string

Inspect returns the value of the string

func (*String) Type

func (s *String) Type() Type

Type returns the type string for the string

type Type

type Type string

Type is the type of an object

Jump to

Keyboard shortcuts

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