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:44] rajit [Importing namespaces] |
language:namespaces [2022/05/13 08:46] (current) 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 107: | Line 107: | ||
- | There are a few things | + | A second version of import uses namespaces directly, but requires |
- | First, duplicate namespaces might exist, especially when re-using old | + | ACT files be placed |
- | files. For instance, suppose | + | hierarchy. The import statement |
- | '' | + | |
- | definitions that are useful. Importing | + | <code act> |
- | the namespaces, and could create naming conflicts (e.g. multiple | + | import processor:: |
- | definition of types having the same name---an error). | + | </ |
- | problem, one can do the following: | + | |
+ | is equivalent to the following: | ||
+ | |||
+ | <code act> | ||
+ | import " | ||
+ | </ | ||
+ | |||
+ | It assumes that the file '' | ||
+ | '' | ||
+ | '' | ||
+ | |||
+ | <code act> | ||
+ | import foo; | ||
+ | </ | ||
+ | |||
+ | would do the following: | ||
+ | * Look for '' | ||
+ | * If unsuccessful, | ||
+ | * If unsuccessful, report an error | ||
+ | |||
+ | After the import, the specified namespace is checked to see if it exists. If not, an error will be reported. | ||
+ | |||
+ | |||
+ | ===== Opening namespaces ===== | ||
+ | |||
+ | If there are two different files that define the same namespace (say defined in multiple projects), importing both the files may result in type conflicts. Consider a scenario where we have two '' | ||
+ | |||
+ | To resolve | ||
- | < | + | < |
import " | import " | ||
open lib -> lib1; | open lib -> lib1; | ||
Line 123: | Line 150: | ||
</ | </ | ||
- | The '' | + | In this example, the '' |
- | has occured, there cannot be any naming conflicts. This version of | + | has occured, there cannot be any naming conflicts. This version of '' |
- | '' | + | |
- | eliminated. | + | |
A second issue is one that is more about convenience. Consider a | A second issue is one that is more about convenience. Consider a | ||
Line 136: | 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:: | ||
Line 148: | Line 173: | ||
namespace, not just the ones that are exported (including types within | namespace, not just the ones that are exported (including types within | ||
nested namespaces). Note that this '' | nested namespaces). Note that this '' | ||
- | all types cannot be uniquely resolved. | + | all types cannot be uniquely resolved. |
- | + | ||
- | The sequence of '' | + | |
at the beginning of an ACT file. | at the beginning of an ACT file. | ||
- | |||
- | A second version of import uses namespaces directly, but requires that | ||
- | ACT files be placed in locations that match the namespace | ||
- | hierarchy. The import statement | ||
- | |||
- | < | ||
- | import processor:: | ||
- | </ | ||
- | |||
- | is equivalent to the following: | ||
- | |||
- | < | ||
- | import " | ||
- | </ | ||
- | |||
- | It assumes that the file '' | ||
- | '' | ||
- | '' | ||
- | |||
- | ===== Opening namespaces ===== | ||
- | |||
- | |||
- | |||