Documentation ¶
Overview ¶
Package bytecode implements a bytecode backend for the Go+ language.
Index ¶
- Constants
- func CallAddrOp(kind Kind, op AddrOperator, data ...interface{})
- func CallBuiltinOp(kind Kind, op Operator, data ...interface{}) interface{}
- func DumpCodeBlock(w io.Writer, data ...Instr)
- func FindGoPackage(pkgPath string) exec.GoPackage
- func ProfileReport()
- func SetProfile(profile bool)
- func ToValues(args []interface{}) []reflect.Value
- type AddrOperator
- type AddrOperatorInfo
- type Builder
- func (p *Builder) Addr(idx int32) *Builder
- func (p *Builder) AddrField(typ reflect.Type, index []int) *Builder
- func (p *Builder) AddrGoVar(addr GoVarAddr) *Builder
- func (p *Builder) AddrIndex(idx int) *Builder
- func (p *Builder) AddrOp(kind Kind, op AddrOperator) *Builder
- func (p *Builder) AddrVar(v *Var) *Builder
- func (p *Builder) Append(typ reflect.Type, arity int) *Builder
- func (p *Builder) BuiltinOp(kind Kind, op Operator) *Builder
- func (p *Builder) CallClosure(arity int) *Builder
- func (p *Builder) CallFunc(fun *FuncInfo) *Builder
- func (p *Builder) CallFuncv(fun *FuncInfo, arity int) *Builder
- func (p *Builder) CallGoClosure(arity int) *Builder
- func (p *Builder) CallGoFunc(fun GoFuncAddr) *Builder
- func (p *Builder) CallGoFuncv(fun GoFuncvAddr, arity int) *Builder
- func (p *Builder) CaseNE(l *Label, arity int) *Builder
- func (p *Builder) Closure(fun *FuncInfo) *Builder
- func (p *Builder) Default() *Builder
- func (p *Builder) Defer() *Builder
- func (p *Builder) DefineFunc(fun *FuncInfo) *Builder
- func (p *Builder) DefineVar(vars ...*Var) *Builder
- func (p *Builder) DefineVars(vars ...exec.Var) *Builder
- func (p *Builder) EndComprehension(c *Comprehension) *Builder
- func (p *Builder) EndForPhrase(f *ForPhrase) *Builder
- func (p *Builder) EndFunc(fun *FuncInfo) *Builder
- func (p *Builder) ErrWrap(nret int, retErr exec.Var, frame *errors.Frame, narg int) *Builder
- func (p *Builder) FilterForPhrase(f *ForPhrase) *Builder
- func (p *Builder) ForPhrase(f *ForPhrase, key, val *Var, hasExecCtx ...bool) *Builder
- func (p *Builder) Go() exec.Builder
- func (p *Builder) GoBuiltin(typ reflect.Type, op GoBuiltin) *Builder
- func (p *Builder) GoClosure(fun *FuncInfo) *Builder
- func (p *Builder) InCurrentCtx(v *Var) bool
- func (p *Builder) Index(idx int) *Builder
- func (p *Builder) Interface() exec.Builder
- func (p *Builder) Jmp(l *Label) *Builder
- func (p *Builder) JmpIf(cond exec.JmpCondFlag, l *Label) *Builder
- func (p *Builder) Label(l *Label) *Builder
- func (p *Builder) ListComprehension(c *Comprehension) *Builder
- func (p *Builder) Load(idx int32) *Builder
- func (p *Builder) LoadField(typ reflect.Type, index []int) *Builder
- func (p *Builder) LoadGoVar(addr GoVarAddr) *Builder
- func (p *Builder) LoadVar(v *Var) *Builder
- func (p *Builder) Make(typ reflect.Type, arity int) *Builder
- func (p *Builder) MakeArray(typ reflect.Type, arity int) *Builder
- func (p *Builder) MakeMap(typ reflect.Type, arity int) *Builder
- func (p *Builder) MapComprehension(c *Comprehension) *Builder
- func (p *Builder) MapIndex(twoValue bool) *Builder
- func (p *Builder) New(typ reflect.Type) *Builder
- func (p *Builder) Pop(n int) *Builder
- func (p *Builder) Push(val interface{}) *Builder
- func (p *Builder) Recv() *Builder
- func (p *Builder) Reserve() Reserved
- func (p *Builder) ReservedAsOpLsh(r exec.Reserved, kind exec.Kind, op exec.Operator) *Builder
- func (p *Builder) ReservedAsPush(r Reserved, val interface{})
- func (p *Builder) Resolve() *Code
- func (p *Builder) Return(n int32) *Builder
- func (p *Builder) Send() *Builder
- func (p *Builder) SetIndex(idx int) *Builder
- func (p *Builder) SetMapIndex() *Builder
- func (p *Builder) Slice(i, j int) *Builder
- func (p *Builder) Slice3(i, j, k int) *Builder
- func (p *Builder) Store(idx int32) *Builder
- func (p *Builder) StoreField(typ reflect.Type, index []int) *Builder
- func (p *Builder) StoreGoVar(addr GoVarAddr) *Builder
- func (p *Builder) StoreVar(v *Var) *Builder
- func (p *Builder) Struct(typ reflect.Type, arity int) *Builder
- func (p *Builder) TypeCast(from, to reflect.Type) *Builder
- func (p *Builder) WrapIfErr(nret int, l *Label) *Builder
- func (p *Builder) Zero(typ reflect.Type) *Builder
- type Closure
- type Code
- type Comprehension
- type ConstKind
- type Context
- func (ctx *Context) Call(f exec.FuncInfo)
- func (ctx *Context) CloneSetVarScope(new *Context)
- func (ctx *Context) Exec(ip, ipEnd int) (currentIP int)
- func (ctx *Context) GetVar(x *Var) interface{}
- func (ctx *Context) Go(arity int, f func(goctx *Context))
- func (ctx *Context) Run()
- func (ctx *Context) SetVar(x *Var, v interface{})
- type ForPhrase
- type FuncInfo
- func (p *FuncInfo) Args(in ...reflect.Type) *FuncInfo
- func (p *FuncInfo) IsUnnamedOut() bool
- func (p *FuncInfo) IsVariadic() bool
- func (p *FuncInfo) Name() string
- func (p *FuncInfo) NumIn() int
- func (p *FuncInfo) NumOut() int
- func (p *FuncInfo) Out(i int) *Var
- func (p *FuncInfo) Return(out ...*Var) *FuncInfo
- func (p *FuncInfo) Type() reflect.Type
- func (p *FuncInfo) Vargs(in ...reflect.Type) *FuncInfo
- type GoBuiltin
- type GoConstInfo
- type GoFuncAddr
- type GoFuncInfo
- type GoFuncvAddr
- type GoFuncvInfo
- type GoPackage
- func (p *GoPackage) Const(name string, kind ConstKind, val interface{}) GoConstInfo
- func (p *GoPackage) Find(name string) (addr uint32, kind SymbolKind, ok bool)
- func (p *GoPackage) FindConst(name string) (ci *GoConstInfo, ok bool)
- func (p *GoPackage) FindFunc(name string) (addr GoFuncAddr, ok bool)
- func (p *GoPackage) FindFuncv(name string) (addr GoFuncvAddr, ok bool)
- func (p *GoPackage) FindType(name string) (typ reflect.Type, ok bool)
- func (p *GoPackage) FindVar(name string) (addr GoVarAddr, ok bool)
- func (p *GoPackage) Func(name string, fn interface{}, exec func(i int, p *Context)) GoFuncInfo
- func (p *GoPackage) Funcv(name string, fn interface{}, exec func(i int, p *Context)) GoFuncvInfo
- func (p *GoPackage) PkgPath() string
- func (p *GoPackage) RegisterConsts(consts ...GoConstInfo)
- func (p *GoPackage) RegisterFuncs(funs ...GoFuncInfo) (base GoFuncAddr)
- func (p *GoPackage) RegisterFuncvs(funs ...GoFuncvInfo) (base GoFuncvAddr)
- func (p *GoPackage) RegisterTypes(typinfos ...GoTypeInfo)
- func (p *GoPackage) RegisterVars(vars ...GoVarInfo) (base GoVarAddr)
- func (p *GoPackage) Rtype(typ reflect.Type) GoTypeInfo
- func (p *GoPackage) Type(name string, typ reflect.Type) GoTypeInfo
- func (p *GoPackage) Var(name string, addr interface{}) GoVarInfo
- type GoTypeInfo
- type GoVarAddr
- type GoVarInfo
- type Instr
- type InstrInfo
- type Kind
- type Label
- type Operator
- type OperatorInfo
- type Package
- func (p *Package) FindGoPackage(pkgPath string) exec.GoPackage
- func (p *Package) GetGoFuncInfo(addr exec.GoFuncAddr) *exec.GoFuncInfo
- func (p *Package) GetGoFuncType(addr exec.GoFuncAddr) reflect.Type
- func (p *Package) GetGoFuncvInfo(addr exec.GoFuncvAddr) *exec.GoFuncInfo
- func (p *Package) GetGoFuncvType(addr exec.GoFuncvAddr) reflect.Type
- func (p *Package) GetGoVarInfo(addr exec.GoVarAddr) *exec.GoVarInfo
- func (p *Package) NewComprehension(out reflect.Type) exec.Comprehension
- func (p *Package) NewForPhrase(in reflect.Type) exec.ForPhrase
- func (p *Package) NewFunc(name string, nestDepth uint32, funcType ...int) exec.FuncInfo
- func (p *Package) NewLabel(name string) exec.Label
- func (p *Package) NewVar(typ reflect.Type, name string) exec.Var
- 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 StructField
- type StructInfo
- type SymbolKind
- type Var
Constants ¶
const ( // SliceConstIndexLast - slice const index max SliceConstIndexLast = exec.SliceConstIndexLast // SliceDefaultIndex - unspecified index SliceDefaultIndex = exec.SliceDefaultIndex )
const ( // ConstBoundRune - bound type: rune ConstBoundRune = exec.ConstBoundRune // ConstBoundString - bound type: string ConstBoundString = exec.ConstBoundString // ConstUnboundInt - unbound int type ConstUnboundInt = exec.ConstUnboundInt // ConstUnboundFloat - unbound float type ConstUnboundFloat = exec.ConstUnboundFloat // ConstUnboundComplex - unbound complex type ConstUnboundComplex = exec.ConstUnboundComplex // ConstUnboundPtr - nil: unbound ptr ConstUnboundPtr = exec.ConstUnboundPtr )
const ( // SymbolVar - variable SymbolVar = exec.SymbolVar // SymbolFunc - function SymbolFunc = exec.SymbolFunc // SymbolFuncv - variadic function SymbolFuncv = exec.SymbolFuncv )
const ( // OpInvalid - invalid operator OpInvalid = exec.OpInvalid // OpAdd '+' String/Int/Uint/Float/Complex OpAdd = exec.OpAdd // OpSub '-' Int/Uint/Float/Complex OpSub = exec.OpSub // OpMul '*' Int/Uint/Float/Complex OpMul = exec.OpMul // OpQuo '/' Int/Uint/Float/Complex OpQuo = exec.OpQuo // OpMod '%' Int/Uint OpMod = exec.OpMod // OpAnd '&' Int/Uint OpAnd = exec.OpAnd // OpOr '|' Int/Uint OpOr = exec.OpOr // OpXor '^' Int/Uint OpXor = exec.OpXor // OpAndNot '&^' Int/Uint OpAndNot = exec.OpAndNot // OpLsh '<<' Int/Uint, Uint OpLsh = exec.OpLsh // OpRsh '>>' Int/Uint, Uint OpRsh = exec.OpRsh // OpLT '<' String/Int/Uint/Float OpLT = exec.OpLT // OpLE '<=' String/Int/Uint/Float OpLE = exec.OpLE // OpGT '>' String/Int/Uint/Float OpGT = exec.OpGT // OpGE '>=' String/Int/Uint/Float OpGE = exec.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 = exec.OpEQ // OpEQNil '==' nil OpEQNil = exec.OpEQNil // OpNE '!=' ComparableType OpNE = exec.OpNE // OpNENil '!=' nil OpNENil = exec.OpNENil // OpLAnd '&&' Bool OpLAnd = exec.OpLAnd // OpLOr '||' Bool OpLOr = exec.OpLOr // OpLNot '!' OpLNot = exec.OpLNot // OpNeg '-' OpNeg = exec.OpNeg // OpBitNot '^' OpBitNot = exec.OpBitNot )
const ( // Bool type Bool = exec.Bool // Int type Int = exec.Int // Int8 type Int8 = exec.Int8 // Int16 type Int16 = exec.Int16 // Int32 type Int32 = exec.Int32 // Int64 type Int64 = exec.Int64 // Uint type Uint = exec.Uint // Uint8 type Uint8 = exec.Uint8 // Uint16 type Uint16 = exec.Uint16 // Uint32 type Uint32 = exec.Uint32 // Uint64 type Uint64 = exec.Uint64 // Uintptr type Uintptr = exec.Uintptr // Float32 type Float32 = exec.Float32 // Float64 type Float64 = exec.Float64 // Complex64 type Complex64 = exec.Complex64 // Complex128 type Complex128 = exec.Complex128 // String type String = exec.String // UnsafePointer type UnsafePointer = exec.UnsafePointer // BigInt type BigInt = exec.BigInt // BigRat type BigRat = exec.BigRat // BigFloat type BigFloat = exec.BigFloat // Slice type Slice = exec.Slice // Map type Map = exec.Map // Chan type Chan = exec.Chan // Ptr type Ptr = exec.Ptr )
const ( // OpAddrVal `*addr` OpAddrVal = exec.OpAddrVal // OpAddAssign `+=` OpAddAssign = exec.OpAddAssign // OpSubAssign `-=` OpSubAssign = exec.OpSubAssign // OpMulAssign `*=` OpMulAssign = exec.OpMulAssign // OpQuoAssign `/=` OpQuoAssign = exec.OpQuoAssign // OpModAssign `%=` OpModAssign = exec.OpModAssign // OpAndAssign '&=' OpAndAssign = exec.OpAndAssign // OpOrAssign '|=' OpOrAssign = exec.OpOrAssign // OpXorAssign '^=' OpXorAssign = exec.OpXorAssign // OpAndNotAssign '&^=' OpAndNotAssign = exec.OpAndNotAssign // OpLshAssign '<<=' OpLshAssign = exec.OpLshAssign // OpRshAssign '>>=' OpRshAssign = exec.OpRshAssign // OpAssign `=` OpAssign = exec.OpAssign // OpInc '++' OpInc = exec.OpInc // OpDec '--' OpDec = exec.OpDec )
const ( // GobLen - len: 1 GobLen = exec.GobLen // GobCap - cap: 2 GobCap = exec.GobCap // GobCopy - copy: 3 GobCopy = exec.GobCopy // GobDelete - delete: 4 GobDelete = exec.GobDelete // GobComplex - complex: 5 GobComplex = exec.GobComplex // GobReal - real: 6 GobReal = exec.GobReal // GobImag - imag: 7 GobImag = exec.GobImag // GobClose - close: 8 GobClose = exec.GobClose )
const InvalidReserved = exec.InvalidReserved
InvalidReserved is an invalid reserved position.
const (
// SameAsFirst means the second argument is same as first argument type.
SameAsFirst = exec.SameAsFirst
)
Variables ¶
This section is empty.
Functions ¶
func CallAddrOp ¶
func CallAddrOp(kind Kind, op AddrOperator, data ...interface{})
CallAddrOp calls AddrOp
func CallBuiltinOp ¶
CallBuiltinOp calls BuiltinOp
func DumpCodeBlock ¶
DumpCodeBlock dumps a code block.
func FindGoPackage ¶
func FindGoPackage(pkgPath string) exec.GoPackage
FindGoPackage lookups a Go package by pkgPath. It returns nil if not found.
Types ¶
type AddrOperatorInfo ¶
type AddrOperatorInfo = exec.AddrOperatorInfo
AddrOperatorInfo represents an addr-operator information.
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder is a class that generates executing byte code.
func NewBuilder ¶
NewBuilder creates a new Code Builder instance.
func (*Builder) CallGoClosure ¶
CallGoClosure instr
func (*Builder) CallGoFuncv ¶
func (p *Builder) CallGoFuncv(fun GoFuncvAddr, arity int) *Builder
CallGoFuncv instr
func (*Builder) DefineVars ¶
DefineVars defines variables.
func (*Builder) EndComprehension ¶
func (p *Builder) EndComprehension(c *Comprehension) *Builder
EndComprehension instr
func (*Builder) EndForPhrase ¶
EndForPhrase instr
func (*Builder) FilterForPhrase ¶
FilterForPhrase instr
func (*Builder) InCurrentCtx ¶
InCurrentCtx returns if a variable is in current context or not.
func (*Builder) Interface ¶
func (p *Builder) Interface() exec.Builder
Interface converts *Builder to exec.Builder interface.
func (*Builder) ListComprehension ¶
func (p *Builder) ListComprehension(c *Comprehension) *Builder
ListComprehension instr
func (*Builder) MapComprehension ¶
func (p *Builder) MapComprehension(c *Comprehension) *Builder
MapComprehension instr
func (*Builder) ReservedAsOpLsh ¶
ReservedAsOpLsh instr
func (*Builder) ReservedAsPush ¶
ReservedAsPush sets Reserved as Push(v)
func (*Builder) StoreField ¶
StoreField instr
type Closure ¶
type Closure struct {
// contains filtered or unexported fields
}
Closure represents a Go+ closure.
type Code ¶
type Code struct {
// contains filtered or unexported fields
}
A Code represents generated instructions to execute.
type Comprehension ¶
Comprehension represents a list/map comprehension.
func NewComprehension ¶
func NewComprehension(out reflect.Type) *Comprehension
NewComprehension creates a new Comprehension instance.
type ConstKind ¶
type ConstKind = exec.ConstKind
A ConstKind represents the specific kind of type that a Type represents. The zero Kind is not a valid kind.
type Context ¶
type Context struct { Stack // contains filtered or unexported fields }
A Context represents the context of an executor.
func NewContext ¶
func NewContext(in exec.Code) *Context
NewContext returns a new context of an executor.
func (*Context) CloneSetVarScope ¶
CloneSetVarScope clone already set varScope to new context
type ForPhrase ¶
type ForPhrase struct {
Key, Value *Var // Key, Value may be nil
Cond, End int
TypeIn reflect.Type
// contains filtered or unexported fields
}
ForPhrase represents a for range phrase.
func NewForPhrase ¶
NewForPhrase creates a new ForPhrase instance.
type FuncInfo ¶
type FuncInfo struct { Pkg *Package // contains filtered or unexported fields }
FuncInfo represents a Go+ function information.
func (*FuncInfo) IsUnnamedOut ¶
IsUnnamedOut returns if function results unnamed or not.
func (*FuncInfo) IsVariadic ¶
IsVariadic returns if this function is variadic or not.
type GoConstInfo ¶
type GoConstInfo = exec.GoConstInfo
GoConstInfo represents a Go constant information.
type GoFuncInfo ¶
type GoFuncInfo struct { Pkg *GoPackage Name string This interface{} // contains filtered or unexported fields }
GoFuncInfo represents a Go function information.
type GoFuncvAddr ¶
type GoFuncvAddr = exec.GoFuncvAddr
GoFuncvAddr represents a variadic Go function address.
type GoFuncvInfo ¶
type GoFuncvInfo struct { GoFuncInfo // contains filtered or unexported fields }
GoFuncvInfo represents a Go function information.
type GoPackage ¶
type GoPackage struct {
// contains filtered or unexported fields
}
GoPackage represents a Go package.
func NewGoPackage ¶
NewGoPackage creates a new builtin Go Package.
func (*GoPackage) Const ¶
func (p *GoPackage) Const(name string, kind ConstKind, val interface{}) GoConstInfo
Const creates a GoConstInfo instance.
func (*GoPackage) Find ¶
func (p *GoPackage) Find(name string) (addr uint32, kind SymbolKind, ok bool)
Find lookups a symbol by specified its name.
func (*GoPackage) FindConst ¶
func (p *GoPackage) FindConst(name string) (ci *GoConstInfo, ok bool)
FindConst lookups a Go constant by name.
func (*GoPackage) FindFunc ¶
func (p *GoPackage) FindFunc(name string) (addr GoFuncAddr, ok bool)
FindFunc lookups a Go function by name.
func (*GoPackage) FindFuncv ¶
func (p *GoPackage) FindFuncv(name string) (addr GoFuncvAddr, ok bool)
FindFuncv lookups a Go function by name.
func (*GoPackage) Func ¶
func (p *GoPackage) Func(name string, fn interface{}, exec func(i int, p *Context)) GoFuncInfo
Func creates a GoFuncInfo instance.
func (*GoPackage) Funcv ¶
func (p *GoPackage) Funcv(name string, fn interface{}, exec func(i int, p *Context)) GoFuncvInfo
Funcv creates a GoFuncvInfo instance.
func (*GoPackage) RegisterConsts ¶
func (p *GoPackage) RegisterConsts(consts ...GoConstInfo)
RegisterConsts registers all exported Go constants of this package.
func (*GoPackage) RegisterFuncs ¶
func (p *GoPackage) RegisterFuncs(funs ...GoFuncInfo) (base GoFuncAddr)
RegisterFuncs registers all exported Go functions of this package.
func (*GoPackage) RegisterFuncvs ¶
func (p *GoPackage) RegisterFuncvs(funs ...GoFuncvInfo) (base GoFuncvAddr)
RegisterFuncvs registers all exported Go functions with variadic arguments of this package.
func (*GoPackage) RegisterTypes ¶
func (p *GoPackage) RegisterTypes(typinfos ...GoTypeInfo)
RegisterTypes registers all exported Go types defined by this package.
func (*GoPackage) RegisterVars ¶
RegisterVars registers all exported Go variables of this package.
func (*GoPackage) Rtype ¶
func (p *GoPackage) Rtype(typ reflect.Type) GoTypeInfo
Rtype gets the real type information.
type GoTypeInfo ¶
GoTypeInfo represents a Go type information.
type GoVarAddr ¶
type GoVarAddr = exec.GoVarAddr
GoVarAddr represents a variadic Go variable address.
type Kind ¶
type Kind = exec.Kind
A Kind represents the specific kind of type that a Type represents.
type Label ¶
type Label struct {
// contains filtered or unexported fields
}
Label represents a label.
type OperatorInfo ¶
type OperatorInfo = exec.OperatorInfo
OperatorInfo represents an operator information.
type Package ¶
type Package struct {
// contains filtered or unexported fields
}
Package represents a Go+ package.
func (*Package) FindGoPackage ¶
FindGoPackage lookups a Go package by pkgPath. It returns nil if not found.
func (*Package) GetGoFuncInfo ¶
func (p *Package) GetGoFuncInfo(addr exec.GoFuncAddr) *exec.GoFuncInfo
GetGoFuncInfo returns a Go function's information.
func (*Package) GetGoFuncType ¶
GetGoFuncType returns a Go function's type.
func (*Package) GetGoFuncvInfo ¶
func (p *Package) GetGoFuncvInfo(addr exec.GoFuncvAddr) *exec.GoFuncInfo
GetGoFuncvInfo returns a Go function's information.
func (*Package) GetGoFuncvType ¶
GetGoFuncvType returns a Go function's type.
func (*Package) GetGoVarInfo ¶
func (p *Package) GetGoVarInfo(addr exec.GoVarAddr) *exec.GoVarInfo
GetGoVarInfo returns a Go variable's information.
func (*Package) NewComprehension ¶
NewComprehension creates a new Comprehension instance.
func (*Package) NewForPhrase ¶
NewForPhrase creates a new ForPhrase instance.
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
A Stack represents a FILO container.
type StructField ¶
type StructField = reflect.StructField
A StructField describes a single field in a struct.
type StructInfo ¶
type StructInfo struct { Fields []StructField // contains filtered or unexported fields }
A StructInfo represents a struct information.
type Var ¶
type Var struct {
// contains filtered or unexported fields
}
Var represents a variable.
func (*Var) IsUnnamedOut ¶
IsUnnamedOut returns if variable unnamed or not.