[comp.sys.apollo] Apollo Pascal and Modules

kjb@zycad.UUCP (Kevin Buchs) (11/07/87)

I have been working on modifying some old Apollo Pascal code 
and in adding new features I have been trying to make it 
more modular. By this I mean the use of seperate source 
code files and the "Module" declaration.  Under this 
implementation, there is a "main" module, which is the one 
headed with Program, instead of Module.  One may call any
procedure/function defined in any non-main module from any 
module including the main module.  There is one thing I 
don't understand:  Why can one not make calls to 
procedures/functions in the "main" module from one of the
non-main modules?

I am using the trivial workaround now of having a 1 line 
main module which calls a routine in a non-main module. 
In other words, I took all the code out of the main module
and put in into a non-main module, where I can call it 
from any other non-main module.

Are there other more clever workarounds, perhaps involving
the use of extern qualifiers?
-- 
Kevin Buchs   3500 Zycad Dr. Oakdale, MN 55109  (612)779-5548
Zycad Corp.   {rutgers,ihnp4,amdahl,umn-cs}!meccts!nis!zycad!kjb

Erstad@HI-MULTICS.ARPA (11/10/87)

You certainly can call main module procedures from any module.  However,
as with any Pascal code tehe procedures you want to call must be
declared.  The declaration is similar to a FORWARD declaration, except
that since the procedures called are outside the non-main compilation
unit an EXTERN declaration is used instead You are probably already
doing this to declare your non-main procedures to your main program (If
not, you should)

The above should work, although I've never had the occasion to call a
main program procedure from a module.  I'm not even sure I can think of
a good situation where I would want to do that...

Dave Erstad, Honeywell SSED

mishkin@apollo.uucp (Nathaniel Mishkin) (11/11/87)

In article <678@zycad.UUCP> kjb@zycad.UUCP (Kevin Buchs) writes:
>One may call any
>procedure/function defined in any non-main module from any 
>module including the main module.  There is one thing I 
>don't understand:  Why can one not make calls to 
>procedures/functions in the "main" module from one of the
>non-main modules?

I can't claim to being a Pascal purist who understands the "deep" reasons
for this sort of behavior, but I think the jist of the answer is this:
Apollo extends Pascal by allowing multiple modules and supporting "global"
("external") and "non-global" ("internal") procedures.  Procedures declared
in "program"s are implicitly (and un-overridably) treated as "internal".
I suspect this is because this is a "natural" extension of standard Pascal
where all procedures could be thought of as being "internal".

>I am using the trivial workaround now of having a 1 line 
>main module which calls a routine in a non-main module. 
>In other words, I took all the code out of the main module
>and put in into a non-main module, where I can call it 
>from any other non-main module.
>
>Are there other more clever workarounds, perhaps involving
>the use of extern qualifiers?

Another technique is to have no "program" but instead have all "module"s,
put the stuff that would have been in the "program"'s "begin/end" block
into a procedure called (say) "main", and use the binder's "-entry" option:

        bind -b myprogram mymod1.bin mymod2.bin -entry main
-- 
                    -- Nat Mishkin
                       Apollo Computer Inc.
                       Chelmsford, MA
                       {decvax,mit-eddie,umix}!apollo!mishkin

Erstad@HI-MULTICS.ARPA.UUCP (11/12/87)

My earlier approach to making main module procedures available to
non-main modules was incorrect.  Isent it off before testing.  I tried
it out, and it doesn't work - DOMAIN Pascal does not consider the main
module procedures to be global symbols.  Sorry about any confusion.

trb@stag.UUCP ( Todd Burkey ) (11/15/87)

In article <678@zycad.UUCP> kjb@zycad.UUCP (Kevin Buchs) writes:
> Why can one not make calls to 
>procedures/functions in the "main" module from one of the
>non-main modules?

Yep, I wasted a morning trying to get this to work too...(it wasn't
too explicit in the Apollo manuals that I couldn't do it). It may seem
like a trivial problem, but it causes other messy coding 'workarounds'
that are likely to haunt you if you every get into an environment like
we have (>1 million lines of code of Apollo Pascal scattered around on
200+ nodes in DSEE). Makes C (or even ADA) look so nice at times.
  -Todd Burkey
  trb@stag.UUCP