Previous Up Next

3.10  Definitions

let-binding::=pattern = expr
    | ident pattern-list = expr
    | node ident pattern-list = expr
    | last ident = expr
    | emit ident = expr
 
infix-op::=infix-symbol  |  *  |  =  |  or  |  &
 
definition::=let-binding
    | match expr with def-match-handlers end
    | reset definition { and definition } every expr
    | automaton def-automaton-handlers end
    | present def-present-handlers end
 
definition-list::=[ definition { and definition } ]
    | є
 
local-definitions::={ let [ rec ] definition { and definition } in }
 
def-match-handlers::=[ | ] def-match-handler { | def-match-handler }
 
def-match-handler::=pattern -> action
 
action::=local-definitions do definition-list done
 
def-automaton-handlers::=[ | ] def-automaton-handler { | def-automaton-handler }
 
def-automaton-handler::=constructor [ pattern ] -> automaton-action
 
automaton-action::=local-definitions do definition-list def-transitions
 
def-transitions::=done
    | then state-expression
    | continue state-expression
    | transition { transition }
 
state-expression::=constructor
    | constructor ( expr )
 
def-present-handlers::=[ | ] def-present-handler { | def-present-handler }
def-present-handler::=signal-pattern -> action done
    | _ -> action done

Value Definition

A definition pattern = expr defines variables and is obtained by matching the value of expr with pattern. An alternate syntax is provided to define functional values. The definition:

ident = fun pattern1 ... patternn -> expr

can be declared in the following way:

ident pattern1 ... patternn = expr

And the definition:

ident = fun pattern1 ... patternn => expr

can be declared in the following way:

node ident pattern1 ... patternn = expr

Both forms define ident to be a function with n arguments.

Shared Memory Initialization

A definition last ident = expr defines a shared memory last ident to be initialized with the value of expr.

Signal Definition

A definition emit ident = expr defines the signal ident to be equal to the value of expr.

Pattern Matching

match expr pattern1 -> action1 | ... | patternn -> actionn end is used for combining n complementary sub-streams. Each of these streams is on the clock defined by the instants where the value of e has the form patterni .

Each action is made of a (possibly empty) sequence of local definitions and a definition list of shared variables. These shared variables can appear in several branches.

Modular Reset

The construction reset definition1 and ... and definitionn every expr allows for resetting the computation made in a set of definitions. All the defined values and expression expr must be on the same clock. This construction acts as a regular multi-definition except that all the streams and automata defined in definition1,..., definitionn restart with their initial value every time the current value of expr is true. In particular automata restart into their initial state.

Automata

The construction automaton def-automaton-handler | ... | def-automaton-handler end defines an automaton. Each branch of the automaton is of the form:

constructor -> automaton-action

or

constructor pattern -> automaton-action

where constructor denotes the name of the state. This state may be parameterized by a pattern. The first branch defines the initial state and this state cannot be parameterized.

The action associated to a state is of the form:

local-definitions do definition-list transitions

It is made of a (possibly empty) sequence of local definitions to the state, a definition list of shared variables and a (possibly empty) list of transitions which are tested sequentially. Transitions may have several forms. Writting:

until signal-pattern then state-expression

defines a weak transition which is executed at the end of the reaction, that is, after definitions from the current state have been executed. When the conditions succeed, the new state is given by the value of state-expression. The keyword then indicates that the new state is entered by reset, that is, all the streams and automata in the next state restart with their initial value. Writting:

until signal-pattern continue state-expression

has the same behavior except that the next state is entered by history, that is, no reset occurs.

The language provides two derived forms of transitions written then state-expression and continue state-expression as short-cut of until true then state-expression and until true continue state-expression.

Moreover, transitions may be either weak of strong. The following form:

unless signal-pattern then state-expression

defines a strong transition which is executed before the reaction starts, that is, before definitions from the current state have been executed. When the conditions succeed, the definitions to be executed belong to the value of state-expression. The keyword then indicates that the new state is entered by reset, that is, every stream and state from the value of state-expression are reseted. Finally, writting:

unless signal-pattern then state-expression

defines a strong transition with entrance by history.

Testing the Presence of Signals

A present statement is pretty much the same as a pattern-matching statement. It is of the form:

present def-present-handler1 | ... | def-present-handlern end

Where a handler is of the form:

signal-pattern -> action

Signal patterns are tested sequentially and the one which succeed defines the corresponding action to execute. Finally, a handler:

_ -> action

defines a condition which always succeed.


Previous Up Next