L0Driver class
Defined in module l0_driver (l0_driver.py).
Stage-1 driver for the L0 compiler.
Responsibilities include:
- Reading source files.
- Tokenizing (lexing).
- Parsing.
- Recursively resolving imports using SourceSearchPaths.
Entry points:
- analyze(name): High-level analysis pipeline for an entry module.
- build_compilation_unit(name): Build a closed set of modules for an entry.
- load_module(name): Load by dotted module name, recursively loading imports.
- load_single_file(path): Ad hoc one-off parsing (no import resolution).
Constructors, destructors, conversion operators
- __init__(self, SourceSearchPaths|None search_paths = None, CompilationContext|None context = None)
- Initialize the L0 driver.
Public functions
- auto analyze(self, str entry_module_name) -> AnalysisResult
- Execute the high-level front-end pipeline.
- auto build_compilation_unit(self, str entry_module_name) -> CompilationUnit
- Build a compilation unit for an entry module.
- auto load_module(self, str module_name) -> Module
- Load a module by its qualified name.
Public attributes
Protected functions
- auto _load_single_file(self, str|Path path) -> Module
- Load a single file as a parsed module.
- auto _parse_source(self, str text, str file_path) -> Module
- Tokenize and parse source text.
Function documentation
l0_driver:: L0Driver:: __init__(self,
SourceSearchPaths|None search_paths = None,
CompilationContext|None context = None)
Initialize the L0 driver.
| Parameters | |
|---|---|
| search_paths | Paths to search for modules. Defaults to an empty set of search paths. |
| context | Compilation context for configuration and logging. Defaults to CompilationContext.default(). |
AnalysisResult l0_driver:: L0Driver:: analyze(self,
str entry_module_name)
Execute the high-level front-end pipeline.
| Parameters | |
|---|---|
| entry_module_name | The name of the module to use as the entry point. |
| Returns | An AnalysisResult containing the compilation unit, environment information, and all collected diagnostics. |
The pipeline consists of the following stages: 1. Build CompilationUnit for entry_module_name. 2. Run NameResolver (module-level symbols). 3. Run SignatureResolver (top-level types). 4. Run LocalScopeResolver (function/block scopes). 5. Run ExpressionTypeChecker (expression types).
CompilationUnit l0_driver:: L0Driver:: build_compilation_unit(self,
str entry_module_name)
Build a compilation unit for an entry module.
| Parameters | |
|---|---|
| entry_module_name | The name of the entry module. |
| Returns | A CompilationUnit containing the entry module and all reachable modules. |
Loads the entry module and recursively walks its imports to build the transitive closure of all required modules.
Module l0_driver:: L0Driver:: load_module(self,
str module_name)
Load a module by its qualified name.
| Parameters | |
|---|---|
| module_name | The qualified (dotted) name of the module. |
| Returns | The loaded and parsed Module object. |
| Exceptions | |
| ImportCycleError | If a cyclic import is detected. |
| FileNotFoundError | If the module source file cannot be found. |
| ValueError | If the module name declared in the file mismatch. |
| SourceEncodingError | If the source file is not valid UTF-8. |
Uses search paths to resolve the module name to a file, loads and parses it, and recursively loads all imported modules. Results are cached.
Module l0_driver:: L0Driver:: _load_single_file(self,
str|Path path) protected
Load a single file as a parsed module.
| Parameters | |
|---|---|
| path | Path to the source file. |
| Returns | The parsed Module object. |
| Exceptions | |
| FileNotFoundError | If the file does not exist. |
| SourceEncodingError | If the file is not valid UTF-8. |
Ignores search paths and does not recursively resolve imports. The module is cached by its declared name.
Module l0_driver:: L0Driver:: _parse_source(self,
str text,
str file_path) protected
Tokenize and parse source text.
| Parameters | |
|---|---|
| text | The source code text. |
| file_path | The path to the file (for diagnostics). |
| Returns | The parsed Module object. |