Picking the last entry in this thread to reply to...

Here's the scoop with register stacks, stacks in general, and continuations.

The pointers to all these stack tops *should* be part of a continuation, the same as the registers themselves should be. When a continuation is taken, all the frames to the top should be marked COW, and any access to the frames should copy them.

This does have the "interesting" side-effect of preserving integer and float values across continuations, while allowing string and PMC values to fluctuate. That is, since string and PMC stack entries are pointers, changes to their contents propagate across continuations, while changes to ints and floats do not. This has some ramifications for code saving loop counters and whatnot on the stack. Short (though not all that satisfying) answer--deal with it, or use a PMC.

Stack frames should probably just be globs of stack frame entry memory with a pobj stuck on the front, allocated in one big hunk (with pointers fixed up on allocation), to make DODing the things easier. That is, a stack chunk should have the structure:

   struct hunk {
     struct pobj header;
     INTVAL used;
     INTVAL avail;
     struct hunk *upchain;
     struct regframe RegisterFrame[FRAMES_PER_HUNK];
   }

more or less. When one's allocated the pointers in the header get set to point to the body, or whatever, with flags set appropriately. Modifying one marked COW should just copy the whole wad to a new hunk and adjust the header pointers as need be.

To avoid massive thrashing, we should add a frameclose op, to mark a frame as closed and start a new one regardless of how many entries might still be free in the frame. When the interpreter is about to do something that'll result in a COW marking of the frame it closes the frame off and starts a new one (though marking a topmost entry as COW could automatically close it. There are issues there)

Also to avoid thrashing some, adding a multi-entry pop will help. Dropping 2 or more stack entries may toss an entire COW'd frame, avoiding the need to make a copy just for the purpose of messing around with the used/avail counts to drop it two or three ops later.
--
Dan


--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                      teddy bears get drunk

Reply via email to