Related articles |
---|
Is multi-level function return possible? noitalmost@cox.net (noitalmost) (2014-03-10) |
Re: Is multi-level function return possible? kaz@kylheku.com (Kaz Kylheku) (2014-03-11) |
Re: Is multi-level function return possible? anton@mips.complang.tuwien.ac.at (2014-03-11) |
Re: Is multi-level function return possible? gneuner2@comcast.net (George Neuner) (2014-03-11) |
Re: Is multi-level function return possible? lkrupp@pssw.com (Louis Krupp) (2014-03-11) |
Re: Is multi-level function return possible? kaz@kylheku.com (Kaz Kylheku) (2014-03-11) |
Re: Is multi-level function return possible? tkowaltowski@gmail.com (Tomasz Kowaltowski) (2014-03-12) |
Re: Is multi-level function return possible? anton@mips.complang.tuwien.ac.at (2014-03-13) |
Re: Is multi-level function return possible? yaldnif.w@blueyonder.co.uk (Bill Findlay) (2014-03-14) |
Re: Is multi-level function return possible? ivan@ootbcomp.com (Ivan Godard) (2014-03-13) |
[34 later articles] |
From: | George Neuner <gneuner2@comcast.net> |
Newsgroups: | comp.compilers |
Date: | Tue, 11 Mar 2014 13:56:01 -0400 |
Organization: | A noiseless patient Spider |
References: | 14-03-020 |
Keywords: | code, history |
Posted-Date: | 11 Mar 2014 17:01:26 EDT |
On Mon, 10 Mar 2014 15:46:31 -0400, noitalmost <noitalmost@cox.net>
wrote:
>Is [multi-level return] a doable thing for a Pascal-like language that is
>meant to be compiled? I have a multi-level break which works within a
>procedure, but the return across procedure boundaries seems to add a lot
>of complications.
>
>I don't recall this being discussed in the dragon book, perhaps because it's
>just a silly idea. But implementing the multi-level break got me curious
>whether it's possible.
The modern term is "exception". See also "non-local" control
transfer, exit and/or return, and "escape" or "backtracking"
continuation.
I don't have my book handy to check but I *think* the purple dragon
has a discussion of exceptions. I'm pretty sure the older books don't
explicitly cover non-local control transfer, but careful reading of
the sections on control flow should allow inferring an implementation.
>[Sure, you can do it. PL/I let you jump out of a routine and I think Algol60
>may have, too. You just need to keep your stack frames sufficiently linked
>so that you can find the one you want and unwind everything below it. Look
>at the way Algol and Pascal reference variables in blocks outside the current
>routine and you'll get most of what you need. -John]
The real issue is whether you simply need to abort the computation
(perhaps with a return value) or whether you need to clean up side
effects: e.g., free heap allocations, restore variable values, etc.
The OP describes the language as "Pascal-like", but that doesn't
necessarily mean "simple" ... there certainly are modern OO and GC'd
Pascal derivatives for which the notion of "cleaning up" after an
exception can be quite involved.
The most primitive mechanism - performing only control transfer - is
something like C's setjmp/longjmp: you save the return point register
state (as if you are calling a function [even if you aren't]) and you
arrange that the state is [at least name] visible to the lower level
functions. In a Pascal-like language the simplest thing is just to
keep the saved state on the stack as a local variable of the
upper-most function and let lower functions refer to it as a non-local
variable.
George
Return to the
comp.compilers page.
Search the
comp.compilers archives again.