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:namespace [2020/12/02 06:00] – external edit 127.0.0.1intro_example:namespace [2025/05/17 11:51] (current) – [Creating a library of building blocks] rajit
Line 7: Line 7:
 (a) For simple projects, design files containing building blocks can be imported using keyword ''import''. For example, the ''gates.act'' file contains basic logic gates. (a) For simple projects, design files containing building blocks can be imported using keyword ''import''. For example, the ''gates.act'' file contains basic logic gates.
  
-<code>+<code act>
 defproc nand2 (bool? a,b; bool! y) defproc nand2 (bool? a,b; bool! y)
 { {
Line 36: Line 36:
 This file can be imported in a new ACT file ''xor2.act'' for creating XOR gate using basic logic gates. This file can be imported in a new ACT file ''xor2.act'' for creating XOR gate using basic logic gates.
  
-<code>+<code act>
 import "gates.act"; import "gates.act";
  
Line 54: Line 54:
 The following example creates a namespace gates in file ''gates.act'' and defines process for basic logic gates within the namespace. The following example creates a namespace gates in file ''gates.act'' and defines process for basic logic gates within the namespace.
  
-<code>+<code act>
 namespace gates namespace gates
 { {
Line 86: Line 86:
 } }
 </code> </code>
 +
 +Note the use of the ''export'' keyword. By default, anything defined in a namespace is only visible within the namespace; it must be explicitly ''export''ed for it to be visible outside the namespace.
  
 As shown below, this library is imported in a new ACT file ''adder.act'' to design full adder using logic gates defined in the library. As shown below, this library is imported in a new ACT file ''adder.act'' to design full adder using logic gates defined in the library.
  
-<code>+<code act>
 import "gates.act"; import "gates.act";
  
Line 102: Line 104:
 } }
  
-adder FA;+adder fa;
 </code> </code>
  
Line 108: Line 110:
 Finally, ACT supports another import format that is similar to those provided by object-oriented languages like Python and Java. Since ''gates.act'' defines the namespace ''gates'', it can be imported as follows: Finally, ACT supports another import format that is similar to those provided by object-oriented languages like Python and Java. Since ''gates.act'' defines the namespace ''gates'', it can be imported as follows:
  
-<code>+<code act>
 import gates; import gates;
  
Line 121: Line 123:
 } }
  
-adder FA;+adder fa;
 </code> </code>
  
Line 129: Line 131:
 Finally, if you are going to be using the ''gates'' namespace a lot, it can be added to the search path used to find type definitions as follows. Finally, if you are going to be using the ''gates'' namespace a lot, it can be added to the search path used to find type definitions as follows.
  
-<code>+<code act>
 import gates; import gates;
 open gates; open gates;
Line 143: Line 145:
 } }
  
-adder FA;+adder fa;
 </code> </code>
  
Line 151: Line 153:
  
 <code> <code>
-prsim adder.act < adder.scr+$ aflat adder.act > adder.prs 
 +$ prsim adder.prs < adder.scr
 </code> </code>
  
Line 157: Line 160:
  
 <code> <code>
-prsim adder.act+prsim adder.prs
 (Prsim) source adder.scr (Prsim) source adder.scr
 </code> </code>