Deutsch English Français Italiano |
<v6tbki$3g9rg$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Lawrence D'Oliveiro <ldo@nz.invalid> Newsgroups: comp.arch Subject: Continuations Date: Sat, 13 Jul 2024 07:50:42 -0000 (UTC) Organization: A noiseless patient Spider Lines: 33 Message-ID: <v6tbki$3g9rg$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Sat, 13 Jul 2024 09:50:42 +0200 (CEST) Injection-Info: dont-email.me; posting-host="4afe4a8ac7caac09e54830e7e7a8837d"; logging-data="3680112"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/o9ZG4ZROmKsYd2ZFHFkfy" User-Agent: Pan/0.158 (Avdiivka; ) Cancel-Lock: sha1:Zv5JSXGk3T+ur9qmWWeb+mn5MgY= Bytes: 2841 Has there ever been a hardware architecture that managed the flow of control via “continuations”? That is, you do away with the hardware concept of a stack. Instead, you have call frames that, while defined to some extent by the architecture, can be located anywhere in memory (allocation managed by the OS, runtime etc as part of the ABI). A call frame has a current program counter, and maybe some other context like local variables and a static link for lexical binding. Instead of a “return from subroutine” instruction, you have a “load new call frame” instruction. You might have a location defined in a call frame for a “pointer to parent call frame” field, in which case “return from subroutine” just loads this pointer into the current-call-frame register. But you could just as easily have pointers to other call frames defining other kinds of interrelationships between them. And note that transferring to a different call frame does not automatically invalidate the previous one. If it stays valid, then there is no reason why you couldn’t, at some point, come back to it and resume execution from where it left off. The beauty of continuations is that they are a single generalized control construct that can be used to implement specific language features like regular routine calls, loops, exceptions and coroutines, all built from the same common abstraction. One thing that is difficult to do with them is arbitrary gotos. (I consider that a feature, not a bug.) Very few high-level languages (outside of the Lisp family, anyway) seem to have implemented continuations as an explicit language concept. This is an integral part of Scheme, not so much it seems of non-Scheme Lisps. I implemented it in my PostScript revival language <https://bitbucket.org/ldo17/gxscript/>, and I am still trying to come up with a useful example, like for instance an implementation of coroutines, that doesn’t do my head in. ;)