Documentation
¶
Index ¶
- Constants
- type Arg
- type Assert
- type Assign
- type Const
- type Effect
- type Expr
- func (n *Expr) Args() []*Node
- func (n *Expr) AsNode() *Node
- func (n *Expr) ConstValue() *big.Int
- func (n *Expr) Effect() Effect
- func (n *Expr) Eq(o *Expr) bool
- func (n *Expr) GlobalIdent() bool
- func (n *Expr) Ident() t.ID
- func (n *Expr) LHS() *Node
- func (n *Expr) MBounds() interval.IntRange
- func (n *Expr) MHS() *Node
- func (n *Expr) MType() *TypeExpr
- func (n *Expr) Mentions(o *Expr) bool
- func (n *Expr) Operator() t.ID
- func (n *Expr) RHS() *Node
- func (n *Expr) SetConstValue(x *big.Int)
- func (n *Expr) SetGlobalIdent()
- func (n *Expr) SetMBounds(x interval.IntRange)
- func (n *Expr) SetMType(x *TypeExpr)
- func (n *Expr) StatusQID() t.QID
- func (n *Expr) Str(tm *t.Map) string
- func (n *Expr) SubExprHasEffect() bool
- type Field
- type File
- type Flags
- type Func
- func (n *Func) AsNode() *Node
- func (n *Func) Asserts() []*Node
- func (n *Func) Body() []*Node
- func (n *Func) Effect() Effect
- func (n *Func) Filename() string
- func (n *Func) FuncName() t.ID
- func (n *Func) In() *Struct
- func (n *Func) Line() uint32
- func (n *Func) Out() *TypeExpr
- func (n *Func) Public() bool
- func (n *Func) QQID() t.QQID
- func (n *Func) Receiver() t.QID
- type IOBind
- type If
- type Iterate
- func (n *Iterate) AsNode() *Node
- func (n *Iterate) Asserts() []*Node
- func (n *Iterate) Assigns() []*Node
- func (n *Iterate) Body() []*Node
- func (n *Iterate) ElseIterate() *Iterate
- func (n *Iterate) HasBreak() bool
- func (n *Iterate) HasContinue() bool
- func (n *Iterate) Label() t.ID
- func (n *Iterate) Length() t.ID
- func (n *Iterate) SetHasBreak()
- func (n *Iterate) SetHasContinue()
- func (n *Iterate) Unroll() t.ID
- type Jump
- type Kind
- type Loop
- type Node
- func (n *Node) AsArg() *Arg
- func (n *Node) AsAssert() *Assert
- func (n *Node) AsAssign() *Assign
- func (n *Node) AsConst() *Const
- func (n *Node) AsExpr() *Expr
- func (n *Node) AsField() *Field
- func (n *Node) AsFile() *File
- func (n *Node) AsFunc() *Func
- func (n *Node) AsIOBind() *IOBind
- func (n *Node) AsIf() *If
- func (n *Node) AsIterate() *Iterate
- func (n *Node) AsJump() *Jump
- func (n *Node) AsRaw() *Raw
- func (n *Node) AsRet() *Ret
- func (n *Node) AsStatus() *Status
- func (n *Node) AsStruct() *Struct
- func (n *Node) AsTypeExpr() *TypeExpr
- func (n *Node) AsUse() *Use
- func (n *Node) AsVar() *Var
- func (n *Node) AsWhile() *While
- func (n *Node) Kind() Kind
- func (n *Node) MBounds() interval.IntRange
- func (n *Node) MType() *TypeExpr
- func (n *Node) SetMBounds(x interval.IntRange)
- func (n *Node) SetMType(x *TypeExpr)
- func (n *Node) Walk(f func(*Node) error) error
- type Raw
- type Ret
- type Status
- type Struct
- type TypeExpr
- func (n *TypeExpr) ArrayLength() *Expr
- func (n *TypeExpr) AsNode() *Node
- func (n *TypeExpr) Bounds() [2]*Expr
- func (n *TypeExpr) Decorator() t.ID
- func (n *TypeExpr) Eq(o *TypeExpr) bool
- func (n *TypeExpr) EqIgnoringRefinements(o *TypeExpr) bool
- func (n *TypeExpr) FuncName() t.ID
- func (n *TypeExpr) HasPointers() bool
- func (n *TypeExpr) Inner() *TypeExpr
- func (n *TypeExpr) Innermost() *TypeExpr
- func (n *TypeExpr) IsArrayType() bool
- func (n *TypeExpr) IsBool() bool
- func (n *TypeExpr) IsIOType() bool
- func (n *TypeExpr) IsIdeal() bool
- func (n *TypeExpr) IsNullptr() bool
- func (n *TypeExpr) IsNumType() bool
- func (n *TypeExpr) IsNumTypeOrIdeal() bool
- func (n *TypeExpr) IsPointerType() bool
- func (n *TypeExpr) IsRefined() bool
- func (n *TypeExpr) IsSliceType() bool
- func (n *TypeExpr) IsStatus() bool
- func (n *TypeExpr) IsTableType() bool
- func (n *TypeExpr) IsUnsignedInteger() bool
- func (n *TypeExpr) Max() *Expr
- func (n *TypeExpr) Min() *Expr
- func (n *TypeExpr) Pointee() *TypeExpr
- func (n *TypeExpr) QID() t.QID
- func (n *TypeExpr) Receiver() *TypeExpr
- func (n *TypeExpr) Str(tm *t.Map) string
- func (n *TypeExpr) Unrefined() *TypeExpr
- type Use
- type Var
- type While
Constants ¶
const ( KInvalid = Kind(iota) KArg KAssert KAssign KConst KExpr KField KFile KFunc KIOBind KIf KIterate KJump KRet KStatus KStruct KTypeExpr KUse KVar KWhile )
const ( FlagsPublic = Flags(0x00000100) FlagsHasBreak = Flags(0x00000200) FlagsHasContinue = Flags(0x00000400) FlagsGlobalIdent = Flags(0x00000800) FlagsClassy = Flags(0x00001000) FlagsSubExprHasEffect = Flags(0x00002000) FlagsRetsError = Flags(0x00004000) FlagsPrivateData = Flags(0x00008000) )
const ( EffectPure = Effect(0) EffectImpure = Effect(effectBitImpure) EffectImpureCoroutine = Effect(effectBitImpure | effectBitCoroutine) )
const MaxBodyDepth = 255
MaxBodyDepth is an advisory limit for a function body's recursion depth.
const MaxExprDepth = 255
MaxExprDepth is an advisory limit for an Expr's recursion depth.
const MaxTypeExprDepth = 63
MaxTypeExprDepth is an advisory limit for a TypeExpr's recursion depth.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Assert ¶
type Assert Node
Assert is "assert RHS via ID2(args)", "pre etc", "inv etc" or "post etc":
- ID0: <IDAssert|IDPre|IDInv|IDPost>
- ID2: <string literal> reason
- RHS: <Expr>
- List0: <Arg> reason arguments
type Assign ¶
type Assign Node
Assign is "LHS = RHS" or "LHS op= RHS" or "RHS":
- ID0: operator
- LHS: <nil|Expr>
- RHS: <Expr>
type Const ¶
type Const Node
Const is "const ID2 LHS = RHS":
- FlagsPublic is "pub" vs "pri"
- ID1: <0|pkg> (set by calling SetPackage)
- ID2: name
- LHS: <TypeExpr>
- RHS: <Expr>
type Expr ¶
type Expr Node
Expr is an expression, such as "i", "+j" or "k + l[m(n, o)].p":
- ID0: <0|operator|IDOpenParen|IDOpenBracket|IDDotDot|IDDot>
- ID1: <0|pkg> (for statuses)
- ID2: <0|literal|ident>
- LHS: <nil|Expr>
- MHS: <nil|Expr>
- RHS: <nil|Expr|TypeExpr>
- List0: <Arg|Expr> function call args, assoc. op args or list members.
A zero ID0 means an identifier or literal in ID2, like `foo`, `42` or a status literal like `"#foo"` or `pkg."$bar"`. For status literals, ID1 is the package.
For unary operators, ID0 is the operator and RHS is the operand.
For binary operators, ID0 is the operator and LHS and RHS are the operands.
For associative operators, ID0 is the operator and List0 holds the operands.
The ID0 operator is in disambiguous form. For example, IDXUnaryPlus, IDXBinaryPlus or IDXAssociativePlus, not a bare IDPlus.
For function calls, like "LHS(List0)", ID0 is IDOpenParen.
For indexes, like "LHS[RHS]", ID0 is IDOpenBracket.
For slices, like "LHS[MHS .. RHS]", ID0 is IDDotDot.
For selectors, like "LHS.ID2", ID0 is IDDot.
For lists, like "[0, 1, 2]", ID0 is IDComma.
func (*Expr) ConstValue ¶
func (*Expr) Eq ¶
Eq returns whether n and o are equal.
It may return false negatives. In general, it will not report that "x + y" equals "y + x". However, if both are constant expressions (i.e. each Expr node, including the sum nodes, has a ConstValue), both sums will have the same value and will compare equal.
func (*Expr) GlobalIdent ¶
func (*Expr) SetConstValue ¶
func (*Expr) SetGlobalIdent ¶
func (n *Expr) SetGlobalIdent()
func (*Expr) SetMBounds ¶ added in v0.2.0
func (*Expr) SubExprHasEffect ¶ added in v0.2.0
type Field ¶
type Field Node
Field is a "name : type" struct field:
- FlagsPrivateData is the initializer need not explicitly memset to zero.
- ID2: name
- LHS: <TypeExpr>
func (*Field) PrivateData ¶ added in v0.2.0
type File ¶
type File Node
File is a file of source code:
- List0: <Const|Func|Status|Struct|Use> top-level declarations
func (*File) TopLevelDecls ¶
type Func ¶
type Func Node
Func is "func ID2.ID0(LHS)(RHS) { List2 }":
- FlagsPublic is "pub" vs "pri"
- ID0: funcName
- ID1: <0|receiverPkg> (set by calling SetPackage)
- ID2: <0|receiverName>
- LHS: <Struct> in-parameters
- RHS: <Struct> out-parameters
- List1: <Assert> asserts
- List2: <Statement> body
Statement means one of:
- Assert
- Assign
- IOBind
- If
- Iterate
- Jump
- Ret
- Var
- While
type IOBind ¶ added in v0.2.0
type IOBind Node
IOBind is "io_bind (io:LHS, data:MHS) { List2 }" or "io_limit (io:LHS, limit:MHS) { List2 }":
- ID0: <IDIOBind|IDIOLimit>
- LHS: <Expr>
- MHS: <Expr>
- List2: <Statement> body
type If ¶
type If Node
If is "if MHS { List2 } else RHS" or "if MHS { List2 } else { List1 }":
- MHS: <Expr>
- RHS: <nil|If>
- List1: <Statement> if-false body
- List2: <Statement> if-true body
func (*If) BodyIfFalse ¶
func (*If) BodyIfTrue ¶
type Iterate ¶
type Iterate Node
Iterate is "iterate.ID1 (assigns)(length:ID2, unroll:ID0), List1 { List2 } else RHS":
- FlagsHasBreak is the iterate has an explicit break
- FlagsHasContinue is the iterate has an explicit continue
- ID0: unroll
- ID1: <0|label>
- ID2: length
- RHS: <nil|Iterate>
- List0: <Assign> assigns
- List1: <Assert> asserts
- List2: <Statement> body
func NewIterate ¶
func (*Iterate) ElseIterate ¶ added in v0.2.0
func (*Iterate) HasContinue ¶
func (*Iterate) SetHasBreak ¶
func (n *Iterate) SetHasBreak()
func (*Iterate) SetHasContinue ¶
func (n *Iterate) SetHasContinue()
type Jump ¶
type Jump Node
Jump is "break" or "continue", with an optional label, "break.label":
- ID0: <IDBreak|IDContinue>
- ID1: <0|label>
func (*Jump) JumpTarget ¶
func (*Jump) SetJumpTarget ¶
type Kind ¶
type Kind uint32
Kind is what kind of node it is. For example, a top-level func or a numeric constant. Kind is different from Type; the latter is used for type-checking in the programming language sense.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
func (*Node) AsTypeExpr ¶ added in v0.2.0
func (*Node) SetMBounds ¶ added in v0.2.0
type Ret ¶ added in v0.2.0
type Ret Node
Ret is "return LHS" or "yield LHS":
- FlagsReturnsError LHS is an error status
- ID0: <IDReturn|IDYield>
- LHS: <Expr>
func (*Ret) SetRetsError ¶ added in v0.2.0
func (n *Ret) SetRetsError()
type Status ¶
type Status Node
Status is "error (RHS) ID2" or "suspension (RHS) ID2":
- FlagsPublic is "pub" vs "pri"
- ID1: <0|pkg> (set by calling SetPackage)
- ID2: message
type Struct ¶
type Struct Node
Struct is "struct ID2(List0)" or "struct ID2?(List0)":
- FlagsPublic is "pub" vs "pri"
- FlagsClassy is "ID2" vs "ID2?"
- ID1: <0|pkg> (set by calling SetPackage)
- ID2: name
- List0: <Field> fields
The question mark indicates a classy struct - one that supports methods, especially coroutines.
func TopologicalSortStructs ¶
type TypeExpr ¶
type TypeExpr Node
TypeExpr is a type expression, such as "base.u32", "base.u32[..= 8]", "foo", "pkg.bar", "ptr T", "array[8] T", "slice T" or "table T":
- ID0: <0|IDArray|IDFunc|IDNptr|IDPtr|IDSlice|IDTable>
- ID1: <0|pkg>
- ID2: <0|type name>
- LHS: <nil|Expr>
- MHS: <nil|Expr>
- RHS: <nil|TypeExpr>
An IDNptr or IDPtr ID0 means "nptr RHS" or "ptr RHS". RHS is the inner type.
An IDArray ID0 means "array[LHS] RHS". RHS is the inner type.
An IDSlice ID0 means "slice RHS". RHS is the inner type.
An IDTable ID0 means "table RHS". RHS is the inner type.
An IDFunc ID0 means "func ID2" or "func (LHS).ID2", a function or method type. LHS is the receiver type, which may be nil. If non-nil, it will be a pointee type: "T" instead of "ptr T", "ptr ptr T", etc.
TODO: method effects: "foo" vs "foo!" vs "foo?".
A zero ID0 means a (possibly package-qualified) type like "pkg.foo" or "foo". ID1 is the "pkg" or zero, ID2 is the "foo".
Numeric types can be refined as "foo[LHS ..= MHS]". LHS and MHS are Expr's, possibly nil. For example, the LHS for "base.u32[..= 4095]" is nil.
TODO: struct types, list types, nptr vs ptr.
func NewTypeExpr ¶
func (*TypeExpr) ArrayLength ¶
func (*TypeExpr) EqIgnoringRefinements ¶
EqIgnoringRefinements returns whether n and o are equal, ignoring the "[i:j]" in "base.u32[i:j]".
func (*TypeExpr) HasPointers ¶
func (*TypeExpr) IsArrayType ¶ added in v0.2.0
func (*TypeExpr) IsNumTypeOrIdeal ¶
func (*TypeExpr) IsPointerType ¶ added in v0.2.0
func (*TypeExpr) IsSliceType ¶ added in v0.2.0
func (*TypeExpr) IsTableType ¶ added in v0.2.0
func (*TypeExpr) IsUnsignedInteger ¶
type While ¶
type While Node
While is "while.ID1 MHS, List1 { List2 }":
- FlagsHasBreak is the while has an explicit break
- FlagsHasContinue is the while has an explicit continue
- ID1: <0|label>
- MHS: <Expr>
- List1: <Assert> asserts
- List2: <Statement> body
TODO: should we be able to unroll while loops too?
func (*While) HasContinue ¶
func (*While) SetHasBreak ¶
func (n *While) SetHasBreak()
func (*While) SetHasContinue ¶
func (n *While) SetHasContinue()