AnyDSL / thorin

The Higher-Order Intermediate Representation
https://anydsl.github.io
GNU Lesser General Public License v3.0
151 stars 15 forks source link

Add a Control construct and re-engineer closure conversion #138

Open Hugobros3 opened 1 year ago

Hugobros3 commented 1 year ago

This 🚧 draft 🚧 PR adds a control construct as found in Shady and performs a significant amount of refactoring on the IR to support closure conversion more robustly. This is not currently merge-able and exists as a tracking issue.

Current changelist:

The lowering for this is tricky: setjmp/longjmp cannot be safely used inside functions because they can overwrite side effects that have happened in-between the control call and consuming the token. One solution is to emit cps-style code instead of direct-style, and then we can use tailcalls and perform manual stack pointer adjustments instead.

However there are backends where this will not be permissible (those who lack true function calls mostly) and we will need to find an alternative solution for those.

Still TODO: