Documentation
¶
Index ¶
- Constants
- Variables
- func FormatInstructions(b []byte, posOffset int) ([]string, error)
- func MakeInstruction(opcode opcode.Opcode, operands ...int) ([]byte, error)
- func MustFormatInstructions(b []byte, posOffset int) []string
- func MustMakeInstruction(opcode opcode.Opcode, operands ...int) []byte
- type Bytecode
- func (b *Bytecode) Decode(r io.Reader) error
- func (b *Bytecode) Encode(w io.Writer) error
- func (b *Bytecode) FormatInstructions() ([]string, error)
- func (b *Bytecode) FormatStatics() (output []string, err error)
- func (b *Bytecode) MustFormatInstructions() []string
- func (b *Bytecode) MustFormatStatics() []string
- type VM
Constants ¶
const ( // GlobalsSize is the maximum number of global variables for a VM. GlobalsSize = 1024 // DefaultStackSize is the maximum stack size for a VM. DefaultStackSize = 2048 // DefaultMaxFrames is the maximum number of function frames for a VM. DefaultMaxFrames = 1024 )
Variables ¶
var BuiltinFunctionNames []string
var BuiltinFunctions = make(map[string]core.Value)
Functions ¶
func FormatInstructions ¶
FormatInstructions returns string representation of bytecode instructions.
func MakeInstruction ¶
MakeInstruction returns a bytecode for an opcode and the operands.
func MustFormatInstructions ¶ added in v0.3.1
MustFormatInstructions is like FormatInstructions but panics if the instructions cannot be formatted.
Types ¶
type Bytecode ¶
type Bytecode struct {
FileSet *parser.SourceFileSet
MainFunction *core.CompiledFunction
Static core.Static
}
Bytecode is a compiled instructions and constants.
func (*Bytecode) Decode ¶
Decode reads Bytecode data from the reader. NB: files in b.FileSet.File does not have their 'set' field properly set to b.FileSet as it's private field and not serialized by gob encoder/decoder.
func (*Bytecode) FormatInstructions ¶
FormatInstructions returns human readable string representations of compiled instructions.
func (*Bytecode) FormatStatics ¶ added in v0.4.1
FormatStatics returns human readable string representations of compiled static values.
func (*Bytecode) MustFormatInstructions ¶ added in v0.3.1
MustFormatInstructions returns human readable string representations of compiled instructions.
func (*Bytecode) MustFormatStatics ¶ added in v0.4.1
MustFormatStatics returns human readable string representations of compiled static values.
type VM ¶
type VM struct {
// contains filtered or unexported fields
}
VM is a virtual machine that executes the bytecode compiled by Compiler. VM must be used in a single-threaded context only.
func (*VM) Clear ¶ added in v0.0.8
func (v *VM) Clear()
Clear drops the VM's Go references to bytecode, globals, and per-frame state so the Go garbage collector can reclaim them. Clear is optional and only useful when the same VM is reused for multiple runs and you want to break Go references between runs to reduce live-heap pressure.
func (*VM) IsStackEmpty ¶
IsStackEmpty tests if the stack is empty or not.
func (*VM) Recover ¶ added in v0.2.1
Recover returns the in-flight error of the surrounding "deferred-for" frame (and clears it) so the surrounding function returns normally; otherwise Undefined.
Effective only when called directly from a deferred script function. Concretely we require:
- v.curFrame is a real compiled Kavun function (not the trampoline / not nil), and
- v.curFrame.deferredFor is non-nil (i.e. the current frame was entered as a deferred call).
Calling recover() one level deeper (through another Kavun function invocation) does not work because OpCall resets deferredFor on the new frame. Host builtins invoked as defers also do not flip deferredFor, so recover() from such a builtin returns Undefined as well. Matches Go's "recover only in a deferred function" rule.