Documentation ¶
Overview ¶
Package sexp provides a high level intermediate representation that contains both Go and Emacs Lisp traits.
Index ¶
- Variables
- func CostOf(forms ...Form) int
- func CostOfList(forms []Form) int
- func IsEmptyForm(form Form) bool
- func IsStmt(form Form) bool
- func Walk(form Form, fn walkFunc)
- type And
- type ArrayIndex
- type ArrayLit
- type ArraySlice
- type ArrayUpdate
- type Bind
- type Block
- type Bool
- type Call
- type CaseClause
- type DoTimes
- type DynCall
- type ExprStmt
- type Float
- type Form
- type FormList
- type Func
- type Goto
- type If
- type Int
- type Label
- type LambdaCall
- type Let
- type LispCall
- func NewAdd(x, y Form) *LispCall
- func NewAdd1(x Form) *LispCall
- func NewBitAnd(x, y Form) *LispCall
- func NewBitOr(x, y Form) *LispCall
- func NewBitXor(x, y Form) *LispCall
- func NewConcat(x, y Form) *LispCall
- func NewLispCall(fn *lisp.Func, args ...Form) *LispCall
- func NewMul(x, y Form) *LispCall
- func NewNeg(x Form) *LispCall
- func NewNot(x Form) *LispCall
- func NewNumEq(x, y Form) *LispCall
- func NewNumGt(x, y Form) *LispCall
- func NewNumGte(x, y Form) *LispCall
- func NewNumLt(x, y Form) *LispCall
- func NewNumLte(x, y Form) *LispCall
- func NewNumNeq(x, y Form) *LispCall
- func NewQuo(x, y Form) *LispCall
- func NewShl(x, y Form) *LispCall
- func NewShr(x, y Form) *LispCall
- func NewStrEq(x, y Form) *LispCall
- func NewStrGt(x, y Form) *LispCall
- func NewStrLt(x, y Form) *LispCall
- func NewStrNeq(x, y Form) *LispCall
- func NewSub(x, y Form) *LispCall
- func NewSub1(x Form) *LispCall
- func NewSubstr(array, low, high Form) *LispCall
- type Local
- type Loop
- type Or
- type Rebind
- type Repeat
- type Return
- type SliceIndex
- type SliceLit
- type SliceSlice
- type SliceUpdate
- type Span
- type SpanKind
- type SparseArrayLit
- type Str
- type StructIndex
- type StructLit
- type StructUpdate
- type Switch
- type SwitchBody
- type SwitchTrue
- type Symbol
- type TypeAssert
- type TypeCast
- type Var
- type VarUpdate
- type While
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func CostOfList ¶
CostOfList calls each form Cost method and returns accumulated cost sum.
func IsEmptyForm ¶
Types ¶
type ArrayIndex ¶
ArrayIndex is array index expression.
func (*ArrayIndex) Copy ¶
func (form *ArrayIndex) Copy() Form
func (*ArrayIndex) Cost ¶
func (form *ArrayIndex) Cost() int
func (*ArrayIndex) Type ¶
func (form *ArrayIndex) Type() types.Type
type ArraySlice ¶
ArraySlice is array slicing (subslice) expression.
func NewArraySlice ¶
func NewArraySlice(array, low, high Form) *ArraySlice
func (*ArraySlice) Copy ¶
func (form *ArraySlice) Copy() Form
func (*ArraySlice) Cost ¶
func (form *ArraySlice) Cost() int
func (*ArraySlice) Type ¶
func (form *ArraySlice) Type() types.Type
type ArrayUpdate ¶
ArrayUpdate is array index expression with assignment.
func (*ArrayUpdate) Copy ¶
func (form *ArrayUpdate) Copy() Form
func (*ArrayUpdate) Cost ¶
func (form *ArrayUpdate) Cost() int
func (*ArrayUpdate) Type ¶
func (form *ArrayUpdate) Type() types.Type
type Block ¶
type Block []Form
Block is a list of statements. Unlike FormList, it creates a new lexical scope.
type CaseClause ¶
CaseClause is a part of SwitchBody.
type DoTimes ¶
DoTimes is like Repeat, but: - N is not necessary a constant. - Has inductive variable inside loop body (Iter).
type ExprStmt ¶
type ExprStmt struct{ Expr Form }
ExprStmt is a Call which discards returned results.
type Form ¶
type Form interface { // Type evaluates Form result type. // Statement-like forms return "types.Typ[types.Invalid]". Type() types.Type // Copy creates a deep copy of Form object. Copy() Form // Cost returns a value that approximates computational complexity. // // If it is impossible to predict complexity, -1 is returned. // Examples of failing forms are loops with dynamic conditions. Cost() int }
Form = universal S-expression node (akin to Go ast.Node).
type Func ¶
type Func struct { Name string Body Block Params []string Variadic bool // Maps param index to interface type. // Nil if function have no interface parameters at all. InterfaceInputs map[int]types.Type Results *types.Tuple DocString string // contains filtered or unexported fields }
Func represents goism function object.
func (*Func) IsInlineable ¶
IsInlineable tells if function can be inlined (not the same as *should* be inlined).
func (*Func) IsNoinline ¶
IsNoinline returns true for functions that should not be inlined. Ever.
func (*Func) LoadDirective ¶
LoadDirective parses function comment directive and updates function info correspondingly.
func (*Func) SetInlineable ¶
SetInlineable sets function inlineable flag to true or false.
type If ¶
If statement evaluates test expression and, depending on the result, one of the branches gets executed. Else branch is optional.
type LambdaCall ¶
LambdaCall is IIFE (Immediately Invoked Function Expression). Used for immediately invoked functions "func() {...}()" and inlining.
func (*LambdaCall) Copy ¶
func (call *LambdaCall) Copy() Form
func (*LambdaCall) Cost ¶
func (call *LambdaCall) Cost() int
func (*LambdaCall) Type ¶
func (call *LambdaCall) Type() types.Type
type Let ¶
type Let struct { Bindings []*Bind // Either of these two is set. // Let wraps expression OR statement. Expr Form Stmt Form }
Let introduces bindings that are visible to a statement or expression. Bindings are destroyed after wrapped form is evaluated.
type Local ¶
Local - reference to a local variable. Shadowing is possible with lexical variables, so Name alone is not enough to distinguish identity.
type Repeat ¶
Repeat is the simplest loop, it executes body N times.
Note that it is always unrolled. If unrolling is not optimal, optimizer should replace it with While.
type Return ¶
type Return struct{ Results []Form }
Return statement exits the function and returns one or more values to the caller.
type SliceIndex ¶
SliceIndex is slice index expression.
func (*SliceIndex) Copy ¶
func (form *SliceIndex) Copy() Form
func (*SliceIndex) Cost ¶
func (form *SliceIndex) Cost() int
func (*SliceIndex) Type ¶
func (form *SliceIndex) Type() types.Type
type SliceSlice ¶
SliceSlice = "Slice[Low:High]".
func NewSubslice ¶
func NewSubslice(slice, low, high Form) *SliceSlice
func (*SliceSlice) Copy ¶
func (form *SliceSlice) Copy() Form
func (*SliceSlice) Cost ¶
func (form *SliceSlice) Cost() int
func (*SliceSlice) Type ¶
func (form *SliceSlice) Type() types.Type
type SliceUpdate ¶
SliceUpdate is slice index expression with assignment.
func (*SliceUpdate) Copy ¶
func (form *SliceUpdate) Copy() Form
func (*SliceUpdate) Cost ¶
func (form *SliceUpdate) Cost() int
func (*SliceUpdate) Type ¶
func (form *SliceUpdate) Type() types.Type
type SparseArrayLit ¶
SparseArrayLit is like ArrayLit, but does not store zero values.
func (*SparseArrayLit) Copy ¶
func (lit *SparseArrayLit) Copy() Form
func (*SparseArrayLit) Cost ¶
func (lit *SparseArrayLit) Cost() int
func (*SparseArrayLit) Type ¶
func (lit *SparseArrayLit) Type() types.Type
type StructIndex ¶
StructIndex is struct selector expression.
func (*StructIndex) Copy ¶
func (form *StructIndex) Copy() Form
func (*StructIndex) Cost ¶
func (form *StructIndex) Cost() int
func (*StructIndex) Type ¶
func (form *StructIndex) Type() types.Type
type StructLit ¶
StructLit is an expression that yields struct object. Each struct member (field) has explicit initializer.
type StructUpdate ¶
StructUpdate = "Struct.[Index] = Expr".
func (*StructUpdate) Copy ¶
func (form *StructUpdate) Copy() Form
func (*StructUpdate) Cost ¶
func (form *StructUpdate) Cost() int
func (*StructUpdate) Type ¶
func (form *StructUpdate) Type() types.Type
type Switch ¶
type Switch struct { Expr Form SwitchBody }
Switch is "expression switch statement" defined by Go spec.
type SwitchBody ¶
type SwitchBody struct { Clauses []CaseClause DefaultBody Block // Can be EmptyBlock (no default clause) }
SwitchBody represents switch statement case sequence with optional default clause.
type SwitchTrue ¶
type SwitchTrue struct{ SwitchBody }
SwitchTrue is like Switch, but Expr is fixed to "true".
func (*SwitchTrue) Copy ¶
func (form *SwitchTrue) Copy() Form
func (*SwitchTrue) Cost ¶
func (form *SwitchTrue) Cost() int
func (*SwitchTrue) Type ¶
func (form *SwitchTrue) Type() types.Type
type TypeAssert ¶
TypeAssert coerces expression to specified type; panics on failure.
func (*TypeAssert) Copy ¶
func (form *TypeAssert) Copy() Form
func (*TypeAssert) Cost ¶
func (form *TypeAssert) Cost() int
func (*TypeAssert) Type ¶
func (form *TypeAssert) Type() types.Type