object

package
v0.0.0-...-f836197 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2025 License: EPL-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	INTEGER_OBJ           = "INTEGER"
	FLOAT_OBJ             = "FLOAT"
	BOOLEAN_OBJ           = "BOOLEAN"
	NULL_OBJ              = "NULL"
	RETURN_VALUE_OBJ      = "RETURN_VALUE"
	ERROR_OBJ             = "ERROR"
	FUNCTION_OBJ          = "FUNCTION"
	STRING_OBJ            = "STRING"
	BUILTIN_OBJ           = "BUILTIN"
	ARRAY_OBJ             = "ARRAY"
	HASH_OBJ              = "HASH"
	COMPILED_FUNCTION_OBJ = "COMPILED_FUNCTION"
	CLOSURE_OBJ           = "CLOSURE"
	CHANNEL_OBJ           = "CHANNEL"
	THREAD_OBJ            = "THREAD"
	TIME_OBJ              = "TIME"
	MUTEX_OBJ             = "MUTEX"
	ATOM_OBJ              = "ATOM"
	FILE_OBJ              = "FILE"
	POINTER_OBJ           = "POINTER"
	MODULE_OBJ            = "MODULE"
)
View Source
const (
	ErrCodeSyntax           = "E001"
	ErrCodeUndefined        = "E002"
	ErrCodeTypeMismatch     = "E003"
	ErrCodeUncheckedError   = "E004"
	ErrCodeRuntime          = "E005"
	ErrCodeIndexOutOfBounds = "E006"
	ErrCodeInvalidOp        = "E007"
	ErrCodeMissingArgs      = "E008"
	ErrCodeTooManyArgs      = "E009"
	ErrCodeSignalLaunch     = "SIGNAL_LAUNCH"
)

Variables

View Source
var Builtins []BuiltinDef

Functions

func GetBuiltinByName

func GetBuiltinByName(name string) int

func RegisterBuiltin

func RegisterBuiltin(name string, fn BuiltinFunction)

func RegisterResource

func RegisterResource(obj Object) memory.Ptr

RegisterResource stores a host object and returns a memory-backed wrapper (Address).

Types

type Array

type Array struct {
	Address memory.Ptr
}

func NewArray

func NewArray(elements []Object) *Array

func (*Array) GetAddress

func (ao *Array) GetAddress() memory.Ptr

func (*Array) GetElements

func (ao *Array) GetElements() []Object

func (*Array) Inspect

func (ao *Array) Inspect() string

func (*Array) Type

func (ao *Array) Type() ObjectType

type Atom

type Atom struct {
	Value   Object
	Mu      sync.Mutex
	Address memory.Ptr
}

func NewAtom

func NewAtom(val Object) *Atom

func (*Atom) GetAddress

func (a *Atom) GetAddress() memory.Ptr

func (*Atom) Inspect

func (a *Atom) Inspect() string

func (*Atom) Type

func (a *Atom) Type() ObjectType

type Boolean

type Boolean struct {
	Address memory.Ptr
}

func NewBoolean

func NewBoolean(val bool) *Boolean

func (*Boolean) GetAddress

func (b *Boolean) GetAddress() memory.Ptr

func (*Boolean) GetValue

func (b *Boolean) GetValue() bool

func (*Boolean) HashKey

func (b *Boolean) HashKey() HashKey

func (*Boolean) Inspect

func (b *Boolean) Inspect() string

func (*Boolean) Type

func (b *Boolean) Type() ObjectType

type Builtin

type Builtin struct {
	Fn      BuiltinFunction
	Address memory.Ptr
}

func (*Builtin) GetAddress

func (b *Builtin) GetAddress() memory.Ptr

func (*Builtin) Inspect

func (b *Builtin) Inspect() string

func (*Builtin) Type

func (b *Builtin) Type() ObjectType

type BuiltinDef

type BuiltinDef struct {
	Name    string
	Builtin *Builtin
}

type BuiltinFunction

type BuiltinFunction func(args ...Object) Object

type Channel

type Channel struct {
	Value   chan Object
	Address memory.Ptr
}

func NewChannel

func NewChannel(val chan Object) *Channel

func (*Channel) GetAddress

func (c *Channel) GetAddress() memory.Ptr

func (*Channel) Inspect

func (c *Channel) Inspect() string

func (*Channel) Type

func (c *Channel) Type() ObjectType

type Closure

type Closure struct {
	Address memory.Ptr
}

func NewClosure

func NewClosure(fn *CompiledFunction, freeVars []Object) *Closure

func (*Closure) Fn

func (c *Closure) Fn() *CompiledFunction

func (*Closure) FreeVariables

func (c *Closure) FreeVariables() []Object

func (*Closure) GetAddress

func (c *Closure) GetAddress() memory.Ptr

func (*Closure) Inspect

func (c *Closure) Inspect() string

func (*Closure) Type

func (c *Closure) Type() ObjectType

type CompiledFunction

type CompiledFunction struct {
	Address memory.Ptr
}

func (*CompiledFunction) GetAddress

func (cf *CompiledFunction) GetAddress() memory.Ptr

func (*CompiledFunction) Inspect

func (cf *CompiledFunction) Inspect() string

func (*CompiledFunction) Instructions

func (cf *CompiledFunction) Instructions() []byte

func (*CompiledFunction) NumLocals

func (cf *CompiledFunction) NumLocals() int

func (*CompiledFunction) NumParameters

func (cf *CompiledFunction) NumParameters() int

func (*CompiledFunction) Type

func (cf *CompiledFunction) Type() ObjectType

type Environment

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

func NewEnclosedEnvironment

func NewEnclosedEnvironment(outer *Environment) *Environment

func NewEnvironment

func NewEnvironment() *Environment

func (*Environment) Get

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

func (*Environment) Set

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

type Error

type Error struct {
	Address memory.Ptr
}

func NewError

func NewError(msg string, code string, line, col int) *Error

func (*Error) GetAddress

func (e *Error) GetAddress() memory.Ptr

func (*Error) GetCode

func (e *Error) GetCode() string

func (*Error) GetMessage

func (e *Error) GetMessage() string

func (*Error) Inspect

func (e *Error) Inspect() string

func (*Error) Type

func (e *Error) Type() ObjectType

type File

type File struct {
	File    *os.File
	Mode    string
	Address memory.Ptr
}

func NewFile

func NewFile(f *os.File, mode string) *File

func (*File) GetAddress

func (f *File) GetAddress() memory.Ptr

func (*File) Inspect

func (f *File) Inspect() string

func (*File) Type

func (f *File) Type() ObjectType

type Float

type Float struct {
	Address memory.Ptr
}

func NewFloat

func NewFloat(val float64) *Float

func (*Float) GetAddress

func (f *Float) GetAddress() memory.Ptr

func (*Float) GetValue

func (f *Float) GetValue() float64

func (*Float) Inspect

func (f *Float) Inspect() string

func (*Float) Type

func (f *Float) Type() ObjectType

type Function

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

func (*Function) GetAddress

func (f *Function) GetAddress() memory.Ptr

func (*Function) Inspect

func (f *Function) Inspect() string

func (*Function) Type

func (f *Function) Type() ObjectType

type Hash

type Hash struct {
	Address memory.Ptr
}

func NewHash

func NewHash(pairs []HashPair) *Hash

func (*Hash) GetAddress

func (h *Hash) GetAddress() memory.Ptr

func (*Hash) GetPairs

func (h *Hash) GetPairs() []HashPair

func (*Hash) Inspect

func (h *Hash) Inspect() string

func (*Hash) Type

func (h *Hash) Type() ObjectType

type HashKey

type HashKey struct {
	Type  ObjectType
	Value uint64
}

type HashPair

type HashPair struct {
	Key   Object
	Value Object
}

type Hashable

type Hashable interface {
	HashKey() HashKey
}

type Integer

type Integer struct {
	Address memory.Ptr
}

func NewInteger

func NewInteger(val int64) *Integer

func (*Integer) GetAddress

func (i *Integer) GetAddress() memory.Ptr

func (*Integer) GetValue

func (i *Integer) GetValue() int64

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 Module

type Module struct {
	Address memory.Ptr
	Name    string
}

func NewModule

func NewModule(name string, init *CompiledFunction) *Module

func (*Module) GetAddress

func (m *Module) GetAddress() memory.Ptr

func (*Module) GetExports

func (m *Module) GetExports() Object

func (*Module) GetInit

func (m *Module) GetInit() *CompiledFunction

func (*Module) Inspect

func (m *Module) Inspect() string

func (*Module) SetExports

func (m *Module) SetExports(obj Object)

func (*Module) Type

func (m *Module) Type() ObjectType

type Mutex

type Mutex struct {
	Mu      sync.Mutex
	Address memory.Ptr
}

func NewMutex

func NewMutex() *Mutex

func (*Mutex) GetAddress

func (m *Mutex) GetAddress() memory.Ptr

func (*Mutex) Inspect

func (m *Mutex) Inspect() string

func (*Mutex) Type

func (m *Mutex) Type() ObjectType

type Null

type Null struct {
	Address memory.Ptr
}

func NewNull

func NewNull() *Null

func (*Null) GetAddress

func (n *Null) GetAddress() memory.Ptr

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
	GetAddress() memory.Ptr
}

func FromPtr

func FromPtr(ptr memory.Ptr) Object

FromPtr rehydrates an Object Wrapper from a raw Memory Pointer. It reads the Header to determine the Type.

func GetResource

func GetResource(ptr memory.Ptr) Object

GetResource retrieves the host object from a memory pointer.

type ObjectType

type ObjectType string

type Pointer

type Pointer struct {
	Address memory.Ptr
}

func NewPointer

func NewPointer(val uint64) *Pointer

func (*Pointer) GetAddress

func (p *Pointer) GetAddress() memory.Ptr

func (*Pointer) GetValue

func (p *Pointer) GetValue() uint64

func (*Pointer) Inspect

func (p *Pointer) Inspect() string

func (*Pointer) Type

func (p *Pointer) Type() ObjectType

type ReturnValue

type ReturnValue struct {
	Value Object
}

func (*ReturnValue) GetAddress

func (rv *ReturnValue) GetAddress() memory.Ptr

func (*ReturnValue) Inspect

func (rv *ReturnValue) Inspect() string

func (*ReturnValue) Type

func (rv *ReturnValue) Type() ObjectType

type String

type String struct {
	Address memory.Ptr
}

func NewString

func NewString(val string) *String

func (*String) GetAddress

func (s *String) GetAddress() memory.Ptr

func (*String) GetValue

func (s *String) GetValue() string

func (*String) HashKey

func (s *String) HashKey() HashKey

func (*String) Inspect

func (s *String) Inspect() string

func (*String) Type

func (s *String) Type() ObjectType

type Thread

type Thread struct {
	Result  chan Object
	Address memory.Ptr
}

func NewThread

func NewThread(res chan Object) *Thread

func (*Thread) GetAddress

func (t *Thread) GetAddress() memory.Ptr

func (*Thread) Inspect

func (t *Thread) Inspect() string

func (*Thread) Type

func (t *Thread) Type() ObjectType

type Time

type Time struct {
	Value   time.Time
	Address memory.Ptr
}

func NewTime

func NewTime(val time.Time) *Time

func (*Time) GetAddress

func (t *Time) GetAddress() memory.Ptr

func (*Time) Inspect

func (t *Time) Inspect() string

func (*Time) Type

func (t *Time) Type() ObjectType

Jump to

Keyboard shortcuts

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