4 ms·
> For instance, Smalltalk had the ability to suspend running programs into a saved image, and resume execution later at the saved point. I'm curious - is this
by WaxProlix 11y ago
> For instance, Smalltalk had the ability to suspend running programs into a saved image, and resume execution later at the saved point.
I'm curious - is this just a continuation? Or is it baked into the language, like exception handling or something? Any smalltalkers want to expound or link to relevant docs/tutorials?
- arnsholt 11y agoYou could call it a continuation, I guess, but continuations don't generally persist between separate invocations of your programming. The image is a file that can be passed around and when you open/execute (or whatever you want to call it), the program resumes where you left off. This is how most Lisp applications are distributed as well. Starting from a clean image (that is, one containing only the language standard library) you build up the initial state of your app by compiling the source files, and then dump the whole shebang as an image.
- david-given 11y agoIt's baked into the VM. When they say that in Smalltalk, everything's an object, they're seriously not kidding. Everything is an object, including compiled code, stack frames, execution contexts, threads, etc. A traditional Smalltalk system uses an object table, where all object pointers are really references to a slot in the table; this allows the garbage collector to move objects around in memory easily. This means that it becomes trivial to dump everything out to disk, reload it later, update the object table, and suddenly the entire state of your system is restored (ignoring host OS resources, of course, but traditionally Smalltalk didn't use an operating system). I did have a handy sample for GNU Smalltalk that would snapshot an image containing a running thread which, when the thread was reloaded, would seamlessly resume but, er, I seem to have lost it.
- cwp 11y agoYes, it is a continuation, although it's more comprehensive than call/cc. When you save a Smalltalk image it serializes not only the call stack but the entire heap. It's rather like a core dump that can resume executing. It's typically implemented in the VM as a primitive function kind of like posix fork(). When it returns, the entire state of the program has been saved to disk. The return value is a boolean, which tells you if you're returning from the original call, or resuming from the saved image. Classical Smalltalk dialects didn't have continuations as a flow control construct, but they did have reified stack frames, so it was possible to implement Scheme-style continuations in a few lines of code.