From: hybl@umbc4.umbc.edu (Dr. Albert Hybl (UMAB-BIOPHYS))
Subject: Re: summary (was Fortran 90:  Pointers to Functions?)
Organization: Univ. of MD, Baltimore County
Date: Tue, 1 Sep 1992 19:41:22 GMT

In message <1992Aug18.181240.8613@news.eng.convex.com> from Patrick F.
McGehearty <patrick@convex.COM> dated Tue, 18 Aug 1992, Patrick writes:
>>In article <16q6bdINNpqh@darkstar.UCSC.EDU> sla@fast.ucsc.edu
>>(Steve Allen) writes:
>>This is the final summary of all gleaned wisdom on the topic of
>>Pointers to Functions in Fortran 90.
>...
>There is a way to get the desired functionality using computed goto's.
>Determine every possible function that might be assigned to the pointer.
>Write a function which is called with the same arguments plus an index.
>Store the index in an integer instead of the function in a pointer.
[Example deleted.]

I have included below a few snippets of code that present another
interesting example of a pointer to an array of functions.
The original code comes from a digital simulation language
called MIMIC that I had working on both a UNIVAC 1108 and
an IBM mainframe.  Since I no longer use either machine,
the code has gone to seed.

MIMIC is a fortran program that assembles machine language commands
into an array based on a model input by the user on card images
using fixed field format.  It would then transfer to the array
and execute the simulation.  It makes use of some fortran
functions and several of its own.  The array of function
names are in the array LMJNAM while the labeled common /LMJLST/
contained the actual machine language transfer commands, LMJCMD.
The INTEGER FUNCTION GETLMJ(NAME) would return the appropriate transfer
command for the function specified by the character argument NAME.

*   ************************************************************
      Integer function getlmj(name)
        Character name*(*)
*
      Common /lmjlst/ lmjcmd(16)
*
      Character lmjnam(16)*3
        Data lmjnam/'LOG','ATN','COS','EXP','SIN','SQR','DMP','HDR',
     &  'PAR','OUT','PLO','PFN','IMP','FUN','RNG','TDL'/
*
      izero = 0
      j = 0
 1035 continue
        j = j + 1
        If (lmjnam(j) .eq. name) goto 1075
      If (j .lt. 16) goto 1035
 1075 continue
*
      getlmj = or(izero,lmjcmd(j))
      Return
      End

The following is the snippet showing how the functions SQRT,
SIN, and COS are assembled into UNIVAC machine code.

*   ************************************************************
      If ((fctn.eq.'SQR').or.(fctn.eq.'SIN').or.(fctn.eq.'COS')) then
        mf(if) = or(bla,loc(mf(if+5))) @ Stash LA   A0,(address pointer)
        mf(if+1) = or(izero,blxi)      @ Stash LXI,U X11,0
        mf(if+2) = getlmj(fctn)        @ Branch via LMJ X11,(Subroutine)
        mf(if+3) = or(bj,aff+6)        @ Jump around parameter list
        mf(if+4) = or(izero,aa)        @ Stash address of 1st operand
        mf(if+5) = or(or(q1one,q2one),loc(mf(if+4))) @ No check,#ars,loc(arg1)
        mf(if+6) = or(bnop,ifls)
        mf(if+7) = or(bsa,ar)          @ Store address for result value
        if = if + 8
        goto 120
      endif

The following snippet is the segment of UNIVAC assembly code that was
used to capture the relocatable addresses of the functions that are
needed by the loader.

*   ************************************************************
$(1)     AXR$.
fxz*       J          FF
fxz5*      J          FF+5
$(2)
P     RES    95
R     RES    2000
S     RES    3000
FF    RES   10000
      INFO  4 2
$(4)       axr$ .
           ascii
           LMJ        X11,FTN$ALOG
           LMJ        X11,FTN$ATAN2
           LMJ        X11,FTN$COS
           LMJ        X11,FTN$EXP
           LMJ        X11,FTN$SIN
           LMJ        X11,FTN$SQRT
           LMJ        X11,DMP
           LMJ        X11,HDR
           LMJ        X11,INP
           LMJ        X11,OUT
           LMJ        X11,PLO
           LMJ        X11,SFN
           LMJ        X11,IMP
           LMJ        X11,MIMFN
           LMJ        X11,MIMRN
           LMJ        X11,MIMTD
lmjlst     info  2 4
           end

This is as close as I have come to working on compiler code.  It
illustrates the lengths to which one would go to create "fast"
looping code.

Regards,
Albert Hybl (hybl@umbc3.umbc.edu)
Newsgroups: comp.lang.fortran