katsaii / catspeak-lang

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

Allowing locals to be cleared before returning the results of a Catspeak function. #91

Closed tabularelf closed 2 months ago

tabularelf commented 9 months ago

What is your feature request?

For performance reasons, locals don't reset their values at all. This makes it a lot faster for code execution, but quickly falls apart if you want to use something like weak references.

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

Say for example you have a Catspeak function that does this

let struct = {};
let weak = weak_ref_create(struct);
return weak;

And you call it once, that Catspeak function doesn't clear its locals til the next time you call it. Meaning that struct reference is never lost. If locals could be cleared instead before returning the results, then weak references will work as expected because structs will be dereferenced. One way is to change the behaviour, but for performance reasons I don't want to enforce that.

If #89 gets added, this could be instead a simple toggle that clears locals for proper dereferencing of structs