implement custom destructors for extensions
git: commit
Ever since I landed the initial version of REPL, I was unhappy about the
fact that #io:readline
did not actually bind to the user input. And
that in turn was caused by the lack of means to free()
the memory
buffer allocated by the readline()
– the VM never signalled that the
value is no longer used.
Here I solve the problem by introducing special “type tag” builtins. I
expect these values to only ever be used in the 0th slot of a stack
object (the same one that can store “next” link in the linked list).
During garbage collection, I iterate through the discarded memory, and
if I find a type tag, then I call the corresponding destructor.
In order to not destruct the values that were merely moved, I added
src[0] = NIL
line into the collection loop of the garbage collector –
this way the type tags of values that are moved by garbage collection
are overwritten before the cleanup loop.
I demo this whole mechanics in the REPL.