Documentation
¶
Index ¶
- Constants
- type Arg
- type Assert
- type Assign
- type Const
- type Expr
- func (n *Expr) Args() []*Node
- func (n *Expr) BoundsCheckOptimized() bool
- func (n *Expr) CallImpure() bool
- func (n *Expr) CallSuspendible() bool
- func (n *Expr) ConstValue() *big.Int
- func (n *Expr) Eq(o *Expr) bool
- func (n *Expr) GlobalIdent() bool
- func (n *Expr) ID0() t.ID
- func (n *Expr) ID1() t.ID
- func (n *Expr) Impure() bool
- func (n *Expr) LHS() *Node
- func (n *Expr) MHS() *Node
- func (n *Expr) MType() *TypeExpr
- func (n *Expr) Mentions(o *Expr) bool
- func (n *Expr) Node() *Node
- func (n *Expr) ProvenNotToSuspend() bool
- func (n *Expr) Pure() bool
- func (n *Expr) RHS() *Node
- func (n *Expr) SetBoundsCheckOptimized()
- func (n *Expr) SetConstValue(x *big.Int)
- func (n *Expr) SetGlobalIdent()
- func (n *Expr) SetMType(x *TypeExpr)
- func (n *Expr) SetProvenNotToSuspend()
- func (n *Expr) String(tm *t.Map) string
- func (n *Expr) Suspendible() bool
- type Field
- type File
- type Flags
- type Func
- func (n *Func) Asserts() []*Node
- func (n *Func) Body() []*Node
- func (n *Func) Filename() string
- func (n *Func) Impure() bool
- func (n *Func) In() *Struct
- func (n *Func) Line() uint32
- func (n *Func) Name() t.ID
- func (n *Func) Node() *Node
- func (n *Func) Out() *Struct
- func (n *Func) Public() bool
- func (n *Func) Pure() bool
- func (n *Func) QID() t.QID
- func (n *Func) Receiver() t.ID
- func (n *Func) Suspendible() bool
- type If
- type Iterate
- func (n *Iterate) Asserts() []*Node
- func (n *Iterate) Body() []*Node
- func (n *Iterate) HasBreak() bool
- func (n *Iterate) HasContinue() bool
- func (n *Iterate) Label() t.ID
- func (n *Iterate) Node() *Node
- func (n *Iterate) SetHasBreak()
- func (n *Iterate) SetHasContinue()
- func (n *Iterate) UnrollCount() *Expr
- func (n *Iterate) Variables() []*Node
- type Jump
- type Kind
- type Loop
- type Node
- func (n *Node) Arg() *Arg
- func (n *Node) Assert() *Assert
- func (n *Node) Assign() *Assign
- func (n *Node) Const() *Const
- func (n *Node) Expr() *Expr
- func (n *Node) Field() *Field
- func (n *Node) File() *File
- func (n *Node) Func() *Func
- func (n *Node) If() *If
- func (n *Node) Iterate() *Iterate
- func (n *Node) Jump() *Jump
- func (n *Node) Kind() Kind
- func (n *Node) PackageID() *PackageID
- func (n *Node) Raw() *Raw
- func (n *Node) Return() *Return
- func (n *Node) SetTypeChecked()
- func (n *Node) Status() *Status
- func (n *Node) Struct() *Struct
- func (n *Node) TypeChecked() bool
- func (n *Node) TypeExpr() *TypeExpr
- func (n *Node) Use() *Use
- func (n *Node) Var() *Var
- func (n *Node) Walk(f func(*Node) error) error
- func (n *Node) While() *While
- type PackageID
- type Raw
- func (n *Raw) ConstValue() *big.Int
- func (n *Raw) Filename() string
- func (n *Raw) FilenameLine() (string, uint32)
- func (n *Raw) Flags() Flags
- func (n *Raw) ID0() t.ID
- func (n *Raw) ID1() t.ID
- func (n *Raw) Kind() Kind
- func (n *Raw) LHS() *Node
- func (n *Raw) Line() uint32
- func (n *Raw) List0() []*Node
- func (n *Raw) List1() []*Node
- func (n *Raw) List2() []*Node
- func (n *Raw) MHS() *Node
- func (n *Raw) MType() *TypeExpr
- func (n *Raw) Node() *Node
- func (n *Raw) QID() t.QID
- func (n *Raw) RHS() *Node
- func (n *Raw) SetFilenameLine(f string, l uint32)
- func (n *Raw) SubLists() [3][]*Node
- func (n *Raw) SubNodes() [3]*Node
- type Return
- type Status
- type Struct
- type TypeExpr
- func (n *TypeExpr) ArrayLength() *Expr
- 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) HasPointers() bool
- func (n *TypeExpr) Inner() *TypeExpr
- func (n *TypeExpr) Innermost() *TypeExpr
- func (n *TypeExpr) IsBool() bool
- func (n *TypeExpr) IsIdeal() bool
- func (n *TypeExpr) IsNumType() bool
- func (n *TypeExpr) IsNumTypeOrIdeal() bool
- func (n *TypeExpr) IsRefined() bool
- func (n *TypeExpr) IsUnsignedInteger() bool
- func (n *TypeExpr) Max() *Expr
- func (n *TypeExpr) Min() *Expr
- func (n *TypeExpr) Name() t.ID
- func (n *TypeExpr) Node() *Node
- func (n *TypeExpr) String(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 KIf KIterate KJump KPackageID KReturn KStatus KStruct KTypeExpr KUse KVar KWhile )
const ( FlagsImpure = Flags(0x00000001) FlagsSuspendible = Flags(0x00000002) FlagsCallImpure = Flags(0x00000004) FlagsCallSuspendible = Flags(0x00000008) FlagsPublic = Flags(0x00000010) FlagsTypeChecked = Flags(0x00000020) FlagsHasBreak = Flags(0x00000040) FlagsHasContinue = Flags(0x00000080) FlagsGlobalIdent = Flags(0x00000100) )
const ( // FlagsProvenNotToSuspend notes that a method such as read_u8 or // write_u16le is proven not to suspend. For example, if it's guaranteed // that there enough buffer space for an I/O method to succeed. // // Some methods, such as unread_u8, are called with the question mark, as // "r.unread_u8?()", so nominally can suspend, but their semantics also // guarantee to either succeed or fail, never suspend and retry later. FlagsProvenNotToSuspend = Flags(0x00010000) // FlagsBoundsCheckOptimized similarly means that some code gen's run time // bounds checks or null pointer checks can be skipped, although such // methods are not called with the question mark. Specifically, those // methods are: // - since_mark FlagsBoundsCheckOptimized = Flags(0x00020000) )
These flags are set by the bounds checker to generate optimized code.
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 ID1(args)", "pre etc", "inv etc" or "post etc":
- ID0: <IDAssert|IDPre|IDInv|IDPost>
- ID1: <string literal> reason
- RHS: <Expr>
- List0: <Arg> reason arguments
type Assign ¶
type Assign Node
Assign is "LHS = RHS" or "LHS op= RHS":
- ID0: operator
- LHS: <Expr>
- RHS: <Expr>
type Const ¶
type Const Node
Const is "const ID1 LHS = RHS":
- FlagsPublic is "pub" vs "pri"
- ID1: 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":
- FlagsImpure is if it or a sub-expr is FlagsCallImpure
- FlagsSuspendible is if it or a sub-expr is FlagsCallSuspendible
- FlagsCallImpure is "f(x)" vs "f!(x)"
- FlagsCallSuspendible is "f(x)" vs "f?(x)", it implies FlagsCallImpure
- ID0: <0|operator|IDOpenParen|IDOpenBracket|IDColon|IDDot>
- ID1: <0|ident|literal>
- 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 ID1, like "foo" or "42".
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 try/function calls, like "try LHS(List0)", ID0 is IDTry.
For indexes, like "LHS[RHS]", ID0 is IDOpenBracket.
For slices, like "LHS[MHS:RHS]", ID0 is IDColon.
For selectors, like "LHS.ID1", ID0 is IDDot.
For lists, like "$(0, 1, 2)", ID0 is IDDollar.
For statuses, like `error "foo"` and `"suspension "bar"`, ID0 is the keyword and ID1 is the message.
func (*Expr) BoundsCheckOptimized ¶
func (*Expr) CallImpure ¶
func (*Expr) CallSuspendible ¶
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) ProvenNotToSuspend ¶
func (*Expr) SetBoundsCheckOptimized ¶
func (n *Expr) SetBoundsCheckOptimized()
func (*Expr) SetConstValue ¶
func (*Expr) SetGlobalIdent ¶
func (n *Expr) SetGlobalIdent()
func (*Expr) SetProvenNotToSuspend ¶
func (n *Expr) SetProvenNotToSuspend()
func (*Expr) Suspendible ¶
type Field ¶
type Field Node
Field is a "name type = default_value" struct field:
- ID1: name
- LHS: <TypeExpr>
- RHS: <nil|Expr>
func (*Field) DefaultValue ¶
type File ¶
type File Node
File is a file of source code:
- List0: <Func|PackageID|Status|Struct|Use> top-level declarations
func (*File) TopLevelDecls ¶
type Func ¶
type Func Node
Func is "func ID0.ID1(LHS)(RHS) { List2 }":
- FlagsImpure is "ID1" vs "ID1!"
- FlagsSuspendible is "ID1" vs "ID1?", it implies FlagsImpure
- FlagsPublic is "pub" vs "pri"
- ID0: <0|receiver>
- ID1: name
- LHS: <Struct> in-parameters
- RHS: <Struct> out-parameters
- List1: <Assert> asserts
- List2: <Statement> function body
Statement means one of:
- Assert
- Assign
- Expr
- If
- Iterate
- Jump
- Return
- Var
- While
func (*Func) Suspendible ¶
type If ¶
type If Node
If is "if MHS { List0 } else RHS" or "if MHS { List0 } else { List1 }":
- MHS: <Expr>
- RHS: <nil|If>
- List0: <Statement> if-true body
- List1: <Statement> if-false body
func (*If) BodyIfFalse ¶
func (*If) BodyIfTrue ¶
type Iterate ¶
type Iterate Node
Iterate is "iterate.LHS:ID1 (vars), List1 { List2 }":
- FlagsHasBreak is the iterate has an explicit break
- FlagsHasContinue is the iterate has an explicit continue
- ID1: <0|label>
- List0: <Var> variables
- List1: <Assert> asserts
- List2: <Statement> loop body
func NewIterate ¶
func (*Iterate) HasContinue ¶
func (*Iterate) SetHasBreak ¶
func (n *Iterate) SetHasBreak()
func (*Iterate) SetHasContinue ¶
func (n *Iterate) SetHasContinue()
func (*Iterate) UnrollCount ¶
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) SetTypeChecked ¶
func (n *Node) SetTypeChecked()
func (*Node) TypeChecked ¶
type Raw ¶
type Raw Node
func (*Raw) ConstValue ¶
func (*Raw) FilenameLine ¶
func (*Raw) SetFilenameLine ¶
type Status ¶
type Status Node
Status is "error ID1" or "suspension ID1":
- FlagsPublic is "pub" vs "pri"
- ID0: <IDError|IDSuspension>
- ID1: message
type Struct ¶
type Struct Node
Struct is "struct ID1(List0)":
- FlagsSuspendible is "ID1" vs "ID1?"
- FlagsPublic is "pub" vs "pri"
- ID1: name
- List0: <Field> fields
func TopologicalSortStructs ¶
func (*Struct) Suspendible ¶
type TypeExpr ¶
type TypeExpr Node
TypeExpr is a type expression, such as "u32", "u32[..8]", "pkg.foo", "ptr T", "[8] T" or "[] T":
- ID0: <0|package name|IDPtr|IDOpenBracket|IDColon>
- ID1: <0|type name>
- LHS: <nil|Expr>
- MHS: <nil|Expr>
- RHS: <nil|TypeExpr>
An IDPtr ID0 means "ptr RHS". RHS is the inner type.
An IDOpenBracket ID0 means "[LHS] RHS". RHS is the inner type.
An IDColon ID0 means "[] RHS". RHS is the inner type.
Other ID0 values mean a (possibly package-qualified) type like "pkg.foo" or "foo". ID0 is the "pkg" or zero, ID1 is the "foo". Such a type can be refined as "foo[LHS..MHS]". LHS and MHS are Expr's, possibly nil. For example, the LHS for "u32[..4095]" is nil.
TODO: function / method types, struct types, list types.
func NewTypeExpr ¶
func (*TypeExpr) ArrayLength ¶
func (*TypeExpr) EqIgnoringRefinements ¶
EqIgnoringRefinements returns whether n and o are equal, ignoring the "[i:j]" in "u32[i:j]".
func (*TypeExpr) HasPointers ¶
func (*TypeExpr) IsNumTypeOrIdeal ¶
func (*TypeExpr) IsUnsignedInteger ¶
type Var ¶
type Var Node
Var is "var ID1 LHS" or "var ID1 LHS = RHS" or an iterate variable declaration "ID1 LHS : RHS":
- ID0: <0|IDEq|IDColon>
- ID1: name
- LHS: <TypeExpr>
- RHS: <nil|Expr>
func (*Var) IterateVariable ¶
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> loop 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()