savi-lang / savi

A fast language for programmers who are passionate about their craft.
BSD 3-Clause "New" or "Revised" License
153 stars 12 forks source link

Add GC finalizers #444

Open mneumann opened 1 year ago

mneumann commented 1 year ago

In my case this would be useful so that GLFW.terminate will be called once all references go out of scope / get recyled (there will only ever be one instance...). Meaning, you cannot terminate GLFW while there are still references to it. Atm, this is not possible, or I didn't find the appropriate functionality.

jemc commented 1 year ago

Yes, finalizers are still missing. The mechanism is there in the Pony runtime (which we leverage in Savi), but the Savi language/compiler is not set up to use it yet.

What do you think of the following syntax?

:class GLFW
  :finalizer
    _FFI.glfwTerminate
jemc commented 1 year ago

A few things at top of mind that the compiler needs to take care of to make finalizers work:

With all that done, then it's just a matter of hooking into the finalizer desc slot in the Pony runtime in the LLVM IR generation pass to make it happen.

mneumann commented 1 year ago

The syntax would work perfectly!