olix3001/PurrLang

[FEAT] Inline variables that are used only once/are constant values

Opened this issue · 3 comments

This title is self-descriptive, when using let a = "hello"; which is not modified later on we could just inline "hello" literal in places where a variable is used.

This nicely overlaps with #7 as It also requires keeping track of compile time-known values.

One way of implementing this optimisation would be going over the generated code and checking for variables that are referenced only once. This introduces another step into the already complex pipeline, but might be worth It as It can optimise not only variables themselves but also call returns and other similar things.

Another approach would be going over the AST and checking for variables and calls usage. When we detect that variable is referenced only once we can inline that.

Keeping track of values during compilation must also be introduced as It is necessary for macros.