// ************************************************************************** //
//                                                                            //
//    eses                   eses                                             //
//   eses                     eses                                            //
//  eses    eseses  esesese    eses   Embedded Systems Group                  //
//  ese    ese  ese ese         ese                                           //
//  ese    eseseses eseseses    ese   Department of Computer Science          //
//  eses   eses          ese   eses                                           //
//   eses   eseses  eseseses  eses    University of Kaiserslautern            //
//    eses                   eses                                             //
//                                                                            //
// ************************************************************************** //
// This module implements a variant of the init operator of the polychronous  //
// language SIGNAL. The output stream y has the same clock as the input stream//
// x, but its values are shifted by one step (where the next clock ticks) into//
// the future. The value of y on the first clock tick is given by the value c.//
// The node therefore implements a simple buffer, so that we call it Buf.     //
// ************************************************************************** //

macro val(x) = x.0;
macro clk(x) = x.1;

module BufBool(event (bool * bool) x,y,bool ?c) {
    bool z;
    z = c;
    loop {
        // await trigger event
        if(clk(x) | clk(y)) {
            // ensure clock consistency
            emit(clk(x));
            emit(clk(y));
            // produce output values
            next(z) = val(x);
            val(y) = z;
        }
        // negative clock information
        if(!clk(x) or !clk(y)) {
            // ensure clock consistency
            clk(x) = false;
            clk(y) = false;
        }
        pause;
    }
}