# 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 is `Parser::parse_expr`. As a result of parsing, `AST` which is a collection of `ast::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 the `Context`. Especially important are `Context::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` converts `HIR` to `CodeObj`. `CodeObj` holds bytecode and execution configuration. Of particular importance is `CodeGenerator::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`.