30.04.2013 Views

BSV by Example - Computation Structures Group

BSV by Example - Computation Structures Group

BSV by Example - Computation Structures Group

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

– instantiating a module and returning its interface<br />

– invoking an ActionValue and returning its value.<br />

To demonstrate variable declaration and initialization syntax, we’ll be working with the example in<br />

Appendix A.3.1. The syntax in this example is more important than the functionality.<br />

Our example has a structure representing a 2-dimensional coordinate:<br />

typedef struct { int x; int y; } Coord<br />

deriving (Bits);<br />

We’ll describe structs in more detail in Section 10.1.3, but will rely here on their familiarity from C.<br />

The above defines a new type Coord with two int fields (members) called x and y. The “deriving<br />

(Bits)” phrase instructs the compiler to pick a canonical representation, here the obvious 64-bit<br />

value concatenating the two 32-bit fields.<br />

4.1.1 Side-effect initialization<br />

One type of side-effect initialization is instantiating a module and returning its interface. Consider<br />

the following statement:<br />

FIFO#(Coord) fi

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!