katsaii / catspeak-lang

A cross-platform modding language for GameMaker games.
https://www.katsaii.com/catspeak-lang/
MIT License
93 stars 6 forks source link

[IR] Allow `allocLocal` to reuse a local that's already defined. #126

Closed tabularelf closed 4 months ago

tabularelf commented 4 months ago

What is your feature request?

If you have this code

let i = 0;

while(foo < 3) {
   do_thing(i);
   i += 1;
}

let i = 10;
while(foo < 3) {
   do_other_thing(i);
   i += 1;
}

The parser will fail because you cannot currently assign a local the same name. While this is actually good practice imho, this also makes code like GML to break because GameMaker allows this. I already have made a quick patcharound in the parser in my own projects, but the IR should handle this.

Please describe in detail how you expect this new feature to behave.

Either:

katsaii commented 4 months ago

This was intentional because Catspeak has block scoping unlike GML. I'll think about changing this.

tabularelf commented 4 months ago

Yeah I have noticed the block scoping part. It did caught me off guard, but it's honestly livable. Though I suppose GML wise, that could too be extended for optional support but wobbles hands I do not have the final say!