runtime

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2020 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const CallFrameSize = 88

Size of a CallFrame.

View Source
const CurrentFunction = -1
View Source
const NoVariadicArgs = -1

Variables

This section is empty.

Functions

This section is empty.

Types

type Addr

type Addr uint32

type Condition

type Condition int8
const (
	ConditionZero            Condition = iota // x == 0
	ConditionNotZero                          // x != 0
	ConditionEqual                            // x == y
	ConditionNotEqual                         // x != y
	ConditionLess                             // x <  y
	ConditionLessEqual                        // x <= y
	ConditionGreater                          // x >  y
	ConditionGreaterEqual                     // x >= y
	ConditionLessU                            // x <  y (unsigned)
	ConditionLessEqualU                       // x <= y (unsigned)
	ConditionGreaterU                         // x >  y (unsigned)
	ConditionGreaterEqualU                    // x >= y (unsigned)
	ConditionLenEqual                         // len(x) == y
	ConditionLenNotEqual                      // len(x) != y
	ConditionLenLess                          // len(x) <  y
	ConditionLenLessEqual                     // len(x) <= y
	ConditionLenGreater                       // len(x) >  y
	ConditionLenGreaterEqual                  // len(x) >= y
	ConditionInterfaceNil                     // x == nil
	ConditionInterfaceNotNil                  // x != nil
	ConditionNil                              // x == nil
	ConditionNotNil                           // x != nil
	ConditionOK                               // [vm.ok]
	ConditionNotOK                            // ![vm.ok]
)

type DebugInfo

type DebugInfo struct {
	Position    Position        // position of the instruction in the source code.
	Path        string          // path of the source code where the instruction is located in.
	OperandKind [3]reflect.Kind // kind of operands A, B and C.
	FuncType    reflect.Type    // type of the function that is called; only for call instructions.
}

DebugInfo represents a set of debug information associated to a given instruction. None of the fields below is mandatory.

type Env

type Env interface {

	// Context returns the context of the environment.
	Context() context.Context

	// Exit exits the environment with the given status code. Deferred functions
	// are not run.
	Exit(code int)

	// Exited reports whether the environment is exited.
	Exited() bool

	// ExitFunc calls f in its own goroutine after the execution of the
	// environment is terminated.
	ExitFunc(f func())

	// Fatal calls panic() with a FatalError error.
	Fatal(v interface{})

	// FilePath can be called from a builtin function to get the absolute path
	// of the file where such builtin was called. If the builtin function was
	// not called by the main virtual machine goroutine, the returned value is
	// not significant.
	FilePath() string

	// Print calls the print built-in function with args as argument.
	Print(args ...interface{})

	// Println calls the println built-in function with args as argument.
	Println(args ...interface{})
}

Env represents an execution environment.

type ExitError

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

ExitError represents an exit error.

func (ExitError) Error

func (err ExitError) Error() string

type FatalError

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

FatalError represents a fatal error. A fatal error cannot be recovered by the running program.

func (*FatalError) Error

func (err *FatalError) Error() string

type Function

type Function struct {
	Pkg        string
	Name       string
	File       string
	Pos        *Position // position of the function declaration.
	Type       reflect.Type
	Parent     *Function
	VarRefs    []int16
	Types      []reflect.Type
	NumReg     [4]int8
	Constants  Registers
	Functions  []*Function
	Predefined []*PredefinedFunction
	Body       []Instruction
	Data       [][]byte
	DebugInfo  map[Addr]DebugInfo
}

Function represents a function.

type Instruction

type Instruction struct {
	Op      Operation
	A, B, C int8
}

type Operation

type Operation int8
const (
	OpNone Operation = iota

	OpAdd
	OpAddInt
	OpAddFloat64

	OpAddr

	OpAnd

	OpAndNot

	OpAssert

	OpAppend

	OpAppendSlice

	OpBreak

	OpCall

	OpCallIndirect

	OpCallPredefined

	OpCap

	OpCase

	OpClose

	OpComplex64
	OpComplex128

	OpContinue

	OpConvert
	OpConvertInt
	OpConvertUint
	OpConvertFloat
	OpConvertString

	OpConcat

	OpCopy

	OpDefer

	OpDelete

	OpDiv
	OpDivInt
	OpDivFloat64

	OpField

	OpFieldRef

	OpGetVar

	OpGetVarAddr

	OpGo

	OpGoto

	OpIf
	OpIfInt
	OpIfFloat
	OpIfString

	OpIndex
	OpIndexString

	OpIndexRef

	OpShl
	OpShlInt

	OpLen

	OpLoadData

	OpLoadFunc

	OpLoadNumber

	OpMakeArray

	OpMakeChan

	OpMakeMap

	OpMakeSlice

	OpMakeStruct

	OpMapIndex

	OpMethodValue

	OpMove

	OpMul
	OpMulInt
	OpMulFloat64

	OpNeg

	OpNew

	OpOr

	OpPanic

	OpPrint

	OpRange

	OpRangeString

	OpRealImag

	OpReceive

	OpRecover

	OpRem
	OpRemInt

	OpReturn

	OpShr
	OpShrInt

	OpSelect

	OpSend

	OpSetField
	OpSetMap

	OpSetSlice

	OpSetVar

	OpSlice

	OpStringSlice

	OpSub
	OpSubInt
	OpSubFloat64

	OpSubInv
	OpSubInvInt
	OpSubInvFloat64

	OpTailCall

	OpTypify

	OpXor

	OpZero
)

type Panic

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

func (*Panic) Error

func (p *Panic) Error() string

func (*Panic) Message

func (p *Panic) Message() interface{}

Message returns the message.

func (*Panic) Next

func (p *Panic) Next() *Panic

Next returns the next panic in the chain.

func (*Panic) Path

func (p *Panic) Path() string

Path returns the path of the file that panicked.

func (*Panic) Position

func (p *Panic) Position() Position

Position returns the position.

func (*Panic) Recovered

func (p *Panic) Recovered() bool

Recovered reports whether it has been recovered.

func (*Panic) String

func (p *Panic) String() string

String returns the message as a string.

type Position

type Position struct {
	Line   int // line starting from 1
	Column int // column in characters starting from 1
	Start  int // index of the first byte
	End    int // index of the last byte
}

Position represents a source position.

func (Position) String

func (p Position) String() string

type PredefinedFunction

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

func NewPredefinedFunction

func NewPredefinedFunction(pkg, name string, function interface{}) *PredefinedFunction

NewPredefinedFunction returns a new predefined function given its package and name and the function value or its reflect value. pkg and name can be empty strings.

func (*PredefinedFunction) Func

func (fn *PredefinedFunction) Func() interface{}

func (*PredefinedFunction) Name

func (fn *PredefinedFunction) Name() string

func (*PredefinedFunction) Package

func (fn *PredefinedFunction) Package() string

type PrintFunc

type PrintFunc func(interface{})

type Registers

type Registers struct {
	Int     []int64
	Float   []float64
	String  []string
	General []interface{}
}

type StackShift

type StackShift [4]int8

type VM

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

VM represents a Scriggo virtual machine.

func NewVM

func NewVM() *VM

NewVM returns a new virtual machine.

func (*VM) Env

func (vm *VM) Env() Env

Env returns the execution environment of vm.

func (*VM) Reset

func (vm *VM) Reset()

Reset resets a virtual machine so that it is ready for a new call to Run.

func (*VM) Run

func (vm *VM) Run(fn *Function, globals []interface{}) (int, error)

Run starts the execution of the function fn with the given global variables and waits for it to complete.

During the execution if a panic occurs and has not been recovered, by default Run panics with the panic message.

If a context has been set and the context is canceled, Run returns as soon as possible with the error returned by the Err method of the context.

func (*VM) SetContext

func (vm *VM) SetContext(ctx context.Context)

SetContext sets the context.

SetContext must not be called after vm has been started.

func (*VM) SetPrint

func (vm *VM) SetPrint(p func(interface{}))

SetPrint sets the "print" builtin function.

SetPrint must not be called after vm has been started.

func (*VM) Stack

func (vm *VM) Stack(buf []byte, all bool) int

Stack returns the current stack trace.

type Wrapper

type Wrapper interface {

	// Wrap wraps a value with a Scriggo type putting into a proxy that exposes
	// methods to Go.
	Wrap(reflect.Value) reflect.Value

	// Unwrap unwraps a value that has been read from Go. If the value given as
	// parameter can be unwrapped using the unwrapper's type, the unwrapped
	// value is returned and the method returns true.
	Unwrap(reflect.Value) (reflect.Value, bool)

	// Underlying returns the underlying type of a Scriggo type. Note that the
	// implementation of the reflect.Type returned by Underlying is the
	// implementation of the package 'reflect', so it's safe to pass the
	// returned value to reflect functions and methods as argument.
	Underlying() reflect.Type
}

A Wrapper wraps and unwraps Scriggo types into Go types. A wrapper is used when an internal implementation of a value must be typified or when an external Go value must be imported into Scriggo.

Jump to

Keyboard shortcuts

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