title: Implementing destructors in generated C code
body: <p>Suppose I sometime would like to write a compiler that generates C code for a language that:</p>
  
  <ul>
    <li>has purely reference counting GC,</li>
    <li>lets you return to a point multiple frames up the stack (stealing Common Lisp's <code>(return-from)</code> form),</li>
    <li>and lets you define a destructor for each data type (to be called immediately before the memory for the data structure is freed).</li>
  </ul>
  
  <p>How would you go about implementing this?  Could you do it (well) with C's <code>setjmp()</code> and <code>longjmp()</code> and a global list of points to return to for clean up while unwinding the stack?</p>
  
  <p>Another possibility is to just generate C++ code.</p>