Documentation
¶
Index ¶
- Constants
- type Assign
- type Bind
- type BindClass
- type BindDescriptor
- type Builtin
- type Call
- type Code
- type Comp
- func (c *Comp) Add(node *ast.BinaryExpr, xe *Expr, ye *Expr) *Expr
- func (c *Comp) AddBind(name string, class BindClass, t xr.Type) *Bind
- func (c *Comp) AddFuncBind(name string, t xr.Type) *Bind
- 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) BindUntyped(value UntypedLit) *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) CompositeLit(node *ast.CompositeLit) *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(val r.Value, rtout r.Type) r.Value
- func (c *Comp) Decl(node ast.Decl)
- func (c *Comp) DeclBindRuntimeValue(bind *Bind) func(*Env, r.Value)
- func (c *Comp) DeclBuiltin0(name string, builtin Builtin) *Bind
- func (c *Comp) DeclConst0(name string, t xr.Type, value I)
- 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) DeclFunc0(name string, fun I) *Bind
- func (c *Comp) DeclMultiVar0(names []string, t xr.Type, init *Expr)
- func (c *Comp) DeclNamedType(name string) xr.Type
- func (c *Comp) DeclType(node 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) DeclTypeAlias0(alias 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)
- 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) ErrorIfCompiled(x interface{})
- func (c *Comp) Expr(in ast.Expr) *Expr
- func (c *Comp) Expr1(in ast.Expr) *Expr
- func (c *Comp) Expr1OrType(node 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) FuncDecl(funcdecl *ast.FuncDecl)
- func (c *Comp) FuncLit(funclit *ast.FuncLit) *Expr
- func (c *Comp) GenDecl(node *ast.GenDecl)
- 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) 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(name, path string) *Import
- 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) IsCompiled() bool
- func (c *Comp) IsCompiledOuter(upn int) bool
- 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) 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) 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) TryResolve(name string) *Symbol
- 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) TypeIdent(name string) xr.Type
- 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 CompThreadGlobals
- func (g *CompThreadGlobals) TypeOfBool() xr.Type
- func (g *CompThreadGlobals) TypeOfBuiltin() xr.Type
- func (g *CompThreadGlobals) TypeOfComplex64() xr.Type
- func (g *CompThreadGlobals) TypeOfComplex128() xr.Type
- func (g *CompThreadGlobals) TypeOfError() xr.Type
- func (g *CompThreadGlobals) TypeOfFloat32() xr.Type
- func (g *CompThreadGlobals) TypeOfFloat64() xr.Type
- func (g *CompThreadGlobals) TypeOfFunction() xr.Type
- func (g *CompThreadGlobals) TypeOfImport() xr.Type
- func (g *CompThreadGlobals) TypeOfInt() xr.Type
- func (g *CompThreadGlobals) TypeOfInt8() xr.Type
- func (g *CompThreadGlobals) TypeOfInt16() xr.Type
- func (g *CompThreadGlobals) TypeOfInt32() xr.Type
- func (g *CompThreadGlobals) TypeOfInt64() xr.Type
- func (g *CompThreadGlobals) TypeOfInterface() xr.Type
- func (g *CompThreadGlobals) TypeOfMacro() xr.Type
- func (g *CompThreadGlobals) TypeOfString() xr.Type
- func (g *CompThreadGlobals) TypeOfUint() xr.Type
- func (g *CompThreadGlobals) TypeOfUint8() xr.Type
- func (g *CompThreadGlobals) TypeOfUint16() xr.Type
- func (g *CompThreadGlobals) TypeOfUint32() xr.Type
- func (g *CompThreadGlobals) TypeOfUint64() xr.Type
- func (g *CompThreadGlobals) TypeOfUintptr() xr.Type
- func (g *CompThreadGlobals) TypeOfUntypedLit() xr.Type
- type CompileOptions
- type EFlags
- type Env
- type Expr
- func (e *Expr) AsStmt() Stmt
- func (e *Expr) AsX() func(*Env)
- func (e *Expr) AsX1() func(*Env) r.Value
- func (e *Expr) AsXV(opts CompileOptions) func(*Env) (r.Value, []r.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) Outs() []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 I
- type I_github_com_cosmos72_gomacro_fast
- type Import
- type Interp
- func (ir *Interp) AddressOfVar(name string) (addr r.Value)
- func (ir *Interp) ChangePackage(name, path string)
- 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) 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) (r.Value, []r.Value)
- func (ir *Interp) Parse(src string) ast2.Ast
- func (ir *Interp) PrepareEnv() *Env
- func (ir *Interp) RunExpr(e *Expr) (r.Value, []r.Value)
- func (ir *Interp) RunExpr1(e *Expr) r.Value
- func (ir *Interp) TypeOf(val interface{}) xr.Type
- func (ir *Interp) ValueOf(name string) (value r.Value)
- type Lit
- type LoopInfo
- type Macro
- type NamedType
- type Place
- type PlaceOption
- type Signal
- type Stmt
- type Symbol
- type ThreadGlobals
- type TypeAssertionError
- type UntypedLit
- type Var
Constants ¶
const ( ConstBind = BindClass(iota) FuncBind VarBind IntBind )
const ( NoIndex = int(0) // index of constants, functions and variables named "_" ConstBindDescriptor = BindDescriptor(ConstBind) // bind descriptor for all constants )
const ( // conventional values AnyDepth = -1 FileDepth = -2 TopDepth = -3 )
const (
PoolCapacity = 32
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
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 ¶
type BindDescriptor ¶
type BindDescriptor BindClass
the zero value of BindDescriptor is a valid descriptor for all constants
func MakeBindDescriptor ¶
func MakeBindDescriptor(class BindClass, index int) BindDescriptor
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 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 {
Binds map[string]*Bind
BindNum int // len(Binds) == BindNum + IntBindNum + # of constants
IntBindNum int
// 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
Types map[string]xr.Type
Code Code // "compiled" code
Loop *LoopInfo // != nil when compiling a for or switch
Func *FuncInfo // != nil when compiling a function
Outer *Comp
Name string // set by "package" directive
Path string
CompileOptions CompileOptions
*CompThreadGlobals
}
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) AddBind ¶
AddBind reserves space for a subsequent constant, function or variable declaration
func (*Comp) AddFuncBind ¶
AddFuncBind reserves space for a subsequent function declaration
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) BindUntyped ¶
func (c *Comp) BindUntyped(value UntypedLit) *Bind
func (*Comp) Branch ¶
func (c *Comp) Branch(node *ast.BranchStmt)
Branch compiles a break, continue, fallthrough or goto statement
func (*Comp) CompositeLit ¶
func (c *Comp) CompositeLit(node *ast.CompositeLit) *Expr
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) DeclFunc0 ¶
DeclFunc0 compiles a function declaration. For caller's convenience, returns allocated Bind
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()
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) DeclTypeAlias0 ¶
DeclTypeAlias0 declares a type alias in Go, types are computed only at compile time - no need for a runtime *Env
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) ErrorIfCompiled ¶
func (c *Comp) ErrorIfCompiled(x interface{})
func (*Comp) Expr1OrType ¶
Expr1OrType compiles an single-valued expression or a type FIXME lookup simultaneously for both types and expressions
func (*Comp) ExprsMultipleValues ¶
ExprsMultipleValues either a single expression returning multiple values, or multiple expressions each returning a value.
func (*Comp) FuncDecl ¶
DeclFunc compiles a function, macro or method declaration For closure declarations, use FuncLit()
func (*Comp) FuncLit ¶
FuncLit compiles a function literal, i.e. a closure. For functions or methods declarations, use FuncDecl()
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 ¶
Import imports a package. Usually invoked as Comp.FileComp().ImportPackage(name, 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) IncDec ¶
func (c *Comp) IncDec(node *ast.IncDecStmt)
IncDec compiles a "place++" or "place--" statement
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) IsCompiled ¶
func (*Comp) IsCompiledOuter ¶
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) 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) SetUnderlyingType ¶
func (*Comp) ShiftUntyped ¶
func (c *Comp) ShiftUntyped(node *ast.BinaryExpr, op token.Token, x UntypedLit, y UntypedLit) *Expr
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
func (*Comp) TypeSwitch ¶
func (c *Comp) TypeSwitch(node *ast.TypeSwitchStmt, labels []string)
func (*Comp) UnaryExprUntyped ¶
type CompThreadGlobals ¶
type CompThreadGlobals struct {
Universe *xr.Universe
*Globals
// contains filtered or unexported fields
}
CompGlobals contains per-goroutine interpreter compile bookeeping information
func (*CompThreadGlobals) TypeOfBool ¶
func (g *CompThreadGlobals) TypeOfBool() xr.Type
func (*CompThreadGlobals) TypeOfBuiltin ¶
func (g *CompThreadGlobals) TypeOfBuiltin() xr.Type
func (*CompThreadGlobals) TypeOfComplex64 ¶
func (g *CompThreadGlobals) TypeOfComplex64() xr.Type
func (*CompThreadGlobals) TypeOfComplex128 ¶
func (g *CompThreadGlobals) TypeOfComplex128() xr.Type
func (*CompThreadGlobals) TypeOfError ¶
func (g *CompThreadGlobals) TypeOfError() xr.Type
func (*CompThreadGlobals) TypeOfFloat32 ¶
func (g *CompThreadGlobals) TypeOfFloat32() xr.Type
func (*CompThreadGlobals) TypeOfFloat64 ¶
func (g *CompThreadGlobals) TypeOfFloat64() xr.Type
func (*CompThreadGlobals) TypeOfFunction ¶
func (g *CompThreadGlobals) TypeOfFunction() xr.Type
func (*CompThreadGlobals) TypeOfImport ¶
func (g *CompThreadGlobals) TypeOfImport() xr.Type
func (*CompThreadGlobals) TypeOfInt ¶
func (g *CompThreadGlobals) TypeOfInt() xr.Type
func (*CompThreadGlobals) TypeOfInt8 ¶
func (g *CompThreadGlobals) TypeOfInt8() xr.Type
func (*CompThreadGlobals) TypeOfInt16 ¶
func (g *CompThreadGlobals) TypeOfInt16() xr.Type
func (*CompThreadGlobals) TypeOfInt32 ¶
func (g *CompThreadGlobals) TypeOfInt32() xr.Type
func (*CompThreadGlobals) TypeOfInt64 ¶
func (g *CompThreadGlobals) TypeOfInt64() xr.Type
func (*CompThreadGlobals) TypeOfInterface ¶
func (g *CompThreadGlobals) TypeOfInterface() xr.Type
func (*CompThreadGlobals) TypeOfMacro ¶
func (g *CompThreadGlobals) TypeOfMacro() xr.Type
func (*CompThreadGlobals) TypeOfString ¶
func (g *CompThreadGlobals) TypeOfString() xr.Type
func (*CompThreadGlobals) TypeOfUint ¶
func (g *CompThreadGlobals) TypeOfUint() xr.Type
func (*CompThreadGlobals) TypeOfUint8 ¶
func (g *CompThreadGlobals) TypeOfUint8() xr.Type
func (*CompThreadGlobals) TypeOfUint16 ¶
func (g *CompThreadGlobals) TypeOfUint16() xr.Type
func (*CompThreadGlobals) TypeOfUint32 ¶
func (g *CompThreadGlobals) TypeOfUint32() xr.Type
func (*CompThreadGlobals) TypeOfUint64 ¶
func (g *CompThreadGlobals) TypeOfUint64() xr.Type
func (*CompThreadGlobals) TypeOfUintptr ¶
func (g *CompThreadGlobals) TypeOfUintptr() xr.Type
func (*CompThreadGlobals) TypeOfUntypedLit ¶
func (g *CompThreadGlobals) TypeOfUntypedLit() xr.Type
type CompileOptions ¶
type CompileOptions int
const ( OptKeepUntyped 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) OptIsCompiled // if set, packages is at least partially compiled. Effect: variables may be pre-existing, so Comp.intBinds cannot be used OptDefaults CompileOptions = 0 )
func (CompileOptions) IsCompiled ¶
func (opts CompileOptions) IsCompiled() bool
type Env ¶
type Env struct {
Binds []r.Value
IntBinds []uint64
Outer *Env
IP int
Code []Stmt
DebugPos []token.Pos // for debugging interpreted code: position of each statement
ThreadGlobals *ThreadGlobals
UsedByClosure bool // a bitfield would introduce more races among goroutines
AddressTaken bool // true if &Env.IntBinds[index] was executed... then we cannot reuse IntBinds
}
Env is the interpreter's runtime environment
func (*Env) FreeEnv ¶
func (env *Env) FreeEnv()
FreeEnv tells the interpreter that given Env is no longer needed.
func (*Env) MarkUsedByClosure ¶
func (env *Env) MarkUsedByClosure()
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
EFlags
}
Expr represents an expression in the "compiler"
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 I_github_com_cosmos72_gomacro_fast ¶
type I_github_com_cosmos72_gomacro_fast struct {
Object interface{}
}
--------------- proxy for github.com/cosmos72/gomacro/fast.I ---------------
type Import ¶
type Import struct {
// no need to split compile-time bind descriptors map from runtime values slice,
// because an import is a singleton - cannot be "instantiated" multiple times.
// Instead function or block activation record (*Env) can:
// think about goroutines, recursive functions or even loops.
Binds map[string]r.Value
BindTypes map[string]xr.Type
Types map[string]xr.Type
Name, Path string
}
Import represents an imported package
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 NewCompEnv ¶
func NewCompEnvTop ¶
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) 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) PrepareEnv ¶
type Lit ¶
type Lit struct {
// Type is nil only for literal nils.
// for all other literals, it is reflect.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
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) DefaultType ¶
DefaultType returns the default type of a constant.
func (*Lit) ReflectValue ¶
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) r.Value
// Fddr 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) r.Value
// used only for map[key], returns key. call it only once, it may have side effects!
MapKey func(*Env) r.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 Symbol ¶
Symbol represents a resolved constant, function, variable or builtin
func (*Symbol) AsVar ¶
func (sym *Symbol) AsVar(opt PlaceOption) *Var
type ThreadGlobals ¶
type ThreadGlobals struct {
FileEnv *Env
TopEnv *Env
Interrupt Stmt
Signal Signal // set by interrupts: Return, Defer...
PoolSize int
Pool [PoolCapacity]*Env
InstallDefer func() // defer function to be installed
Panic interface{} // current panic. needed for recover()
PanicFun *Env // the currently panicking function
DeferOfFun *Env // function whose defer are running
StartDefer bool // true if next executed function body is a defer
IsDefer bool // true if function body being executed is a defer
*Globals
}
ThreadGlobals contains per-goroutine interpreter runtime bookeeping information
func NewThreadGlobals ¶
func NewThreadGlobals() *ThreadGlobals
type TypeAssertionError ¶
type TypeAssertionError struct {
Interface r.Type
Concrete r.Type
Asserted r.Type
MissingMethod string // 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 ¶
type UntypedLit struct {
Kind r.Kind // default type. matches Obj.Kind() except for rune literals, where Kind == reflect.Int32
Obj constant.Value
Universe *xr.Universe
}
UntypedLit represents an untyped literal value, i.e. an untyped constant
func (*UntypedLit) ConstTo ¶
func (untyp *UntypedLit) ConstTo(t xr.Type) I
ConstTo checks that an UntypedLit can be used as the given type. performs actual untyped -> typed conversion and subsequent overflow checks. returns the constant converted to given type
func (*UntypedLit) DefaultType ¶
func (untyp *UntypedLit) DefaultType() xr.Type
DefaultType returns the default type of an untyped constant.
func (*UntypedLit) IsLiteralNumber ¶
func (untyp *UntypedLit) IsLiteralNumber(n int64) bool
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
- code.go
- compile.go
- compositelit.go
- convert.go
- declaration.go
- expr.go
- expr1.go
- func0ret0.go
- func0ret1.go
- func1ret0.go
- func1ret1.go
- func2ret0.go
- function.go
- global.go
- identifier.go
- import.go
- index.go
- interface.go
- interpreter.go
- literal.go
- macroexpand.go
- place_get.go
- place_ops.go
- place_set.go
- place_set_value.go
- place_shifts.go
- quasiquote.go
- range.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