Skip to content

Commit

Permalink
WIP: Generate an IR.
Browse files Browse the repository at this point in the history
The compiler has come a long way, but we still can't do int64, because
it requires a non-cell storage size. There's no (sane) way to express
conversions between int32 and int64 within the AST, because we have no
uniform way of inserting conversion nodes. This is already a deep
problem that has been hacked around for operator overloads and property
accessors, and it doesn't scale.

The solution is obvious: transform the AST into an IR. That's what we
should have done from the beginning but didn't. Unfortunately it
requires a *lot* of refactoring and a ton of boilerplate. So far, I have
most of the boilerplate done, but the refactoring is only halfway there.
CodeGenerator has not been ported to the IR yet.

Once this gigantic patch is done, we'll have the following changes:

- `struct value` will be eliminated, and good riddance.
- The AST will be immutable after parsing.
- The semantic analysis phase will output a new IR tree.
- CodeGenerator will generate off the IR instead. Since the IR is a
  transformation of the AST, I'm expecting minimal changes to the end
  result.
- functag_t will be replaced by FunctionType.
- Temporary heap allocations will be replaced with pre-allocated stack
  slots.

V2: CG-IR can now assemble trivial programs.
V3: CG-IR supports basic calls; 341 test failures.
V4: CG-IR supports binary ops; 333 test failures.
V5: CG-IR supports do-while and if; 329 test failures.
V6: CG-IR supports args, local incdec, switch; 319 test failures.
V7: Dropped IncDecOp in favor of Store/BinaryOp primitives.
    Added global variable support.
V8: Added support for heap scopes. 294 test failures.
V9: Add support for Load(IndexOp) and arrays as arguments. 290 test
    failures.
V10: Add support for varargs. 289 test failures.
V11: Port array helpers to IR. 280 test failures.
V12: Add for-loop support. 273 test failures.
V13: Get effective address calculation working. 271 test failures.
V14: Move array type resolution into the semantic pass, due to not
     having full semantic powers during name resolution.
     250 test failures.
V15: Fix argument type deduction. 247 test failures.
V16: Fix by-ref arguments. 243 test failures.
V17: Add support for "delete".
     Add support for operator overloads.
     Introduce the concept of temporary stack slots.
     233 test failures.
V18: Replace TempRef with StackRef.
     Implement FieldRef.
     Implement Paamayim Nekudotayim.
     225 test failures.
V19: Implement IncDec properly. 222 test failures.
V20: Implement PropertyRef.
     Implement varargs corner cases.
     208 test failures.
  • Loading branch information
dvander committed Sep 30, 2024
1 parent fd82555 commit f1b7c0e
Show file tree
Hide file tree
Showing 35 changed files with 3,864 additions and 2,522 deletions.
1 change: 1 addition & 0 deletions compiler/AMBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.sources += [
'data-queue.cpp',
'errors.cpp',
'expressions.cpp',
'ir.cpp',
'lexer.cpp',
'main.cpp',
'name-resolution.cpp',
Expand Down
Loading

0 comments on commit f1b7c0e

Please sign in to comment.