Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
intro_example:pure_struct [2025/05/07 18:30] – [Methods] rajitintro_example:pure_struct [2025/05/18 15:07] (current) rajit
Line 1: Line 1:
 ====== Using pure structures ====== ====== Using pure structures ======
  
-A [[language:types2:data#pure_structures|pure structure]] is a user-defined data type that contains only ''int''/''bool'' or other pure structures. An example of a pure structure is:+A [[language:types2:data#pure_structures|pure structure]] is a user-defined data type that contains only ''int''/''bool'' or other pure structures. Pure structures are analogous to C/C++ ''struct''s, and can be used to organize data and  
 +make CHP more human-readable. An example of a pure structure is:
  
 <code act> <code act>
Line 56: Line 57:
  
  
-defproc cache(chan?(int<32>) A; chan?(bool) RD; chan!(int<32>) DI; chan!(int<32>) DO)+defproc cache(chan?(int<32>) A; chan?(bool) RD; chan?(int<32>) DI; chan!(int<32>) DO)
 { {
    cache_entry C[256];    cache_entry C[256];
Line 93: Line 94:
            }            }
          }          }
-         macro setfields(int<32> addr; int<32> dv) {+         macro setval (int<32> addr; int<32> dv) {
             valid+;              valid+; 
             data := dv;             data := dv;
Line 101: Line 102:
 } }
  
-defproc cache(chan?(int<32>) A; chan?(bool) RD; chan!(int<32>) DI; chan!(int<32>) DO)+defproc cache(chan?(int<32>) A; chan?(bool) RD; chan?(int<32>) DI; chan!(int<32>) DO)
 { {
    cache_entry C[256];    cache_entry C[256];
Line 117: Line 118:
        []~cmd -> // write command        []~cmd -> // write command
              DI?dv;              DI?dv;
-             ce.setaddr (addr, dv);+             ce.setval (addr, dv);
              C[addr{7..0}] := ce              C[addr{7..0}] := ce
       ]       ]