vm

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: MIT Imports: 12 Imported by: 122

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FuncTypes = []any{
	1:  new(func() time.Duration),
	2:  new(func() time.Month),
	3:  new(func() time.Time),
	4:  new(func() time.Weekday),
	5:  new(func() []uint8),
	6:  new(func() []interface{}),
	7:  new(func() bool),
	8:  new(func() uint8),
	9:  new(func() float64),
	10: new(func() int),
	11: new(func() int64),
	12: new(func() interface{}),
	13: new(func() map[string]interface{}),
	14: new(func() int32),
	15: new(func() string),
	16: new(func() uint),
	17: new(func() uint64),
	18: new(func(time.Duration) time.Duration),
	19: new(func(time.Duration) time.Time),
	20: new(func(time.Time) time.Duration),
	21: new(func(time.Time) bool),
	22: new(func([]interface{}, string) string),
	23: new(func([]string, string) string),
	24: new(func(bool) bool),
	25: new(func(bool) float64),
	26: new(func(bool) int),
	27: new(func(bool) string),
	28: new(func(float64) bool),
	29: new(func(float64) float64),
	30: new(func(float64) int),
	31: new(func(float64) string),
	32: new(func(int) bool),
	33: new(func(int) float64),
	34: new(func(int) int),
	35: new(func(int) string),
	36: new(func(int, int) int),
	37: new(func(int, int) string),
	38: new(func(int64) time.Time),
	39: new(func(string) []string),
	40: new(func(string) bool),
	41: new(func(string) float64),
	42: new(func(string) int),
	43: new(func(string) string),
	44: new(func(string, uint8) int),
	45: new(func(string, int) int),
	46: new(func(string, int32) int),
	47: new(func(string, string) bool),
	48: new(func(string, string) string),
	49: new(func(interface{}) bool),
	50: new(func(interface{}) float64),
	51: new(func(interface{}) int),
	52: new(func(interface{}) string),
	53: new(func(interface{}) interface{}),
	54: new(func(interface{}) []interface{}),
	55: new(func(interface{}) map[string]interface{}),
	56: new(func([]interface{}) interface{}),
	57: new(func([]interface{}) []interface{}),
	58: new(func([]interface{}) map[string]interface{}),
	59: new(func(interface{}, interface{}) bool),
	60: new(func(interface{}, interface{}) string),
	61: new(func(interface{}, interface{}) interface{}),
	62: new(func(interface{}, interface{}) []interface{}),
}
View Source
var MemoryBudget uint = 1e6

Functions

func Run

func Run(program *Program, env any) (any, error)

Types

type Function

type Function = func(params ...any) (any, error)

type Opcode

type Opcode byte
const (
	OpInvalid Opcode = iota
	OpPush
	OpInt
	OpPop
	OpStore
	OpLoadVar
	OpLoadConst
	OpLoadField
	OpLoadFast
	OpLoadMethod
	OpLoadFunc
	OpLoadEnv
	OpFetch
	OpFetchField
	OpMethod
	OpTrue
	OpFalse
	OpNil
	OpNegate
	OpNot
	OpEqual
	OpEqualInt
	OpEqualString
	OpJump
	OpJumpIfTrue
	OpJumpIfFalse
	OpJumpIfNil
	OpJumpIfNotNil
	OpJumpIfEnd
	OpJumpBackward
	OpIn
	OpLess
	OpMore
	OpLessOrEqual
	OpMoreOrEqual
	OpAdd
	OpSubtract
	OpMultiply
	OpDivide
	OpModulo
	OpExponent
	OpRange
	OpMatches
	OpMatchesConst
	OpContains
	OpStartsWith
	OpEndsWith
	OpSlice
	OpCall
	OpCall0
	OpCall1
	OpCall2
	OpCall3
	OpCallN
	OpCallFast
	OpCallTyped
	OpCallBuiltin1
	OpValidateArgs
	OpArray
	OpMap
	OpLen
	OpCast
	OpDeref
	OpIncrementIndex
	OpDecrementIndex
	OpIncrementCount
	OpGetIndex
	OpSetIndex
	OpGetCount
	OpGetLen
	OpGetGroupBy
	OpGetAcc
	OpPointer
	OpThrow
	OpGroupBy
	OpSetAcc
	OpBegin
	OpEnd // This opcode must be at the end of this list.
)

type Program

type Program struct {
	Bytecode  []Opcode
	Arguments []int
	Constants []any
	// contains filtered or unexported fields
}

Program represents a compiled expression.

func NewProgram

func NewProgram(
	source *file.Source,
	node ast.Node,
	locations []file.Location,
	variables int,
	constants []any,
	bytecode []Opcode,
	arguments []int,
	functions []Function,
	debugInfo map[string]string,
) *Program

NewProgram returns a new Program. It's used by the compiler.

func (*Program) Disassemble

func (program *Program) Disassemble() string

Disassemble returns opcodes as a string.

func (*Program) DisassembleWriter

func (program *Program) DisassembleWriter(w io.Writer)

DisassembleWriter takes a writer and writes opcodes to it.

func (*Program) Node added in v1.16.0

func (program *Program) Node() ast.Node

Node returns origin ast.Node.

func (*Program) Source added in v1.15.7

func (program *Program) Source() *file.Source

Source returns origin file.Source.

type Scope

type Scope struct {
	Array   reflect.Value
	Index   int
	Len     int
	Count   int
	GroupBy map[any][]any
	Acc     any
}

type VM

type VM struct {
	Stack     []any
	Scopes    []*Scope
	Variables []any
	// contains filtered or unexported fields
}

func Debug

func Debug() *VM

func (*VM) Position

func (vm *VM) Position() chan int

func (*VM) Run

func (vm *VM) Run(program *Program, env any) (_ any, err error)

func (*VM) Step

func (vm *VM) Step()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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