The languages I'm faced with compiling in the near future have nonlocal
go to statements and nested procedures.
A procedure gets implemented as a structure containing its entry point
and an environment pointer. It is easy enough to call its entry point
and pass the environment pointer as an extra argument (rather like the
pointer to this or self in object-oriented code). It's no problem. The
trampoline intrinsic is a neat way of packaging this so as to retrofit
into C's one-address-only function pointer, but that's not necessary in a
language where procedures are all known to have this behaviour.
The problem is with the go to statement. Again, local go to's, that go
somewhere within the same function are no particular problem -- though I
haven't studied the interaction with alloca yet; that might offer a few
surprises. The questions I have are about goto's that exit from a
function. The traditional mechanism is to implement a label as an
instruction-pointer/environment-pointer pair, just as for procedures.
You just load the environment-pointer into the appropriate register, and
jump to the address. (again there are technical details about the size
of the local stack at the destination, disposition of alloca storage, and
the like, and nowadays, unwinding the stack).
I don't see a mechanism for this.
The closest I see is the mechanism for exceptions. I cannot tell by
reading the documentation for exception-handling whether it is
sufficiently flexible to accomodate nonlocal goto's. It's plain that on
modern systems (which dribble saved registers all over the sack) some
kind of unwinding is necessary, and that the traditional model of loading
a register and jumping is no longer sufficient. What's not clear is
whether the exception handling mechanism is sufficiently dynamic to
permit an accurate specification of the jump target. It's not
necessarily the most local version of the label on the stack that's the
target; it's the one whose stack frame is reached by the jumping
procedure's array of static links.