object

package
v0.0.1-lw Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: MIT, MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NUMBER_OBJ   = "NUMBER"
	STRING_OBJ   = "STRING"
	BOOLEAN_OBJ  = "BOOLEAN"
	NULL_OBJ     = "NULL"
	RETURN_OBJ   = "RETURN"
	FUNCTION_OBJ = "FUNCTION"
	BUILTIN_OBJ  = "BUILTIN"
	ERROR_OBJ    = "ERROR"
	RANGE_OBJ    = "RANGE"
	// vector
	VECTOR_OBJ = "VECTOR"
	// dict
	DICT_OBJ = "DICT"

	// colors
	COLOR_BLUE  = "\033[34m"
	COLOR_RESET = "\033[0m"
)

Variables

View Source
var FALSE = &Boolean{Value: false}
View Source
var NULL = &Null{}

only need one "constant" object for true, false and null

View Source
var TRUE = &Boolean{Value: true}

Functions

func IsError

func IsError(obj Object) bool

Types

type BaseVector

type BaseVector struct {
	Elements []Object
}

the inner element for all vectors, provides implementation for methods in IVector (doesn't have to be of IVector itself)

func (*BaseVector) Append

func (bv *BaseVector) Append(vals ...Object) Object

append objects to vector, flattening if necessary

func (*BaseVector) ElementType

func (bv *BaseVector) ElementType() ObjectType

func (*BaseVector) Head

func (bv *BaseVector) Head(n int) []Object

func (*BaseVector) Infix

func (bv *BaseVector) Infix(f func(Object, Object) Object, other IVector) Object

func (*BaseVector) Inspect

func (bv *BaseVector) Inspect() string

func (*BaseVector) Length

func (bv *BaseVector) Length() int

func (*BaseVector) Print

func (bv *BaseVector) Print(dtype string) string

func (*BaseVector) Replace

func (bv *BaseVector) Replace(start int, end int, replacement IVector, t ObjectType) Object

func (*BaseVector) Set

func (bv *BaseVector) Set(index int, val Object, t ObjectType) Object

func (*BaseVector) Slice

func (bv *BaseVector) Slice(start int, end int) Object

func (*BaseVector) Tail

func (bv *BaseVector) Tail(n int) []Object

func (*BaseVector) Type

func (bv *BaseVector) Type() ObjectType

func (*BaseVector) Values

func (bv *BaseVector) Values(n int) []Object

type Boolean

type Boolean struct {
	Value bool
}

func (*Boolean) Hash

func (b *Boolean) Hash() DictKey

func (*Boolean) Inspect

func (b *Boolean) Inspect() string

func (*Boolean) Type

func (b *Boolean) Type() ObjectType

type Builtin

type Builtin struct {
	RequiredParametersNum int
	Fn                    BuiltinFunction
}

func (*Builtin) Inspect

func (b *Builtin) Inspect() string

func (*Builtin) Type

func (b *Builtin) Type() ObjectType

type BuiltinFunction

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

type CharacterVector

type CharacterVector struct {
	BaseVector
}

vectors with object.String

func (*CharacterVector) Append

func (cv *CharacterVector) Append(objects ...Object) Object

func (*CharacterVector) ElementType

func (bv *CharacterVector) ElementType() ObjectType

func (*CharacterVector) Head

func (cv *CharacterVector) Head(n int) Object

func (*CharacterVector) Infix

func (cv *CharacterVector) Infix(f func(Object, Object) Object, other IVector) Object

func (*CharacterVector) Inspect

func (cv *CharacterVector) Inspect() string

func (*CharacterVector) Length

func (cv *CharacterVector) Length() int

func (*CharacterVector) New

func (cv *CharacterVector) New(elements []Object) IVector

func (*CharacterVector) Print

func (cv *CharacterVector) Print() string

func (*CharacterVector) Replace

func (cv *CharacterVector) Replace(start int, end int, replacement IVector) Object

func (*CharacterVector) Set

func (cv *CharacterVector) Set(index int, val Object) Object

func (*CharacterVector) Slice

func (cv *CharacterVector) Slice(start int, end int) Object

func (*CharacterVector) Tail

func (cv *CharacterVector) Tail(n int) Object

func (*CharacterVector) Type

func (cv *CharacterVector) Type() ObjectType

func (*CharacterVector) Values

func (cv *CharacterVector) Values() []Object

type Dict

type Dict struct {
	Pairs map[DictKey]DictPair
}

{"a": 1} => &Dict{Pairs: {"a".Hash(): {"a": 1}}}

func (*Dict) Get

func (d *Dict) Get(key Object) (Object, bool)

func (*Dict) Inspect

func (d *Dict) Inspect() string

func (*Dict) Keys

func (d *Dict) Keys() []Object

func (*Dict) Set

func (d *Dict) Set(key Object, value Object)

func (*Dict) Type

func (d *Dict) Type() ObjectType

type DictKey

type DictKey struct {
	Type  ObjectType // the type of the origional key in DictLiteral, one of String, Integer, or Boolean
	Value uint64
}

type DictPair

type DictPair struct {
	Key   Object // the origional key in DictLiteral, one of String, Integer, or Boolean
	Value Object
}

type Env

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

func NewEnclosedEnvironment

func NewEnclosedEnvironment(outer *Env) *Env

func NewEnv

func NewEnv() *Env

func (*Env) Get

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

func (*Env) GetAllEnvs

func (e *Env) GetAllEnvs() []*Env

func (*Env) GetOuterEnv

func (e *Env) GetOuterEnv() *Env

func (*Env) InStore

func (e *Env) InStore(name string) bool

func (*Env) Set

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

type Error

type Error struct {
	Message string
}

func NewError

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

func (*Error) Inspect

func (e *Error) Inspect() string

func (*Error) Type

func (e *Error) Type() ObjectType

type Function

type Function struct {
	Parameters            []*ast.Identifier
	Defaults              map[string]ast.Expression
	RequiredParametersNum int
	Body                  *ast.BlockStatement
	Env                   *Env
}

func (*Function) Inspect

func (f *Function) Inspect() string

func (*Function) Type

func (f *Function) Type() ObjectType

type Hashable

type Hashable interface {
	Hash() DictKey
}

type IVector

type IVector interface {
	Type() ObjectType
	Inspect() string
	Print() string
	ElementType() ObjectType
	Length() int
	Head(n int) Object
	Tail(n int) Object
	Values() []Object
	Slice(start int, end int) Object
	Append(objects ...Object) Object
	Set(start int, val Object) Object
	Replace(start int, end int, replacement IVector) Object
	Infix(func(Object, Object) Object, IVector) Object
}

interface for all vectors

type Integer

type Integer struct {
	Value int64
}

not used, all numbers are stored as float64

func (*Integer) Hash

func (i *Integer) Hash() DictKey

func (*Integer) Inspect

func (n *Integer) Inspect() string

func (*Integer) Type

func (n *Integer) Type() ObjectType

type LogicalVector

type LogicalVector struct {
	BaseVector
}

vectors with object.Boolean

func (*LogicalVector) Append

func (lv *LogicalVector) Append(objects ...Object) Object

func (*LogicalVector) ElementType

func (bv *LogicalVector) ElementType() ObjectType

func (*LogicalVector) Head

func (lv *LogicalVector) Head(n int) Object

func (*LogicalVector) Infix

func (lv *LogicalVector) Infix(f func(Object, Object) Object, other IVector) Object

func (*LogicalVector) Inspect

func (lv *LogicalVector) Inspect() string

func (*LogicalVector) Length

func (lv *LogicalVector) Length() int

func (*LogicalVector) New

func (lv *LogicalVector) New(elements []Object) IVector

func (*LogicalVector) Print

func (lv *LogicalVector) Print() string

func (*LogicalVector) Replace

func (lv *LogicalVector) Replace(start int, end int, replacement IVector) Object

func (*LogicalVector) Set

func (lv *LogicalVector) Set(index int, val Object) Object

func (*LogicalVector) Slice

func (lv *LogicalVector) Slice(start int, end int) Object

func (*LogicalVector) Tail

func (lv *LogicalVector) Tail(n int) Object

func (*LogicalVector) Type

func (lv *LogicalVector) Type() ObjectType

func (*LogicalVector) Values

func (lv *LogicalVector) Values() []Object

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

func (*Number) Clone

func (i *Number) Clone() Object

func (*Number) Hash

func (i *Number) Hash() DictKey

func (*Number) Inspect

func (n *Number) Inspect() string

func (*Number) Type

func (n *Number) Type() ObjectType

type NumericVector

type NumericVector struct {
	BaseVector
}

vectors with object.Number

func (*NumericVector) Append

func (nv *NumericVector) Append(objects ...Object) Object

func (*NumericVector) ElementType

func (bv *NumericVector) ElementType() ObjectType

func (*NumericVector) Head

func (nv *NumericVector) Head(n int) Object

func (*NumericVector) Infix

func (nv *NumericVector) Infix(f func(Object, Object) Object, other IVector) Object

func (*NumericVector) Inspect

func (nv *NumericVector) Inspect() string

func (*NumericVector) Length

func (nv *NumericVector) Length() int

func (*NumericVector) New

func (nv *NumericVector) New(elements []Object) IVector

func (*NumericVector) Print

func (nv *NumericVector) Print() string

func (*NumericVector) Replace

func (nv *NumericVector) Replace(start int, end int, replacement IVector) Object

func (*NumericVector) Set

func (nv *NumericVector) Set(index int, val Object) Object

func (*NumericVector) Slice

func (nv *NumericVector) Slice(start int, end int) Object

func (*NumericVector) Tail

func (nv *NumericVector) Tail(n int) Object

func (*NumericVector) Type

func (nv *NumericVector) Type() ObjectType

func (*NumericVector) Values

func (nv *NumericVector) Values() []Object

type Object

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

func NewVector

func NewVector(elements []Object) Object

create vector based on type of first element

type ObjectType

type ObjectType string

type Range

type Range struct {
	Start int
	End   int
}

func (*Range) Inspect

func (r *Range) Inspect() string

func (*Range) Type

func (r *Range) Type() ObjectType

type ReturnValue

type ReturnValue struct {
	Value Object
}

func (*ReturnValue) Inspect

func (r *ReturnValue) Inspect() string

func (*ReturnValue) Type

func (r *ReturnValue) Type() ObjectType

type String

type String struct {
	Value string
}

func (*String) Clone

func (s *String) Clone() Object

func (*String) Hash

func (s *String) Hash() DictKey

func (*String) Inspect

func (s *String) Inspect() string

func (*String) Type

func (s *String) Type() ObjectType

type Vector

type Vector struct {
	BaseVector
}

vector with mixed types

func (*Vector) Append

func (v *Vector) Append(objects ...Object) Object

func (*Vector) ElementType

func (bv *Vector) ElementType() ObjectType

func (*Vector) Head

func (v *Vector) Head(n int) Object

func (*Vector) Infix

func (v *Vector) Infix(f func(Object, Object) Object, other IVector) Object

func (*Vector) Inspect

func (v *Vector) Inspect() string

func (*Vector) Length

func (v *Vector) Length() int

func (*Vector) Print

func (v *Vector) Print() string

func (*Vector) Replace

func (v *Vector) Replace(start int, end int, replacement IVector) Object

func (*Vector) Set

func (v *Vector) Set(index int, val Object) Object

func (*Vector) Slice

func (v *Vector) Slice(start int, end int) Object

func (*Vector) Tail

func (v *Vector) Tail(n int) Object

func (*Vector) Type

func (v *Vector) Type() ObjectType

func (*Vector) Values

func (v *Vector) Values() []Object

Jump to

Keyboard shortcuts

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