Documentation
¶
Index ¶
- Constants
- Variables
- func GENERICS_V1_CXX() bool
- func GENERICS_V2_CTI() bool
- func TailIdentifier(s string) string
- type Assign
- type Bind
- func (bind *Bind) AsSymbol(upn int) *Symbol
- func (bind *Bind) AsVar(upn int, opt PlaceOption) *Var
- func (bind *Bind) Const() bool
- func (bind *Bind) ConstValue() xr.Value
- func (bind *Bind) Expr(g *CompGlobals) *Expr
- func (bind *Bind) RuntimeValue(g *CompGlobals, env *Env) xr.Value
- func (bind *Bind) String() string
- type BindClass
- type BindDescriptor
- type Builtin
- type Call
- type Cmd
- type Cmds
- type Code
- type Comp
- func (c *Comp) Add(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr
- func (c *Comp) AddressOf(node *ast.UnaryExpr) *Expr
- func (c *Comp) AddressOfVar(name string) *Expr
- func (c *Comp) And(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr
- func (c *Comp) Andnot(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr
- func (c *Comp) Append(stmt Stmt, pos token.Pos)
- func (c *Comp) Assign(node *ast.AssignStmt)
- func (c *Comp) BasicLit(node *ast.BasicLit) *Expr
- func (c *Comp) BinaryExpr(node *ast.BinaryExpr) *Expr
- func (c *Comp) BinaryExpr1(node *ast.BinaryExpr, x *Expr, y *Expr) *Expr
- func (c *Comp) BinaryExprUntyped(node *ast.BinaryExpr, x UntypedLit, y UntypedLit) *Expr
- func (c *Comp) Bind(bind *Bind) *Expr
- func (c *Comp) BindUntyped(kind untyped.Kind, value constant.Value) *Bind
- func (c *Comp) Block(block *ast.BlockStmt)
- func (c *Comp) Branch(node *ast.BranchStmt)
- func (c *Comp) Break(node *ast.BranchStmt)
- func (c *Comp) CallExpr(node *ast.CallExpr) *Expr
- func (c *Comp) Compile(in Ast) *Expr
- func (c *Comp) CompileNode(node ast.Node) *Expr
- func (c *Comp) CompleteWords(words []string) []string
- func (c *Comp) CompositeLit(node *ast.CompositeLit, t xr.Type) *Expr
- func (c *Comp) Continue(node *ast.BranchStmt)
- func (c *Comp) Convert(node ast.Expr, t xr.Type) *Expr
- func (c *Comp) Converter(tin, tout xr.Type) func(xr.Value) xr.Value
- func (c *Comp) Decl(node ast.Decl)
- func (c *Comp) DeclBindRuntimeValue(bind *Bind) func(*Env, xr.Value)
- func (c *Comp) DeclBuiltin0(name string, builtin Builtin) *Bind
- func (c *Comp) DeclConst0(name string, t xr.Type, value I, valueType xr.Type)
- func (c *Comp) DeclConsts(node ast.Spec, defaultType ast.Expr, defaultExprs []ast.Expr)
- func (c *Comp) DeclConsts0(names []string, t xr.Type, inits []*Expr)
- func (c *Comp) DeclEnvFunc0(name string, envfun Function) *Bind
- func (c *Comp) DeclFunc(funcdecl *ast.FuncDecl)
- func (c *Comp) DeclFunc0(name string, fun I) *Bind
- func (c *Comp) DeclGenericFunc(decl *ast.FuncDecl)
- func (c *Comp) DeclGenericType(spec *ast.TypeSpec)
- func (c *Comp) DeclMultiVar0(names []string, t xr.Type, init *Expr, pos []token.Pos)
- func (c *Comp) DeclNamedType(name string) xr.Type
- func (c *Comp) DeclType(spec ast.Spec)
- func (c *Comp) DeclType0(t xr.Type) xr.Type
- func (c *Comp) DeclTypeAlias(name string, t xr.Type) xr.Type
- func (c *Comp) DeclVar0(name string, t xr.Type, init *Expr) *Bind
- func (c *Comp) DeclVars(node ast.Spec)
- func (c *Comp) DeclVars0(names []string, t xr.Type, inits []*Expr, pos []token.Pos)
- func (c *Comp) DeclVarsShort(lhs []ast.Expr, rhs []ast.Expr)
- func (c *Comp) Defer(node *ast.DeferStmt)
- func (c *Comp) Deref(addr *Expr) *Expr
- func (c *Comp) Eql(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr
- func (c *Comp) Expr(in ast.Expr, t xr.Type) *Expr
- func (c *Comp) Expr1(in ast.Expr, t xr.Type) *Expr
- func (c *Comp) Expr1OrType(expr ast.Expr) (e *Expr, t xr.Type)
- func (c *Comp) Exprs(nodes []ast.Expr) []*Expr
- func (c *Comp) ExprsMultipleValues(nodes []ast.Expr, expectedValuesN int) (inits []*Expr)
- func (c *Comp) File(node *ast.File)
- func (c *Comp) FileComp() *Comp
- func (c *Comp) For(node *ast.ForStmt, labels []string)
- func (c *Comp) FuncLit(funclit *ast.FuncLit) *Expr
- func (c *Comp) GenDecl(node *ast.GenDecl)
- func (c *Comp) GenericFunc(node *ast.IndexExpr) *Expr
- func (c *Comp) GenericType(node *ast.IndexExpr) xr.Type
- func (c *Comp) Geq(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr
- func (c *Comp) GetPlace(place *Place) *Expr
- func (c *Comp) Go(node *ast.GoStmt)
- func (c *Comp) Goto(node *ast.BranchStmt)
- func (c *Comp) Gtr(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr
- func (c *Comp) Ident(name string) *Expr
- func (c *Comp) IdentPlace(name string, opt PlaceOption) *Place
- func (c *Comp) If(node *ast.IfStmt)
- func (c *Comp) Import(node ast.Spec)
- func (c *Comp) ImportPackage(alias, path string) *Import
- func (c *Comp) ImportPackageOrError(alias, path string) (*Import, error)
- func (c *Comp) IncDec(node *ast.IncDecStmt)
- func (c *Comp) IndexExpr(node *ast.IndexExpr) *Expr
- func (c *Comp) IndexExpr1(node *ast.IndexExpr) *Expr
- func (c *Comp) IndexPlace(node *ast.IndexExpr, opt PlaceOption) *Place
- func (c *Comp) InterfaceProxy(t xr.Type) r.Type
- func (c *Comp) Land(node *ast.BinaryExpr, x *Expr, y *Expr) *Expr
- func (c *Comp) Leq(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr
- func (c *Comp) List(list []ast.Stmt)
- func (c *Comp) LookupField(t xr.Type, name string) (field xr.StructField, numfound int)
- func (c *Comp) LookupFieldOrMethod(t xr.Type, name string) (xr.StructField, bool, xr.Method, bool)
- func (c *Comp) LookupMethod(t xr.Type, name string) (mtd xr.Method, numfound int)
- func (c *Comp) LookupVar(name string) *Var
- func (c *Comp) Lor(node *ast.BinaryExpr, x *Expr, y *Expr) *Expr
- func (c *Comp) Lss(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr
- func (c *Comp) MacroExpand(form Ast) (out Ast, everExpanded bool)
- func (c *Comp) MacroExpand1(in Ast) (out Ast, expanded bool)
- func (c *Comp) MacroExpandCodewalk(in Ast) (out Ast, anythingExpanded bool)
- func (c *Comp) MacroExpandNode(in ast.Node) (out ast.Node, everExpanded bool)
- func (c *Comp) MacroExpandNode1(in ast.Node) (out ast.Node, expanded bool)
- func (c *Comp) MacroExpandNodeCodewalk(in ast.Node) (out ast.Node, anythingExpanded bool)
- func (c *Comp) Mul(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr
- func (c *Comp) Neq(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr
- func (c *Comp) NewBind(name string, class BindClass, t xr.Type) *Bind
- func (c *Comp) NewFuncBind(name string, t xr.Type) *Bind
- func (c *Comp) Or(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr
- func (c *Comp) Parse(src string) Ast
- func (c *Comp) Place(node ast.Expr) *Place
- func (c *Comp) Quasiquote(in Ast) *Expr
- func (c *Comp) Quo(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr
- func (c *Comp) Range(node *ast.RangeStmt, labels []string)
- func (c *Comp) Recv(node *ast.UnaryExpr, xe *Expr) *Expr
- func (c *Comp) Recv1(node *ast.UnaryExpr, xe *Expr) *Expr
- func (c *Comp) Rem(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr
- func (c *Comp) Resolve(name string) *Symbol
- func (c *Comp) ResolveType(name string) xr.Type
- func (c *Comp) Return(node *ast.ReturnStmt)
- func (c *Comp) Select(node *ast.SelectStmt, labels []string)
- func (c *Comp) SelectorExpr(node *ast.SelectorExpr) *Expr
- func (c *Comp) SelectorPlace(node *ast.SelectorExpr, opt PlaceOption) *Place
- func (c *Comp) Send(node *ast.SendStmt)
- func (c *Comp) SetPlace(place *Place, op token.Token, init *Expr)
- func (c *Comp) SetUnderlyingType(t, underlying xr.Type)
- func (c *Comp) SetVar(va *Var, op token.Token, init *Expr)
- func (c *Comp) ShiftUntyped(node *ast.BinaryExpr, op token.Token, x UntypedLit, y UntypedLit) *Expr
- func (c *Comp) Shl(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr
- func (c *Comp) Shr(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr
- func (c *Comp) SliceExpr(node *ast.SliceExpr) *Expr
- func (c *Comp) StarExpr(node *ast.StarExpr) *Expr
- func (c *Comp) Stmt(in ast.Stmt)
- func (c *Comp) Sub(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr
- func (c *Comp) Switch(node *ast.SwitchStmt, labels []string)
- func (c *Comp) Symbol(sym *Symbol) *Expr
- func (c *Comp) TopComp() *Comp
- func (c *Comp) TryLookupFieldOrMethod(t xr.Type, name string) (xr.StructField, bool, xr.Method, bool, error)
- func (c *Comp) TryResolve(name string) *Symbol
- func (c *Comp) TryResolveType(name string) xr.Type
- func (c *Comp) Type(node ast.Expr) xr.Type
- func (c *Comp) TypeArray(node *ast.ArrayType) (t xr.Type, ellipsis bool)
- func (c *Comp) TypeAssert1(node *ast.TypeAssertExpr) *Expr
- func (c *Comp) TypeAssert2(node *ast.TypeAssertExpr) *Expr
- func (c *Comp) TypeFields(fields *ast.FieldList) (types []xr.Type, names []string)
- func (c *Comp) TypeFunction(node *ast.FuncType) (t xr.Type, paramNames []string, resultNames []string)
- func (c *Comp) TypeFunctionOrMethod(recv *ast.Field, node *ast.FuncType) (t xr.Type, paramNames []string, resultNames []string)
- func (c *Comp) TypeInterface(node *ast.InterfaceType) xr.Type
- func (c *Comp) TypeOf(val interface{}) xr.Type
- func (c *Comp) TypeSwitch(node *ast.TypeSwitchStmt, labels []string)
- func (c *Comp) UnaryExpr(node *ast.UnaryExpr) *Expr
- func (c *Comp) UnaryExprUntyped(node *ast.UnaryExpr, xe *Expr) *Expr
- func (c *Comp) UnaryMinus(node *ast.UnaryExpr, xe *Expr) *Expr
- func (c *Comp) UnaryNot(node *ast.UnaryExpr, xe *Expr) *Expr
- func (c *Comp) UnaryPlus(node *ast.UnaryExpr, xe *Expr) *Expr
- func (c *Comp) UnaryXor(node *ast.UnaryExpr, xe *Expr) *Expr
- func (c *Comp) Xor(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr
- type CompBinds
- type CompGlobals
- func (cg *CompGlobals) CompileOptions() CompileOptions
- func (g *CompGlobals) NewImport(pkgref *genimport.PackageRef) *Import
- func (g *CompGlobals) TypeOfBool() xr.Type
- func (g *CompGlobals) TypeOfBuiltin() xr.Type
- func (g *CompGlobals) TypeOfComplex128() xr.Type
- func (g *CompGlobals) TypeOfComplex64() xr.Type
- func (g *CompGlobals) TypeOfError() xr.Type
- func (g *CompGlobals) TypeOfFloat32() xr.Type
- func (g *CompGlobals) TypeOfFloat64() xr.Type
- func (g *CompGlobals) TypeOfFunction() xr.Type
- func (g *CompGlobals) TypeOfInt() xr.Type
- func (g *CompGlobals) TypeOfInt16() xr.Type
- func (g *CompGlobals) TypeOfInt32() xr.Type
- func (g *CompGlobals) TypeOfInt64() xr.Type
- func (g *CompGlobals) TypeOfInt8() xr.Type
- func (g *CompGlobals) TypeOfInterface() xr.Type
- func (g *CompGlobals) TypeOfMacro() xr.Type
- func (g *CompGlobals) TypeOfPtrGenericFunc() xr.Type
- func (g *CompGlobals) TypeOfPtrGenericType() xr.Type
- func (g *CompGlobals) TypeOfPtrImport() xr.Type
- func (g *CompGlobals) TypeOfString() xr.Type
- func (g *CompGlobals) TypeOfUint() xr.Type
- func (g *CompGlobals) TypeOfUint16() xr.Type
- func (g *CompGlobals) TypeOfUint32() xr.Type
- func (g *CompGlobals) TypeOfUint64() xr.Type
- func (g *CompGlobals) TypeOfUint8() xr.Type
- func (g *CompGlobals) TypeOfUintptr() xr.Type
- func (g *CompGlobals) TypeOfUntypedLit() xr.Type
- func (cg *CompGlobals) UnloadPackage(path string)
- type CompileOptions
- type DebugOp
- type Debugger
- type EFlags
- type Env
- type EnvBinds
- type ExecFlags
- type Expr
- func (e *Expr) AsStmt(c *Comp) Stmt
- func (e *Expr) AsUint64() func(*Env) uint64
- func (e *Expr) AsX() func(*Env)
- func (e *Expr) AsX1() func(*Env) xr.Value
- func (e *Expr) AsXV(opts CompileOptions) func(*Env) (xr.Value, []xr.Value)
- func (e *Expr) CheckX1()
- func (e *Expr) Const() bool
- func (e *Expr) ConstTo(t xr.Type) I
- func (e *Expr) DefaultType() xr.Type
- func (expr *Expr) EvalConst(opts CompileOptions) I
- func (e *Expr) NumOut() int
- func (e *Expr) Out(i int) xr.Type
- func (e *Expr) SetTypes(tout []xr.Type)
- func (e *Expr) String() string
- func (e *Expr) To(c *Comp, t xr.Type)
- func (e *Expr) TryAsPred() (value bool, fun func(*Env) bool, err bool)
- func (e *Expr) WithFun() I
- type FuncInfo
- type Function
- type GenericFunc
- type GenericFuncDecl
- type GenericFuncInstance
- type GenericType
- type GenericTypeDecl
- type I
- type Import
- type Interp
- func (ir *Interp) AddressOfVar(name string) (addr xr.Value)
- func (ir *Interp) ChangePackage(name, path string)
- func (ir *Interp) Cmd(src string) (string, base.CmdOpt)
- func (ir *Interp) Compile(src string) *Expr
- func (ir *Interp) CompileAst(form ast2.Ast) *Expr
- func (ir *Interp) CompileNode(node ast.Node) *Expr
- func (ir *Interp) CompleteWords(line string, pos int) (head string, completions []string, tail string)
- func (ir *Interp) Debug(src string) ([]xr.Value, []xr.Type)
- func (ir *Interp) DebugExpr(e *Expr) ([]xr.Value, []xr.Type)
- func (ir *Interp) DebugExpr1(e *Expr) (xr.Value, xr.Type)
- func (ir *Interp) DeclBuiltin(name string, builtin Builtin)
- func (ir *Interp) DeclConst(name string, t xr.Type, value I)
- func (ir *Interp) DeclEnvFunc(name string, function Function)
- func (ir *Interp) DeclFunc(name string, fun I)
- func (ir *Interp) DeclType(t xr.Type)
- func (ir *Interp) DeclTypeAlias(alias string, t xr.Type)
- func (ir *Interp) DeclVar(name string, t xr.Type, value I)
- func (ir *Interp) Eval(src string) ([]xr.Value, []xr.Type)
- func (ir *Interp) Eval1(src string) (xr.Value, xr.Type)
- func (ir *Interp) EvalFile(filepath string) (comments string, err error)
- func (ir *Interp) EvalReader(src io.Reader) (comments string, err error)
- func (ir *Interp) ImportPackage(alias, path string) *Import
- func (ir *Interp) ImportPackageOrError(alias, path string) (*Import, error)
- func (ir *Interp) Inspect(src string)
- func (ir *Interp) Interrupt(os.Signal)
- func (ir *Interp) Parse(src string) ast2.Ast
- func (ir *Interp) ParseEvalPrint(src string) (callAgain bool)
- func (ir *Interp) PrepareEnv() *Env
- func (ir *Interp) Read() (string, int)
- func (ir *Interp) ReadParseEvalPrint() (callAgain bool)
- func (ir *Interp) Repl(in *bufio.Reader)
- func (ir *Interp) ReplStdin()
- func (ir *Interp) RunExpr(e *Expr) ([]xr.Value, []xr.Type)
- func (ir *Interp) RunExpr1(e *Expr) (xr.Value, xr.Type)
- func (ir *Interp) SetDebugger(debugger Debugger)
- func (ir *Interp) SetInspector(inspector base.Inspector)
- func (ir *Interp) ShowAsPackage()
- func (ir *Interp) ShowImportedPackage(name string)
- func (ir *Interp) ShowPackage(name string)
- func (ir *Interp) TypeOf(val interface{}) xr.Type
- func (ir *Interp) ValueOf(name string) (value xr.Value)
- type IrGlobals
- type Jit
- func (j *Jit) AsStmt(e *Expr) Stmt
- func (j *Jit) BinaryExpr(e *Expr, op token.Token, xe *Expr, ye *Expr) *Expr
- func (j *Jit) Cast(e *Expr, t xr.Type, xe *Expr) *Expr
- func (j *Jit) Const(e *Expr) *Expr
- func (j *Jit) Deref(e *Expr, xe *Expr) *Expr
- func (j *Jit) Fun(e *Expr) *Expr
- func (j *Jit) Identity(e *Expr, xe *Expr) *Expr
- func (j *Jit) SetVar(va *Var, op token.Token, init *Expr) Stmt
- func (j *Jit) Symbol(e *Expr) *Expr
- func (j *Jit) UnaryExpr(e *Expr, op token.Token, xe *Expr) *Expr
- type Lit
- type LoopInfo
- type Macro
- type Place
- type PlaceOption
- type Run
- type Stmt
- type Symbol
- type TypeAssertionError
- type UntypedLit
- type Var
Constants ¶
const ( NoIndex = int(-1) // index of functions, variables named "_" and of constants ConstBindDescriptor = BindDescriptor(ConstBind) // bind descriptor for all constants )
const (
MaxInt = base.MaxInt
)
Variables ¶
Functions ¶
func TailIdentifier ¶
return the trailing substring of s that is a valid identifier
Types ¶
type Bind ¶
type Bind struct { Lit Desc BindDescriptor Name string }
Bind represents a constant, variable, function or builtin in the "compiler"
func (*Bind) ConstValue ¶
return bind value for constant binds. if bind is untyped constant, returns UntypedLit wrapped in reflect.Value
func (*Bind) Expr ¶
func (bind *Bind) Expr(g *CompGlobals) *Expr
Expr returns an expression that will read the given Bind at runtime
func (*Bind) RuntimeValue ¶
func (bind *Bind) RuntimeValue(g *CompGlobals, env *Env) xr.Value
return bind value. if bind is untyped constant, returns UntypedLit wrapped in reflect.Value
type BindClass ¶
type BindClass uint
BindDescriptor uses two bits to store the class. use all remaining bits as unsigned => we lose only one bit when representing non-negative ints
func (BindClass) MakeDescriptor ¶
func (class BindClass) MakeDescriptor(index int) BindDescriptor
type BindDescriptor ¶
type BindDescriptor BindClass
the zero value of BindDescriptor is a valid descriptor for all constants, and also for functions and variables named "_"
func (BindDescriptor) Class ¶
func (desc BindDescriptor) Class() BindClass
IntBind returns true if BindIndex refers to a slot in Env.IntBinds (the default is a slot in Env.Binds)
func (BindDescriptor) Index ¶
func (desc BindDescriptor) Index() int
Index returns the slice index to use in Env.Binds or Env.IntBinds to access a variable or function. returns NoIndex for variables and functions named "_"
func (BindDescriptor) Settable ¶
func (desc BindDescriptor) Settable() bool
func (BindDescriptor) String ¶
func (desc BindDescriptor) String() string
type Builtin ¶
type Builtin struct { // interpreted code should not access "compile": not exported. // compile usually needs to modify Symbol: pass it by value. Compile func(c *Comp, sym Symbol, node *ast.CallExpr) *Call ArgMin uint16 ArgMax uint16 }
Builtin represents a builtin function in the fast interpreter
type Call ¶
type Call struct { Fun *Expr Args []*Expr OutTypes []xr.Type Builtin bool // if true, call is a builtin function Const bool // if true, call has no side effects and always returns the same result => it can be invoked at compile time Ellipsis bool // if true, must use reflect.Value.CallSlice or equivalent to invoke the function }
type Cmd ¶
type Cmd struct { Name string Func func(interp *Interp, arg string, opt base.CmdOpt) (string, base.CmdOpt) Help string }
Cmd is an interpreter special command.
The following Interp methods look for special commands and execute them: Cmd, EvalFile, EvalReader, ParseEvalPrint, ReadParseEvalPrint, Repl, ReplStdin note that Interp.Eval() does **not** look for special commands!
Cmd.Name is the command name **without** the initial ':'
it must be a valid Go identifier and must not be empty. Using a reserved Go keyword (const, for, func, if, package, return, switch, type, var...) or predefined identifier (bool, int, rune, true, false, nil...) is a bad idea because it interferes with gomacro preprocessor mode. Current limitation: Cmd.Name[0] must be ASCII.
Cmd.Help is the help string that will be displayed by :help
please look at current :help output and use the same layout if possible.
Cmd.Func is the command implementation. it receives as arguments:
- the current Interp object,
- the (possibly multi-line) argument string typed by the user note: it will always have balanced amounts of {} [] () ” "" and “
- the current command options
Cmd.Func can perform any action desired by the implementor, including calls to Interp methods, and it must return:
- a string to be subsequently evaluated by the interpreter. return the empty string if the command does not need any subsequent evaluation, or if it performed the evaluation by itself.
- the updated command options. return the received 'opt' argument unless you need to update it.
If Cmd.Func needs to print something, it's recommended to use
g := &interp.Comp.Globals g.Fprintf(g.Stdout, FORMAT, ARGS...) instead of the various fmt.*Print* functions, in order to pretty-print interpreter-generated objects (g.Fprintf) and to honour configured redirections (g.Stdout)
To register a new special command, use Commands.Add() To unregister an existing special command, use Commands.Del() To list existing special commands, use Commands.List()
type Cmds ¶
type Cmds struct {
// contains filtered or unexported fields
}
var Commands Cmds
func (Cmds) Add ¶
register a new Cmd. if cmd.Name is the empty string, do nothing and return false. overwrites any existing Cmd with the same name
type Code ¶
type Code struct { List []Stmt DebugPos []token.Pos // for debugging interpreted code: position of each statement WithDefers bool // true if code contains some defers }
type Comp ¶
type Comp struct { *CompGlobals CompBinds // UpCost is the number of *Env.Outer hops to perform at runtime to reach the *Env corresponding to *Comp.Outer // usually equals one. will be zero if this *Comp defines no local variables/functions. UpCost int Depth int Code Code // "compiled" code Loop *LoopInfo // != nil when compiling a for or switch Func *FuncInfo // != nil when compiling a function Labels map[string]*int Outer *Comp FuncMaker *funcMaker // used by debugger command 'backtrace' to obtain function name, type and binds for arguments and results }
Comp is a tree-of-closures builder: it transforms ast.Nodes into closures for faster execution. Consider it a poor man's compiler (hence the name)
func (*Comp) AddressOfVar ¶
func (*Comp) Assign ¶
func (c *Comp) Assign(node *ast.AssignStmt)
Assign compiles an *ast.AssignStmt into an assignment to one or more place
func (*Comp) BinaryExpr ¶
func (c *Comp) BinaryExpr(node *ast.BinaryExpr) *Expr
func (*Comp) BinaryExpr1 ¶
func (*Comp) BinaryExprUntyped ¶
func (c *Comp) BinaryExprUntyped(node *ast.BinaryExpr, x UntypedLit, y UntypedLit) *Expr
func (*Comp) Bind ¶
Bind compiles a read operation on a constant, variable or function declared in 'c'
func (*Comp) BindUntyped ¶
func (*Comp) Branch ¶
func (c *Comp) Branch(node *ast.BranchStmt)
Branch compiles a break, continue, fallthrough or goto statement
func (*Comp) CompileNode ¶
compile code. support out-of-order declarations too
func (*Comp) CompleteWords ¶
implement code completion on ident.ident.ident.ident...
func (*Comp) CompositeLit ¶
func (*Comp) Continue ¶
func (c *Comp) Continue(node *ast.BranchStmt)
Continue compiles a "continue" statement
func (*Comp) Converter ¶
Converter returns a function that converts reflect.Value from tin to tout also supports conversion from interpreted types to interfaces
func (*Comp) DeclBindRuntimeValue ¶
DeclBindRuntimeValue compiles a variable, function or constant declaration with a reflect.Value passed at runtime
func (*Comp) DeclBuiltin0 ¶
DeclBuiltin0 compiles a builtin function declaration. For caller's convenience, returns allocated Bind
func (*Comp) DeclConst0 ¶
DeclConst0 compiles a constant declaration
func (*Comp) DeclConsts ¶
DeclConsts compiles a set of constant declarations
func (*Comp) DeclEnvFunc0 ¶
DeclEnvFunc0 compiles a function declaration that accesses interpreter's Env. For caller's convenience, returns allocated Bind
func (*Comp) DeclFunc ¶
DeclFunc compiles a function, macro or method declaration For closure declarations, use FuncLit()
This method is named DeclFunc instead of FuncDecl for uniformity with DeclType, DeclConst*, DeclVar*, DeclGeneric*
func (*Comp) DeclFunc0 ¶
DeclFunc0 compiles a function declaration. For caller's convenience, returns allocated Bind
func (*Comp) DeclGenericFunc ¶
DeclGenericFunc stores a generic function or method declaration for later instantiation
func (*Comp) DeclGenericType ¶
DeclGenericType stores a generic type declaration for later instantiation
func (*Comp) DeclMultiVar0 ¶
DeclMultiVar0 compiles multiple variable declarations from a single multi-valued expression
func (*Comp) DeclNamedType ¶
DeclNamedType executes a named type forward declaration. Returns nil if name == "_" Otherwise it must be followed by Comp.SetUnderlyingType(t) where t is the returned type
func (*Comp) DeclType0 ¶
DeclType0 declares a type in Go, types are computed only at compile time - no need for a runtime *Env
func (*Comp) DeclTypeAlias ¶
DeclTypeAlias compiles a typealias declaration, i.e. type Foo = /*...*/ Returns the second argument.
func (*Comp) DeclVar0 ¶
DeclVar0 compiles a variable declaration. For caller's convenience, returns allocated Bind
func (*Comp) DeclVars ¶
DeclVars compiles a set of variable declarations i.e. "var x1, x2... [type] = expr1, expr2..."
func (*Comp) DeclVarsShort ¶
DeclVarsShort compiles a set of variable short declarations i.e. "x1, x2... := expr1, expr2..."
func (*Comp) Expr ¶
Expr compiles an expression. t is optional and used for type inference on composite literals, see https://golang.org/ref/spec#Composite_literals
func (*Comp) Expr1 ¶
Expr1 compiles an expression that returns a single value t is optional and used for type inference on composite literals, see https://golang.org/ref/spec#Composite_literals
func (*Comp) Expr1OrType ¶
Expr1OrType compiles an single-valued expression or a type. performs simultaneous lookup for type names, constants, variables and functions
func (*Comp) ExprsMultipleValues ¶
ExprsMultipleValues either a single expression returning multiple values, or multiple expressions each returning a value.
func (*Comp) FuncLit ¶
FuncLit compiles a function literal, i.e. a closure. For functions or methods declarations, use FuncDecl()
func (*Comp) GenericFunc ¶
GenericFunc compiles a generic function name#[T1, T2...] instantiating it if needed.
func (*Comp) GenericType ¶
GenericType compiles a generic type name#[T1, T2...] instantiating it if needed.
func (*Comp) IdentPlace ¶
func (c *Comp) IdentPlace(name string, opt PlaceOption) *Place
IdentPlace compiles an assignment to a variable, or taking the address of a variable
func (*Comp) ImportPackage ¶
ImportPackage imports a package. Panics if the import fails. Usually invoked as Comp.FileComp().ImportPackage(alias, path) because imports are usually top-level statements in a source file. But we also support local imports, i.e. import statements inside a function or block.
func (*Comp) ImportPackageOrError ¶
ImportPackageOrError imports a package. If name is the empty string, it defaults to the identifier specified in the package clause of the imported package
func (*Comp) IncDec ¶
func (c *Comp) IncDec(node *ast.IncDecStmt)
IncDec compiles a "place++" or "place--" statement
func (*Comp) IndexExpr ¶
IndexExpr compiles a read operation on obj[idx] or a generic function name#[T1, T2...]
func (*Comp) IndexExpr1 ¶
IndexExpr1 compiles a single-valued read operation on obj[idx] or a generic function name#[T1, T2...]
func (*Comp) IndexPlace ¶
func (c *Comp) IndexPlace(node *ast.IndexExpr, opt PlaceOption) *Place
func (*Comp) InterfaceProxy ¶
InterfaceProxy returns the proxy struct that implements a compiled interface
func (*Comp) LookupField ¶
LookupField performs a breadth-first search for struct field with given name
func (*Comp) LookupFieldOrMethod ¶
lookup fields and methods at the same time... it's and error if both exist at the same depth
func (*Comp) LookupMethod ¶
LookupMethod performs a breadth-first search for method with given name
func (*Comp) LookupVar ¶
LookupVar compiles the left-hand-side of an assignment, in case it's an identifier (i.e. a variable name)
func (*Comp) MacroExpand ¶
MacroExpand repeatedly invokes MacroExpand as long as the node represents a macro call. it returns the resulting node.
func (*Comp) MacroExpand1 ¶
if node represents a macro call, MacroExpandNode1 executes it and returns the resulting node. Otherwise returns the node argument unchanged
func (*Comp) MacroExpandCodewalk ¶
MacroExpandCodewalk traverses the whole AST tree using pre-order traversal, and replaces each node with the result of MacroExpand(node). It implements the macroexpansion phase
func (*Comp) MacroExpandNode ¶
MacroExpandNode repeatedly invokes MacroExpandNode1 as long as the node represents a macro call. it returns the resulting node.
func (*Comp) MacroExpandNode1 ¶
if node represents a macro call, MacroExpandNode1 executes it and returns the resulting node. Otherwise returns the node argument unchanged
func (*Comp) MacroExpandNodeCodewalk ¶
MacroExpandNodeCodewalk traverses the whole AST tree using pre-order traversal, and replaces each node with the result of MacroExpandNode(node). It implements the macroexpansion phase
func (*Comp) NewBind ¶
NewBind reserves space for a subsequent constant, function or variable declaration
func (*Comp) NewFuncBind ¶
NewFuncBind reserves space for a subsequent function declaration
func (*Comp) Quasiquote ¶
Quasiquote expands and compiles ~quasiquote, if Ast starts with it
func (*Comp) Return ¶
func (c *Comp) Return(node *ast.ReturnStmt)
Return compiles a "return" statement
func (*Comp) SelectorExpr ¶
func (c *Comp) SelectorExpr(node *ast.SelectorExpr) *Expr
SelectorExpr compiles foo.bar, i.e. read access to methods, struct fields and imported packages
func (*Comp) SelectorPlace ¶
func (c *Comp) SelectorPlace(node *ast.SelectorExpr, opt PlaceOption) *Place
SelectorPlace compiles a.b returning a settable and/or addressable Place
func (*Comp) SetPlace ¶
SetPlace compiles an assignment to a place: 'place op constant' and 'place op expression'
func (*Comp) SetUnderlyingType ¶
func (*Comp) SetVar ¶
SetVar compiles an assignment to a variable: 'variable op constant' and 'variable op expression'
func (*Comp) ShiftUntyped ¶
func (c *Comp) ShiftUntyped(node *ast.BinaryExpr, op token.Token, x UntypedLit, y UntypedLit) *Expr
func (*Comp) TryLookupFieldOrMethod ¶
func (c *Comp) TryLookupFieldOrMethod(t xr.Type, name string) (xr.StructField, bool, xr.Method, bool, error)
lookup fields and methods at the same time... it's and error if both exist at the same depth
func (*Comp) TryResolve ¶
func (*Comp) TypeAssert1 ¶
func (c *Comp) TypeAssert1(node *ast.TypeAssertExpr) *Expr
TypeAssert1 compiles a single-valued type assertion
func (*Comp) TypeAssert2 ¶
func (c *Comp) TypeAssert2(node *ast.TypeAssertExpr) *Expr
TypeAssert2 compiles a multi-valued type assertion
func (*Comp) TypeFields ¶
func (*Comp) TypeFunction ¶
func (*Comp) TypeFunctionOrMethod ¶
func (c *Comp) TypeFunctionOrMethod(recv *ast.Field, node *ast.FuncType) (t xr.Type, paramNames []string, resultNames []string)
TypeFunctionOrMethod compiles a function type corresponding to given receiver and function declaration If receiver is not null, the returned tFunc will have it as receiver.
func (*Comp) TypeInterface ¶
func (c *Comp) TypeInterface(node *ast.InterfaceType) xr.Type
compile an interface definition
func (*Comp) TypeSwitch ¶
func (c *Comp) TypeSwitch(node *ast.TypeSwitchStmt, labels []string)
func (*Comp) UnaryExprUntyped ¶
type CompBinds ¶
type CompBinds struct { Binds map[string]*Bind BindNum int // len(Binds) == BindNum + IntBindNum + # of constants IntBindNum int // if address of some Env.Ints[index] was taken, we must honor it: // we can no longer reallocate Env.Ints[], thus we cannot declare IntBind variables // beyond Env.Ints[] capacity. In such case, we set IntBindMax to cap(Env.Ints): // Comp.NewBind() will allocate IntBind variables only up to IntBindMax, // then switch and allocate them as VarBind instead (they are slower and each one allocates memory) IntBindMax int Types map[string]xr.Type Name string // set by "package" directive Path string }
type CompGlobals ¶
type CompGlobals struct { *IrGlobals Universe *xr.Universe KnownImports map[string]*Import // map[path]*Import cache of known imports Prompt string Jit *Jit // contains filtered or unexported fields }
CompGlobals contains interpreter compile bookeeping information
func (*CompGlobals) CompileOptions ¶
func (cg *CompGlobals) CompileOptions() CompileOptions
func (*CompGlobals) NewImport ¶
func (g *CompGlobals) NewImport(pkgref *genimport.PackageRef) *Import
func (*CompGlobals) TypeOfBool ¶
func (g *CompGlobals) TypeOfBool() xr.Type
func (*CompGlobals) TypeOfBuiltin ¶
func (g *CompGlobals) TypeOfBuiltin() xr.Type
func (*CompGlobals) TypeOfComplex128 ¶
func (g *CompGlobals) TypeOfComplex128() xr.Type
func (*CompGlobals) TypeOfComplex64 ¶
func (g *CompGlobals) TypeOfComplex64() xr.Type
func (*CompGlobals) TypeOfError ¶
func (g *CompGlobals) TypeOfError() xr.Type
func (*CompGlobals) TypeOfFloat32 ¶
func (g *CompGlobals) TypeOfFloat32() xr.Type
func (*CompGlobals) TypeOfFloat64 ¶
func (g *CompGlobals) TypeOfFloat64() xr.Type
func (*CompGlobals) TypeOfFunction ¶
func (g *CompGlobals) TypeOfFunction() xr.Type
func (*CompGlobals) TypeOfInt ¶
func (g *CompGlobals) TypeOfInt() xr.Type
func (*CompGlobals) TypeOfInt16 ¶
func (g *CompGlobals) TypeOfInt16() xr.Type
func (*CompGlobals) TypeOfInt32 ¶
func (g *CompGlobals) TypeOfInt32() xr.Type
func (*CompGlobals) TypeOfInt64 ¶
func (g *CompGlobals) TypeOfInt64() xr.Type
func (*CompGlobals) TypeOfInt8 ¶
func (g *CompGlobals) TypeOfInt8() xr.Type
func (*CompGlobals) TypeOfInterface ¶
func (g *CompGlobals) TypeOfInterface() xr.Type
func (*CompGlobals) TypeOfMacro ¶
func (g *CompGlobals) TypeOfMacro() xr.Type
func (*CompGlobals) TypeOfPtrGenericFunc ¶
func (g *CompGlobals) TypeOfPtrGenericFunc() xr.Type
func (*CompGlobals) TypeOfPtrGenericType ¶
func (g *CompGlobals) TypeOfPtrGenericType() xr.Type
func (*CompGlobals) TypeOfPtrImport ¶
func (g *CompGlobals) TypeOfPtrImport() xr.Type
func (*CompGlobals) TypeOfString ¶
func (g *CompGlobals) TypeOfString() xr.Type
func (*CompGlobals) TypeOfUint ¶
func (g *CompGlobals) TypeOfUint() xr.Type
func (*CompGlobals) TypeOfUint16 ¶
func (g *CompGlobals) TypeOfUint16() xr.Type
func (*CompGlobals) TypeOfUint32 ¶
func (g *CompGlobals) TypeOfUint32() xr.Type
func (*CompGlobals) TypeOfUint64 ¶
func (g *CompGlobals) TypeOfUint64() xr.Type
func (*CompGlobals) TypeOfUint8 ¶
func (g *CompGlobals) TypeOfUint8() xr.Type
func (*CompGlobals) TypeOfUintptr ¶
func (g *CompGlobals) TypeOfUintptr() xr.Type
func (*CompGlobals) TypeOfUntypedLit ¶
func (g *CompGlobals) TypeOfUntypedLit() xr.Type
func (*CompGlobals) UnloadPackage ¶
func (cg *CompGlobals) UnloadPackage(path string)
remove package 'path' from the list of known packages. later attempts to import it again will trigger a recompile.
type CompileOptions ¶
type CompileOptions int
const ( COptKeepUntyped CompileOptions = 1 << iota // if set, Compile() on expressions will keep all untyped constants as such (in expressions where Go compiler would compute an untyped constant too) COptDefaults CompileOptions = 0 )
type DebugOp ¶
type DebugOp struct { // statements at env.CallDepth < Depth will be executed in single-stepping mode, // i.e. invoking the debugger after every statement Depth int // nil = do not panic. // otherwise, address of value to panic() in order to terminate execution Panic *interface{} }
type Env ¶
type Env struct { EnvBinds Outer *Env IP int Code []Stmt Run *Run FileEnv *Env DebugPos []token.Pos // for debugging interpreted code: position of each statement DebugComp *Comp // for debugging interpreted code: compiler with Binds, and to rebuild an Interp if needed Caller *Env // for debugging interpreted code: previous function in call stack. nil for nested *Env CallDepth int // for debugging interpreted code: depth of call stack UsedByClosure bool // a bitfield would introduce more races among goroutines IntAddressTaken bool // true if &Env.Ints[index] was executed... then we cannot reuse or reallocate Ints }
Env is the interpreter's runtime environment
func (*Env) FreeEnv ¶
func (env *Env) FreeEnv()
FreeEnv tells the interpreter that given nested *Env is no longer needed.
func (*Env) MarkUsedByClosure ¶
func (env *Env) MarkUsedByClosure()
type ExecFlags ¶
type ExecFlags uint32
func (*ExecFlags) SetStartDefer ¶
func (ExecFlags) StartDefer ¶
type Expr ¶
type Expr struct { Lit Types []xr.Type // in case the expression produces multiple values. if nil, use Lit.Type. Fun I // function that evaluates the expression at runtime. Sym *Symbol // in case the expression is a symbol Jit jitExpr // expression to jit-compile, or nil if not supported EFlags }
Expr represents an expression in the "compiler"
func (*Expr) AsUint64 ¶
* used by Comp.Shl(), Comp.Shr(), Comp.varSh{l,r}Expr() and Comp.placeSh{l,r}Expr(). * If e returns a signed integer type, the returned function * panics at runtime when the integer is negative. * This reproduces the behaviour of shift by signed integer introduced in Go 1.13
func (*Expr) CheckX1 ¶
func (e *Expr) CheckX1()
CheckX1() panics if given expression cannot be used in single-value context, for example because it returns no value at all. It just prints a warning if expression returns multiple values.
func (*Expr) ConstTo ¶
ConstTo checks that a constant Expr can be used as the given type. panics if not constant, or if Expr is a typed constant of different type actually performs type conversion (and subsequent overflow checks) ONLY on untyped constants.
func (*Expr) DefaultType ¶
DefaultType returns the default type of an expression.
func (*Expr) EvalConst ¶
func (expr *Expr) EvalConst(opts CompileOptions) I
func (*Expr) NumOut ¶
NumOut returns the number of values that an expression will produce when evaluated
func (*Expr) To ¶
To checks that an Expr can be used as (i.e. is assignable to) the given type, and converts Expr to the given type. panics if Expr has an incompatible type.
func (*Expr) WithFun ¶
WithFun ensures that Expr.Fun is a closure that will return the expression result:
if Expr is an untyped constant, WithFun converts the constant to its default type (panics on overflows),
then sets Expr.Fun to a closure that will return such constant.
if Expr is a typed constant, WithFun sets Expr.Fun to a closure that will return such constant. if Expr is not a constant, WithFun does nothing (Expr.Fun must be set already)
type GenericFunc ¶
type GenericFunc struct { Master GenericFuncDecl // master (i.e. non specialized) declaration Special map[string]GenericFuncDecl // partially or fully specialized declarations. key is GenericFuncDecl.For converted to string Instances map[I]*GenericFuncInstance // cache of instantiated functions. key is [N]interface{}{T1, T2...} DeclScope *Comp // scope where generic function is declared }
generic function
func (*GenericFunc) HasParam ¶
func (f *GenericFunc) HasParam(name string) bool
func (*GenericFunc) Pos ¶
func (f *GenericFunc) Pos() token.Pos
func (*GenericFunc) Signature ¶
func (f *GenericFunc) Signature(name string) string
func (*GenericFunc) String ¶
func (f *GenericFunc) String() string
type GenericFuncDecl ¶
type GenericFuncDecl struct { Decl *ast.FuncLit // generic function declaration. use a *ast.FuncLit because we will compile it with Comp.FuncLit() Params []string // generic param names For []ast.Expr // partial or full specialization }
a generic function declaration. either general, or partially specialized or fully specialized
func (*GenericFuncDecl) HasParam ¶
func (master *GenericFuncDecl) HasParam(name string) bool
func (*GenericFuncDecl) Signature ¶
func (master *GenericFuncDecl) Signature(name string) string
type GenericFuncInstance ¶
an instantiated (and compiled) generic function.
type GenericType ¶
type GenericType struct { Master GenericTypeDecl // master (i.e. non specialized) declaration Special map[string]GenericTypeDecl // partially or fully specialized declarations. key is TemplateTypeDecl.For converted to string Instances map[I]xr.Type // cache of instantiated types. key is [N]interface{}{T1, T2...} }
func (*GenericType) Pos ¶
func (t *GenericType) Pos() token.Pos
func (*GenericType) String ¶
func (t *GenericType) String() string
type GenericTypeDecl ¶
type GenericTypeDecl struct { Decl ast.Expr // type declaration body. use an ast.Expr because we will compile it with Comp.Type() Alias bool // true if declaration is an alias: 'type Foo = ...' Params []string // generic param names For []ast.Expr // for partial or full specialization }
a generic type declaration. either general, or partially specialized or fully specialized
type Import ¶
type Import struct { // model as a combination of CompBinds and EnvBinds, because to support the command 'package PATH' // we must convert Comp+Env to Import and vice-versa. // This has the added benefit of allowing packages to freely mix // interpreted and compiled constants, functions, variables and types. CompBinds *EnvBinds // contains filtered or unexported fields }
Import represents an imported package. we cannot name it "Package" because it conflicts with ast2.Package
func (*Import) Show ¶
func (imp *Import) Show(g *CompGlobals, env *Env)
type Interp ¶
type Interp struct { Comp *Comp // contains filtered or unexported fields }
Interp is the fast interpreter. It contains both the tree-of-closures builder Comp and the interpreter's runtime environment Env
func (*Interp) AddressOfVar ¶
AddressOfVar compiles the expression &name, then executes it returns the zero value if name is not found or is not addressable
func (*Interp) ChangePackage ¶
func (*Interp) Cmd ¶
execute one of the REPL commands starting with ':' return any remainder string to be evaluated, and the options to evaluate it
func (*Interp) CompleteWords ¶
func (ir *Interp) CompleteWords(line string, pos int) (head string, completions []string, tail string)
implement code completion API github.com/pererh/liner.WordCompleter Currently only supports global symbols and imported packages, optionally followed by a dot-separated sequence of field or method names, including embedded fields and wrapper methods.
func (*Interp) DebugExpr ¶
execute with single-step debugging. to run without debugging, use Interp.RunExpr() instead
func (*Interp) DebugExpr1 ¶
execute with single-step debugging. to run without debugging, use Interp.RunExpr() instead
func (*Interp) DeclBuiltin ¶
DeclBuiltin compiles a builtin function declaration
func (*Interp) DeclEnvFunc ¶
DeclEnvFunc compiles a function declaration that accesses interpreter's *CompEnv
func (*Interp) DeclTypeAlias ¶
DeclType declares a type alias
func (*Interp) EvalReader ¶
func (*Interp) ImportPackage ¶
ImportPackage imports a package. Panics if the import fails. If alias is the empty string, it defaults to the identifier specified in the package clause of the imported package
func (*Interp) ImportPackageOrError ¶
ImportPackageOrError imports a package. If alias is the empty string, it defaults to the identifier specified in the package clause of the imported package
func (*Interp) ParseEvalPrint ¶
func (*Interp) PrepareEnv ¶
func (*Interp) Read ¶
return read string and position of first non-comment token. return "", -1 on EOF
func (*Interp) ReadParseEvalPrint ¶
func (*Interp) RunExpr ¶
run without debugging. to execute with single-step debugging, use Interp.DebugExpr() instead
func (*Interp) RunExpr1 ¶
run without debugging. to execute with single-step debugging, use Interp.DebugExpr() instead
func (*Interp) SetDebugger ¶
func (*Interp) SetInspector ¶
func (*Interp) ShowAsPackage ¶
func (ir *Interp) ShowAsPackage()
func (*Interp) ShowImportedPackage ¶
func (*Interp) ShowPackage ¶
type IrGlobals ¶
IrGlobals contains interpreter configuration
func NewIrGlobals ¶
func NewIrGlobals() *IrGlobals
type Jit ¶
type Jit struct{}
func (*Jit) AsStmt ¶
if supported, return a jit-compiled Stmt that will evaluate Expr. return nil on failure
func (*Jit) BinaryExpr ¶
if supported, set e.Jit to jit expression that will compute xe op ye always returns e.
func (*Jit) Cast ¶
if supported, set e.Jit to jit expression that will compute t(xe) always returns e.
func (*Jit) Deref ¶
if supported, set e.Jit to jit expression that will compute *xe always returns e.
func (*Jit) Fun ¶
if supported, replace e.Fun with a jit-compiled equivalent function. always returns e.
func (*Jit) Identity ¶
if supported, set e.Jit to jit expression that will compute xe always returns e.
func (*Jit) SetVar ¶
if supported, return a jit-compiled statement that will perform va OP= init return nil on failure
type Lit ¶
type Lit struct { // Type is nil for literal nils. // For all other literals, Type is xr.TypeOf(Lit.Value) // // when Lit is embedded in other structs that represent non-constant expressions, // Type is the first type returned by the expression (nil if returns no values) Type xr.Type // Value is one of: // nil, bool, int, int8, int16, int32, int64, // uint, uint8, uint16, uint32, uint64, uintptr, // float32, float64, complex64, complex128, string, // UntypedLit // // when Lit is embedded in other structs that represent non-constant expressions, // Value is usually nil // // when Lit is embedded in a Bind with class == GenericFuncBind, // Value is the *GenericFunc containing the function source code // to be specialized and compiled upon instantiation. Value I }
Lit represents a literal value, i.e. a typed or untyped constant
func (*Lit) ConstTo ¶
ConstTo checks that a Lit can be used as the given type. panics if Lit is a typed constant of different type actually performs type conversion (and subsequent overflow checks) ONLY on untyped constants.
func (*Lit) ConstValue ¶
func (*Lit) DefaultType ¶
DefaultType returns the default type of a constant.
func (*Lit) UntypedKind ¶
UntypedKind returns the reflect.Kind of untyped constants, i.e. their "default type"
type LoopInfo ¶
type Macro ¶
type Macro struct {
// contains filtered or unexported fields
}
Macro represents a macro in the fast interpreter
type Place ¶
type Place struct { Var // Fun is nil for variables. // For non-variables, returns a settable and addressable reflect.Value: the place itself. // For map[key], Fun returns the map itself (which may NOT be settable). // Call Fun only once, it may have side effects! Fun func(*Env) xr.Value // Addr is nil for variables. // For non-variables, it will return the address of the place. // For map[key], it is nil since map[key] is not addressable // Call Addr only once, it may have side effects! Addr func(*Env) xr.Value // used only for map[key], returns key. call it only once, it may have side effects! MapKey func(*Env) xr.Value MapType xr.Type }
Place represents a settable place or, equivalently, its address
type PlaceOption ¶
type PlaceOption bool // the reason why we want a place: either to write into it, or to take its address
const ( PlaceSettable PlaceOption = false PlaceAddress PlaceOption = true )
func (PlaceOption) String ¶
func (opt PlaceOption) String() string
type Run ¶
type Run struct { *IrGlobals Interrupt Stmt Signals base.Signals // set by defer, return, breakpoint, debugger and Run.interrupt(os.Signal) ExecFlags ExecFlags CurrEnv *Env // caller of current function. used ONLY at function entry to build call stack InstallDefer func() // defer function to be installed DeferOfFun *Env // function whose defer are running PanicFun *Env // the currently panicking function Panic interface{} // current panic. needed for recover() CmdOpt base.CmdOpt Debugger Debugger DebugDepth int // depth of function to debug with single-step PoolSize int Pool [poolCapacity]*Env // contains filtered or unexported fields }
Run contains per-goroutine interpreter runtime bookeeping information
type Symbol ¶
Symbol represents a resolved constant, function, variable or builtin
func (*Symbol) AsVar ¶
func (sym *Symbol) AsVar(opt PlaceOption) *Var
type TypeAssertionError ¶
type TypeAssertionError struct { Interface xr.Type Concrete xr.Type ReflectConcrete r.Type // in case Concrete is not available Asserted xr.Type MissingMethod *xr.Method // one method needed by Interface, missing from Concrete }
A TypeAssertionError explains a failed type assertion.
func (*TypeAssertionError) Error ¶
func (e *TypeAssertionError) Error() string
func (*TypeAssertionError) RuntimeError ¶
func (*TypeAssertionError) RuntimeError()
type UntypedLit ¶
Source Files
¶
- address.go
- assignment.go
- binary.go
- binary_eqlneq.go
- binary_ops.go
- binary_relops.go
- binary_shifts.go
- builtin.go
- call.go
- call0ret1.go
- call1ret1.go
- call2ret1.go
- call_ellipsis.go
- call_multivalue.go
- call_variadic.go
- callnret0.go
- callnret1.go
- channel.go
- cmd.go
- code.go
- compile.go
- compositelit.go
- convert.go
- debug.go
- declaration.go
- expr.go
- expr1.go
- func0ret0.go
- func0ret1.go
- func1ret0.go
- func1ret1.go
- func2ret0.go
- function.go
- generic_func.go
- generic_infer.go
- generic_maker.go
- generic_type.go
- global.go
- identifier.go
- import.go
- index.go
- inspect.go
- interface.go
- interpreter.go
- jit_stub.go
- literal.go
- macroexpand.go
- output.go
- place_get.go
- place_ops.go
- place_set.go
- place_set_value.go
- place_shifts.go
- quasiquote.go
- range.go
- range_map.go
- repl.go
- select.go
- selector.go
- slice.go
- statement.go
- switch.go
- switch2.go
- switch_type.go
- type.go
- unary.go
- unary_ops.go
- util.go
- var_ops.go
- var_set.go
- var_set_value.go
- var_shifts.go
- x_package.go