mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-01 05:11:09 +00:00
36 lines
1.4 KiB
Markdown
36 lines
1.4 KiB
Markdown
# Overview of `erg
|
|
|
|
This section introduces the function of each layer and especially important functions and methods.
|
|
|
|
## 1. Lexical analysis
|
|
|
|
* `Lexer` performs lexical analysis. `Lexer::next` (`Lexer` is implemented as an iterator) handles the main logic of lexical analysis. `Token` is output as a result of parsing.
|
|
|
|
## 2. Parsing
|
|
|
|
* `Parser` performs the parsing. Especially important is `Parser::parse_expr`. The result of parsing is `AST`, a collection of `ast::Expr`.
|
|
|
|
## 3. Desugaring
|
|
|
|
* `Desugarer` performs desugaring. An `AST` is output.
|
|
|
|
## 4. Type checking/type inference
|
|
|
|
* `ASTLowerer` performs typing. Type checking is mainly done by `Context`. Of particular importance are `Context::supertype_of` (to determine subtype relationships), `Context::unify/sub_unify` (to unify/semi-unify type variables) and `Context::init_builtin_*` (to define built-in API). The `HIR` is output as a result of the analysis.
|
|
|
|
## 5. Side Effect Check
|
|
|
|
* `SideEffectChecker` does this.
|
|
|
|
## 6. Ownership check
|
|
|
|
* Performed by `OwnershipChecker`.
|
|
|
|
## 7. Bytecode generation
|
|
|
|
* `CodeGenerator` converts `HIR` to `CodeObj`. The `CodeObj` holds the bytecode and execution settings. Especially important is `CodeGenerator::compile_expr`.
|
|
|
|
---
|
|
|
|
* All the above processes are put together by `Compiler` as a facade.
|
|
* Execution of the generated bytecode is of course done by Python, which is called by `DummyVM`.
|