vm

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2021 License: MIT Imports: 18 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 ErrDivideByZero = errors.New("divide by zero")
View Source
var ErrIsNotIterable = errors.New("is not iterable")
View Source
var ErrIsNotReadable = errors.New("is not readable")

Functions

func CoerceToBool

func CoerceToBool(v Value) bool

func IsIterable

func IsIterable(v Value) bool

func IsReadable

func IsReadable(v Value) bool

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) Back

func (a *Array) Back() Value

func (*Array) EvalOp

func (a *Array) EvalOp(op Op, operand Value) (Value, error)

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) Type

func (a *Array) Type() string

type BaseValue

type BaseValue struct {
	TypeName string
}

func (BaseValue) EvalOp

func (v BaseValue) EvalOp(op Op, operand Value) (Value, error)

func (BaseValue) String

func (v BaseValue) String() string

func (BaseValue) Type

func (v BaseValue) 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) 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) EvalOp

func (c *Closure) EvalOp(op Op, operand Value) (Value, error)

func (*Closure) String

func (c *Closure) String() string

func (*Closure) Type

func (c *Closure) Type() string

type Emitter

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

func NewEmitter

func NewEmitter() *Emitter

func (*Emitter) AddExternalFunc

func (e *Emitter) AddExternalFunc(fn NativeFn) int

func (*Emitter) AddGlobalParam

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

func (*Emitter) AddLiteral

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

func (*Emitter) AddString

func (e *Emitter) AddString(s string) 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) ToProgram

func (e *Emitter) ToProgram() *Program

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) 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) EvalOp

func (f *Fn) EvalOp(op Op, operand Value) (Value, error)

func (*Fn) String

func (f *Fn) String() string

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) EvalOp

func (e *ILIterator) EvalOp(op Op, operand Value) (Value, error)

func (*ILIterator) IterNRet

func (i *ILIterator) IterNRet() int

func (*ILIterator) String

func (e *ILIterator) String() string

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) Type

func (i Int) Type() string

type InvalidUsageError

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

func NewInvalidUsageError

func NewInvalidUsageError(expected string) *InvalidUsageError

func (*InvalidUsageError) Error

func (e *InvalidUsageError) Error() 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 NativeFn, 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 func(m *VM, args []Value, nRet int) ([]Value, error)

func (NativeFn) Call

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

func (NativeFn) EvalOp

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

func (NativeFn) String

func (f NativeFn) String() string

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) EvalOp

func (i *NativeIterator) EvalOp(op Op, operand Value) (Value, error)

func (*NativeIterator) IterNRet

func (i *NativeIterator) IterNRet() int

func (*NativeIterator) String

func (i *NativeIterator) String() string

func (*NativeIterator) Type

func (i *NativeIterator) Type() string

type Object

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

func NewObject

func NewObject() *Object

func NewObjectWithCapacity

func NewObjectWithCapacity(c int) *Object

func (*Object) Delete

func (o *Object) Delete(key Value)

func (*Object) EvalOp

func (o *Object) EvalOp(op Op, operand Value) (Value, error)

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) 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
	OpLoadGlobalDeref
	OpLoadLocal
	OpLoadLocalRef
	OpLoadLocalDeref
	OpCaptureLocal
	OpLoadArg
	OpLoadArgRef
	OpLoadArgDeref
	OpCaptureArg
	OpLoadCapture
	OpLoadCaptureRef
	OpLoadFn
	OpLoadNativeFn
	OpLoadLiteral
	OpEvalBinOp
	OpNot
	OpUnaryMinus
	OpObjectPutNoPop
	OpObjectGet
	OpObjectGetRef
	OpArrayAppendNoPop
	OpRet
	OpStore
	OpInitCallFrame
	OpMakeIter
	OpBeginTry
	OpEndTry
	OpSwap
	OpThrow
	OpDefer
	OpNext
	OpSlice
	OpIterYield
	OpIterRet
	OpNewIter
	OpLiftArg
	OpInitLiftedLocal
	OpInitLiftedGlobal
)

type Param

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

type Program

type Program struct {
	Metadata *meta.Metadata
	// contains filtered or unexported fields
}

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) EvalOp

func (r *Regex) EvalOp(op Op, operand Value) (Value, error)

func (*Regex) String

func (r *Regex) String() string

func (*Regex) Type

func (r *Regex) Type() string

type RuntimeError

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

func (*RuntimeError) Error

func (e *RuntimeError) Error() string

func (*RuntimeError) EvalOp

func (e *RuntimeError) EvalOp(op Op, operand Value) (Value, error)

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) 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) EvalUnaryMinus

func (s String) EvalUnaryMinus() (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) MakeIterator

func (s String) MakeIterator() Iterator

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) Type

func (s String) Type() string

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 {
	fmt.Stringer

	Type() string
	EvalOp(op Op, operand Value) (Value, error)
}

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) EvalOp

func (r ValueRef) EvalOp(op Op, operand Value) (Value, error)

func (ValueRef) Refo

func (r ValueRef) Refo() *Value

func (ValueRef) String

func (r ValueRef) String() string

func (ValueRef) Type

func (r ValueRef) Type() string

Jump to

Keyboard shortcuts

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