object

package
v0.0.0-...-95ae90b Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NullConst  = &Null{}
	TrueConst  = &Boolean{Value: true}
	FalseConst = &Boolean{Value: false}
)

These are all constants in the language that can be represented with a single instance

Functions

func ArrayToStringSlice

func ArrayToStringSlice(a *Array) []string

func InstanceOf

func InstanceOf(class string, i *Instance) bool

func InstanceOfAny

func InstanceOfAny(instance Object, classes ...string) bool

func IsConstErr

func IsConstErr(e error) bool

func ObjectIs

func ObjectIs(o Object, t ...ObjectType) bool

func ObjectsAre

func ObjectsAre(t ObjectType, o ...Object) bool

Types

type Array

type Array struct {
	Elements []Object
}

func MakeStringArray

func MakeStringArray(e []string) *Array

func (*Array) Dup

func (a *Array) Dup() Object

func (*Array) Inspect

func (a *Array) Inspect() string

func (*Array) Type

func (a *Array) Type() ObjectType

type Boolean

type Boolean struct {
	Value bool
}

func NativeBoolToBooleanObj

func NativeBoolToBooleanObj(input bool) *Boolean

func (*Boolean) Dup

func (b *Boolean) Dup() Object

func (*Boolean) Inspect

func (b *Boolean) Inspect() string

func (*Boolean) Type

func (b *Boolean) Type() ObjectType

type Builtin

type Builtin struct {
	Fn BuiltinFunction
}

func (*Builtin) Dup

func (b *Builtin) Dup() Object

func (*Builtin) Inspect

func (b *Builtin) Inspect() string

func (*Builtin) Type

func (b *Builtin) Type() ObjectType

type BuiltinFunction

type BuiltinFunction func(i Interpreter, env *Environment, args ...Object) Object

type BuiltinMethod

type BuiltinMethod struct {
	Fn       BuiltinMethodFunction
	Instance *Instance
}

func MakeBuiltinMethod

func MakeBuiltinMethod(fn BuiltinMethodFunction) *BuiltinMethod

func (*BuiltinMethod) ClassMethod

func (b *BuiltinMethod) ClassMethod()

func (*BuiltinMethod) Dup

func (b *BuiltinMethod) Dup() Object

func (*BuiltinMethod) Inspect

func (b *BuiltinMethod) Inspect() string

func (*BuiltinMethod) Type

func (b *BuiltinMethod) Type() ObjectType

type BuiltinMethodFunction

type BuiltinMethodFunction func(i Interpreter, self *Instance, env *Environment, args ...Object) Object

type Class

type Class struct {
	Name    string
	Parent  *Class
	Fields  []*ast.DefStatement
	Methods map[string]ClassMethod
}

func (*Class) Dup

func (c *Class) Dup() Object

func (*Class) GetMethod

func (c *Class) GetMethod(name string) ClassMethod

func (*Class) Inspect

func (c *Class) Inspect() string

func (*Class) Type

func (c *Class) Type() ObjectType

type ClassMethod

type ClassMethod interface {
	Object
	ClassMethod()
}

type Environment

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

func NewEnclosedEnv

func NewEnclosedEnv(outer *Environment) *Environment

func NewEnvironment

func NewEnvironment() *Environment

func NewSizedEnclosedEnv

func NewSizedEnclosedEnv(outer *Environment, size int) *Environment

func NewSizedEnvironment

func NewSizedEnvironment(size int) *Environment

func (*Environment) Clone

func (e *Environment) Clone() *Environment

func (*Environment) Create

func (e *Environment) Create(name string, val Object) (Object, error)

func (*Environment) CreateConst

func (e *Environment) CreateConst(name string, val Object) (Object, error)

func (*Environment) Get

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

func (*Environment) GetLocal

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

func (*Environment) IsConst

func (e *Environment) IsConst(name string) bool

func (*Environment) IsConstLocal

func (e *Environment) IsConstLocal(name string) bool

func (*Environment) Parent

func (e *Environment) Parent() *Environment

func (*Environment) Print

func (e *Environment) Print(indent string)

func (*Environment) Set

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

func (*Environment) SetForce

func (e *Environment) SetForce(name string, val Object, readonly bool)

func (*Environment) SetLocal

func (e *Environment) SetLocal(name string, val Object) (Object, error)

func (*Environment) SetParent

func (e *Environment) SetParent(env *Environment)

func (*Environment) Unset

func (e *Environment) Unset(name string)

func (*Environment) UnsetLocal

func (e *Environment) UnsetLocal(name string)

type Error

type Error struct {
	Message string
}

func NewError

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

func (*Error) Dup

func (e *Error) Dup() Object

func (*Error) Inspect

func (e *Error) Inspect() string

func (*Error) String

func (e *Error) String() string

func (*Error) Type

func (e *Error) Type() ObjectType

type Exception

type Exception struct {
	Catchable     bool
	Message       string
	Caught        bool
	HasStackTrace bool
}

TODO: Expand with line/column numbers and stack trace

func NewException

func NewException(format string, a ...interface{}) *Exception

func NewPanic

func NewPanic(format string, a ...interface{}) *Exception

func (*Exception) Dup

func (e *Exception) Dup() Object

func (*Exception) Inspect

func (e *Exception) Inspect() string

func (*Exception) String

func (e *Exception) String() string

func (*Exception) Type

func (e *Exception) Type() ObjectType

type Float

type Float struct {
	Value float64
}

func MakeFloatObj

func MakeFloatObj(v float64) *Float

func (*Float) Dup

func (f *Float) Dup() Object

func (*Float) Inspect

func (f *Float) Inspect() string

func (*Float) Type

func (f *Float) Type() ObjectType

type Function

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

func (*Function) ClassMethod

func (f *Function) ClassMethod()

func (*Function) Dup

func (f *Function) Dup() Object

func (*Function) Inspect

func (f *Function) Inspect() string

func (*Function) Type

func (f *Function) Type() ObjectType

type Hash

type Hash struct {
	Pairs map[HashKey]HashPair
}

func MakeEmptyHash

func MakeEmptyHash() *Hash

func StringMapToHash

func StringMapToHash(src map[string]string) *Hash

func (*Hash) Dup

func (h *Hash) Dup() Object

func (*Hash) Inspect

func (h *Hash) Inspect() string

func (*Hash) Keys

func (h *Hash) Keys() *Array

func (*Hash) LookupKey

func (h *Hash) LookupKey(key string) Object

func (*Hash) SetKey

func (h *Hash) SetKey(key string, val Object)

func (*Hash) Type

func (h *Hash) Type() ObjectType

type HashKey

type HashKey struct {
	Type  ObjectType
	Value uint64
}

func (HashKey) Dup

func (k HashKey) Dup() HashKey

type HashPair

type HashPair struct {
	Key   Object
	Value Object
}

func (HashPair) Dup

func (p HashPair) Dup() HashPair

type Hashable

type Hashable interface {
	HashKey() HashKey
}

type IfaceMethodDef

type IfaceMethodDef struct {
	Name       string
	Parameters []string
}

func (*IfaceMethodDef) Inspect

func (i *IfaceMethodDef) Inspect() string

type Instance

type Instance struct {
	Class  *Class
	Fields *Environment
}

func GetSelf

func GetSelf(env *Environment) *Instance

func (*Instance) Dup

func (i *Instance) Dup() Object

func (*Instance) GetMethod

func (i *Instance) GetMethod(name string) ClassMethod

func (*Instance) Inspect

func (i *Instance) Inspect() string

func (*Instance) Type

func (i *Instance) Type() ObjectType

type Integer

type Integer struct {
	Value int64
}

func MakeIntObj

func MakeIntObj(v int64) *Integer

func (*Integer) Dup

func (i *Integer) Dup() Object

func (*Integer) HashKey

func (i *Integer) HashKey() HashKey

func (*Integer) Inspect

func (i *Integer) Inspect() string

func (*Integer) Type

func (i *Integer) Type() ObjectType

type Interface

type Interface struct {
	Name    string
	Methods map[string]*IfaceMethodDef
}

func (*Interface) Dup

func (i *Interface) Dup() Object

func (*Interface) GetMethod

func (i *Interface) GetMethod(name string) *IfaceMethodDef

func (*Interface) Inspect

func (i *Interface) Inspect() string

func (*Interface) Type

func (i *Interface) Type() ObjectType

type Interpreter

type Interpreter interface {
	Eval(node ast.Node, env *Environment) Object
	GetCurrentScriptPath() string
	GetStdout() io.Writer
	GetStderr() io.Writer
	GetStdin() io.Reader
}

type LoopControl

type LoopControl struct {
	Continue bool
}

func (*LoopControl) Dup

func (lc *LoopControl) Dup() Object

func (*LoopControl) Inspect

func (lc *LoopControl) Inspect() string

func (*LoopControl) Type

func (lc *LoopControl) Type() ObjectType

type Module

type Module struct {
	Name    string
	Methods map[string]BuiltinFunction
	Vars    map[string]Object
}

func (*Module) Dup

func (m *Module) Dup() Object

func (*Module) Inspect

func (m *Module) Inspect() string

func (*Module) Type

func (m *Module) Type() ObjectType

type Null

type Null struct{}

func (*Null) Dup

func (n *Null) Dup() Object

func (*Null) Inspect

func (n *Null) Inspect() string

func (*Null) Type

func (n *Null) Type() ObjectType

type Object

type Object interface {
	Type() ObjectType
	Inspect() string // Returns the value the object represents
	Dup() Object     // Returns a duplicate of the object
}

type ObjectType

type ObjectType int
const (
	IntergerObj ObjectType = iota
	FloatObj
	BooleanObj
	NullObj
	ReturnObj
	ExceptionObj
	ErrorObj
	FunctionObj
	StringObj
	BuiltinObj
	ArrayObj
	HashObj
	LoopControlObj
	// ResourceObj can be used by modules to denote a generic resource. The implementation may be module specific.
	ResourceObj
	ModuleObj
	ClassObj
	InterfaceObj
	InstanceObj
	BuiltinMethodObj
	BoundMethodObj
)

These are all the internal object types used in the interpreter

func (ObjectType) String

func (o ObjectType) String() string

type ReturnValue

type ReturnValue struct {
	Value Object
}

func (*ReturnValue) Dup

func (r *ReturnValue) Dup() Object

func (*ReturnValue) Inspect

func (r *ReturnValue) Inspect() string

func (*ReturnValue) Type

func (r *ReturnValue) Type() ObjectType

type Stack

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

func NewStack

func NewStack() *Stack

func (*Stack) GetFront

func (s *Stack) GetFront() Object

func (*Stack) Len

func (s *Stack) Len() int

func (*Stack) Pop

func (s *Stack) Pop() Object

func (*Stack) Push

func (s *Stack) Push(val Object)

type String

type String struct {
	Value []rune
}

func MakeStringObj

func MakeStringObj(s string) *String

func MakeStringObjRunes

func MakeStringObjRunes(r []rune) *String

func (*String) Dup

func (s *String) Dup() Object

func (*String) HashKey

func (s *String) HashKey() HashKey

func (*String) Inspect

func (s *String) Inspect() string

func (*String) String

func (s *String) String() string

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