comp.lang.ada
 help / color / mirror / Atom feed
From: "Robert I. Eachus" <rieachus@comcast.net>
Subject: Re: Where are returned values stored?
Date: Tue, 01 Jun 2004 23:14:58 -0400
Date: 2004-06-01T23:14:58-04:00	[thread overview]
Message-ID: <juidnUukO-Gu2yDd4p2dnA@comcast.com> (raw)
In-Reply-To: <2lNtc.56154$tb4.2140194@news20.bellglobal.com>

Warren W. Gay VE3WWG wrote:

> If this indeed happens (on a given platform), I would think
> that the calling convention used is +critical+. For example,
> if you forced an Ada routine to use the C calling convention,
> I would bet that on most platforms, that all return values
> must be _copied_ or placed on the heap (temporarily). At least
> this would be true for strings/arrays etc. where the size
> was not known in advance.
> 
> This is because most platforms (I think), have C
> programs pop off their stack frame as part of the
> return "process" (I believe this to be true of
> Wintel and Linux on Intel for example).
> 
> So the compiler might be forced to copy the return
> value to some other location, or make some other
> arrangement for non Ada calling conventions. You
> obviously can't just re-extend the stack frame after
> a return because of the possibility of UNIX process
> signal calls or interrupt processing that
> may overwrite the stack area of interest.
> 
> For this reason, I would expect that an Ada calling
> convention (when it supports this "return value in
> place" concept) probably has the called function Foo,
> performing the shrink of its stack frame
> as part of the return "processing"; but only enough
> to keep the return value protected. The caller then
> must finish the job by some prior arrangement known
> to the compiler, after the return value is no longer
> required.

Several Ada compilers used a two-stack strategy.  One was the normal 
call stack, and the other was mostly for function return values.  Since 
you only needed to create things on the second stack for functions with 
return values that were not passed in registers, the overhead only 
appeared when you did have such functions.  And the compilers were 
'smart' enough to do any necessary splicing of values correctly.

So a function fubar returning "foo(x) & bar(y)" where foo and bar were 
functions returning strings would pass the descriptors in registers or 
as part of the calling sequence on the first stack.  Only the characters 
in the strings would go on the second stack, and of course fubar would 
just do the descriptor arithmetic and not touch the second stack at all.

I think Softech's ALS had a variation, on the two stack approach, but I 
didn't think much of it.  They used ping-pong stacks.  There were two 
stacks but the stack frames for the caller and callee were always on 
different stacks.  That way the caller could inspect the whole stack 
frame of a function that had just returned if necessary--but all it did 
was look for the location of the return value and also for the 
descriptor information if necessary.  However, in the case of nested 
calls with variable sized arguments returned through, the return values 
  had to be copied back and forth.

-- 

                                           Robert I. Eachus

"The terrorists rejoice in the killing of the innocent, and have 
promised similar violence against Americans, against all free peoples, 
and against any Muslims who reject their ideology of murder. Their 
barbarism cannot be appeased, and their hatred cannot be satisfied. 
There's only one way to deal with terror: We must confront the enemy and 
stay on the offensive until these killers are defeated." -- George W. Bush




  parent reply	other threads:[~2004-06-02  3:14 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-26 19:46 Where are returned values stored? (follow up to yesterday's question) James Alan Farrell
2004-05-26 20:44 ` Simon Wright
2004-05-27  7:51   ` Dmitry A. Kazakov
2004-05-27  9:39 ` Where are returned values stored? Marius Amado Alves
2004-05-27 17:05   ` Warren W. Gay VE3WWG
2004-05-27 20:24     ` James Alan Farrell
2004-05-28 20:33       ` Warren W. Gay VE3WWG
2004-05-29  7:03         ` Martin Krischik
2004-05-29 13:19           ` Larry Kilgallen
2004-05-30  7:10             ` Martin Krischik
2004-06-02  3:14         ` Robert I. Eachus [this message]
2004-05-30 21:17     ` Nick Roberts
2004-05-31 12:58       ` Warren W. Gay VE3WWG
2004-06-02  4:07         ` Robert I. Eachus
2004-06-02 12:42           ` Warren W. Gay VE3WWG
2004-06-03  2:00             ` Nick Roberts
2004-06-03  4:34             ` Robert I. Eachus
2004-06-03 16:06               ` Warren W. Gay VE3WWG
2004-06-03 16:13               ` Nick Roberts
2004-06-07  1:53                 ` Robert I. Eachus
2004-06-07 13:09                   ` Larry Kilgallen
2004-06-09  7:03                     ` Robert I. Eachus
2004-06-05 17:13             ` Simon Wright
2004-05-27 17:11   ` Martin Krischik
2004-05-27 17:07 ` Where are returned values stored? (follow up to yesterday's question) Martin Krischik
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox