|Created:||Tuesday, August 23, 2022|
This LEP specifies the techniques used by the compiler to generate code in the target language.
After parsing the source code into an Abstract Syntax Tree, the compiler needs to generate valid Rust code that can be compiled.
Multiple solutions can achieve this goal:
Generated code is located in a folder named
.llbuild with the following
Cargo.toml file in this folder describe a Cargo workspace, whose members
are the crates located in the
Each Letlang module will be translated to a library crate.
For example, the following module:
module example::main; # module code
Will produce a crate with the following structure:
One of the modules is defined as a main module. This module must provide a
The compiler will generate an executable crate which depends on that module. Its role is to start the node and spawn the main process:
Every time a module use the
import statement, the imported module is added as
a dependency to the library crate (in the
For external dependencies (standard library, external projects, …), the
toolchain will fetch the dependency and compile the library crates in the
.llbuild/modules/ folder accordingly.
Using the Rust crate
askama, the compiler uses
templates to transform the Letlang AST into source-code.
rustfmt binary should be executed on the output, to facilitate
The Rust crate
rustc_ast is unstable and subject to
There are too few ressources at the moment to target the AST directly.
Cargo simplifies the crate dependency management, avoiding re-inventing the wheel.