Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| language:namespaces [2020/05/01 20:44] – [Importing namespaces] rajit | language:namespaces [2024/07/27 16:52] (current) – [Renaming namespaces] 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 that might create issues in such a situation. | + | A second version of import uses namespaces |
| - | First, duplicate | + | ACT files be placed in locations |
| - | files. For instance, suppose we have two files: '' | + | hierarchy. The import statement |
| - | '' | + | |
| - | definitions | + | |
| - | 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: | + | |
| - | <code> | + | <code act> |
| - | import "lib1.act"; | + | import |
| - | open lib -> lib1; | + | |
| - | import | + | |
| - | open lib -> lib2; | + | |
| </ | </ | ||
| - | The '' | + | is equivalent to the following: |
| - | has occured, there cannot be any naming conflicts. This version of | + | |
| - | '' | + | <code act> |
| - | eliminated. | + | import " |
| + | </ | ||
| + | |||
| + | It assumes that the file '' | ||
| + | '' | ||
| + | '' | ||
| + | |||
| + | <code act> | ||
| + | import foo; | ||
| + | </ | ||
| + | |||
| + | would do the following: | ||
| + | * Look for '' | ||
| + | * If unsuccessful, | ||
| + | * If unsuccessful, | ||
| + | |||
| + | After the import, | ||
| + | |||
| + | |||
| + | ===== Opening namespaces ===== | ||
| - | A second issue is one that is more about convenience. Consider | + | If |
| - | project | + | to have each component/ |
| own namespace to avoid naming conflicts. This situation can result in | own namespace to avoid naming conflicts. This situation can result in | ||
| very long type names. Plus it would be more bookkeeping to have to | very long type names. Plus it would be more bookkeeping to have to | ||
| create a test environment for the types within, say, | create a test environment for the types within, say, | ||
| '' | '' | ||
| - | because not all types might be exported! | + | because not all types might be exported! |
| - | < | + | As a syntactic convenience, |
| + | |||
| + | < | ||
| import " | import " | ||
| open processor:: | open processor:: | ||
| Line 148: | Line 161: | ||
| 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 | + | ===== Renaming |
| - | ACT files be placed in locations that match the namespace | + | |
| - | hierarchy. The import statement | + | |
| - | < | ||
| - | import processor:: | ||
| - | </ | ||
| - | is equivalent | + | 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. |
| - | import "processor/lib/_all_.act"; | + | |
| + | < | ||
| + | import "lib1.act"; | ||
| + | open lib -> lib1; | ||
| + | import "lib2.act"; | ||
| + | open lib -> lib2; | ||
| </ | </ | ||
| - | It assumes that the file '' | + | In this example, |
| - | '' | + | has occured, there cannot be any naming conflicts. This version of '' |
| - | '' | + | |
| - | + | ||
| - | ===== Opening namespaces ===== | + | |
| - | + | ||
| - | + | ||
| + | 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 '' | ||