nim-works / phy

compiler and vm experiments
MIT License
3 stars 2 forks source link

add a higher-level IL to use as a target for `source2il` #21

Closed zerbina closed 2 months ago

zerbina commented 2 months ago

Summary

Add the L10 intermediate language, which is the first IL not structured around basic blocks (i.e., continuations). The pass10 pass lowers it into the L4 language.

Details

Motivation

Directly translating the source language into a language with explicit basic blocks is hard. L10 is intended to bridge the gap between the source language and L4.

Language

The name L10 is chosen so that there's still space for more ILs. It does away with the basic-block centered structure, instead providing higher- level control-flow constructs such as if, case, and loop.

A try/except like facility is currently missing, meaning that exception handling (where Raise is used) cannot be expressed.

Some way to delimit lifetimes of locals is also missing. Locals are currently treated as being alive for the whole duration, which can lead to locals that have their address taken being kept alive longer than necessary.

Apart from the new control-flow constructs, L10 stays close to L4, so that the lowering can focus on the splitting the procedure into basic blocks.


To-Do

Notes For Reviewers