Documentation ¶
Index ¶
- Constants
- Variables
- func GetMemberVar(m interface{}, key interface{}) interface{}
- func SetMemberVar(m interface{}, args ...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 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 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") // ErrNewObjectWithNotClass is returned when new T but T is not a class. ErrNewObjectWithNotClass = errors.New("can't new object: not a class") // 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 = errors.New("return")
)
var (
OnPop func(v interface{})
)
Functions ¶
func GetMemberVar ¶
func GetMemberVar(m interface{}, key interface{}) interface{}
GetMemberVar implements get(object, key).
func SetMemberVar ¶
func SetMemberVar(m interface{}, args ...interface{})
SetMemberVar implements set(object, k1, v1, k2, v2, ...), ie. sets values of qlang object's multiple members.
Types ¶
type Class ¶
A Class represents a qlang class.
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 }
func NewFunction ¶
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 (
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 (
Recover Instr = iRecover(0)
)
var TypeOf Instr = typeOf(0)
TypeOf is the type(v) instruction.
func JmpIfFalse ¶
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.
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.