greg-d128 / caretaker

Experimental code, demonstrates code self healing
GNU General Public License v3.0
10 stars 0 forks source link

Re-entry into exception code #1

Open greg-d128 opened 1 month ago

greg-d128 commented 1 month ago

If code in in exception handler generates an exception in turn, weird things happen.

Either allow the handler to handle itself, or just make sure that code cannot throw an exception.

I like the idea of allowing the handler to handle its own code. Is it even possible to change the global exception hook while processing inside a function called via global exception hook?

If allowed, what happens? When would the function that was evicted be garbage collected? At that point that reference is likely the only reference to that function.

This will require some testing.

greg-d128 commented 1 month ago

Some more thinking and testing.

The code for dealing interacting with code through global exception hook has been moved to necromancer directory. Funny name, but actually pretty accurate.

At the moment the global exception hook is called, the program is effectively dead. All the scopes are still live, but the execution context has moved up the frame basically outside of the program. Restarting code at this point really is closer to reanimating dead body than anything else. Thus: necromancer.

Having said that, it is actually possible to reanimate this body, as long as exceptions were not caught and re-thrown (this question needs a separate investigation).

Having said that, since each scope's variables are still live, I can substitute the code and execute each line of code within the appropriate context. When reaching the end, I would need to go up the stack frame and continue there. Basically, I need to re-implement the execution within necromancer. This should be doable.