vm

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CallArgCountMask uint32 = 0x3FFFFFFF
	CallExpandFlag   uint32 = 0x80000000
	CallPipelineFlag uint32 = 0x40000000
)

Variables

View Source
var (
	True  = Bool{true}
	False = Bool{false}
)
View Source
var ErrCannotCallNil = errors.New("cannot evaluate function call because target is nil")
View Source
var ErrDivByZero = errors.New("divide by zero")
View Source
var ErrDivideByZero = errors.New("divide by zero")
View Source
var ErrIsNotIterable = errors.New("is not iterable")
View Source
var ErrIsNotReadable = errors.New("is not readable")
View Source
var ErrOperationNotSupported = errors.New("operation not supported")

Functions

func CoerceToBool

func CoerceToBool(v Value) bool

func IsIterable

func IsIterable(v Value) bool

func IsReadable

func IsReadable(v Value) bool

func MakeNonRecoverableError added in v0.3.0

func MakeNonRecoverableError(err error) error

func ToString

func ToString(v Value) string

func TypeName

func TypeName(v Value) string

Types

type Array

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

func NewArray

func NewArray() *Array

func NewArrayWithSlice

func NewArrayWithSlice(s []Value) *Array

func (*Array) Add

func (a *Array) Add(v Value)

func (*Array) AddIter added in v0.5.0

func (a *Array) AddIter(vm *VM, iter Iterator) error

func (*Array) Find added in v0.3.0

func (a *Array) Find(v Value) int

func (*Array) Get

func (a *Array) Get(index int) Value

func (*Array) Index

func (a *Array) Index(key Value) (Value, error)

func (*Array) IndexRef

func (a *Array) IndexRef(key Value) (ValueRef, error)

func (*Array) Len

func (a *Array) Len() int

func (*Array) MakeIterator

func (a *Array) MakeIterator() Iterator

func (*Array) Put

func (a *Array) Put(index int, v Value)

func (*Array) Slice

func (a *Array) Slice(b, e Value) (Value, error)

func (*Array) String

func (a *Array) String() string

func (*Array) Traits added in v0.3.0

func (a *Array) Traits() Traits

func (*Array) Type

func (a *Array) Type() string

type Bool

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

func NewBool

func NewBool(v bool) Bool

func (Bool) Bool

func (b Bool) Bool() bool

func (Bool) EvalOp

func (b Bool) EvalOp(op Op, operand Value) (Value, error)

func (Bool) String

func (b Bool) String() string

func (Bool) Traits added in v0.3.0

func (b Bool) Traits() Traits

func (Bool) Type

func (b Bool) Type() string

type Callable

type Callable interface {
	Value
	Call(m *VM, args []Value, nRet int) ([]Value, error)
}

type CloseFn

type CloseFn func(m *VM) error

type Closer

type Closer interface {
	Value
	io.Closer
}

type Closure

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

func (*Closure) Call

func (c *Closure) Call(m *VM, args []Value, nRet int) ([]Value, error)

func (*Closure) String

func (c *Closure) String() string

func (*Closure) Traits added in v0.3.0

func (c *Closure) Traits() Traits

func (*Closure) Type

func (c *Closure) Type() string

type CompiledPackage added in v0.3.0

type CompiledPackage struct {
	Name    string
	Builtin bool

	// Index is the index of the CompiledPackage in the list of program packages.
	Index int

	Metadata  *meta.Metadata
	MainFnNdx int

	Literals []Value

	Deps    []*CompiledPackage
	Symbols map[string]int // symbolName => LiteralsIndex
	// contains filtered or unexported fields
}

type Emitter

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

func NewEmitter

func NewEmitter() *Emitter

func (*Emitter) AddGlobalParam

func (e *Emitter) AddGlobalParam(
	name string,
	global int,
) bool

func (*Emitter) AddLiteral

func (e *Emitter) AddLiteral(v Value) int

func (*Emitter) Emit

func (e *Emitter) Emit(pos token.Pos, op OpCode, operand1 uint32, operand2 uint16)

func (*Emitter) EmitJump

func (e *Emitter) EmitJump(pos token.Pos, op OpCode, label *Label, operand2 uint16)

func (*Emitter) NewFn

func (e *Emitter) NewFn(name string) int

func (*Emitter) NewLabel

func (e *Emitter) NewLabel() *Label

func (*Emitter) PopFn

func (e *Emitter) PopFn()

func (*Emitter) PushFn

func (e *Emitter) PushFn(fn int)

func (*Emitter) ResolveLabel

func (e *Emitter) ResolveLabel(label *Label)

func (*Emitter) SetFuncMinArgs

func (e *Emitter) SetFuncMinArgs(n int)

func (*Emitter) SetGlobalCount

func (e *Emitter) SetGlobalCount(n int)

func (*Emitter) ToCompiledPackage added in v0.3.0

func (e *Emitter) ToCompiledPackage() *CompiledPackage

type FallbackEvaluator added in v0.3.0

type FallbackEvaluator interface {
	Operable
	FallbackEvalOp(op Op, left Value) (Value, error)
}

type Float

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

func NewFloat

func NewFloat(v float64) Float

func (Float) EvalOp

func (f Float) EvalOp(op Op, operand Value) (Value, error)

func (Float) Float64

func (f Float) Float64() float64

func (Float) String

func (f Float) String() string

func (Float) ToInt added in v0.5.0

func (f Float) ToInt() (Int, error)

func (Float) Traits added in v0.3.0

func (f Float) Traits() Traits

func (Float) Type

func (f Float) Type() string

type Fn

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

func (*Fn) Call

func (f *Fn) Call(m *VM, args []Value, nRet int) ([]Value, error)

func (*Fn) String

func (f *Fn) String() string

func (*Fn) Traits added in v0.3.0

func (f *Fn) Traits() Traits

func (*Fn) Type

func (f *Fn) Type() string

type FrameCrumb

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

func (*FrameCrumb) IsZero

func (c *FrameCrumb) IsZero() bool

type FrameInfo

type FrameInfo struct {
	Filename string
	Line     int
	Func     string
}

func (FrameInfo) String

func (i FrameInfo) String() string

type ILIterator

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

func (*ILIterator) IterNRet

func (i *ILIterator) IterNRet() int

func (*ILIterator) String

func (e *ILIterator) String() string

func (*ILIterator) Traits added in v0.3.0

func (e *ILIterator) Traits() Traits

func (*ILIterator) Type

func (e *ILIterator) Type() string

type Indexable

type Indexable interface {
	Value
	Index(key Value) (Value, error)
	IndexRef(key Value) (ValueRef, error)
}

type Instr

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

type Int

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

func NewInt

func NewInt(v int64) Int

func (Int) EvalOp

func (i Int) EvalOp(op Op, operand Value) (Value, error)

func (Int) Int64

func (i Int) Int64() int64

func (Int) String

func (i Int) String() string

func (Int) Traits added in v0.3.0

func (i Int) Traits() Traits

func (Int) Type

func (i Int) Type() string

type Iterable

type Iterable interface {
	Value
	MakeIterator() Iterator
}

type Iterator

type Iterator interface {
	Value
	IterNRet() int
	// contains filtered or unexported methods
}

func MakeIterator

func MakeIterator(m *VM, v Value) (Iterator, error)

func NewIterator

func NewIterator(extFn func(m *VM, args []Value, nRet int) ([]Value, error), closeFn CloseFn, nret int) Iterator

type Label

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

type Location

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

type NativeFn

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

func NewNativeFn added in v0.2.0

func NewNativeFn(fn func(m *VM, args []Value, nRet int) ([]Value, error)) *NativeFn

func (*NativeFn) Call

func (f *NativeFn) Call(m *VM, args []Value, nRet int) ([]Value, error)

func (*NativeFn) Name added in v0.2.0

func (f *NativeFn) Name() string

func (*NativeFn) String

func (f *NativeFn) String() string

func (*NativeFn) Traits added in v0.3.0

func (f *NativeFn) Traits() Traits

func (*NativeFn) Type

func (f *NativeFn) Type() string

type NativeIterator

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

func (*NativeIterator) Close

func (i *NativeIterator) Close(m *VM) error

func (*NativeIterator) Closed

func (i *NativeIterator) Closed() bool

func (*NativeIterator) IterNRet

func (i *NativeIterator) IterNRet() int

func (*NativeIterator) String

func (i *NativeIterator) String() string

func (*NativeIterator) Traits added in v0.3.0

func (i *NativeIterator) Traits() Traits

func (*NativeIterator) Type

func (i *NativeIterator) Type() string

type NonRecoverableError added in v0.3.0

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

func (*NonRecoverableError) Error added in v0.3.0

func (e *NonRecoverableError) Error() string

func (*NonRecoverableError) Unwrap added in v0.3.0

func (e *NonRecoverableError) Unwrap() error

type Object

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

func NewObject

func NewObject() *Object

func NewObjectWithCapacity

func NewObjectWithCapacity(c int) *Object

func (*Object) Clone added in v0.3.0

func (o *Object) Clone() *Object

func (*Object) Delete

func (o *Object) Delete(key Value)

func (*Object) ForEach

func (o *Object) ForEach(f func(k, v Value) bool)

func (*Object) Get

func (o *Object) Get(k Value) (Value, bool)

func (*Object) GetFirst

func (o *Object) GetFirst() (key Value, val Value)

func (*Object) GetNext

func (o *Object) GetNext(key Value) (nextKey Value, nextVal Value)

func (*Object) Has

func (o *Object) Has(k Value) bool

func (*Object) Index

func (o *Object) Index(k Value) (Value, error)

func (*Object) IndexRef

func (o *Object) IndexRef(k Value) (ValueRef, error)

func (*Object) Len

func (o *Object) Len() int

func (*Object) MakeIterator

func (o *Object) MakeIterator() Iterator

func (*Object) Put

func (o *Object) Put(k, v Value)

func (*Object) String

func (o *Object) String() string

func (*Object) Traits added in v0.3.0

func (o *Object) Traits() Traits

func (*Object) Type

func (o *Object) Type() string

type Op

type Op byte
const (
	OpUMinus Op = iota
	OpAdd
	OpSub
	OpMult
	OpDiv
	OpMod
	OpLT
	OpLE
	OpGT
	OpGE
	OpEq
	OpNE
)

type OpCode

type OpCode byte
const (
	OpNop OpCode = iota
	OpJump
	OpJumpIfTrue
	OpJumpIfFalse
	OpDup
	OpPop
	OpCall
	OpNil
	OpNewClosure
	OpNewInt
	OpNewBool
	OpNewObject
	OpNewArray
	OpLoadGlobal
	OpLoadGlobalRef
	OpLoadLocal
	OpLoadLocalRef
	OpLoadLocalDeref
	OpCaptureLocal
	OpLoadArg
	OpLoadArgRef
	OpLoadArgDeref
	OpCaptureArg
	OpLoadCapture
	OpLoadCaptureRef
	OpLoadLiteral
	OpEvalBinOp
	OpNot
	OpUnaryMinus
	OpObjectPutNoPop
	OpObjectGet
	OpObjectGetRef
	OpArrayAppendNoPop
	OpArrayExpandElemNoPop
	OpRet
	OpStore
	OpInitCallFrame
	OpMakeIter
	OpBeginTry
	OpEndTry
	OpSwap
	OpThrow
	OpDefer
	OpNext
	OpSlice
	OpIterYield
	OpIterRet
	OpNewIter
	OpLiftArg
	OpInitLocal
	OpInitLiftedLocal
	OpInitGlobal
)

type Operable added in v0.3.0

type Operable interface {
	Value
	EvalOp(op Op, right Value) (Value, error)
}

type PackageSymbolType added in v0.3.0

type PackageSymbolType uint8

type Param

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

type Program

type Program struct {
	Packages []*CompiledPackage
}

func (*Program) MainPackage added in v0.5.0

func (p *Program) MainPackage() *CompiledPackage

func (*Program) Metadata

func (p *Program) Metadata() *meta.Metadata

type Readable

type Readable interface {
	Value
	MakeReader() Reader
}

type Reader

type Reader interface {
	Value
	io.Reader
}

func MakeReader

func MakeReader(vm *VM, v Value) (Reader, error)

type Regex

type Regex struct {
	*regexp.Regexp
}

func NewRegex

func NewRegex(r *regexp.Regexp) *Regex

func (*Regex) String

func (r *Regex) String() string

func (*Regex) Traits added in v0.3.0

func (r *Regex) Traits() Traits

func (*Regex) Type

func (r *Regex) Type() string

type RuntimeError

type RuntimeError struct {
	Err         error
	ErrValue    Value
	Stack       []FrameInfo
	Recoverable bool
}

func (*RuntimeError) Error

func (e *RuntimeError) Error() string

func (*RuntimeError) Index

func (e *RuntimeError) Index(k Value) (Value, error)

func (*RuntimeError) IndexRef

func (e *RuntimeError) IndexRef(k Value) (ValueRef, error)

func (*RuntimeError) Message

func (e *RuntimeError) Message() string

func (*RuntimeError) String

func (e *RuntimeError) String() string

func (*RuntimeError) Traits added in v0.3.0

func (e *RuntimeError) Traits() Traits

func (*RuntimeError) Type

func (e *RuntimeError) Type() string

func (*RuntimeError) Unwrap

func (e *RuntimeError) Unwrap() error

type String

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

func NewString

func NewString(v string) String

func (String) EvalOp

func (s String) EvalOp(op Op, operand Value) (Value, error)

func (String) Index

func (s String) Index(key Value) (Value, error)

func (String) IndexRef

func (s String) IndexRef(key Value) (ValueRef, error)

func (String) Len

func (s String) Len() int

func (String) MakeReader

func (s String) MakeReader() Reader

func (String) Slice

func (s String) Slice(b, e Value) (Value, error)

func (String) String

func (s String) String() string

func (String) ToInt added in v0.5.0

func (s String) ToInt() (Int, error)

func (String) Traits added in v0.3.0

func (s String) Traits() Traits

func (String) Type

func (s String) Type() string

type Traits added in v0.3.0

type Traits uint32
const (
	TraitNone Traits = 0
	TraitEq   Traits = 1 << iota
)

type VM

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

func NewVM

func NewVM(prog *Program) *VM

func (*VM) Block

func (m *VM) Block(f func(ctx context.Context))

func (*VM) Call

func (m *VM) Call(callable Value, args []Value, nret int) ([]Value, error)

func (*VM) Context

func (m *VM) Context() context.Context

func (*VM) GetCallerArgs

func (m *VM) GetCallerArgs() []Value

func (*VM) GetCallerNArg

func (m *VM) GetCallerNArg() int

func (*VM) GetFrameCrumb

func (m *VM) GetFrameCrumb(n int) FrameCrumb

func (*VM) GetFrameInfo

func (m *VM) GetFrameInfo(crumb FrameCrumb) FrameInfo

func (*VM) GetStackInfo

func (m *VM) GetStackInfo() []FrameInfo

func (*VM) GetUserData

func (m *VM) GetUserData(key interface{}) interface{}

func (*VM) IsCallerPipeline

func (m *VM) IsCallerPipeline() bool

func (*VM) IsPipeline

func (m *VM) IsPipeline() bool

func (*VM) IterClose

func (m *VM) IterClose(iter Iterator) error

func (*VM) IterNext

func (m *VM) IterNext(iter Iterator, nret int) ([]Value, error)

func (*VM) PopContext

func (m *VM) PopContext() context.Context

func (*VM) PushContext

func (m *VM) PushContext(ctx context.Context)

func (*VM) RegisterCloser

func (m *VM) RegisterCloser(c Closer)

func (*VM) Run

func (m *VM) Run(args []Value) error

func (*VM) SetParam

func (m *VM) SetParam(n string, v Value) error

func (*VM) SetUserData

func (m *VM) SetUserData(key, value interface{})

func (*VM) ShuttingDown

func (m *VM) ShuttingDown() bool

func (*VM) SignalError

func (m *VM) SignalError(err error)

func (*VM) StartCoroutine

func (m *VM) StartCoroutine(callable Value) error

func (*VM) UnregisterCloser

func (m *VM) UnregisterCloser(c Closer)

type Value

type Value interface {
	String() string
	Type() string
	Traits() Traits
}

func EvalOp

func EvalOp(op Op, operand1, operand2 Value) (Value, error)

type ValueRef

type ValueRef struct {
	Ref *Value
}

func NewValueRef

func NewValueRef(ref *Value) ValueRef

func (ValueRef) Refo

func (r ValueRef) Refo() *Value

func (ValueRef) String

func (r ValueRef) String() string

func (ValueRef) Traits added in v0.3.0

func (r ValueRef) Traits() Traits

func (ValueRef) Type

func (r ValueRef) Type() string

type Writer added in v0.5.0

type Writer interface {
	Value
	io.Writer
}

Jump to

Keyboard shortcuts

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