// Dror Third: This Streamit program reads in a stream of // bits and outputs the same stream of bits, except each third // bit is dropped. See the tutorial on how to run this program. // below, DThrd is a stream "filter" that reads a // stream of bits and produces a stream of bits. bit->bit filter DThrd { // the filter reads 3 bits from its inputs stream and outputs // 2 bits to its oputput stream; // this repeats until the input stream is consumed. work push 2 pop 3 { for(int i=0; i<3; ++i){ // first two input bits are copied to the output stream if( i<2) push(pop()); // the third bit is dropped else pop(); } } } // This filter will be used to generate a test input stream // It produces a stream of bits, one word (int) of bits at a time. // It consumes no input stream. void->int filter Generate{ // Variable x keeps internal state of the filter int x=0; // create 1 word of bits at a time work push 1{ // put the word of bits to the output stream push(x); x = x+1; } } // This filter will print the inout stream, one word of bits // at a time. int->void filter Read{ work pop 1{ // printB is built-in. It prints the word in binary. printB( pop() ); } } // Now the three filters are put together into a pipeline, which // is the entire program. void->void pipeline Ex1_DThrd_reference { add Generate(); // Generates feeds into DThrd. add DThrd(); // DThrd feeds into Read. add Read(); // input/output rates are adjusted // by buffering the bits. }