Documentation ¶
Index ¶
- Constants
- Variables
- func GetMemberVar(m interface{}, key interface{}) interface{}
- type Class
- type Code
- func (p *Code) Block(code ...Instr) int
- func (p *Code) CheckConst(ip int) (v interface{}, ok bool)
- func (p *Code) CodeLine(file string, line int)
- func (p *Code) Dump(ranges ...int)
- func (p *Code) Exec(ip, ipEnd int, stk *Stack, ctx *Context)
- func (p *Code) Len() int
- func (p *Code) Line(ip int) (file string, line int)
- func (p *Code) Reserve() ReservedInstr
- func (p *Code) ToVar()
- type Context
- func (p *Context) ExecBlock(ip, ipEnd int)
- func (p *Context) ExecDefers()
- func (p *Context) Exports() map[string]interface{}
- func (p *Context) SetVar(name string, v interface{})
- func (p *Context) Unset(name string)
- func (p *Context) Var(name string) (v interface{}, ok bool)
- func (p *Context) Vars() map[string]interface{}
- type Error
- type Function
- type Instr
- func AddAssign(name string) Instr
- func And(delta int) Instr
- func AnonymFn(start, end int) Instr
- func As(name string) Instr
- func Assign(name string) Instr
- func Call(fn interface{}, varity ...int) Instr
- func CallFn(arity int) Instr
- func CallFnv(arity int) Instr
- func Case(delta int) Instr
- func Dec(name string) Instr
- func Defer(start, end int) Instr
- func Export(names ...string) Instr
- func ForRange(args []string, start, end int) Instr
- func Func(cls *Class, start, end int, args []string, variadic bool) Instr
- func Go(start, end int) Instr
- func INew(nArgs int) Instr
- func Inc(name string) Instr
- func Jmp(delta int) Instr
- func JmpIfFalse(delta int) Instr
- func Macro(start, end int) Instr
- func MapInit(arity int) Instr
- func MemberRef(name string) Instr
- func MemberVar(name string) Instr
- func ModAssign(name string) Instr
- func Module(id string, start, end int) Instr
- func MulAssign(name string) Instr
- func MultiAssign(names []string) Instr
- func MultiAssignEx(arity int) Instr
- func MultiAssignFromSlice(names []string) Instr
- func MultiAssignFromSliceEx(arity int) Instr
- func Op3(op func(v, a, b interface{}) interface{}, hasA, hasB bool) Instr
- func OpAssign(name string, op func(a, b interface{}) interface{}) Instr
- func Or(delta int) Instr
- func PopEx() Instr
- func Push(v interface{}) Instr
- func QuoAssign(name string) Instr
- func Ref(name string) Instr
- func Rem(file string, line int, code string) Instr
- func Return(arity int) Instr
- func SliceFrom(arity int) Instr
- func SliceFromTy(arity int) Instr
- func StructInit(arity int) Instr
- func SubAssign(name string) Instr
- func Unset(name string) Instr
- func Var(name string) Instr
- type Method
- type Object
- type RefToVar
- type ReservedInstr
- type Stack
- func (p *Stack) BaseFrame() int
- func (p *Stack) Pop() (v interface{}, ok bool)
- func (p *Stack) PopArgs(arity int) (args []reflect.Value, ok bool)
- func (p *Stack) PopFnArgs(arity int) []string
- func (p *Stack) PopNArgs(arity int) []interface{}
- func (p *Stack) Push(v interface{})
- func (p *Stack) PushRet(ret []reflect.Value) error
- func (p *Stack) SetFrame(n int)
- func (p *Stack) Top() (v interface{}, ok bool)
Constants ¶
const ( BreakForRange = -1 ContinueForRange = -2 )
Variables ¶
var ( // ErrStackDamaged is returned when stack is damaged. ErrStackDamaged = errors.New("unexpected: stack damaged") // ErrArityRequired is returned when calling `Call` without providing `arity`. ErrArityRequired = errors.New("arity required") // ErrArgumentsNotEnough is returned when calling a function without enough arguments. ErrArgumentsNotEnough = errors.New("arguments not enough") )
var ( // ErrNewWithoutClassName is returned when new doesn't specify a class. ErrNewWithoutClassName = errors.New("new object without class name") // ErrNewObjectWithNotType is returned when new T but T is not a type. ErrNewObjectWithNotType = errors.New("can't new object: not a type") // ErrRefWithoutObject is returned when refer member without specified an object. ErrRefWithoutObject = errors.New("reference without object") )
var ( // ErrAssignWithoutVal is returned when variable assign without value ErrAssignWithoutVal = errors.New("variable assign without value") // ErrMultiAssignExprMustBeSlice is returned when expression of multi assignment must be a slice ErrMultiAssignExprMustBeSlice = errors.New("expression of multi assignment must be a slice") )
var ( // ErrReturn is used for `panic(ErrReturn)` ErrReturn = errors.New("return") )
var ( // Exit is the instruction that executes `exit(<code>)`. Exit = Call(doExit) )
var (
OnPop func(v interface{})
)
Functions ¶
func GetMemberVar ¶
func GetMemberVar(m interface{}, key interface{}) interface{}
GetMemberVar implements get(object, key).
Types ¶
type Class ¶
A Class represents a qlang class.
func (*Class) NewInstance ¶
func (p *Class) NewInstance(args ...interface{}) interface{}
NewInstance creates a new instance of a qlang type. required by `qlang type` spec.
type Code ¶
type Code struct {
// contains filtered or unexported fields
}
A Code represents generated instructions to execute.
func (*Code) CheckConst ¶
CheckConst returns the value, if code[ip] is a const instruction.
func (*Code) Reserve ¶
func (p *Code) Reserve() ReservedInstr
Reserve reserves an instruction and returns it.
type Context ¶
type Context struct { Stack *Stack Code *Code Recov interface{} // contains filtered or unexported fields }
A Context represents the context of an executor.
func NewSimpleContext ¶
func NewSimpleContext(vars map[string]interface{}, stk *Stack, code *Code, parent *Context) *Context
NewSimpleContext returns a new context of an executor, without module support.
type Function ¶
type Function struct { Cls *Class Parent *Context Args []string Variadic bool // contains filtered or unexported fields }
A Function represents a function object.
func NewFunction ¶
NewFunction creates a new function object.
type Instr ¶
A Instr represents a instruction of the executor.
var ( AddAssignEx Instr = iAddAssignEx(0) SubAssignEx Instr = iSubAssignEx(0) MulAssignEx Instr = iMulAssignEx(0) QuoAssignEx Instr = iQuoAssignEx(0) ModAssignEx Instr = iModAssignEx(0) XorAssignEx Instr = iXorAssignEx(0) BitAndAssignEx Instr = iBitAndAssignEx(0) BitOrAssignEx Instr = iBitOrAssignEx(0) AndNotAssignEx Instr = iAndNotAssignEx(0) LshrAssignEx Instr = iLshrAssignEx(0) RshrAssignEx Instr = iRshrAssignEx(0) IncEx Instr = iIncEx(0) DecEx Instr = iDecEx(0) )
var AssignEx Instr = iAssignEx(0)
AssignEx is qlang AssignEx instruction.
var Chan Instr = tchan(0)
Chan is an instruction that returns chan T.
var (
Clear Instr = iClear(0)
)
var Get Instr = iGet(0)
Get is the Get instruction.
var GetVar Instr = iGetVar(0)
GetVar is the Get instruction.
var Map Instr = tmap(0)
Map is an instruction that returns `map[key]elem`.
var ( // Recover is the instruction that executes `recover()`. Recover Instr = iRecover(0) )
var Slice Instr = slice(0)
Slice is an instruction that returns []T.
func JmpIfFalse ¶
func MapInit ¶
MapInit returns a MapInit instruction that means `map[key]elem{key1: expr1, key2: expr2, ...}`.
func MultiAssign ¶
MultiAssign returns an instruction that means $name1, $name2, ..., $nameN = $stk[top-N+1], ..., $stk[top]
func MultiAssignEx ¶
MultiAssignEx returns a MultiAssignEx instruction.
func MultiAssignFromSlice ¶
MultiAssignFromSlice returns an instruction that means $name1, $name2, ..., $nameN = $stk[top]
func MultiAssignFromSliceEx ¶
MultiAssignFromSliceEx returns a MultiAssignFromSliceEx instruction.
func SliceFromTy ¶
SliceFromTy is an instruction that creates slice in []T{a1, a2, ...} form.
func StructInit ¶
StructInit returns a StructInit instruction that means `&StructType{name1: expr1, name2: expr2, ...}`.
type Method ¶
type Method struct {
// contains filtered or unexported fields
}
A Method represents a method of an Object.
type Object ¶
type Object struct { Cls *Class // contains filtered or unexported fields }
A Object represents a qlang object.
type RefToVar ¶
type RefToVar interface {
ToVar() Instr
}
RefToVar converts a value reference instruction into a assignable variable instruction.
type ReservedInstr ¶
type ReservedInstr struct {
// contains filtered or unexported fields
}
A ReservedInstr represents a reserved instruction to be assigned.
func (ReservedInstr) Delta ¶
func (p ReservedInstr) Delta(b ReservedInstr) int
Delta returns distance from b to p.
func (ReservedInstr) Next ¶
func (p ReservedInstr) Next() int
Next returns next instruction position.
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
A Stack represents a FILO container.