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

Simplify codegen by using the new lowering strategies #1388

Open
4 tasks
ghaith opened this issue Jan 15, 2025 · 0 comments
Open
4 tasks

Simplify codegen by using the new lowering strategies #1388

ghaith opened this issue Jan 15, 2025 · 0 comments

Comments

@ghaith
Copy link
Collaborator

ghaith commented Jan 15, 2025

With the new lowering introduced in #1379 we were able to remove some parts of the codegen by simplifying the AST
we can push that further:

  • Convert generics at an early stage
    • After annotation, we can replace the generic call with the appropriate type, we can also create the new functions
    • Monomorphisation can happen early if we implement it.
  • Convert methods, programs and function blocks to functions
    • A function_block is a function with a this pointer as the first parameter
    • A program is a function_block with a global instance
    • A method is a function_block with additional parameters
    • An action is a function_block
  • Simplify conditions and loops by converting them to labels and jumps
    • LLVM does not have loops or if statements, we convert these concepts to labels and jumps, which we already have in our AST
    • There should be no problem converting them early
  • Resolve auto pointers for in/outs, arrays and aggregate returns at an early stage
    • Instead of keeping the logic of auto pointer variables all the way to the codegen, we can rewrite the access to such variables as pointer access and let the codegen only worry about pointers.

The basic idea is that the logic we currently do in codegen can be moved to an earlier stage. While it would mostly remain the same logic, codegen would be simplified greatly which would make it easier to update to newer inkwell versions.
The changes we make can then also be reflected in the AST and tested without the need to go into a codegen phase.
Ideally, the codegen only creates datatypes, variables and functions.
In the functions, the codegen ideally just creates expressions, calls and jumps

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

No branches or pull requests

1 participant