You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: COMPILER_GUIDELINES.md
+10-35Lines changed: 10 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ The goal is not to copy Rust or any other compiler blindly. The goal is to build
13
13
14
14
Do not cargo-cult architecture.
15
15
16
-
When reusing ideas from Rust or any other compiler:
16
+
When reusing ideas from Rust, Zig or any other compiler:
17
17
18
18
- copy the idea only if it fits this language
19
19
- simplify when the full design is not needed yet
@@ -58,10 +58,9 @@ These decisions are already part of the language design and should not drift acc
58
58
- Zig-style literals are used: `.{ ... }`
59
59
- methods are declared outside types using attached-method syntax with receivers.
60
60
-`defer` and `panic` are part of the core control-flow model
61
-
- builtin functions are declared in `ember_libs_dev/global.em`
62
-
- stdlib source modules are declared in `ember_libs_dev/std/*.em`
63
-
- builtin declarations use `#[builtin]` and may omit a body
64
-
- external declarations use `#[extern(\"...\")]` and may omit a body
61
+
- builtin functions are declared in `_builtin_library/global.em`
62
+
- stdlib source modules are declared in `_builtin_library/std/*.em`
63
+
- external declarations use `#[extern(\"...\")]` and may omit a body. extern can contain the external linking function name as parameter or keep empty for default behavior.
65
64
- error unions are explicit value-level control flow and are not exceptions
66
65
67
66
If implementation changes conflict with this, update the language spec first.
@@ -77,10 +76,6 @@ The compiler should be split into clear layers.
77
76
-`hir`: all HIR data structures and HIR-local transforms
78
77
-`mir`: MIR and MIR-local transforms
79
78
-`semantics`: name resolution, type checking, ownership checks
80
-
-`layout`: physical type layout, alignment, size, and field-slot mapping
81
-
-`cfg`: CFG data model only
82
-
-`cfganalysis`: CFG construction and CFG-based analyses
83
-
-`codegen`: lowering and backend work
84
79
85
80
No package should mix all of these concerns.
86
81
@@ -90,27 +85,7 @@ HIR-specific rule:
90
85
- keep HIR-related code under `hir`
91
86
- if HIR grows, prefer subpackages under `hir/...` over creating parallel top-level `hir*` packages again
92
87
93
-
## 5. Lexer Rules
94
-
95
-
The lexer is not a parser.
96
-
97
-
- tokenize only
98
-
- no semantic decisions
99
-
- no type inference
100
-
- no ownership analysis
101
-
- no parser-level hacks
102
-
103
-
Use regex/token-pattern driven tokenization when it improves clarity.
104
-
Do not use regex just because another compiler did. Use it only when the token class is naturally pattern-based, such as numeric literals.
105
-
106
-
When adding token support:
107
-
108
-
- keep token names general enough for later phases
109
-
- prefer `NUMBER` over fake subcategories unless syntax requires the split
110
-
- keep literals normalized only when that is clearly beneficial
111
-
- do not silently erase information needed by later phases
112
-
113
-
## 6. Parser Rules
88
+
## 5. Parser Rules
114
89
115
90
The parser should build syntax, not interpretation.
116
91
@@ -127,7 +102,7 @@ Parser code should answer:
127
102
128
103
If a function makes that hard to see, rewrite it.
129
104
130
-
## 7. AST Rules
105
+
## 6. AST Rules
131
106
132
107
AST nodes represent source structure, not semantic conclusions.
133
108
@@ -140,7 +115,7 @@ Examples:
140
115
-`NumberLit` is better than `IntLit` if the lexer accepts non-integer numerics
141
116
-`ImportDecl` should exist if imports are part of module syntax
142
117
143
-
## 8. Context And Pipeline Rules
118
+
## 7. Context And Pipeline Rules
144
119
145
120
Use a central compiler context for shared state.
146
121
@@ -175,7 +150,7 @@ The pipeline owns:
175
150
176
151
Do not hide pipeline behavior inside parser or lexer code.
177
152
178
-
## 8.1 Phase Responsibilities
153
+
## 7.1 Phase Responsibilities
179
154
180
155
Phase ownership must stay explicit.
181
156
@@ -255,7 +230,7 @@ Reason:
255
230
- it interacts with control flow, reinitialization, and escapes
256
231
- keeping it separate makes the typechecker simpler and keeps ownership logic aligned with later CFG/data-flow work
257
232
258
-
## 8.2 Unwind And Error Model
233
+
## 7.2 Unwind And Error Model
259
234
260
235
Do not conflate `panic` with `E!T`.
261
236
@@ -273,7 +248,7 @@ This implies:
273
248
274
249
Do not fake panic semantics by lowering it to an ordinary call and hoping codegen reconstructs unwind behavior later.
275
250
276
-
## 8.3 Semantic Order vs Physical Layout
251
+
## 7.3 Semantic Order vs Physical Layout
277
252
278
253
Semantic field order and physical field layout are different concepts.
0 commit comments