Sujet : Re: Continuations
De : mitchalsup (at) *nospam* aol.com (MitchAlsup1)
Groupes : comp.archDate : 15. Jul 2024, 21:59:23
Autres entêtes
Organisation : Rocksolid Light
Message-ID : <b8e363fbdd6dbe028902981b0b336a0f@www.novabbs.org>
References : 1
User-Agent : Rocksolid Light
On Sat, 13 Jul 2024 7:50:42 +0000, Lawrence D'Oliveiro wrote:
Has there ever been a hardware architecture that managed the flow of
control via “continuations”?
I want to simply ask WHY ??
Why do you think this would add value to an ISA ??
Why do you think this would add value to an HLL ??
Why do you think this would add value to a programmer ??
>
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 could learn to fly an airplane by coupling 16 or more electrodes
to your head and practicing flying until your brain figured it out !!
But there is a reason planes are not flow this way.....
>
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.
Block structured languages allow for this, they are not "in that great
a favor" right now.
>
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.)
The ugliness is (as BGB indicates) their poor performance.
So, whatever they bring to the party, does not seem to be
the "guest of honor".
>
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. ;)