Documentation
¶
Index ¶
- Constants
- type Addr
- type Condition
- type Context
- type DebugInfo
- type Env
- type ExitError
- type FatalError
- type Format
- type Function
- type Instruction
- type Operation
- type Panic
- type Position
- type PredefinedFunction
- type PrintFunc
- type Registers
- type Renderer
- type StackShift
- type Types
- type VM
- func (vm *VM) Env() Env
- func (vm *VM) Reset()
- func (vm *VM) Run(fn *Function, types Types, globals []reflect.Value) (int, error)
- func (vm *VM) SetContext(ctx context.Context)
- func (vm *VM) SetPrint(p func(interface{}))
- func (vm *VM) SetRenderer(r Renderer)
- func (vm *VM) Stack(buf []byte, all bool) int
- type Wrapper
Constants ¶
const CallFrameSize = 88
Size of a CallFrame.
const CurrentFunction = -1
const NoVariadicArgs = -1
const ReturnString = -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 Context ¶ added in v0.44.0
type Context byte
Context represents a context in Show and Text instructions.
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 global function to get the absolute path
// of the file where such global was called. If the global 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{})
// Types returns a Types value that allows to manipulate all the types,
// including new types defined in the executed code.
Types() Types
}
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
FinalRegs [][2]int8 // [indirect -> return parameter registers]
Macro bool
Format Format
Values Registers
FieldIndexes [][]int
Functions []*Function
Predefined []*PredefinedFunction
Body []Instruction
Text [][]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 OpCallFunc OpCallIndirect OpCallMacro OpCallPredefined OpCap OpCase OpClose OpComplex64 OpComplex128 OpConcat OpContinue OpConvert OpConvertInt OpConvertUint OpConvertFloat OpConvertString OpCopy OpDefer OpDelete OpDiv OpDivInt OpDivFloat64 OpField OpGetVar OpGetVarAddr OpGo OpGoto OpIf OpIfInt OpIfFloat OpIfString OpIndex OpIndexString OpIndexRef OpLen OpLoad OpLoadFunc OpMakeArray OpMakeChan OpMakeMap OpMakeSlice OpMakeStruct OpMapIndex OpMethodValue OpMove OpMul OpMulInt OpMulFloat64 OpNeg OpNew OpOr OpPanic OpPrint OpRange OpRangeString OpRealImag OpReceive OpRecover OpRem OpRemInt OpReturn OpSelect OpSend OpSetField OpSetMap OpSetSlice OpSetVar OpShl OpShlInt OpShow OpShr OpShrInt OpSlice OpStringSlice OpSub OpSubInt OpSubFloat64 OpSubInv OpSubInvInt OpSubInvFloat64 OpTailCall OpText 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 Types ¶ added in v0.31.0
type Types interface {
// New is like reflect.New but if typ is a Scriggo type, the returned
// Value refers to the underling type of typ.
New(typ reflect.Type) reflect.Value
// TypeOf is like reflect.TypeOf but if i has a Scriggo type it returns
// its Scriggo reflect type instead of the reflect type of the proxy.
TypeOf(i interface{}) reflect.Type
// ValueOf is like reflect.ValueOf but if i has a Scriggo type it returns
// its underling value instead of the reflect value of the proxy.
ValueOf(i interface{}) reflect.Value
}
A Types implementation allows to manipulate all the types, including new types defined in a executed code.
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 ¶
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.
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) SetRenderer ¶ added in v0.31.0
SetRenderer sets the renderer.
SetRenderer 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.