I've seen several posts by people who are trying to write programs in HDL. I'd like to offer the following, hopefully useful, perspective.
HDL is not a programming language, it's a soldering iron!
The IN and OUT statements tell what pins are available on the IC that you are designing. Users of this new IC will be able to solder wires to these pins, but not to any of its internal wiring.
The PARTS section tells how to solder together the internal parts of this new IC, and which internal parts' pins connect to the IC's pins. These are not function calls; they are soldering instructions. The identifiers are not variables; they are wire names (colors, if you will). You may have more than one wire connected to a part's output. The order that you solder your wires does not matter.
Consider wiring this circuit for "Bob":
+-----------------------+
| Bob |
| +-----+ +-----+ |
| | Foo | | Bar | |
pin1 >--->a c>--->q s>---> pin3
| | | | | |
pin2 >--->b d>-*->r | |
| | | | | | |
| +-----+ | +-----+ |
| | |
| +-----------> pin4
| |
+-----------------------+
CHIP Bob {
IN pin1, pin2;
OUT pin3, pin4;
PARTS:
Bar(q=red, s=pin3, r=green);
Foo(a=pin1, d=green, d=pin4, c=red, b=pin2);
}
Buses are like
ribbon cables. You can't break them apart in the middle and solder to individual wires or subgroups. Just like other wires, you can solder more than one to a part's pins:
WordBuffer(in=inword, out=outword, out[0..7]=outbyte0, out[8..15]=outbyte1);
BE CAREFUL! It is is possible to burn your virtual fingers with a virtual soldering iron!
--Mark