mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 04:09:05 +00:00
Add directories.md
This commit is contained in:
parent
4f46ee46b6
commit
0b54ef3b40
3 changed files with 88 additions and 0 deletions
42
doc/EN/compiler/architecture.md
Normal file
42
doc/EN/compiler/architecture.md
Normal file
|
@ -0,0 +1,42 @@
|
|||
# Architecture of `ergc`
|
||||
|
||||
## 1. Scan an Erg script (.er) and generate a `TokenStream` (parser/lex.rs)
|
||||
|
||||
* parser/lexer/Lexer generates `TokenStream` (this is an iterator of Token, TokenStream can be generated by lexer.collect())
|
||||
* `Lexer` is constructed from `Lexer::new` or `Lexer::from_str`, where `Lexer::new` reads the code from a file or command option.
|
||||
* `Lexer` can generate tokens sequentially as an iterator; if you want to get a `TokenStream` all at once, use `Lexer::lex`.
|
||||
* `Lexer` outputs `LexError`s as errors, but `LexError` does not have enough information to display itself. If you want to display the error, use the `LexerRunner` to convert the error.
|
||||
* `LexerRunner` can also be used if you want to use `Lexer` as standalone; `Lexer` is just an iterator and does not implement the `Runnable` trait.
|
||||
* `Runnable` is implemented by `LexerRunner`, `ParserRunner`, `Compiler`, and `VirtualMachine`.
|
||||
|
||||
## 2. Convert `TokenStream` -> `AST` (parser/parse.rs)
|
||||
|
||||
* `Parser`, like `Lexer`, has two constructors, `Parser::new` and `Parser::from_str`, and `Parser::parse` will give the `AST`.
|
||||
* `AST` is the wrapper type of `Vec<Expr>`. It is for "Abstract Syntax Tree".
|
||||
|
||||
### 2.5 Desugaring `AST`
|
||||
|
||||
* expand nested vars (`Desugarer::desugar_nest_vars_pattern`)
|
||||
* desugar multiple pattern definition syntax (`Desugarer::desugar_multiple_pattern_def`)
|
||||
|
||||
## 3. Type checking & inference, Convert `AST` -> `HIR` (compiler/lower.rs)
|
||||
|
||||
* `HIR` has every variable's type information. It is for "High-level Intermediate Representation".
|
||||
* `HIR` only holds the type of the variable, but that's enough. In extreme cases, this is because Erg has only conversion (or operator) applications. If we know the type of the conversion, we have already know the type of the object of the argument.
|
||||
* `ASTLowerer` can be constructed in the same way as `Parser` and `Lexer`.
|
||||
* `ASTLowerer::lower` will output a tuple of `HIR` and `CompileWarnings` if no errors occur.
|
||||
* `ASTLowerer` is owned by `Compiler`. Unlike conventional structures, `ASTLowerer` handles code contexts and is not a one-time disposable.
|
||||
* If the result of type inference is incomplete (if there is an unknown type variable), an error will occur during name resolution.
|
||||
|
||||
## 4. Check side-effects (compiler/effectcheck.rs)
|
||||
|
||||
## 4. Check ownerships (compiler/memcheck.rs)
|
||||
|
||||
## 5. Generate Bytecode (`CodeObj`) from `HIR` (compiler/codegen.rs)
|
||||
|
||||
* From the type information of the expression, name resolution of the quantified subroutines will be performed.
|
||||
|
||||
## (6. (Future plans) Convert Bytecode -> LLVM IR)
|
||||
|
||||
* Bytecode is stack-based, whereas LLVM IR is register-based.
|
||||
There will be several more layers of intermediate processes for this conversion process.
|
23
doc/EN/dev_guide/directories.md
Normal file
23
doc/EN/dev_guide/directories.md
Normal file
|
@ -0,0 +1,23 @@
|
|||
# Directory Structure of Erg
|
||||
|
||||
```console
|
||||
└─┬ assets: images
|
||||
├─ CODE_OF_CONDUCT: Code of Conduct
|
||||
├─┬ compiler
|
||||
│ ├─ erg_common: common utilities
|
||||
│ ├─ erg_compiler: Compiler
|
||||
│ └─ erg_parser: Parser
|
||||
├─┬ doc
|
||||
│ ├─┬ EN
|
||||
│ │ ├─ API: Erg standard API
|
||||
│ │ ├─ compiler: about implementation of the compiler
|
||||
│ │ ├─ dev_guide: guide for developers & contributors
|
||||
│ │ ├─ python: Knowledge of Python required for Erg development
|
||||
│ │ ├─ syntax: syntax of Erg
|
||||
│ │ └─ tools: about Erg's CLI tools
|
||||
│ └─ JA
|
||||
├─ examples: sample code
|
||||
├─ library: Erg libraries
|
||||
├─ src: main.rs & driver
|
||||
└─ tests: test code
|
||||
```
|
23
doc/JA/dev_guide/directories.md
Normal file
23
doc/JA/dev_guide/directories.md
Normal file
|
@ -0,0 +1,23 @@
|
|||
# Ergリポジトリのディレクトリ構造
|
||||
|
||||
```console
|
||||
└─┬ assets: 画像など
|
||||
├─ CODE_OF_CONDUCT: 行動規範
|
||||
├─┬ compiler
|
||||
│ ├─ erg_common: 共通のユーティリティ
|
||||
│ ├─ erg_compiler
|
||||
│ └─ erg_parser: パーサー
|
||||
├─┬ doc
|
||||
│ ├─┬ EN
|
||||
│ │ ├─ API: Erg標準API
|
||||
│ │ ├─ compiler: コンパイラの実装に関して
|
||||
│ │ ├─ dev_guide: 開発・貢献者向けガイド
|
||||
│ │ ├─ python: Ergの開発に必要なPythonの知識
|
||||
│ │ ├─ syntax: Ergの文法
|
||||
│ │ └─ tools: Ergのコマンドラインツールに関して
|
||||
│ └─ JA
|
||||
├─ examples: サンプルコード
|
||||
├─ library: Ergスクリプトによるライブラリ
|
||||
├─ src: main.rsとドライバの置かれたディレクトリ
|
||||
└─ tests: テストコード
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue