mfichman/apollo — Issue #43: Coroutine cleanup/initial destructor work
Author: mfichman
Created: 2011-12-17 23:05:48+00:00
State: open

Reserve a global (or thread-local) variable to store a pointer to the current exception. Analyze to determine if a function can throw an exception:
1. Set `can_throw = false` initially (`true` if there is a throw statement)
1. Compute `can_throw` for child functions
1. If a child can throw, set `can_throw = false`
1. Use an enum: `can_throw = true | false | undef`

If a function `can_throw`, then generate an `if` block after the call to check if `current_exception` is non-null. If it is, then cleanup, and jump to the `finally` or `catch` if there is one; otherwise, return garbage to `rax` and leave `current_exception` set.

Justification for this plan (vs. a table-driven exception handling scheme like C++ has): C interoperability, performance during exception throw/stack unwind. Cost: slight code performance loss from error-checking `if` blocks.