comp.lang.ada
 help / color / mirror / Atom feed
* Re: Elaboration and parameters
@ 1993-06-29 19:51 cis.ohio-state.edu!math.ohio-state.edu!howland.reston.ans.net!noc.near.ne
  0 siblings, 0 replies; 5+ messages in thread
From: cis.ohio-state.edu!math.ohio-state.edu!howland.reston.ans.net!noc.near.ne @ 1993-06-29 19:51 UTC (permalink / raw)


In article <1993Jun29.190648.14096@news.eng.convex.com> 
  pelakh@convex.com (Boris Pelakh) writes:

>In article <rkaivola.741367993@mits> 
> rkaivola@mits.mdata.fi (Risto Kaivola) writes:
>>-- The purpose of this program is test exactly when PROGRAM_ERROR is
>>-- raised if the body of a subprogram has not yet been elaborated.
>>--
>
>	... Program removed ...
>
>>So, are the parameters of a subprogram evaluated if a body has
>>not been provided?  In my opinion, the Ada83 LRM is not exactly
>>clear on this.
>
>From my experience, most compilers generate the elaboration code in the
>prologue section of the subprogram, along with the storage check. Therefore
>the program_error would not be raised until all args have been evaluated.
>I could not find out from the LRM if that is actually the correct behaviour.

RM 3.9(5) only says:
  For a subprogram call, a check is made that the body of the
  subprogram is already elaborated.

This has been amended by AI-00406 (binding interpretation), implying
the following sentence should be added to the above:

  The check and the evaluations of any actual parameters of the
  call are done in an order not defined by the language.

In other words, the language does not specify the order.
I would agree with Boris that many compilers perform
the check after evaluating the actual parameters.  There
are a few compilers that perform the elaboration check at the 
call-site, and for these, I don't know which ones choose to do
the check before rather than after evaluating the actuals.

When it comes to failing language-defined checks,
there is a growing sense that overspecifying the order
is unwise (especially in the absence of a local handler
for the corresponding predefined exception), so you
should avoid programming in a way that
is dependent on the exact timing of language-defined checks.

>Boris Pelakh		Ada Project Leader          pelakh@convex.com

S. Tucker Taft
Intermetrics, Inc.
Cambridge, MA  02138

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Elaboration and parameters
@ 1993-06-29 21:06 Gene Ouye
  0 siblings, 0 replies; 5+ messages in thread
From: Gene Ouye @ 1993-06-29 21:06 UTC (permalink / raw)


Risto Kaivola (rkaivola@mits.mdata.fi) wrote:
:   Consider the following Ada program:

: --------------
: --
: -- The purpose of this program is test exactly when PROGRAM_ERROR is
: -- raised if the body of a subprogram has not yet been elaborated.
: --

: with TEXT_IO; use TEXT_IO;

: procedure PROC is
:   MY_EXCEPTION : exception;

:   subtype S is INTEGER range 0 .. 1;
:   A : S;

:   function EXCEPT(ARG : S) return S is
:   begin
:     raise MY_EXCEPTION;
:     return S(0);
:   end EXCEPT;

:   procedure CURIOUS(ARG : S) is separate;

: begin
:   CURIOUS(EXCEPT(A));
: exception
:   when MY_EXCEPTION =>
:     PUT("E");
:   when PROGRAM_ERROR =>
:     PUT("NE");
: end PROC;

: ------------

: So, are the parameters of a subprogram evaluated if a body has
: not been provided?  In my opinion, the Ada83 LRM is not exactly
: clear on this.

Are you asking what will happen if you try to execute the above
code without the corresponding subunit for the procedure CURIOUS?
If so, you should not get Program_Error because the program should
not be linked without the subunit.  To do so would violate LRM 10.2(4).

If you want to raise Program_Error, try the following:

  procedure I_Wont_Elaborate; -- this spec will elaborate, but the body won't

  package A_Package is
      procedure Some_Procedure_That_Wont_Get_Called;
  end A_Package;

  with A_Package;
  procedure I_Wont_Elaborate is
  begin
      A_Package.Some_Procedure_That_Wont_Get_Called;
  end I_Wont_Elaborate;

  with I_Wont_Elaborate;
  package body A_Package is
      procedure Some_Procedure_That_Wont_Get_Called is
      begin
          null; -- it doesn't matter here, we won't get called
      end Some_Procedure_That_Wont_Get_Called;
  begin
      I_Wont_Elaborate; -- an appropriate call...
  end A_Package;


I make no claims as to the invalidity of this code, I just typed it in
off the top of my head.  I'm sure others can come up with more succinct
examples (but that's not an invitation for a new thread!-)

Have fun with this,
Gene Ouye (geneo@rational.com)

(301) 897-4014

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Elaboration and parameters
@ 1993-06-29 23:20 Risto Kaivola
  0 siblings, 0 replies; 5+ messages in thread
From: Risto Kaivola @ 1993-06-29 23:20 UTC (permalink / raw)


Several people have pointed out that the original program is
no good for illuminating the issue because it won't be capable
of being bound.  The reason that the example turned out incorrect
is that I had actually a longish, working sample program, and
decided to strip it down a bit, and didn't bother to check the
new version even by compiling it.  Yes, I should have known better,
but I though it obvious it would work :-).  Nevertheless, you all
understood my intent correctly.  In case someone is interested, here
is the original example program, which should be correct apart from
possible types made in keying it in for this post.

-------------------- [sample program] --------------------

--- Compilation unit 1 ---
package P1 is
  MY_EXCEPTION : exception;

  subtype S is INTEGER range 0 .. 1;
  function EXCEPT(ARG : S) return S;

end P1;


--- Compilation unit 2 ---
package body P1 is
  function EXCEPT(ARG : S) return S is
  begin
    raise MY_EXCEPTION;
    return S(0);
  end EXCEPT;
end P1;


--- Compilation unit 3 ---
with P1;

package P2 is
  procedure PROC(ARG : P1.S);
end P2;


--- Compilation unit 4 ---
package body P2 is
  procedure PROC(ARG : P1.S) is
  begin
    null;
  end PROC;
end P2;


--- Compilation unit 5 ---
with TEXT_IO; use TEXT_IO;
with P1, P2;
pragma ELABORATE(P1);
-- Note: no ELABORATE pragma for P2.

procedure MY_MAIN is
  OBJ : P1.S := 0;
begin
  P2.PROC(P1.EXCEPT(OBJ));
    -- What happens here if the body of P2 has not yet been elaborated?
exception
  when PROGRAM_ERROR =>
    PUT("NE");
  when P1.MY_EXCEPTION =>
    PUT("E");
end MY_MAIN;

----------------- [end of program] -----------------

But anyway, if one of the exception handlers of the procedure MY_MAIN is
executed, the consensus seems to be that it is implementation dependent
whether NE or E is put, or are you of a different opinion?
 

--
Risto Kaivola
(Internet address:   rkaivola@mits.mdata.fi)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Elaboration and parameters
@ 1993-07-02  7:00 Richard A. O'Keefe
  0 siblings, 0 replies; 5+ messages in thread
From: Richard A. O'Keefe @ 1993-07-02  7:00 UTC (permalink / raw)


In article <rkaivola.741367993@mits>, rkaivola@mits.mdata.fi (Risto Kaivola) wr
ites:
> procedure PROC is
...
>   procedure CURIOUS(ARG : S) is separate;
> begin
>   CURIOUS(EXCEPT(A));
...
> end PROC;
 
> So, are the parameters of a subprogram evaluated if a body has
> not been provided?

Ada/Ed won't let me run this.  In order to run a program, I first have to
bind it, and if it thinks I'm using a subprogram it demands that there
_must_ be a body.  Is that valid behaviour?  I do hope so; the point of
using Ada is to learn about build errors _early_.

-- 
Richard A. O'Keefe; ok@goanna.cs.rmit.oz.au; RMIT, Melbourne, Australia.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Elaboration and parameters
@ 1993-07-04 16:49 Simon Wright
  0 siblings, 0 replies; 5+ messages in thread
From: Simon Wright @ 1993-07-04 16:49 UTC (permalink / raw)


References: <20650@goanna.cs.rmit.oz.au>
X-Newsreader: TIN [version 1.1 PL6]

Richard A. O'Keefe (ok@goanna.cs.rmit.oz.au) wrote:
> In article <rkaivola.741367993@mits>, rkaivola@mits.mdata.fi (Risto Kaivola) 
writes:
> > procedure PROC is
> ...
> >   procedure CURIOUS(ARG : S) is separate;
> > begin
> >   CURIOUS(EXCEPT(A));
> ...
> > end PROC;
>  
> > So, are the parameters of a subprogram evaluated if a body has
> > not been provided?
> 
> Ada/Ed won't let me run this.  In order to run a program, I first have to
> bind it, and if it thinks I'm using a subprogram it demands that there
> _must_ be a body.  Is that valid behaviour?  I do hope so; the point of
> using Ada is to learn about build errors _early_.
> 
> -- 
> Richard A. O'Keefe; ok@goanna.cs.rmit.oz.au; RMIT, Melbourne, Australia.

Ada/Ed 1.7.3 (Amiga version) runs fine; the output is `E'.

--
Simon Wright
Ferranti International, Defence Systems Integration

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1993-07-04 16:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1993-07-02  7:00 Elaboration and parameters Richard A. O'Keefe
  -- strict thread matches above, loose matches on Subject: below --
1993-07-04 16:49 Simon Wright
1993-06-29 23:20 Risto Kaivola
1993-06-29 21:06 Gene Ouye
1993-06-29 19:51 cis.ohio-state.edu!math.ohio-state.edu!howland.reston.ans.net!noc.near.ne

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