Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an optimizing compiler #239

Open
wants to merge 88 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
fe964e2
Another IR, maybe for real this time
tekknolagi Jan 22, 2025
6214f3b
Pretty printing
tekknolagi Jan 22, 2025
cd64df3
Fix tests
tekknolagi Jan 22, 2025
1e6c8a3
.
tekknolagi Jan 23, 2025
7c97f7c
Add var
tekknolagi Jan 23, 2025
682c194
Add project section for uv
tekknolagi Jan 23, 2025
4ae6d33
.
tekknolagi Jan 23, 2025
34a528b
Support id function
tekknolagi Jan 23, 2025
9529131
Support let binding
tekknolagi Jan 23, 2025
b2f4c6c
.
tekknolagi Jan 23, 2025
0e5fa90
Add closures/closureref
tekknolagi Jan 23, 2025
3724850
Add list pattern matching
tekknolagi Jan 23, 2025
2f72953
.
tekknolagi Jan 23, 2025
6953478
List cons
tekknolagi Jan 23, 2025
1d3c948
Test non-const list
tekknolagi Jan 23, 2025
85067e8
Support call
tekknolagi Jan 23, 2025
05fc0d2
.
tekknolagi Jan 23, 2025
3eefe3a
Add int mul
tekknolagi Jan 23, 2025
ee96fcb
Let functions refer to themselves; support recursion
tekknolagi Jan 23, 2025
270a983
.
tekknolagi Jan 24, 2025
71fb887
.
tekknolagi Jan 24, 2025
528557a
.
tekknolagi Jan 24, 2025
528698f
.
tekknolagi Jan 24, 2025
4d25aeb
Add silly dominator analysis
tekknolagi Jan 24, 2025
c7f438b
Add RPO traversal tests
tekknolagi Jan 24, 2025
c227a85
Compute preds
tekknolagi Jan 24, 2025
2c15680
Run dominator tests on IR
tekknolagi Jan 24, 2025
075dc2d
Fix mypy
tekknolagi Jan 25, 2025
f7fee26
Start SCCP
tekknolagi Jan 25, 2025
bec1be1
SCCP list
tekknolagi Jan 25, 2025
0b66b8b
Fix mypy
tekknolagi Jan 25, 2025
528c01a
Start thinking about RefineType
tekknolagi Jan 25, 2025
d9d0e72
Add union-find infra
tekknolagi Jan 25, 2025
cf22dc1
Make MatchFail a terminator
tekknolagi Jan 25, 2025
1fd47fd
Print blocks in RPO
tekknolagi Jan 25, 2025
d0a1b14
Add CleanCFG
tekknolagi Jan 25, 2025
a77b71e
Return true if remove_unreachable_blocks changed
tekknolagi Jan 25, 2025
a5517da
.
tekknolagi Jan 25, 2025
2a21cb3
.
tekknolagi Jan 25, 2025
4b56aae
Support NewClosure and Call in SCCP
tekknolagi Jan 25, 2025
5408f74
ruff format
tekknolagi Jan 25, 2025
7cf0642
.
tekknolagi Jan 25, 2025
518dde2
Use InstrId.name
tekknolagi Jan 25, 2025
b0e90da
ruff format
tekknolagi Jan 25, 2025
da3fb54
Well, very silly simple cases work...
tekknolagi Jan 26, 2025
9274f00
.
tekknolagi Jan 26, 2025
da28a4c
Use handles (remove with analysis later)
tekknolagi Jan 26, 2025
33ad68e
.
tekknolagi Jan 26, 2025
56cc31b
Get a little closer to pattern matching and closures
tekknolagi Jan 26, 2025
47ddb7d
Forward declare functions
tekknolagi Jan 26, 2025
fb97c50
.
tekknolagi Jan 26, 2025
318d1dc
Compile closures
tekknolagi Jan 26, 2025
427f32e
Use OBJECT_HANDLE
tekknolagi Jan 26, 2025
adc3350
.
tekknolagi Jan 26, 2025
a2ae5f1
Support calls
tekknolagi Jan 26, 2025
367f000
.
tekknolagi Jan 26, 2025
4651981
.
tekknolagi Jan 26, 2025
b5d18a6
.
tekknolagi Jan 26, 2025
92e00e7
.
tekknolagi Jan 26, 2025
a257baf
Port some tests over
tekknolagi Jan 26, 2025
782eaad
.
tekknolagi Jan 26, 2025
121e9d5
Test closure vars
tekknolagi Jan 26, 2025
315819b
.
tekknolagi Jan 26, 2025
19b8b04
Optimize functions in to_c tests
tekknolagi Jan 26, 2025
84eacde
Constant fold
tekknolagi Jan 26, 2025
db79a5b
Tests opts on CFG
tekknolagi Jan 26, 2025
c0a8e9a
Support allocating empty records
tekknolagi Jan 26, 2025
c71f899
Add RecordSet, record_keys
tekknolagi Jan 26, 2025
a7f0cfd
Add RecordGet
tekknolagi Jan 26, 2025
134cc1f
Add IR test for RecordGet
tekknolagi Jan 26, 2025
9358bfd
Support Hole
tekknolagi Jan 26, 2025
fb830e8
Add string
tekknolagi Jan 27, 2025
2b4cd06
Compile int sub
tekknolagi Jan 27, 2025
171e3d9
Just use RPO in to_c
tekknolagi Jan 27, 2025
1bcff97
Add instructions for list matching
tekknolagi Jan 27, 2025
869fc44
Simplify
tekknolagi Jan 27, 2025
e89aec4
.
tekknolagi Jan 27, 2025
94d2699
.
tekknolagi Jan 27, 2025
9498b66
Support matching list spread
tekknolagi Jan 27, 2025
4179244
Support record pattern matching
tekknolagi Jan 27, 2025
e2b9876
Debugging cleanup
tekknolagi Jan 27, 2025
d4bc1e5
.
tekknolagi Jan 27, 2025
257ff85
.
tekknolagi Feb 2, 2025
6d885ee
.
tekknolagi Feb 2, 2025
cbc8896
.
tekknolagi Feb 2, 2025
b18f832
DCE; Nop
tekknolagi Feb 2, 2025
95f3b3d
.
tekknolagi Feb 7, 2025
763af02
.
tekknolagi Feb 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ jobs:
run: CC=${{matrix.CC}} CFLAGS="-fsanitize=undefined ${{matrix.USE_STATIC_HEAP}}" uv run python compiler_tests.py
- name: Run compiler tests with Valgrind
run: CC=${{matrix.CC}} CFLAGS="${{matrix.USE_STATIC_HEAP}}" USE_VALGRIND=1 uv run python compiler_tests.py
- name: Run IR tests (remove when merged)
run: CC=${{matrix.CC}} CFLAGS="${{matrix.USE_STATIC_HEAP}}" uv run python ir.py
run_compiler_unit_tests_other_cc:
runs-on: ubuntu-latest
steps:
Expand Down
11 changes: 4 additions & 7 deletions compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,19 @@ def try_match(self, env: Env, arg: str, pattern: Object, fallthrough: str) -> En
self._emit(f"if (!is_list({arg})) {{ goto {fallthrough}; }}")
updates = {}
the_list = arg
use_spread = False
for i, pattern_item in enumerate(pattern.items):
if isinstance(pattern_item, Spread):
use_spread = True
if pattern_item.name:
updates[pattern_item.name] = the_list
break
return updates
# Not enough elements
self._emit(f"if (is_empty_list({the_list})) {{ goto {fallthrough}; }}")
list_item = self._mktemp(f"list_first({the_list})")
# Recursive pattern match
updates.update(self.try_match(env, list_item, pattern_item, fallthrough))
the_list = self._mktemp(f"list_rest({the_list})")
if not use_spread:
# Too many elements
self._emit(f"if (!is_empty_list({the_list})) {{ goto {fallthrough}; }}")
# Too many elements
self._emit(f"if (!is_empty_list({the_list})) {{ goto {fallthrough}; }}")
return updates
if isinstance(pattern, Record):
self._emit(f"if (!is_record({arg})) {{ goto {fallthrough}; }}")
Expand Down Expand Up @@ -496,7 +494,6 @@ def compile_to_string(program: Object, debug: bool) -> str:
dirname = os.path.dirname(__file__)
with open(os.path.join(dirname, "runtime.c"), "r") as runtime:
print(runtime.read(), file=f)
print("#define OBJECT_HANDLE(name, exp) GC_HANDLE(struct object*, name, exp)", file=f)
if compiler.record_keys:
print("const char* record_keys[] = {", file=f)
for key in compiler.record_keys:
Expand Down
Loading
Loading