Johan-Mi / scratch-compiler-2

Yet another language that compiles to Scratch
The Unlicense
3 stars 0 forks source link

Mid-level intermediate representation (MIR) #4

Closed Johan-Mi closed 10 months ago

Johan-Mi commented 10 months ago

To make certain transformations easier—mainly constant folding and (return) variable allocation/removal—it might be a good idea to introduce a mid-level intermediate representation. This would be a flattened version of the HIR where function calls cannot be nested. Instead they would be assigned to temporary variables, ensuring that side effects do not get reordered. We could also throw away a bunch of information from the HIR since that's the last representation that we perform error checking on. We might also want to turn builtin function calls into their own expression kind to make it easier to check for them.

Johan-Mi commented 10 months ago

This would bring us one step closer to fixing #3.

Johan-Mi commented 10 months ago

Update: I've started working on this on the mir branch.

Johan-Mi commented 10 months ago

Problem: the current representation of block parent pointers can't work since reaching a block by traversing a function means that the parent block is already mutably borrowed. Maybe store the values assigned to the variables separately and only put the evaluation order in the blocks?