Re: Multiple return values

Ray Dillinger <bear@sonic.net>
13 May 1997 22:55:19 -0400

          From comp.compilers

Related articles
[24 earlier articles]
Re: Multiple return values Robert.Harley@inria.fr (1997-05-04)
Re: Multiple return values tim@franck.Princeton.EDU (1997-05-04)
Re: Multiple return values jens.hansson@mailbox.swipnet.se (1997-05-04)
Re: Multiple return values jamesl@netcom.com (1997-05-08)
Re: Multiple return values hbaker@netcom.com (1997-05-08)
Re: Multiple return values mark@omnifest.uwm.edu (1997-05-13)
Re: Multiple return values bear@sonic.net (Ray Dillinger) (1997-05-13)
Re: Multiple return values jan@fsnif.neuroinformatik.ruhr-uni-bochum.de (Jan Vorbrueggen) (1997-05-14)
Re: Multiple return values hbaker@netcom.com (1997-05-14)
Re: Multiple return values markt@harlequin.co.uk (Mark Tillotson) (1997-05-25)
Re: Multiple return values hbaker@netcom.com (1997-05-25)
Re: Multiple return values jmccarty@sun1307.spd.dsccc.com (1997-05-30)
| List of all articles for this month |

From: Ray Dillinger <bear@sonic.net>
Newsgroups: comp.compilers,comp.lang.misc
Date: 13 May 1997 22:55:19 -0400
Organization: Cognitive Dissidents
References: 97-04-091 97-04-112 97-04-135 97-05-045 97-05-094
Keywords: design, code, Scheme

Henry Baker wrote:
>
> From an implementation point of view, there are two critical properties
> of the multiple value that is just 'an ordered pair' (or tuple):
> * it is a _read-only_ pair (or tuple), which means that you don't have to
> supply it with an 'object identity' (address/pointer); and
> * it is received by exactly one receiver and then discarded (linear/unique
> property)
> Knowing these two properties allows for an extraordinarily efficient
> implementation of multiple return values. If you try to emulate
> multiple return values using 'heavier' objects --- those with object
> identity and reference counts >1 --- then prepare yourself for a very
> slow implementation.


Yes, this conversation often comes up on comp.lang.scheme. The
upcoming R5RS scheme language standard ("Real Soon Now! Honest!")
specifies multiple-result function returns and multi-argument
continuations.


As an implementor, I've been trying to dream up a "nice" and efficient
way to handle multiple returns from functions, and I'd like to hear
more about the method whose existence you mention above.


As far as I've gotten in thinking about it is to try to detect whether
the calling code wants (will actually use) one return value or more
(most of the time I figure it'll only want one) and compile separate
versions of the function; one which returns a single value (in
registers or on the stack) and one which returns more than a single
value (likewise).


That's been my standard approach to several optimization problems; I
have an intermediate form whose types closely match scheme's, and then
where the actual representations differ (such as between pointers at
bignums vs. immediate integer values), I compile separate versions of
the function calls. I then use type inference in the calling code to
link to the proper chunk o' machine code, which is sometimes explicit
type-checks and dispatching and sometimes just the raw compiled
functions themselves. This leads to a fair amount of code duplication
but minimizes runtime type checking. It sucks up memory, but it
executes with blazing speed.


Anyway, that will avoid using a "heavy" object to return function
results, but it will *further* bloat the compiled executable, and your
communication seems to indicate another approach. Perhaps I'm being
dense, but I don't see it -- can you say a little more?


Bear
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.