>>103600810
I need it because coroutines are basically continuations anyway, might as well do the entire thing.
>Isn't it the opposite? that you can more easily copy the stack if it's in the heap?
That's right but the problem is primitive functions implemented in C won't get captured by a continuation even if I have a virtual machine with an explicit stack, and if I find a way to capture it I can just capture the whole evaluator state without bothering with a machine and manual stack management.
if (is_fn(car(expr)))
fn = car(expr)
args = cdr(expr)
for all args, args[i] = eval(args[i])
env = nest(env)
for all variables, bind(env, variable_names[i], args[i])
for all expr in fn.body, eval(expr)
if (is_primitive(car(expr)))
// eval args
primitive.func(env, args) // C function call with C stack
The primitive function call on the native stack can't be captured. At least not without some heavy wizardry?
>That's the kind of stuff you need to do in assembly.
That's fine. I was hoping someone would have done this before so I could read and study source code.
>You could maybe memcpy the C stack from C
That's my idea.
>but you need to fiddle in the dark about the start and end of the section you need to copy.
Yeah. My idea is to use some GCC builtins to get the frame pointers when delimiting and when capturing, and using those. I'll also need to save many of the registers according to platform ABI.
>Besides, you need to modify RSP and RBP anyway.
Those are all trivial... I'm worried about pointers into the stack. Looks like I'll need to scan the entire stack like an array of longs and update everything that falls within range to point at the new values somehow. This looks wrong