Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
intro_example:alu [2025/04/21 23:34] – [Using enumerations] rajitintro_example:alu [2025/04/21 23:49] (current) rajit
Line 35: Line 35:
           [] c = 2 -> O!(a&b)           [] c = 2 -> O!(a&b)
           [] c = 3 -> O!(a|b)           [] c = 3 -> O!(a|b)
 +       ] ]
 +    }
 +}
 +</code>
 +
 +====== Using enumerations ======
 +
 +Rather than hard-coding the control values, a user-defined enumeration can be used to make the ACT 
 +more readable.
 +
 +<code act>
 +defenum alu_ctrl {
 +   ADD, SUB, AND, OR
 +};   
 +
 +defproc alu (chan?(int) A, B; chan?(alu_ctrl) ctrl; chan!(int) O)
 +{
 +   int a, b;
 +   alu_ctrl c;
 +   
 +   chp {
 +      *[ A?a, B?b, ctrl?c;
 +          [ c = alu_ctrl.ADD -> O!(a+b)
 +          [] c = alu_ctrl.SUB -> O!(a-b)
 +          [] c = alu_ctrl.AND -> O!(a&b)
 +          [] c = alu_ctrl.OR -> O!(a|b)
        ] ]        ] ]
     }     }