Download Lucid Synchrone Manual

Transcript
1.5
Valued Signals
The language provides a way to manage valued signals. Signals are built and accessed through
the construction emit and present. A value signal is a pair made of (1) a boolean stream c
indicating when the signal is present and (2) a stream sampled on that clock c 6 . In circuit
terminology, we get circuits with enable.
1.5.1
Signals as Clock Abstraction
Signals can be built from sampled streams by abstracting their internal clock. Consider again
the example given in section 1.2.5. This program can now be accepted if we write:
let node within min max x = o where
rec clock c = (min <= x) & (x <= max)
and emit o = true when c
val within : ’a -> ’a -> ’a => bool sig
val within :: ’a -> ’a -> ’a -> ’a sig
It computes a condition c and a sampled stream true when c. The equation emit o =
when c defines a signal o which is present and equal to true when c is true. The
construction can be considered as a boxing mechanism which pack a value with its
condition. The right part of the construction emit must be an expression with some
type a on c. In that case, it defines a signal with clock type a sig.
1.5.2
true
emit
clock
clock
Testing the Presence and Signal Matching
It is possible to test for the presence of a signal expression e by writting the boolean expression
?e. The following program, for example, counts the number of instants where x is emitted.
let node count x = cpt where
rec cpt = if ?x then 1 -> pre cpt + 1 else 0 -> pre cpt
val count : ’a sig => int
val count :: ’a sig -> ’a
The language provides a more general mechanism to test for the presence of several signals
and access their values. It is reminiscent of the pattern-matching construct of ML. This
pattern matching mechanisn is safe in the sense that it is possible to access the value of a
signal only at the instant where it is emitted. This is in contrast with Esterel, for example,
where the value of a signal implicitly holds and can be accessed even when it is not emitted.
The following program takes two signals x and y and returns an integer which equals the
sum of x and y when both are emitted, it returns the value of x when x is emitted only and
the value 0 when only y is emitted and 0 otherwise.
6
In type notation, a signal is a dependent pair with clock type Σ(c : a).a on c.