Leo is a compiler for the Aleo blockchain. Code flows through:
Source (.leo) -> Lexer (logos) -> Rowan Parse Tree -> AST -> Passes -> Aleo Bytecode
leo-span- provides Span/source locations (has third-party deps: fxhash, indexmap, serde)leo-errors- depends on span, all error typesleo-ast- depends on span/errors, all AST nodesleo-parser-rowan- lexer (logos) + rowan-based parser; grammar defined ingrammar.rsleo-parser- converts rowan parse tree to typed ASTleo-passes- ~25 compiler passes (validation, optimization, codegen)leo-compiler- orchestrates parsing and passesleo-abi/leo-abi-types- ABI generation for compiled programsleo-fmt- Leo source formatter (usesleo-parser-rowan)leo-disassembler- Aleo bytecode disassemblerleo-package- project structure parsingleo-test-framework- test harness for .leo files
- All AST nodes must implement the
Nodetrait (usesimple_node_impl!macro). - Every node needs
SpanandNodeIDfor error reporting and traversal. - Prefer
IndexMap(over HashMap) for deterministic ordering. - Large enum variants should be boxed.
parser-rowanuses a rowan-based grammar defined ingrammar.rswith logos for lexing.parserconverts the rowan parse tree to a typed AST.- Parser tests use expectation files in
tests/expectations/parser/.
- Each pass implements the
Passtrait withdo_pass(input, state) -> Result<Output>. - Passes run sequentially via
CompilerState. - Common passes: type checking, loop unrolling, monomorphization, flattening, code generation.
- Test passes in isolation where possible.
- All errors use macros in
leo-errors/src/common/macros.rs. - Error codes: format
E{PREFIX}037{CODE}(e.g.,EPAR0370042for parser error 42; categories: PAR 0-999, AST 2000-2999, CMP 6000-6999). - Use
Result<T>fromleo_errors. - Avoid leaking internal details in error messages.