Documentation ¶
Index ¶
- Constants
- Variables
- func GetMemberVar(m interface{}, key interface{}) interface{}
- func SymbolIndex(id, scope int) int
- 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) CopyVars() map[string]interface{}
- func (p *Context) ExecBlock(ip, ipEnd int, symtbl map[string]int)
- func (p *Context) ExecDefers()
- func (p *Context) Exports() map[string]interface{}
- func (p *Context) FastGetVar(name int) interface{}
- func (p *Context) FastRefVar(name int) *interface{}
- func (p *Context) FastSetVar(name int, v interface{})
- func (p *Context) GetVar(name string) (v interface{}, ok bool)
- func (p *Context) ResetVars(vars map[string]interface{})
- func (p *Context) ResizeVars()
- func (p *Context) SetVar(name string, v interface{})
- func (p *Context) UnsetVar(name string)
- func (p *Context) Var(name string) interface{}
- func (p *Context) Vars() []interface{}
- type Error
- type Function
- type Instr
- func And(delta int) Instr
- func AnonymFn(start, end int, symtbl map[string]int) Instr
- func As(name int) Instr
- func Call(fn interface{}, varity ...int) Instr
- func CallFn(arity int) Instr
- func CallFnv(arity int) Instr
- func Case(delta int) Instr
- func Defer(start, end int) Instr
- func Export(names ...string) Instr
- func ForRange(args []int, start, end int) Instr
- func Func(cls *Class, start, end int, symtbl map[string]int, args []string, ...) Instr
- func GfnRef(v interface{}, toVar func() Instr) Instr
- func Go(start, end int) Instr
- func INew(nArgs int) Instr
- func Jmp(delta int) Instr
- func JmpIfFalse(delta int) Instr
- func MapInit(arity int) Instr
- func MemberRef(name string) Instr
- func MemberVar(name string) Instr
- func Module(id string, start, end int, symtbl map[string]int) Instr
- func MultiAssignEx(arity int) Instr
- func MultiAssignFromSliceEx(arity int) Instr
- func Op3(op func(v, a, b interface{}) interface{}, hasA, hasB bool) Instr
- func Or(delta int) Instr
- func PopEx() Instr
- func Push(v interface{}) Instr
- func Ref(name int) 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 Var(name int) 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 ¶
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 NewContextEx ¶
NewContextEx returns a new context of an executor.
func (*Context) CopyVars ¶
func (p *Context) CopyVars() map[string]interface{}
CopyVars copies and returns all variables.
func (*Context) FastGetVar ¶
func (p *Context) FastGetVar(name int) interface{}
FastGetVar returns a variable value.
func (*Context) FastRefVar ¶
func (p *Context) FastRefVar(name int) *interface{}
FastRefVar returns a variable address.
func (*Context) FastSetVar ¶
func (p *Context) FastSetVar(name int, v interface{})
FastSetVar sets a variable value.
func (*Context) ResetVars ¶
func (p *Context) ResetVars(vars map[string]interface{})
ResetVars resets all variables.
func (*Context) ResizeVars ¶
func (p *Context) ResizeVars()
ResizeVars is reserved for internal use.
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 ¶
func NewFunction(cls *Class, start, end int, symtbl map[string]int, args []string, variadic bool) *Function
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 MultiAssignEx ¶
MultiAssignEx returns a MultiAssignEx instruction.
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.