Documentation
¶
Overview ¶
Package program is the execution-owned IR: the identity every lowered record carries independent of the syntax tree, assigned by lower and read by executors.
Index ¶
- Constants
- func AliasRedefined(aliases map[string]string, redefined, name string) map[string]string
- func Canonical(aliases map[string]string, name string) string
- type Calc
- func (c *Calc) BodyScope() *symbols.Scope
- func (c *Calc) HasInitialOutput() bool
- func (c *Calc) HasParameter(name string) bool
- func (c *Calc) IsCase() bool
- func (c *Calc) OutputNames() string
- func (c *Calc) Parameter(name string) *CalcParam
- func (c *Calc) Performs() bool
- func (c *Calc) PositionalArity() int
- func (c *Calc) PositionalIndexes() []int
- func (c *Calc) ResultOutput() *CalcOutput
- func (c *Calc) ResultOutputIndex() int
- func (c *Calc) SubjectParameter() (*CalcParam, bool)
- func (c *Calc) UsageSpelling(output string) string
- type CalcMember
- type CalcOutput
- type CalcParam
- type EdgeID
- type Expr
- type ExprID
- type ExprKind
- type GraphID
- type NodeID
- type NodeKind
- type Operator
- type Origin
- type PseudoID
- type RegionID
- type Site
- type StateID
- type StmtID
- type SymbolRef
- type TransID
- type VertexKind
- type VertexRef
Constants ¶
const ResultOutputName = "result"
ResultOutputName is the name an unnamed result parameter answers to.
Variables ¶
This section is empty.
Functions ¶
func AliasRedefined ¶
AliasRedefined records that name now binds the feature redefined was known by. Aliases already pointing at redefined follow it to name.
Types ¶
type Calc ¶
type Calc struct {
Sym *symbols.Symbol
// Origin names the calc the way a message does: Path and Name are its
// qualified name, Kind the word diagnostics name the behavior by.
Origin Origin
// Name is the qualified name; Kind the behavior's keyword (`calc`, `analysis`,
// `verification`, a predicate's kind); Label is Kind then Name, as diagnostics say it.
Name string
Kind string
Label string
// Chain is the calcs the invoked one takes members from, most general first,
// then the invoked calc itself.
Chain []*symbols.Symbol
Params []CalcParam
// ParamNames are the Params' names by position: the slots an invocation binds.
ParamNames []string
// Aliases map the name of a parameter or output redeclared under a new name
// (`in g :>> x`) to that name, which an inherited body reads it by.
Aliases map[string]string
// Outputs are the calc's output features — its `out` parameters and the
// result parameter a `return` declares — in declaration order.
Outputs []CalcOutput
// BodyOwner is the calc whose body the invocation runs: the invoked calc's own
// when it states one, else the closest inherited body.
BodyOwner *symbols.Symbol
// BodyOutputs are the output features some statement of the body assigns on any
// path: a calc binding its outputs this way states a computation without returning.
BodyOutputs map[string]bool
// Result is the expression a binding connector binds to `result`, 0 when none.
Result ExprID
// Returns reports a body that returns a value on some path; StepsReturn says
// the same of its steps alone, the bindings of its outputs left out.
Returns bool
StepsReturn bool
// StepCount counts the action nodes a case's body performs as its steps.
StepCount int
// StatesFlow reports a body, or a loop or branch block of it, stating a token
// flow of its own: successions or control nodes among its members.
StatesFlow bool
// PerformsActions reports a body stating, at any depth, a step only a performance
// can take: a nested action or `perform`, an accept, or a terminate.
PerformsActions bool
// FlowBody reports the body itself stating that flow, lowered as a case body is:
// its statements are steps of the flow, not a list to order.
FlowBody bool
}
Calc is a calculation's lowered invocation interface: its positional inputs, its outputs and its result, each resolved across the specialization chain the usage inherits from.
func (*Calc) HasInitialOutput ¶
HasInitialOutput reports whether some output starts the body holding a value (`:=`), which the calc yields when the body leaves it as it is.
func (*Calc) HasParameter ¶
HasParameter reports whether the calc declares an input parameter of that name.
func (*Calc) IsCase ¶
IsCase reports whether the calc is a case — an analysis or a verification — rather than a plain calc.
func (*Calc) OutputNames ¶
OutputNames renders the output features the calc declares, for a diagnostic about one it does not.
func (*Calc) Performs ¶
Performs reports whether the body runs as a performance whose action nodes are its steps: a case's, and a calc's stating a token flow or a step of an action (SysML v2 §7.19.1).
func (*Calc) PositionalArity ¶
PositionalArity counts the parameters a positional argument can bind.
func (*Calc) PositionalIndexes ¶
PositionalIndexes are the indexes in Params a positional argument can bind, in declaration order: every parameter but the actors, which bind by name only.
func (*Calc) ResultOutput ¶
func (c *Calc) ResultOutput() *CalcOutput
ResultOutput returns the result parameter a `return` declares, if the calc has one.
func (*Calc) ResultOutputIndex ¶
ResultOutputIndex is the position in Outputs of the result parameter a `return` declares, -1 when the calc declares none.
func (*Calc) SubjectParameter ¶
SubjectParameter is the parameter the case's subject binds to, if it declares one.
func (*Calc) UsageSpelling ¶
UsageSpelling writes the calc usage a modeler declares to read the outputs of a calc that designates no result, with the inputs it has to bind.
type CalcMember ¶
CalcMember is one declaration of a parameter or output: the feature declared and the calc declaring it, under the name the declaration binds.
type CalcOutput ¶
type CalcOutput struct {
Name string // feature name the output answers to, empty for an anonymous result parameter
// Value is the value-binding expression, 0 when the calc gives the output no value.
Value ExprID
Owner *symbols.Symbol // the calc declaring the binding, whose scope it is written in
// Declarations are the output's declarations along the chain, most general first.
Declarations []CalcMember
IsResult bool // declared with `return`: the result an invocation of the calc yields
// IsInOut marks an `inout` parameter: an output feature (KerML 7.4.9) bound by
// the invocation rather than by a declaration or an assignment.
IsInOut bool
// IsInitial marks a value declared with `:=`: what the output holds when the
// body starts, which the body's assignments may then replace.
IsInitial bool
}
CalcOutput is one output feature of a calc — an `out` parameter, or the result parameter a `return` declares — read by name rather than run as a statement.
type CalcParam ¶
type CalcParam struct {
Name string // parameter name arguments bind to
// Default is the value-binding expression used when no argument is passed, 0 if none.
Default ExprID
Owner *symbols.Symbol // the calc that declares the default (a supertype for an inherited one)
Sym *symbols.Symbol // the parameter's own symbol, which its effective multiplicity is read off
// Declarations are the parameter's declarations along the chain, most general
// first: what a bound value answers to, the closest to the invoked calc winning.
Declarations []CalcMember
// IsSubject marks a case's subject parameter, the object the case is about.
IsSubject bool
// IsActor marks an actor parameter (SysML v2 §7.19.2, §7.24.2): bound by name
// like the subject, never by position, and left unvalued when nothing binds it.
IsActor bool
// IsCalc marks a calc usage parameter (`in calc f`), which a function value binds.
IsCalc bool
}
CalcParam is one input parameter of a calc, in positional order.
type Expr ¶
type Expr struct {
Kind ExprKind
// Op is the operator an ExprOp applies.
Op Operator
// Bracket marks an ExprIndex written `operand [unit]`, the quantity form.
Bracket bool
// Global marks an ExprRef whose name began with `$::`.
Global bool
// Receiver marks an ExprInvoke written `operand->F(args)`: its first argument is the operand.
Receiver bool
// Applied marks an ExprInvoke written `operand.f(args)`: Args begin with the
// chain applied and then the operand its last member is read from.
Applied bool
// Origin is where the expression was written.
Origin Site
// Args are an operator's operands, a sequence's elements, an index's operand then index, a chain's
// first operand, a collect's or select's operand then body, a call's or construction's arguments.
Args []ExprID
// Named are the labels of the arguments written `name = value`, which are the
// last len(Named) of Args.
Named []SymbolRef
// Ref is what an ExprRef names, the type an ExprOp classifies or casts by, and
// the name an ExprInvoke, ExprConstruct or ExprMetadata is written with.
Ref SymbolRef
// Path is the segments of an ExprRef or ExprInvoke written as a qualified name, an ExprRef's
// each with the element the name reaches there; nil for a simple name.
Path []SymbolRef
// Chain is the members an ExprChain reads after its operand, in order.
Chain []SymbolRef
// Params are the parameters an ExprBody declares, in order, by name.
Params []SymbolRef
// Result is what an ExprBody answers, lowered in the scope of its parameters; 0 for none.
Result ExprID
// Locals counts the members an ExprBody declares besides its parameters and result.
Locals int
// Const is the constant a literal spells; its Kind is invalid for a numeric
// literal whose spelling is none or exceeds the default size budget.
Const semantics.Value
// Text is a numeric literal as written, and an ExprString's decoded text.
Text string
}
Expr is one lowered expression: its kind and, by kind, its operands, the names it reads as lowering resolved them, or the constant it spells.
type ExprID ¶
type ExprID uint32
ExprID indexes an expression, shared by the action, state machine and calculation graphs.
type ExprKind ¶
type ExprKind uint8
ExprKind is what an expression is, which the evaluators switch on.
const ( // ExprNone is the zero kind: syntax no expression kind covers. ExprNone ExprKind = iota // ExprInt is an Integer literal, `42`. ExprInt // ExprReal is a decimal literal, `0.1`, read as the exact Rational it denotes. ExprReal // ExprBool is `true` or `false`. ExprBool // ExprString is a string literal. ExprString // ExprInfinity is `*` in expression position. ExprInfinity // ExprNull is `null` or `()`. ExprNull // ExprRef is a name read as what it names, `rate` or `A::B::x`. ExprRef // ExprChain is one read from an operand through every member in turn, `a.b.c`. ExprChain // ExprOp is an operator applied to its operands. ExprOp // ExprSequence is `(a, b, c)`. ExprSequence // ExprIndex is `seq#(i)` or the quantity form `magnitude [unit]`. ExprIndex // ExprCollect is `seq.{body}`. ExprCollect // ExprSelect is `seq.?{body}`. ExprSelect // ExprInvoke is `F(args)`, `operand->F(args)` or `operand.f(args)`. ExprInvoke // ExprConstruct is `new T(args)`. ExprConstruct // ExprBody is a body expression, `{ in x; x + 1 }`. ExprBody // ExprMetadata is `ref.metadata`. ExprMetadata )
type GraphID ¶
type GraphID [16]byte
GraphID is the digest of a graph's canonical encoding, the same for two lowerings of one model; its encoder is not written yet, and a zero GraphID is "not computed".
type NodeKind ¶
type NodeKind uint8
NodeKind is what a node of an action graph does when a token reaches it.
const ( // NodeNone is the zero kind, carried by no node. NodeNone NodeKind = iota // NodeInitial is the flow's entry, `first start`. NodeInitial // NodeFinal is a node the flow ends at, `done`. NodeFinal // NodeFork splits a token across every outgoing succession. NodeFork // NodeJoin waits for a token on every incoming succession. NodeJoin // NodeMerge passes a token on from any incoming succession. NodeMerge // NodeDecision chooses one guarded outgoing succession. NodeDecision // NodeExecution runs a nested action, `action a { ... }`. NodeExecution // NodePerform performs a referenced action, `perform action a`. NodePerform // NodeAccept waits for an event, `accept e`. NodeAccept // NodeSend dispatches an event, `send e to t`. NodeSend // NodeAssign writes a feature, `assign x := e`. NodeAssign // NodeTerminate ends the enclosing behavior, `terminate`. NodeTerminate // NodeIf branches on a condition, `if c { ... }`. NodeIf // NodeLoop repeats a body, `while c { ... }` and `for i in s { ... }`. NodeLoop // NodeBlock runs a body-local block of nodes. NodeBlock // NodeStatement runs the statements written between two nodes of a block as one step. NodeStatement )
type Operator ¶
type Operator uint8
Operator is an operator of the expression ladder, whatever its arity.
const ( OpInvalid Operator = iota OpConditional // if C ? A else B OpNullCoalesce // ?? OpImplies // implies OpOr // | OpConditionalOr // or OpXor // xor OpAnd // & OpConditionalAnd // and OpEq // == OpNeq // != OpEqEqEq // === OpNeqEqEq // !== OpHasType // hastype OpIsType // istype OpAt // @ OpMetaAt // @@ OpAs // as OpMeta // meta OpLt // < OpGt // > OpLe // <= OpGe // >= OpRange // .. OpAdd // + OpSub // - OpMul // * OpDiv // / OpMod // % OpPow // ** or ^ OpNeg // unary - OpPos // unary + OpBitNot // unary ~ OpNot // unary not OpAll // extent: all OpIndex // [ ... ] )
type Origin ¶
type Origin struct {
// Doc is the name of the document the declaration was written in, "" outside any.
Doc string
// Span is the declaration's extent in Doc.
Span source.Span
// Path is unique within the graph: the declaration's qualified name, else its
// owner's and its position among the owner's unnamed members of its kind (`A#if[2]`).
Path string
// Element is the declaration's element id when one is known, else "".
Element string
// Kind is the word a message names the declaration by when it is unnamed: an
// action node's NodeKind.Word (`if action`), a vertex's `state` or `pseudostate`.
Kind string
// Name is the declaration's name as messages use it, "" when it has none.
Name string
// Docs is the declaration's documentation prose; "" when it has none or the lowering read no source text.
Docs string
}
Origin is where a lowered record came from, as plain data: what a message, a trace or a hover says about it once the syntax tree is gone.
type Site ¶
type Site struct {
// Doc is the name of the document the expression was written in, "" outside any.
Doc string
// Span is the expression's extent in Doc.
Span source.Span
}
Site is where an expression was written: an expression is named by its text, so it carries none of what an Origin says of a declaration.
type SymbolRef ¶
type SymbolRef struct {
Sym *symbols.Symbol
// Name is the name as written, which a run resolves by where Sym is nil.
Name string
Span source.Span
}
SymbolRef is a name as lowering resolved it: the element it denotes in the scope the expression was lowered in, nil where only a run can tell.
type VertexKind ¶
type VertexKind uint8
VertexKind tells which table of a state graph a VertexRef indexes.
const ( VertexNone VertexKind = iota VertexState VertexPseudostate VertexTerminate )
func (VertexKind) String ¶
func (k VertexKind) String() string
String spells the kind the way messages name vertices.
type VertexRef ¶
type VertexRef struct {
Kind VertexKind
Index uint32
}
VertexRef names a vertex of a lowered state graph: a StateID, a PseudoID or a terminate action's 1-based ordinal in the graph's terminate table; the zero VertexRef names no vertex.
func PseudoVertex ¶
PseudoVertex refers to the pseudostate id, or to no vertex when id is 0.
func StateVertex ¶
StateVertex refers to the state id, or to no vertex when id is 0.
func TerminateVertex ¶
TerminateVertex refers to the terminate action at ordinal, or to no vertex when ordinal is 0.
func (VertexRef) Pseudo ¶
Pseudo is the pseudostate the reference names, 0 when it names another kind of vertex.