Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
language:namespaces [2019/04/18 14:30] rajit [Creating a namespace] |
language:namespaces [2024/07/27 12:52] (current) rajit [Renaming namespaces] |
||
---|---|---|---|
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 84: | Line 84: | ||
only have global data types or channels---i.e. no circuits. | only have global data types or channels---i.e. no circuits. | ||
+ | ===== Importing namespaces ===== | ||
+ | |||
+ | There are two mechanisms to import other files in ACT. These | ||
+ | imports have to be at the beginning of an ACT file. If the same | ||
+ | file is imported twice within the same scope, ACT automatically | ||
+ | skips the second import. | ||
+ | |||
+ | The basic form of import statement is shown below: | ||
+ | |||
+ | <code act> | ||
+ | import " | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | This import searches for a file called '' | ||
+ | part of the ACT design. ACT has multiple mechanisms that can be used | ||
+ | to specify search paths for the files that an import statement can access: | ||
+ | |||
+ | * the current directory: if the file is located in the current working directory, then it is used. | ||
+ | * the colon-separated path specified by '' | ||
+ | * '' | ||
+ | |||
+ | |||
+ | 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 | ||
+ | |||
+ | <code act> | ||
+ | import processor:: | ||
+ | </ | ||
+ | |||
+ | 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, | ||
+ | |||
+ | After the import, the specified namespace is checked to see if it exists. If not, an error will be reported. | ||
+ | |||
+ | |||
+ | ===== Opening namespaces ===== | ||
+ | |||
+ | If a project has many different people working on it, it can be convenient | ||
+ | to have each component/ | ||
+ | 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! | ||
+ | |||
+ | As a syntactic convenience, | ||
+ | |||
+ | <code act> | ||
+ | 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. Note that the sequence of '' | ||
+ | at the beginning of an ACT file. | ||
+ | |||
+ | ===== Renaming 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 this issue, ACT provides a way to rename a namespace that has been imported. | ||
+ | |||
+ | <code act> | ||
+ | import " | ||
+ | open lib -> lib1; | ||
+ | import " | ||
+ | open lib -> lib2; | ||
+ | </ | ||
+ | |||
+ | In this example, the '' | ||
+ | has occured, there cannot be any naming conflicts. This version of '' | ||
+ | |||
+ | Another renaming scenario that can be useful is to move a namespace into another one. | ||
+ | <code act> | ||
+ | import lib; | ||
+ | import lib => priv; | ||
+ | </ | ||
+ | The first import statement above loads in the '' |