Skip to content

Instantly share code, notes, and snippets.

@gerdr
Created September 6, 2011 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gerdr/1197666 to your computer and use it in GitHub Desktop.
Save gerdr/1197666 to your computer and use it in GitHub Desktop.
precise gc of stack vars

###IDEA keep PMC pointers in explicit shadow-stack, a linked list of frames

###IMPLEMENTATION

struct frame
{
    struct frame *prev;
    size_t size;
    PMC **pmcs;
};
  • function prolog (add frame to stack):

      PMC *pmcs[42] = { 0 };
      struct frame frame = { interp->last_frame, sizeof pmcs / sizeof *pmcs, pmcs };
      interp->last_frame = &frame;
    
  • function epilogue (remove frame from stack):

      interp->last_frame = frame.prev;
    

###PRO

  • can be done in standard C
  • resembles current approach, but portable

###CONTRA

  • awkward: PMC variables could never be named
  • not general enough for all use cases

###ALTERNATIVES

  • add ref count to PMCs which tracks external references; such a more general approach would make things like easy C++ integration via smart pointers possible
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment