Documentation
¶
Overview ¶
Package exec defines the specification of a Go+ backend.
Index ¶
- Constants
- Variables
- func SizeofKind(kind Kind) uintptr
- func TypeFromKind(kind Kind) reflect.Type
- type AddrOperator
- type AddrOperatorInfo
- type Builder
- type Code
- type Comprehension
- type ConstKind
- type ForPhrase
- type FuncInfo
- type GoBuiltin
- type GoConstInfo
- type GoFuncAddr
- type GoFuncInfo
- type GoFuncvAddr
- type GoPackage
- type GoSymInfo
- type GoVarAddr
- type GoVarInfo
- type JmpCondFlag
- type Kind
- type Label
- type Operator
- type OperatorInfo
- type Package
- type Reserved
- type Stack
- func (p *Stack) Get(idx int) interface{}
- func (p *Stack) GetArgs(arity int) []interface{}
- func (p *Stack) Init()
- func (p *Stack) Len() int
- func (p *Stack) Pop() interface{}
- func (p *Stack) PopN(n int)
- func (p *Stack) Push(v interface{})
- func (p *Stack) Ret(arity int, results ...interface{})
- func (p *Stack) Set(idx int, v interface{})
- func (p *Stack) SetLen(base int)
- type SymbolKind
- type Var
Constants ¶
const ( // Bool type Bool = reflect.Bool // Int type Int = reflect.Int // Int8 type Int8 = reflect.Int8 // Int16 type Int16 = reflect.Int16 // Int32 type Int32 = reflect.Int32 // Int64 type Int64 = reflect.Int64 // Uint type Uint = reflect.Uint // Uint8 type Uint8 = reflect.Uint8 // Uint16 type Uint16 = reflect.Uint16 // Uint32 type Uint32 = reflect.Uint32 // Uint64 type Uint64 = reflect.Uint64 // Uintptr type Uintptr = reflect.Uintptr // Float32 type Float32 = reflect.Float32 // Float64 type Float64 = reflect.Float64 // Complex64 type Complex64 = reflect.Complex64 // Complex128 type Complex128 = reflect.Complex128 // String type String = reflect.String // UnsafePointer type UnsafePointer = reflect.UnsafePointer // BigInt type BigInt = spec.BigInt // BigRat type BigRat = spec.BigRat // BigFloat type BigFloat = spec.BigFloat // Slice type Slice = spec.Slice // Map type Map = spec.Map // Chan type Chan = spec.Chan // Ptr type Ptr = spec.Ptr )
const ( // ConstBoundRune - bound type: rune ConstBoundRune = spec.ConstBoundRune // ConstBoundString - bound type: string ConstBoundString = spec.ConstBoundString // ConstUnboundInt - unbound int type ConstUnboundInt = spec.ConstUnboundInt // ConstUnboundFloat - unbound float type ConstUnboundFloat = spec.ConstUnboundFloat // ConstUnboundComplex - unbound complex type ConstUnboundComplex = spec.ConstUnboundComplex // ConstUnboundPtr - nil: unbound ptr ConstUnboundPtr = spec.ConstUnboundPtr )
const ( // OpAddrVal `*addr` OpAddrVal = AddrOperator(0) // OpAddAssign `+=` OpAddAssign = AddrOperator(OpAdd) // OpSubAssign `-=` OpSubAssign = AddrOperator(OpSub) // OpMulAssign `*=` OpMulAssign = AddrOperator(OpMul) // OpQuoAssign `/=` OpQuoAssign = AddrOperator(OpQuo) // OpModAssign `%=` OpModAssign = AddrOperator(OpMod) // OpAndAssign '&=' OpAndAssign = AddrOperator(OpAnd) // OpOrAssign '|=' OpOrAssign = AddrOperator(OpOr) // OpXorAssign '^=' OpXorAssign = AddrOperator(OpXor) // OpAndNotAssign '&^=' OpAndNotAssign = AddrOperator(OpAndNot) // OpLshAssign '<<=' OpLshAssign = AddrOperator(OpLsh) // OpRshAssign '>>=' OpRshAssign = AddrOperator(OpRsh) // OpAssign `=` OpAssign AddrOperator = iota // OpInc '++' OpInc // OpDec '--' OpDec )
const ( // BitNone - bitNone BitNone = bitNone // BitsAllIntUint - bitsAllIntUint BitsAllIntUint = bitsAllIntUint )
Operator related constants, for Operator/AddrOperator instr.
const ( // SliceConstIndexLast - slice const index max SliceConstIndexLast = (1 << 13) - 3 // SliceDefaultIndex - unspecified index SliceDefaultIndex = -2 )
Slice related constants, for Slice/Slice3 instr.
const ( // BuiltinTypesLen - len(builtinTypes) BuiltinTypesLen = len(builtinTypes) )
const ( // SameAsFirst means the second argument is same as first argument type. SameAsFirst = reflect.Invalid )
Variables ¶
var ( // TyBool type TyBool = reflect.TypeOf(true) // TyInt type TyInt = reflect.TypeOf(int(0)) // TyInt8 type TyInt8 = reflect.TypeOf(int8(0)) // TyInt16 type TyInt16 = reflect.TypeOf(int16(0)) // TyInt32 type TyInt32 = reflect.TypeOf(int32(0)) // TyInt64 type TyInt64 = reflect.TypeOf(int64(0)) // TyUint type TyUint = reflect.TypeOf(uint(0)) // TyUint8 type TyUint8 = reflect.TypeOf(uint8(0)) // TyUint16 type TyUint16 = reflect.TypeOf(uint16(0)) // TyUint32 type TyUint32 = reflect.TypeOf(uint32(0)) // TyUint64 type TyUint64 = reflect.TypeOf(uint64(0)) // TyUintptr type TyUintptr = reflect.TypeOf(uintptr(0)) // TyFloat32 type TyFloat32 = reflect.TypeOf(float32(0)) // TyFloat64 type TyFloat64 = reflect.TypeOf(float64(0)) // TyComplex64 type TyComplex64 = reflect.TypeOf(complex64(0)) // TyComplex128 type TyComplex128 = reflect.TypeOf(complex128(0)) // TyString type TyString = reflect.TypeOf("") // TyUnsafePointer type TyUnsafePointer = reflect.TypeOf(unsafe.Pointer(nil)) // TyEmptyInterface type TyEmptyInterface = reflect.TypeOf((*interface{})(nil)).Elem() // TyError type TyError = reflect.TypeOf((*error)(nil)).Elem() // TyBigInt type TyBigInt = reflect.TypeOf((*big.Int)(nil)) // TyBigRat type TyBigRat = reflect.TypeOf((*big.Rat)(nil)) // TyBigFloat type TyBigFloat = reflect.TypeOf((*big.Float)(nil)) )
var ( // TyByte type TyByte = reflect.TypeOf(byte(0)) // TyRune type TyRune = reflect.TypeOf(rune(0)) // TyEmptyInterfaceSlice type TyEmptyInterfaceSlice = reflect.SliceOf(TyEmptyInterface) // TySlice type TySlice = reflect.SliceOf(TyEmptyInterface) // TyMap type TyMap = reflect.MapOf(TyEmptyInterface, TyEmptyInterface) // Chan type TyChan = reflect.ChanOf(reflect.BothDir, TyEmptyInterface) // TyPtr type TyPtr = TyUnsafePointer )
Functions ¶
func SizeofKind ¶
SizeofKind returns sizeof type who has this kind.
func TypeFromKind ¶
TypeFromKind returns the type who has this kind.
Types ¶
type AddrOperator ¶
type AddrOperator Operator
AddrOperator type.
func (AddrOperator) GetInfo ¶
func (op AddrOperator) GetInfo() *AddrOperatorInfo
GetInfo returns the information of this operator.
func (AddrOperator) String ¶
func (op AddrOperator) String() string
type AddrOperatorInfo ¶
type AddrOperatorInfo struct {
Lit string
InFirst uint64 // first argument supported types.
InSecond uint64 // second argument supported types. It may have SameAsFirst flag.
}
AddrOperatorInfo represents an addr-operator information.
type Builder ¶
type Builder interface {
// Push instr
Push(val interface{}) Builder
// Pop instr
Pop(n int) Builder
// BuiltinOp instr
BuiltinOp(kind Kind, op Operator) Builder
// Label defines a label to jmp here.
Label(l Label) Builder
// Jmp instr
Jmp(l Label) Builder
// JmpIf instr
JmpIf(cond JmpCondFlag, l Label) Builder
// CaseNE instr
CaseNE(l Label, arity int) Builder
// Default instr
Default() Builder
// WrapIfErr instr
WrapIfErr(nret int, l Label) Builder
// ErrWrap instr
ErrWrap(nret int, retErr Var, frame *errors.Frame, narg int) Builder
// ForPhrase instr
ForPhrase(f ForPhrase, key, val Var, hasExecCtx ...bool) Builder
// FilterForPhrase instr
FilterForPhrase(f ForPhrase) Builder
// EndForPhrase instr
EndForPhrase(f ForPhrase) Builder
// ListComprehension instr
ListComprehension(c Comprehension) Builder
// MapComprehension instr
MapComprehension(c Comprehension) Builder
// EndComprehension instr
EndComprehension(c Comprehension) Builder
// Closure instr
Closure(fun FuncInfo) Builder
// GoClosure instr
GoClosure(fun FuncInfo) Builder
// CallClosure instr
CallClosure(nexpr, arity int, ellipsis bool) Builder
// CallGoClosure instr
CallGoClosure(nexpr, arity int, ellipsis bool) Builder
// CallFunc instr
CallFunc(fun FuncInfo, nexpr int) Builder
// CallFuncv instr
CallFuncv(fun FuncInfo, nexpr, arity int) Builder
// CallGoFunc instr
CallGoFunc(fun GoFuncAddr, nexpr int) Builder
// CallGoFuncv instr
CallGoFuncv(fun GoFuncvAddr, nexpr, arity int) Builder
// GoBuiltin instr
GoBuiltin(typ reflect.Type, op GoBuiltin) Builder
// Defer instr
Defer() Builder
// Go instr
Go() Builder
// DefineFunc instr
DefineFunc(fun FuncInfo) Builder
// DefineType name string,reflect.Typeinstr
DefineType(typ reflect.Type, name string) Builder
// Return instr
Return(n int32) Builder
// Load instr
Load(idx int32) Builder
// Addr instr
Addr(idx int32) Builder
// Store instr
Store(idx int32) Builder
// EndFunc instr
EndFunc(fun FuncInfo) Builder
// DefineVar defines variables.
DefineVar(vars ...Var) Builder
// InCurrentCtx returns if a variable is in current context or not.
InCurrentCtx(v Var) bool
// LoadVar instr
LoadVar(v Var) Builder
// StoreVar instr
StoreVar(v Var) Builder
// AddrVar instr
AddrVar(v Var) Builder
// LoadGoVar instr
LoadGoVar(addr GoVarAddr) Builder
// StoreGoVar instr
StoreGoVar(addr GoVarAddr) Builder
// AddrGoVar instr
AddrGoVar(addr GoVarAddr) Builder
// LoadField instr
LoadField(typ reflect.Type, index []int) Builder
// StoreField instr
StoreField(typ reflect.Type, index []int) Builder
// AddrField instr
AddrField(typ reflect.Type, index []int) Builder
// AddrOp instr
AddrOp(kind Kind, op AddrOperator) Builder
// MakeArray instr
MakeArray(typ reflect.Type, arity int) Builder
// MakeMap instr
MakeMap(typ reflect.Type, arity int) Builder
// Make instr
Make(typ reflect.Type, arity int) Builder
// Val instr
Struct(typ reflect.Type, arity int) Builder
// Append instr
Append(typ reflect.Type, arity int) Builder
// MapIndex instr
MapIndex(twoValue bool) Builder
// SetMapIndex instr
SetMapIndex() Builder
// Index instr
Index(idx int) Builder
// AddrIndex instr
AddrIndex(idx int) Builder
// SetIndex instr
SetIndex(idx int) Builder
// Slice instr
Slice(i, j int) Builder
// Slice3 instr
Slice3(i, j, k int) Builder
// TypeCast instr
TypeCast(from, to reflect.Type) Builder
// Zero instr
Zero(typ reflect.Type) Builder
// New instr
New(typ reflect.Type) Builder
// StartStmt emit a `StartStmt` event.
StartStmt(stmt interface{}) interface{}
// EndStmt emit a `EndStmt` event.
EndStmt(stmt, start interface{}) Builder
// Reserve reserves an instruction.
Reserve() Reserved
// ReservedAsPush sets Reserved as Push(v)
ReservedAsPush(r Reserved, v interface{})
// ReserveOpLsh reserves an instruction.
ReserveOpLsh() Reserved
// ReservedAsOpLsh sets Reserved as OpLsh
ReservedAsOpLsh(r Reserved, kind Kind, op Operator)
// GetPackage returns the Go+ package that the Builder works for.
GetPackage() Package
// Resolve resolves all unresolved labels/functions/consts/etc.
Resolve() Code
// DefineBlock instr
DefineBlock() Builder
// EndBlock instr
EndBlock() Builder
// Send instr
Send() Builder
// Recv instr
Recv() Builder
}
Builder represents a executing byte code generator.
type Code ¶
type Code interface {
// Len returns code length.
Len() int
}
A Code represents generated instructions to execute.
type Comprehension ¶
type Comprehension interface {
}
Comprehension represents a list/map comprehension.
type ConstKind ¶
A ConstKind represents the specific kind of type that a Type represents. The zero Kind is not a valid kind.
type FuncInfo ¶
type FuncInfo interface {
// Name returns the function name.
Name() string
// Type returns type of this function.
Type() reflect.Type
// Args sets argument types of a Go+ function.
Args(in ...reflect.Type) FuncInfo
// Vargs sets argument types of a variadic Go+ function.
Vargs(in ...reflect.Type) FuncInfo
// Return sets return types of a Go+ function.
Return(out ...Var) FuncInfo
// NumIn returns a function's input parameter count.
NumIn() int
// NumOut returns a function's output parameter count.
NumOut() int
// Out returns the type of a function type's i'th output parameter.
// It panics if i is not in the range [0, NumOut()).
Out(i int) Var
// IsVariadic returns if this function is variadic or not.
IsVariadic() bool
// IsUnnamedOut returns if function results unnamed or not.
IsUnnamedOut() bool
}
FuncInfo represents a Go+ function information.
type GoBuiltin ¶
type GoBuiltin uint
GoBuiltin represents go builtin func.
const ( // GobLen - len: 1 GobLen GoBuiltin // GobCap - cap: 2 GobCap // GobCopy - copy: 3 GobCopy // GobDelete - delete: 4 GobDelete // GobComplex - complex: 5 GobComplex // GobReal - real: 6 GobReal // GobImag - imag: 7 GobImag // GobClose - close: 8 GobClose // GobRecover - recover:9 GobRecover )
type GoConstInfo ¶
GoConstInfo represents a Go constant information.
type GoPackage ¶
type GoPackage interface {
PkgPath() string
// Find lookups a symbol by specified its name.
Find(name string) (addr uint32, kind SymbolKind, ok bool)
// FindFunc lookups a Go function by name.
FindFunc(name string) (addr GoFuncAddr, ok bool)
// FindFuncv lookups a Go function by name.
FindFuncv(name string) (addr GoFuncvAddr, ok bool)
// FindType lookups a Go type by name.
FindType(name string) (typ reflect.Type, ok bool)
// FindConst lookups a Go constant by name.
FindConst(name string) (ci *GoConstInfo, ok bool)
}
GoPackage represents a Go package.
type JmpCondFlag ¶
type JmpCondFlag uint32
JmpCondFlag represents condition of Jmp intruction.
const ( // JcFalse - JmpIfFalse JcFalse JmpCondFlag = 0 // JcTrue - JmpIfTrue JcTrue JmpCondFlag = 1 // JcNil - JmpIfNil JcNil JmpCondFlag = 2 // JcNotNil - JmpIfNotNil JcNotNil JmpCondFlag = 3 // JcNotPopMask - jump but not pop JcNotPopMask JmpCondFlag = 4 )
func (JmpCondFlag) IsNotPop ¶
func (v JmpCondFlag) IsNotPop() bool
IsNotPop returns to pop condition value or not
type Label ¶
type Label interface {
// Name returns the label name.
Name() string
}
Label represents a label.
type Operator ¶
type Operator uint
Operator type.
const ( // OpInvalid - invalid operator OpInvalid Operator = iota // OpAdd '+' String/Int/Uint/Float/Complex OpAdd // OpSub '-' Int/Uint/Float/Complex OpSub // OpMul '*' Int/Uint/Float/Complex OpMul // OpQuo '/' Int/Uint/Float/Complex OpQuo // OpMod '%' Int/Uint OpMod // OpAnd '&' Int/Uint OpAnd // OpOr '|' Int/Uint OpOr // OpXor '^' Int/Uint OpXor // OpAndNot '&^' Int/Uint OpAndNot // OpLsh '<<' Int/Uint, Uint OpLsh // OpRsh '>>' Int/Uint, Uint OpRsh // OpLT '<' String/Int/Uint/Float OpLT // OpLE '<=' String/Int/Uint/Float OpLE // OpGT '>' String/Int/Uint/Float OpGT // OpGE '>=' String/Int/Uint/Float OpGE // OpEQ '==' ComparableType // Slice, map, and function values are not comparable. However, as a special case, a slice, map, // or function value may be compared to the predeclared identifier nil. OpEQ // OpEQNil '==' nil OpEQNil // OpNE '!=' ComparableType OpNE // OpNENil '!=' nil OpNENil // OpLAnd '&&' Bool OpLAnd // OpLOr '||' Bool OpLOr // OpLNot '!' OpLNot // OpNeg '-' OpNeg // OpBitNot '^' OpBitNot )
func (Operator) GetInfo ¶
func (op Operator) GetInfo() *OperatorInfo
GetInfo returns the information of this operator.
type OperatorInfo ¶
type OperatorInfo struct {
Lit string
InFirst uint64 // first argument supported types.
InSecond uint64 // second argument supported types. It may have SameAsFirst flag.
Out reflect.Kind // result type. It may be SameAsFirst.
}
OperatorInfo represents an operator information.
type Package ¶
type Package interface {
// NewVar creates a variable instance.
NewVar(typ reflect.Type, name string) Var
// NewLabel creates a label object.
NewLabel(name string) Label
// NewForPhrase creates a new ForPhrase instance.
NewForPhrase(in reflect.Type) ForPhrase
// NewComprehension creates a new Comprehension instance.
NewComprehension(out reflect.Type) Comprehension
// NewFunc creates a Go+ function.
NewFunc(name string, nestDepth uint32, funcType ...int) FuncInfo
// FindGoPackage lookups a Go package by pkgPath. It returns nil if not found.
FindGoPackage(pkgPath string) GoPackage
// GetGoFuncType returns a Go function's type.
GetGoFuncType(addr GoFuncAddr) reflect.Type
// GetGoFuncvType returns a Go function's type.
GetGoFuncvType(addr GoFuncvAddr) reflect.Type
// GetGoFuncInfo returns a Go function's information.
GetGoFuncInfo(addr GoFuncAddr) *GoFuncInfo
// GetGoFuncvInfo returns a Go function's information.
GetGoFuncvInfo(addr GoFuncvAddr) *GoFuncInfo
// GetGoVarInfo returns a Go variable's information.
GetGoVarInfo(addr GoVarAddr) *GoVarInfo
}
Package represents a Go+ package.
type Reserved ¶
type Reserved int
Reserved represents a reserved instruction position.
const InvalidReserved Reserved = -1
InvalidReserved is an invalid reserved position.
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
A Stack represents a FILO container.
type SymbolKind ¶
type SymbolKind uint32
SymbolKind represents symbol kind.
const ( // SymbolVar - variable SymbolVar SymbolKind = 0 // SymbolFunc - function SymbolFunc SymbolKind = 1 // SymbolFuncv - variadic function SymbolFuncv SymbolKind = 2 )