Documentation
¶
Index ¶
Constants ¶
const CallFrameSize = 88
Size of a CallFrame.
const CurrentFunction = -1
const NoVariadicArgs = -1
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Condition ¶
type Condition int8
const ( ConditionZero Condition = iota // x == 0 ConditionNotZero // x != 0 ConditionEqual // x == y ConditionNotEqual // x != y ConditionInterfaceEqual // x == y ConditionInterfaceNotEqual // 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 ConditionContainsSubstring // x contains y ConditionContainsRune // x contains y ConditionContainsElement // x contains y ConditionContainsKey // x contains y ConditionContainsNil // x contains nil ConditionNotContainsSubstring // x not contains y ConditionNotContainsRune // x not contains y ConditionNotContainsElement // x not contains y ConditionNotContainsKey // x not contains y ConditionNotContainsNil // x not contains 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.
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 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
}
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.
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 StackShift ¶
type StackShift [4]int8
type TypeOfFunc ¶ added in v0.28.0
A TypeOfFunc function returns a type of a value.
type VM ¶
type VM struct {
// contains filtered or unexported fields
}
VM represents a Scriggo virtual machine.
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, typeOf TypeOfFunc, 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 ¶
SetContext sets the context.
SetContext must not be called after vm has been started.
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.