mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-01 05:11:09 +00:00
1.4 KiB
1.4 KiB
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 isParser::parse_expr
. The result of parsing isAST
, a collection ofast::Expr
.
3. Desugaring
Desugarer
performs desugaring. AnAST
is output.
4. Type checking/type inference
ASTLowerer
performs typing. Type checking is mainly done byContext
. Of particular importance areContext::supertype_of
(to determine subtype relationships),Context::unify/sub_unify
(to unify/semi-unify type variables) andContext::init_builtin_*
(to define built-in API). TheHIR
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
convertsHIR
toCodeObj
. TheCodeObj
holds the bytecode and execution settings. Especially important isCodeGenerator::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
.