Import System

XXML uses a file-based module system for code organization and reuse. The #import directive loads all XXML files from a directory based on a qualified namespace path.

Syntax

xxml
#import Language::Core;

The #import directive takes a qualified namespace path and imports all XXML files found in the corresponding directory.

How Import Resolution Works

1. Path Conversion

The namespace path is converted to a directory path by replacing :: with /:

text
Language::Core  →  Language/Core

2. Search Path Lookup

The compiler searches for the directory in multiple locations, in order:

  1. Executable directory - The folder containing xxml.exe
  2. Language folder - <executable_dir>/Language (if it exists)
  3. Fallback Language folder - ./Language relative to current directory
  4. Current directory - .
  5. Source file directory - The parent directory of the file being compiled

3. File Discovery

Once a matching directory is found, the compiler loads all .XXML files in that directory. For example, if Language/Core/ contains:

text
Language/Core/
├── String.XXML
├── Integer.XXML
├── Bool.XXML
└── Console.XXML

Then #import Language::Core; loads all four files.

4. Module Naming

Each file becomes a module with a name derived from its path:

File PathModule Name
Language/Core/String.XXMLLanguage::Core::String
Language/Core/Integer.XXMLLanguage::Core::Integer
MyLib/Utils.XXMLMyLib::Utils

Module Caching

Modules are cached after first load to avoid redundant parsing. If a module is requested that has already been loaded, the cached version is returned.

Compiler Output

When the compiler finds modules, it prints diagnostic messages:

text
✓ Found standard library at: C:/path/to/xxml/Language
✓ Added source directory to search paths: D:/MyProject
Auto-discovering XXML files in search paths...
  Scanning: C:/path/to/xxml
  Scanning: C:/path/to/xxml/Language
    Found: Language/Core/String.XXML -> Language::Core::String

Example Project Structure

A typical project layout:

text
xxml/
├── xxml.exe              # Compiler executable
└── Language/             # Standard library
    ├── Core/
    │   ├── String.XXML
    │   ├── Integer.XXML
    │   ├── Bool.XXML
    │   └── Console.XXML
    └── GLFW/
        └── GLFW.XXML     # Third-party library

MyProject/
├── Main.XXML             # Your code
└── Utils/
    └── Helpers.XXML      # Your modules

In Main.XXML:

xxml
#import Language::Core;    // Loads all files from xxml/Language/Core/
#import Language::GLFW;    // Loads xxml/Language/GLFW/GLFW.XXML
#import Utils;             // Loads MyProject/Utils/*.XXML

[ Entrypoint
{
    // Use imported types
    Run Console::printLine(String::Constructor("Hello!"));
}]

Importing Single-File Modules

Currently, XXML imports all files from a directory. To import from a single-file module, create a directory containing just that file:

text
Language/
└── GLFW/
    └── GLFW.XXML    # Single file in directory

Then #import Language::GLFW; loads just GLFW.XXML.

Auto-Discovery

The import resolver can discover all XXML files in search paths automatically. This scans directories non-recursively and skips build/ and x64/ directories to avoid compiled artifacts.

Module Structure

Each module tracks:

FieldDescription
moduleNameQualified name (e.g., Language::Core::String)
filePathPath to the source file
fileContentRaw source code
astParsed abstract syntax tree
exportedSymbolsSymbol table for exported declarations
importsList of modules this module depends on
isParsedWhether parsing is complete
isAnalyzedWhether semantic analysis is complete
isCompiledWhether code generation is complete

Error Handling

If the Language folder is not found, the compiler prints a warning:

text
Warning: Language folder not found (searched: C:/path/to/xxml/Language and ./Language)

If a module file fails to load:

text
Warning: Failed to load module file: path/to/File.XXML

Warning

Make sure the Language/ directory exists relative to your compiler location or current working directory. Without it, standard library imports will fail.

Next Steps

Learn about the CLI Reference for compilation options, or explore the Compiler Architecture for implementation details.