exec

package
v0.7.19 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package exec defines the specification of a Go+ backend.

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
	// 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
)
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)
	// 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
)
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()
	// TyBigInt type
	TyBigInt = reflect.TypeOf((*big.Int)(nil))
	// TyBigRat type
	TyBigRat = reflect.TypeOf((*big.Rat)(nil))
	// TyBigFloat type
	TyBigFloat = reflect.TypeOf((*big.Float)(nil))
)
View Source
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

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(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

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 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
)

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 = GoSymInfo

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)

	// 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 GoSymInfo

type GoSymInfo struct {
	Pkg  GoPackage
	Name string
	This interface{} // address of this symbol
}

GoSymInfo represents a Go symbol (function or variable) information.

type GoVarAddr

type GoVarAddr uint32

GoVarAddr represents a variadic Go variable address.

type GoVarInfo

type GoVarInfo = GoSymInfo

GoVarInfo represents a Go variable information.

type JmpCondFlag added in v0.7.8

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 added in v0.7.8

func (v JmpCondFlag) IsNotPop() bool

IsNotPop returns to pop condition value or not

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
	// 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.

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 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.

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