Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| language:types2:data [2025/05/02 10:12] – [User-defined data types] rajit | language:types2:data [2025/11/20 15:27] (current) – [Pure structures] rajit | ||
|---|---|---|---|
| Line 7: | Line 7: | ||
| In addition, data types can also be // | In addition, data types can also be // | ||
| + | |||
| ===== Data types ===== | ===== Data types ===== | ||
| Line 104: | Line 105: | ||
| semantics of the channel permit waiting.) | semantics of the channel permit waiting.) | ||
| - | ===== Enumerations ===== | ||
| - | |||
| - | A user-defined enumeration can be specified as follows: | ||
| - | |||
| - | <code act> | ||
| - | defenum myenum { | ||
| - | ADD, SUB, MULT | ||
| - | }; | ||
| - | </ | ||
| - | |||
| - | This defines an enumeration called '' | ||
| - | |||
| - | The enumeration constants can be accessed using the enumeration type name as follows: | ||
| - | |||
| - | <code act> | ||
| - | ... | ||
| - | myenum x; | ||
| - | ... | ||
| - | chp { | ||
| - | ... | ||
| - | x := myenum.SUB; | ||
| - | ... | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | Trying to set an enumeration to an integer will result in a type error: | ||
| - | |||
| - | <code act> | ||
| - | chp { | ||
| - | ... | ||
| - | x := 1; | ||
| - | ... | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | will lead to: | ||
| - | |||
| - | < | ||
| - | -[ERROR]-> | ||
| - | stmt: x := 1 | ||
| - | Enumeration/ | ||
| - | </ | ||
| - | |||
| - | However, sometimes a user may want to use user-defined enumerations as integers. In order to do so, | ||
| - | the enumeration can be declared to be a valid integer as follows: | ||
| - | |||
| - | <code act> | ||
| - | defenum myenum : int { | ||
| - | ADD, SUB, MULT | ||
| - | }; | ||
| - | </ | ||
| - | |||
| - | This version will permit integer assignments. Note that it is up to the user to ensure that integer assignments are within range. The ACT simulator '' | ||
| ===== Structures ===== | ===== Structures ===== | ||
| Line 181: | Line 129: | ||
| to what is normally viewed as a record/ | to what is normally viewed as a record/ | ||
| - | Pure structures can be used with special function methods, providing a degree of object-oriented | + | Pure structures can be used with [[language: |
| programming capability within ACT. | programming capability within ACT. | ||
| Line 216: | Line 164: | ||
| It can be convenient to group a collection of parameters for readability/ | It can be convenient to group a collection of parameters for readability/ | ||
| <code act> | <code act> | ||
| - | | + | |
| </ | </ | ||
| Line 236: | Line 184: | ||
| q = myps (4, 8, false); | q = myps (4, 8, false); | ||
| </ | </ | ||
| + | |||
| + | ===== Enumerations ===== | ||
| + | |||
| + | A user-defined enumeration can be specified as follows: | ||
| + | |||
| + | <code act> | ||
| + | defenum myenum { | ||
| + | ADD, SUB, MULT | ||
| + | }; | ||
| + | </ | ||
| + | |||
| + | This defines an enumeration called '' | ||
| + | |||
| + | The enumeration constants can be accessed using the enumeration type name as follows: | ||
| + | |||
| + | <code act> | ||
| + | ... | ||
| + | myenum x; | ||
| + | ... | ||
| + | chp { | ||
| + | ... | ||
| + | x := myenum.SUB; | ||
| + | ... | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Trying to set an enumeration to an integer will result in a type error: | ||
| + | |||
| + | <code act> | ||
| + | chp { | ||
| + | ... | ||
| + | x := 1; | ||
| + | ... | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | will lead to: | ||
| + | |||
| + | < | ||
| + | -[ERROR]-> | ||
| + | stmt: x := 1 | ||
| + | Enumeration/ | ||
| + | </ | ||
| + | |||
| + | However, sometimes a user may want to use user-defined enumerations as integers. In order to do so, | ||
| + | the enumeration can be declared to be a valid integer as follows: | ||
| + | |||
| + | <code act> | ||
| + | defenum myenum : int { | ||
| + | ADD, SUB, MULT | ||
| + | }; | ||
| + | </ | ||
| + | |||
| + | This version will permit integer assignments. Note that it is up to the user to ensure that integer assignments are within range. The ACT simulator '' | ||