Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
language:namespaces [2020/05/01 16:47] rajit [Opening namespaces] |
language:namespaces [2022/05/13 08:46] rajit |
||
---|---|---|---|
Line 12: | Line 12: | ||
A namespace is created by using the '' | A namespace is created by using the '' | ||
- | < | + | < |
namespace lib { | namespace lib { | ||
... | ... | ||
Line 38: | Line 38: | ||
namespaces is shown below. | namespaces is shown below. | ||
- | < | + | < |
namespace datapath { | namespace datapath { | ||
export defproc bus_interface(...) { ... } | export defproc bus_interface(...) { ... } | ||
Line 64: | Line 64: | ||
the entire namespace '' | the entire namespace '' | ||
- | < | + | < |
namespace datapath { | namespace datapath { | ||
export defproc bus_interface(...) { ... } | export defproc bus_interface(...) { ... } | ||
Line 93: | Line 93: | ||
The basic form of import statement is shown below: | The basic form of import statement is shown below: | ||
- | < | + | < |
import " | import " | ||
... | ... | ||
Line 106: | Line 106: | ||
* '' | * '' | ||
- | |||
- | There are a few things that might create issues in such a situation. | ||
- | First, duplicate namespaces might exist, especially when re-using old | ||
- | files. For instance, suppose we have two files: '' | ||
- | '' | ||
- | definitions that are useful. Importing both would result in the union of | ||
- | the namespaces, and could create naming conflicts (e.g. multiple | ||
- | definition of types having the same name---an error). To solve this | ||
- | problem, one can do the following: | ||
- | |||
- | < | ||
- | import " | ||
- | open lib -> lib1; | ||
- | import " | ||
- | open lib -> lib2; | ||
- | </ | ||
- | |||
- | The '' | ||
- | has occured, there cannot be any naming conflicts. This version of | ||
- | '' | ||
- | eliminated. | ||
- | |||
- | A second issue is one that is more about convenience. Consider a | ||
- | project that has many different people working on it, each in their | ||
- | own namespace to avoid naming conflicts. This situation can result in | ||
- | very long type names. Plus it would be more bookkeeping to have to | ||
- | create a test environment for the types within, say, | ||
- | '' | ||
- | because not all types might be exported! In this case we can say: | ||
- | |||
- | < | ||
- | import " | ||
- | open processor:: | ||
- | |||
- | a1of2 d; | ||
- | </ | ||
- | |||
- | This version of the '' | ||
- | functions: (i) it adds '' | ||
- | types, and (ii) it allows one to access all types within the | ||
- | namespace, not just the ones that are exported (including types within | ||
- | nested namespaces). Note that this '' | ||
- | all types cannot be uniquely resolved. | ||
- | |||
- | The sequence of '' | ||
- | at the beginning of an ACT file. | ||
A second version of import uses namespaces directly, but requires that | A second version of import uses namespaces directly, but requires that | ||
Line 157: | Line 111: | ||
hierarchy. The import statement | hierarchy. The import statement | ||
- | < | + | < |
import processor:: | import processor:: | ||
</ | </ | ||
Line 163: | Line 117: | ||
is equivalent to the following: | is equivalent to the following: | ||
- | < | + | < |
import " | import " | ||
</ | </ | ||
Line 169: | Line 123: | ||
It assumes that the file '' | It assumes that the file '' | ||
'' | '' | ||
- | '' | + | '' |
+ | |||
+ | <code act> | ||
+ | import foo; | ||
+ | </ | ||
+ | |||
+ | would do the following: | ||
+ | * Look for '' | ||
+ | * If unsuccessful, | ||
+ | * If unsuccessful, | ||
+ | |||
+ | After the import, the specified namespace is checked to see if it exists. If not, an error will be reported. | ||
===== Opening namespaces ===== | ===== Opening namespaces ===== | ||
Line 177: | Line 143: | ||
To resolve this issue, ACT provides a way to rename a namespace that has been imported. | To resolve this issue, ACT provides a way to rename a namespace that has been imported. | ||
- | < | + | < |
import " | import " | ||
open lib -> lib1; | open lib -> lib1; | ||
Line 195: | Line 161: | ||
because not all types might be exported! In this case we can say: | because not all types might be exported! In this case we can say: | ||
- | < | + | < |
import " | import " | ||
open processor:: | open processor:: |