mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-07 12:18:22 +00:00
1.4 KiB
1.4 KiB
overview of erg
We will introduce the function of each layer and the particularly important functions and methods.
1. Lexical Analysis
- The
Lexer
does the lexical analysis.Lexer::next
(Lexer
is implemented as an iterator) is responsible for the main logic of lexical analysis.Token
is output as a result of parsing.
2. Parsing
Parser
does the parsing. Of particular importance isParser::parse_expr
. As a result of parsing,AST
which is a collection ofast::Expr
is output.
3. Desugaring
- Desugaring is done by
Desugarer
.AST
will be output.
4. Type checking/type inference
ASTLowerer
does the typing. Type checking is primarily done by theContext
. Especially important areContext::supertype_of
(determine subtype relation),Context::unify/sub_unify
(unify/semi-unify type variables),Context::init_builtin_*
( defines built-in APIs).HIR
is output as a result of analysis.
5. Side effect check
SideEffectChecker
does.
6. Ownership check
OwnershipChecker
does.
7. Bytecode Generation
CodeGenerator
convertsHIR
toCodeObj
.CodeObj
holds bytecode and execution configuration. Of particular importance isCodeGenerator::compile_expr
.
- All the above processing is put together by the
Compiler
as a facade. - Of course Python executes the generated bytecode, which is called
DummyVM
.