---------------------------------------------------------------------- -- node Simple -- in "pure" lustre each node must have at least one input and one output ---------------------------------------------------------------------- node Simple(A: bool) returns (B: bool); let B = A; tel ---------------------------------------------------------------------- -- node And -- Boolean operator ---------------------------------------------------------------------- node And(A: bool; B:bool) returns (C: bool); let C = A and B; tel ---------------------------------------------------------------------- -- node Neg, "toggles" its Boolean input ---------------------------------------------------------------------- node Neg(X: bool) returns(Y: bool); let Y = not X; tel ---------------------------------------------------------------------- -- node Abs, returns the absolute value of its integer input ---------------------------------------------------------------------- node Abs( X : int ) returns ( Y : int ); let Y = if X < 0 then -X else X; tel ---------------------------------------------------------------------- -- node Adder ---------------------------------------------------------------------- node Adder (A,B,Cin : bool) returns (S,Cout : bool); let S = A xor B xor Cin; Cout = (A and B) or (B and Cin) or (A and Cin); tel ---------------------------------------------------------------------- -- node FourbitAdder -- multiple instances of the same node -- local variables -- tuple returns ---------------------------------------------------------------------- node FourbitAdder (A3,A2,A1,A0,B3,B2,B1,B0,Cin:bool) returns (Cout,S3,S2,S1,S0:bool); var C2,C1,C0:bool; let (S0,C0) = Adder(A0,B0,Cin); (S1,C1) = Adder(A1,B1,C0); (S2,C2) = Adder(A2,B2,C1); (S3,Cout) = Adder(A3,B3,C2); tel ---------------------------------------------------------------------- -- node RisingEdge -- returns true if input changes from negative to positive ---------------------------------------------------------------------- node RisingEdge( X : bool ) returns ( Y : bool ); let Y = false -> X and not pre X; tel ---------------------------------------------------------------------- -- node DownCounter ---------------------------------------------------------------------- node DownCounter( Time : int; Restart : bool ) returns ( Ctr : int ); let Ctr = Time -> if Restart then Time else if pre(Ctr) > 0 then pre(Ctr) - 1 else pre(Ctr); tel ---------------------------------------------------------------------- -- node DownCounters -- each flow instance has its own "memory" ---------------------------------------------------------------------- node DownCounters( Time1,Time2 : int; Restart : bool ) returns ( Ctr1,Ctr2 : int ); let Ctr1 = DownCounter(Time1,Restart); Ctr2 = DownCounter(Time2,Restart); tel ---------------------------------------------------------------------- -- Study how the -> "followed by" operator works by trying to -- construct the stream X = 1,2,3,3,3,3,... ---------------------------------------------------------------------- node FollowedBy() returns ( X : int ); let X = (1 -> 2) -> 3; tel ---------------------------------------------------------------------- -- Study how the -> "followed by" operator works by trying to -- construct the stream X = 1,2,3,3,3,3,... ---------------------------------------------------------------------- node FollowedBy2() returns ( X,X2 : int ); let X = (1 -> 2) -> 3; -- study the difference to X2 = 1 -> pre(2 -> 3); tel ---------------------------------------------------------------------- -- Similarly, study the following version ---------------------------------------------------------------------- node Fby( A, B, C : int ) returns ( X : int ); let X = (A -> B) -> C; tel ---------------------------------------------------------------------- -- This node produces the well-known sequence of numbers that are -- called the Fibonacci numbers: 1,1,2,3,5,8,13,... -- -- Run luke with different bitwidth for integers and see what happens, -- for instance: "luke --node Fibonacci Fibonacci.lus --int 8" ---------------------------------------------------------------------- node Fibonacci() returns(Fib: int); let Fib = 1 -> pre(1 -> Fib + pre(Fib)); tel