local protocol
The behavior of one component, written as one ordered sequence of statements.
component Radar;
component CommandPost;
message struct TrackReport {
track_id: uint32;
}
message struct Ack {
track_id: uint32;
}
local protocol Sweep in Radar {
send any TrackReport to CommandPost;
recv _: Ack from CommandPost;
}Statements
local protocol P in C says that P runs in component C. The name is a global declaration, and C
names a component. The body is a sequence of statements, executed in order:
sendandrecv— a message leaving, and a message arriving.branchandlisten— a choice the component makes itself, and a choice the arriving message makes for it.loopandbreak.do— running another protocol on the same component.let,var, andset— the state the protocol keeps.- A standalone annotation.
An empty body is legal: a protocol may declare a component's behavior to be nothing.
A local protocol says which messages cross and in what order, never how the component computes one —
send any TrackReport names the type and no value. The implementation lives outside Flex, and the
protocol is what it is checked against.
Variables
let binds a value once, var binds one that can be reassigned, and set reassigns a var. All
three are local-protocol statements; a global protocol binds with exch … into let or inside an
in block.
- A protocol
letorvarbinds one identifier. There is no tuple pattern here, unlike theletin an expression block. - The type annotation is optional. Without one the initializer's type has to be fully determined, so a bare numeric literal needs an annotation or an ascription.
- With an annotation, the initializer is assignable to it.
settargets avarin scope, and its right side is assignable to that variable's type.- A binding may not shadow a variable or parameter already in scope.
- A binding is visible to every later statement of the same block.
component Radar;
component CommandPost;
message struct TrackReport {
track_id: uint32;
}
local protocol Sweep in Radar {
var count: int32 = 0;
let limit: int32 = 10;
let active = true;
send any TrackReport to CommandPost;
set count = count + 1;
}Errors
Running a protocol in something that is not a component
component CommandPost;
message struct TrackReport {
track_id: uint32;
}
local protocol Sweep in TrackReport { // error: local-protocol-component-not-component
send any TrackReport to CommandPost;
}Reassigning a let binding
set writes to a var. A let is bound once.
component Radar;
component CommandPost;
message struct TrackReport {
track_id: uint32;
}
local protocol Sweep in Radar {
let limit: int32 = 10;
set limit = 20; // error: set-target-not-var
send any TrackReport to CommandPost;
}Related
- global protocol — the same conversation written once, for every component.
- send — the message-sending statement and its four payload forms.
- recv — the message-receiving statement.
- do — handing control to another protocol on this component.
- system — the set of local protocols that make up one deployment.