exec

package
v6.0.0-...-a3052e6 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
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
)
View Source
const (
	// OpAddrVal `*addr`
	OpAddrVal = AddrOperator(0)
	// OpAddAssign `+=`
	OpAddAssign = AddrOperator(OpAdd)
	// OpSubAssign `-=`
	OpSubAssign = AddrOperator(OpSub)
	// OpMulAssign `*=`
	OpMulAssign = AddrOperator(OpMul)
	// OpDivAssign `/=`
	OpDivAssign = AddrOperator(OpDiv)
	// OpModAssign `%=`
	OpModAssign = AddrOperator(OpMod)

	// OpBitAndAssign '&='
	OpBitAndAssign = AddrOperator(OpBitAnd)
	// OpBitOrAssign '|='
	OpBitOrAssign = AddrOperator(OpBitOr)
	// OpBitXorAssign '^='
	OpBitXorAssign = AddrOperator(OpBitXor)
	// OpBitAndNotAssign '&^='
	OpBitAndNotAssign = AddrOperator(OpBitAndNot)
	// OpBitSHLAssign '<<='
	OpBitSHLAssign = AddrOperator(OpBitSHL)
	// OpBitSHRAssign '>>='
	OpBitSHRAssign = AddrOperator(OpBitSHR)
	// OpAssign `=`
	OpAssign AddrOperator = iota
	// OpInc '++'
	OpInc
	// OpDec '--'
	OpDec
)
View Source
const (
	// BitNone - bitNone
	BitNone = bitNone
	// BitsAllIntUint - bitsAllIntUint
	BitsAllIntUint = bitsAllIntUint
)

Operator related constants, for Operator/AddrOperator instr.

View Source
const (
	// SliceConstIndexLast - slice const index max
	SliceConstIndexLast = (1 << 13) - 3
	// SliceDefaultIndex - unspecified index
	SliceDefaultIndex = -2
)

Slice related constants, for Slice/Slice3 instr.

View Source
const (
	// BuiltinTypesLen - len(builtinTypes)
	BuiltinTypesLen = len(builtinTypes)
)
View Source
const (
	// SameAsFirst means the second argument is same as first argument type.
	SameAsFirst = reflect.Invalid
)

Variables

View Source
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()
)
View Source
var (
	// TyByte type
	TyByte = reflect.TypeOf(byte(0))
	// TyRune type
	TyRune = reflect.TypeOf(rune(0))

	// TyEmptyInterfaceSlice type
	TyEmptyInterfaceSlice = reflect.SliceOf(TyEmptyInterface)
)

Functions

func SizeofKind

func SizeofKind(kind Kind) uintptr

SizeofKind returns sizeof type who has this kind.

func TypeFromKind

func TypeFromKind(kind Kind) reflect.Type

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(zeroOrOne uint32, l Label) Builder

	// CaseNE instr
	CaseNE(l Label, arity int) Builder

	// Default instr
	Default() 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

	// DefineFunc instr
	DefineFunc(fun FuncInfo) Builder

	// Return instr
	Return(n int32) Builder

	// Load instr
	Load(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

	// AddrOp instr
	AddrOp(kind Kind, op AddrOperator) Builder

	// Append instr
	Append(typ reflect.Type, arity int) 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

	// MapIndex instr
	MapIndex() Builder

	// SetMapIndex instr
	SetMapIndex() Builder

	// Index instr
	Index(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

	// GoBuiltin instr
	GoBuiltin(typ reflect.Type, op GoBuiltin) Builder

	// Zero instr
	Zero(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{})

	// GlobalInterface returns the global Interface.
	GlobalInterface() Interface

	// Resolve resolves all unresolved labels/functions/consts/etc.
	Resolve() Code
}

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

type ConstKind = spec.ConstKind

A ConstKind represents the specific kind of type that a Type represents. The zero Kind is not a valid kind.

type ForPhrase

type ForPhrase interface {
}

ForPhrase represents a for range phrase.

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 qlang function.
	Args(in ...reflect.Type) FuncInfo

	// Vargs sets argument types of a variadic qlang function.
	Vargs(in ...reflect.Type) FuncInfo

	// Return sets return types of a qlang function.
	Return(out ...Var) FuncInfo

	// NumOut returns a function type's output parameter count.
	// It panics if the type's Kind is not Func.
	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 qlang 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
)

func (GoBuiltin) String

func (p GoBuiltin) String() string

type GoConstInfo

type GoConstInfo struct {
	Pkg   GoPackage
	Name  string
	Kind  ConstKind
	Value interface{}
}

GoConstInfo represents a Go constant information.

type GoFuncAddr

type GoFuncAddr uint32

GoFuncAddr represents a Go function address.

type GoFuncInfo

type GoFuncInfo struct {
	Pkg  GoPackage
	Name string
	This interface{}
}

GoFuncInfo represents a Go function information.

type GoFuncvAddr

type GoFuncvAddr uint32

GoFuncvAddr represents a variadic Go function address.

type GoPackage

type GoPackage interface {
	PkgPath() string

	// Find lookups a symbol by specified its name.
	Find(name string) (addr uint32, kind SymbolKind, 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 GoVarAddr

type GoVarAddr uint32

GoVarAddr represents a variadic Go variable address.

type Interface

type Interface 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 create a qlang function.
	NewFunc(name string, nestDepth uint32) 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
}

Interface represents all global functions of a executing byte code generator.

type Kind

type Kind = reflect.Kind

A Kind represents the specific kind of type that a Type represents.

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
	// OpDiv '/' Int/Uint/Float/Complex
	OpDiv
	// OpMod '%' Int/Uint
	OpMod
	// OpBitAnd '&' Int/Uint
	OpBitAnd
	// OpBitOr '|' Int/Uint
	OpBitOr
	// OpBitXor '^' Int/Uint
	OpBitXor
	// OpBitAndNot '&^' Int/Uint
	OpBitAndNot
	// OpBitSHL '<<' Int/Uint, Uint
	OpBitSHL
	// OpBitSHR '>>' Int/Uint, Uint
	OpBitSHR
	// 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
	// OpNeg '-'
	OpNeg
	// OpNot '!'
	OpNot
	// OpBitNot '^'
	OpBitNot
)

func (Operator) GetInfo

func (op Operator) GetInfo() *OperatorInfo

GetInfo returns the information of this operator.

func (Operator) String

func (op Operator) String() string

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 Reserved

type Reserved int

Reserved represents a reserved instruction position.

const InvalidReserved Reserved = -1

InvalidReserved is an invalid reserved position.

func (Reserved) Push

func (p Reserved) Push(b Builder, val interface{})

Push instr

type Stack

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

A Stack represents a FILO container.

func NewStack

func NewStack() (p *Stack)

NewStack creates a Stack instance.

func (*Stack) Get

func (p *Stack) Get(idx int) interface{}

Get returns the value at specified index.

func (*Stack) GetArgs

func (p *Stack) GetArgs(arity int) []interface{}

GetArgs returns all arguments of a function.

func (*Stack) Init

func (p *Stack) Init()

Init initializes this Stack object.

func (*Stack) Len

func (p *Stack) Len() int

Len returns count of stack elements.

func (*Stack) Pop

func (p *Stack) Pop() interface{}

Pop pops a value from this stack.

func (*Stack) PopN

func (p *Stack) PopN(n int)

PopN pops n elements.

func (*Stack) Push

func (p *Stack) Push(v interface{})

Push pushes a value into this stack.

func (*Stack) Ret

func (p *Stack) Ret(arity int, results ...interface{})

Ret pops n values from this stack, and then pushes results.

func (*Stack) Set

func (p *Stack) Set(idx int, v interface{})

Set returns the value at specified index.

func (*Stack) SetLen

func (p *Stack) SetLen(base int)

SetLen sets count of stack elements.

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
)

type Var

type Var interface {
	// Name returns the variable name.
	Name() string

	// Type returns the variable type.
	Type() reflect.Type

	// IsUnnamedOut returns if variable unnamed or not.
	IsUnnamedOut() bool
}

Var represents a variable.

Jump to

Keyboard shortcuts

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