rusty
rusty copied to clipboard
Simplify codegen by using the new lowering strategies
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_blockis afunctionwith athispointer as the first parameter - A
programis afunction_blockwith a global instance - A
methodis afunction_blockwith additional parameters - An
actionis afunction_block
- A
- [ ] 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