Differences

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

Link to this comparison view

Next revision
Previous revision
intro_example:namespace [2020/06/16 23:24]
prafull created
intro_example:namespace [2022/05/13 09:20] (current)
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 89: Line 89:
 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 104: Line 104:
 adder FA; adder FA;
 </code> </code>
 +
 +
 +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 act>
 +import gates;
 +
 +defproc adder (bool? a,b,ci; bool! s,co)
 +{
 +  bool y1,y2,y3;
 +  gates::xor2 X1(a, b, y1);
 +  gates::and2 A1(a,b,y2);
 +  gates::xor2 X2 (y1,ci,s);
 +  gates::and2 A2(y1,ci,y3);
 +  gates::or2 O1(y2,y3,co);
 +}
 +
 +adder FA;
 +</code>
 +
 +The ''import'' statement looks for ''gates.act'' (details are in [[language:namespaces|Namespaces]]), and imports it if it is found. It also checks that the namespace ''gates'' exists after the import.
 +
 +
 +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 act>
 +import gates;
 +open gates;
 +
 +defproc adder (bool? a,b,ci; bool! s,co)
 +{
 +  bool y1,y2,y3;
 +  xor2 X1(a, b, y1);
 +  and2 A1(a,b,y2);
 +  xor2 X2 (y1,ci,s);
 +  and2 A2(y1,ci,y3);
 +  or2 O1(y2,y3,co);
 +}
 +
 +adder FA;
 +</code>
 +
  
 ===== Simulating with prsim script ===== ===== Simulating with prsim script =====