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

Port the whole Jou compiler to Jou #562

Merged
merged 39 commits into from
Jan 8, 2025
Merged

Port the whole Jou compiler to Jou #562

merged 39 commits into from
Jan 8, 2025

Conversation

Akuli
Copy link
Owner

@Akuli Akuli commented Jan 8, 2025

I ported the whole Jou compiler to Jou. The self-hosted compiler can now compile anything that the original Jou compiler can.

The self-hosted compiler can compile itself. In the below command, I called the result compiler2.

$ ./self_hosted_compiler -o compiler2 --linker-flags "-L/usr/lib/llvm-14/lib -lLLVM-14" self_hosted/main.jou 
$ ./compiler2 examples/hello.jou 
Hello World

Of course, the self-hosted compiler compiled with the self-hosted compiler can also compile the self-hosted compiler. I called it compiler3.

$ ./compiler2 -o compiler3 --linker-flags "-L/usr/lib/llvm-14/lib -lLLVM-14" self_hosted/main.jou 
$ ./compiler3 examples/hello.jou 
Hello World

This is something I have wanted to achieve for quite some time.

Caveats:

  • Code is messy. I ported most of it by taking C code and modifying it until it works.
  • It leaks memory. Some memory freeing code is commented out.
  • It lacks the simplify_cfg compilation step. Apparently, the only real consequence of this is that you won't get a compiler warning if you forget a return statement in a function.

See also other checkboxes in #116.

@Akuli Akuli changed the title Build the whole Jou compiler to Jou Port the whole Jou compiler to Jou Jan 8, 2025
@Akuli
Copy link
Owner Author

Akuli commented Jan 8, 2025

The diff of this pull request looks big because I moved the old self-hosted compiler to new folder self_hosted_old.

That said, the new self-hosted compiler is quite different from the old one, so in that sense I did a lot of work:

screenshot-1736359789

@Akuli Akuli merged commit 5b48fac into main Jan 8, 2025
23 checks passed
@Akuli Akuli deleted the full-compiler-port branch January 8, 2025 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant