Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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:

  1. The parser resolves the target file in the module search path.
  2. The imported module AST is parsed and analyzed.
  3. Symbol tables are merged or qualified, ensuring every @link source needed by the combined program is included exactly once in the emitted assembly.