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
#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 /:
Language::Core → Language/Core2. Search Path Lookup
The compiler searches for the directory in multiple locations, in order:
- Executable directory - The folder containing
xxml.exe - Language folder -
<executable_dir>/Language(if it exists) - Fallback Language folder -
./Languagerelative to current directory - Current directory -
. - 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:
Language/Core/
├── String.XXML
├── Integer.XXML
├── Bool.XXML
└── Console.XXMLThen #import Language::Core; loads all four files.
4. Module Naming
Each file becomes a module with a name derived from its path:
| File Path | Module Name |
|---|---|
Language/Core/String.XXML | Language::Core::String |
Language/Core/Integer.XXML | Language::Core::Integer |
MyLib/Utils.XXML | MyLib::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:
✓ 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::StringExample Project Structure
A typical project layout:
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 modulesIn Main.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:
Language/
└── GLFW/
└── GLFW.XXML # Single file in directoryThen #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:
| Field | Description |
|---|---|
moduleName | Qualified name (e.g., Language::Core::String) |
filePath | Path to the source file |
fileContent | Raw source code |
ast | Parsed abstract syntax tree |
exportedSymbols | Symbol table for exported declarations |
imports | List of modules this module depends on |
isParsed | Whether parsing is complete |
isAnalyzed | Whether semantic analysis is complete |
isCompiled | Whether code generation is complete |
Error Handling
If the Language folder is not found, the compiler prints a warning:
Warning: Language folder not found (searched: C:/path/to/xxml/Language and ./Language)If a module file fails to load:
Warning: Failed to load module file: path/to/File.XXMLWarning
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.