3 ms·
> I don't see why you couldn't implement continuations in modern Free Pascal/Lazarus, all you really have to do is make a copy of the stack(using the heap), the
by a1369209993 5y ago
> I don't see why you couldn't implement continuations in modern Free Pascal/Lazarus, all you really have to do is make a copy of the stack(using the heap), then adjust BP and SP, everything else on the stack is relative to those two registers.
Easy-to-understand but nonsystematic counterexample: what happens when the stack contains a pointer to dynamically allocated memory? If you shallow copy it, you have a double free. If you deep copy it, how? Do you even know how much memory to allocate? What if it's a file descriptor instead?
(Fork only works because the OS can blindly duplicate the entire process and everything in it, and even then you have problems like IO buffers.)
- mikewarot 5y agoThis is quite similar to an unsafe use of a variable in a thread, and would have the same consequences. You have to make certain assumptions about the nature of the program as compiled, if those assumptions are wrong, poof!
- a1369209993 5y agoThe problem in this case is that the assumptions will be wrong for any nontrivial program. (Edit: pedantically, any nontrivial use of continuations in a program.)