rusty icon indicating copy to clipboard operation
rusty copied to clipboard

Simplify codegen by using the new lowering strategies

Open ghaith opened this issue 1 year ago • 0 comments

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

ghaith avatar Jan 15 '25 06:01 ghaith