olix3001 / PurrLang

Another attempt at programming language that compiles to scratch blocks.
3 stars 0 forks source link

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

Open olix3001 opened 2 weeks ago

olix3001 commented 2 weeks ago

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.

olix3001 commented 2 weeks ago

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.

olix3001 commented 2 weeks ago

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.

olix3001 commented 2 weeks ago

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