Experimenting with my MMG script, I've noticed that I sometimes want to abort its execution. When I do that, all the fancy statistics I print out on normal exit don't get printed.
I can envision having a couple of functions that would be invoked whenever ASH terminates a script, normally or abnormally.
void onExit();
called whenever a script terminates without error, either by running off the end of main() (or the end of the script, if you have no main() and are executing top-level statements), or by using the "exit" command.
void onAbort();
called whenever a script terminates prematurely, either because the user said to stop, the script said to abort, or a runtime error happens.
Questions:
- do we need both?
- obviously no recursion: if you get an error while executing one of these functions, no call to onAbort().
- should these be fixed-named functions (like main()), or should there be a way to declare that such-and-such a function is your "onAbort function", say?
How would people use this kind of feature? What do you think?
I can envision having a couple of functions that would be invoked whenever ASH terminates a script, normally or abnormally.
void onExit();
called whenever a script terminates without error, either by running off the end of main() (or the end of the script, if you have no main() and are executing top-level statements), or by using the "exit" command.
void onAbort();
called whenever a script terminates prematurely, either because the user said to stop, the script said to abort, or a runtime error happens.
Questions:
- do we need both?
- obviously no recursion: if you get an error while executing one of these functions, no call to onAbort().
- should these be fixed-named functions (like main()), or should there be a way to declare that such-and-such a function is your "onAbort function", say?
How would people use this kind of feature? What do you think?