Skip to content

Commit 0012708

Browse files
committed
docs: Add ARCHITECTURE.md
1 parent 8250345 commit 0012708

File tree

2 files changed

+69
-62
lines changed

2 files changed

+69
-62
lines changed

ARCHITECTURE.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# ARCHITECTURE
2+
3+
(*What is ARCHITECTURE.md?* See [this article: ARCHITECTURE.md](https://matklad.github.io/2021/02/06/ARCHITECTURE.md.html).)
4+
5+
## Code map
6+
7+
Projects:
8+
9+
- MiloneShared: Shared types and utils
10+
- MiloneSyntax: Syntax analysis and type checking
11+
- MiloneTransform: Code generation
12+
- MiloneCli: CLI app
13+
- MiloneLspServer: LSP server implementation (F#)
14+
15+
Diagram of project dependencies:
16+
17+
Shared
18+
^
19+
/ \
20+
/ \
21+
Syntax Transform
22+
^ ^ ^
23+
| \ /
24+
| \ /
25+
| Cli
26+
LSP
27+
28+
Note that Transform is not depended by Syntax and LSP server.
29+
That illustrates modification of Transform doesn't affect interface of the language.
30+
31+
### Data structures
32+
33+
- Abstract Syntax Tree (AST)
34+
- Typed intermediate representation (TIR)
35+
- Functional-style IR. For checking.
36+
- High-level intermediate representation (HIR)
37+
- Functional-style IR. For transformation.
38+
- Mid-level intermediate representation (MIR)
39+
- For C code generation.
40+
- Imperative-style IR.
41+
- C intermediate representation (CIR)
42+
- Similar to AST of C language.
43+
44+
Diagram of data flow.
45+
46+
FileSystem (*.milone)
47+
| tokenize & parse
48+
v
49+
AST
50+
|
51+
v
52+
TIR -- type checking etc.
53+
|
54+
~ -- Syntax / Transform boundary
55+
|
56+
v
57+
HIR -- closure conversion etc.
58+
59+
MIR
60+
61+
CIR
62+
63+
FileSystem (*.c)
64+
65+
### Others
66+
67+
- FSharpOnly and Program.fs is F# only part.
68+
- MiloneOnly is milone-lang only part.

internals.md

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,68 +4,7 @@ Notes for milone-lang developers.
44

55
## Architecture
66

7-
See comments written at the top of each file.
8-
9-
Utilities:
10-
11-
- [Util](MiloneLang/Util.fs)
12-
- Utility functions for string, list etc.
13-
14-
Domains (types and functions):
15-
16-
- [Syntax](MiloneLang/Syntax.fs)
17-
- Tokens, abstract syntax tree (AST), source location information etc.
18-
- [Hir](MiloneLang/Hir.fs):
19-
- Functional-style intermediate representation
20-
- [Mir](MiloneLang/Mir.fs):
21-
- Imperative-style intermediate representation
22-
- [Cir](MiloneLang/Cir.fs)
23-
- AST of the C code to be pretty printed
24-
25-
Program analysis:
26-
27-
- [SyntaxTokenize](MiloneLang/SyntaxTokenize.fs) (milone-lang source code -> Token list)
28-
- [SyntaxParse](MiloneLang/SyntaxParse.fs) (Token list -> AST)
29-
- [AstToHir](MiloneLang/AstToHir.fs) (AST -> HIR)
30-
- [AstBundle](MiloneLang/AstBundle.fs) (\*files\* -> HIR)
31-
- Loads source files of project and concatenates them into single HIR program
32-
- [NameRes](MiloneLang/NameRes.fs) (Name resolution) (HIR)
33-
- [Typing](MiloneLang/Typing.fs) (Type inference) (HIR)
34-
35-
Transformations:
36-
37-
- [AutoBoxing](MiloneLang/AutoBoxing.fs)
38-
- Resolves recursive nominal types
39-
- [RecordRes](MiloneLang/RecordRes.fs)
40-
- Resolves use of field names
41-
- [ClosureConversion](MiloneLang/ClosureConversion.fs)
42-
- Resolves non-closed functions
43-
- [EtaExpansion](MiloneLang/EtaExpansion.fs)
44-
- Resolves partial applications and function references
45-
- [Hoist](MiloneLang/Hoist.fs)
46-
- Just a preparation of monomorphization
47-
- [Monomorphization](MiloneLang/Monomorphization.fs)
48-
- Resolves use of generic functions by code cloning
49-
- [TailRecOptimizing](MiloneLang/TailRecOptimizing.fs)
50-
- Marks tail-recursive calls to be optimized
51-
- [MirGen](MiloneLang/MirGen.fs) (HIR -> MIR)
52-
- Resolves pattern matches
53-
- [CirGen](MiloneLang/CirGen.fs) (MIR -> CIR)
54-
- [CirDump](MiloneLang/CirDump.fs) (CIR -> C source code)
55-
56-
Entrypoints:
57-
58-
- [Cli.fs](MiloneLang/Cli.fs)
59-
- CLI application logic shared by F# and milone-lang
60-
- [Program.fs](MiloneLang/Program.fs)
61-
- .NET entrypoint
62-
- [MiloneLang.milone](MiloneLang/MiloneLang.milone)
63-
- milone-lang entrypoint
64-
65-
Language-specific parts:
66-
67-
- [FSharpOnly](MiloneLang/FSharpOnly.fs)
68-
- [MiloneOnly](MiloneLang/MiloneOnly.milone)
7+
[ARCHITECTURE.md](ARCHITECTURE.md)
698

709
## Development
7110

0 commit comments

Comments
 (0)