Modules & Imports
AzLang organizes codebases into self-contained modules imported using the import statement.
1. Importing Modules
To import definitions from another .az file:
import lib
write(Stdout, "Hello from imported module\n", 27)
In the AzLang SDK, sample.az imports lib.az:
// sample.az
import lib
write(Stdout, "Hello World", 11)
Where lib.az contains common type definitions, enums (FD, FLAG, FMODE), and external system call links:
// lib.az
enum FD
Stdin
Stdout
Stderr
@link("./sdk/src/exit.s")
op exit(const int val): void
@link("./sdk/src/write.s")
op write(FD fd, const str val, const int size): void
2. Compilation Model for Modules
When an import directive is encountered:
- The parser resolves the target file in the module search path.
- The imported module AST is parsed and analyzed.
- Symbol tables are merged or qualified, ensuring every
@linksource needed by the combined program is included exactly once in the emitted assembly.