home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / fortran / 3343 < prev    next >
Encoding:
Text File  |  1992-09-01  |  4.4 KB  |  121 lines

  1. Newsgroups: comp.lang.fortran
  2. Path: sparky!uunet!gatech!darwin.sura.net!haven.umd.edu!news.umbc.edu!umbc4.umbc.edu!hybl
  3. From: hybl@umbc4.umbc.edu (Dr. Albert Hybl (UMAB-BIOPHYS))
  4. Subject: Re: summary (was Fortran 90:  Pointers to Functions?)
  5. Message-ID: <1992Sep1.194122.20832@umbc3.umbc.edu>
  6. Sender: newspost@umbc3.umbc.edu (News posting account)
  7. Organization: Univ. of MD, Baltimore County
  8. Date: Tue, 1 Sep 1992 19:41:22 GMT
  9. Lines: 110
  10.  
  11. In message <1992Aug18.181240.8613@news.eng.convex.com> from Patrick F.
  12. McGehearty <patrick@convex.COM> dated Tue, 18 Aug 1992, Patrick writes:
  13. >>In article <16q6bdINNpqh@darkstar.UCSC.EDU> sla@fast.ucsc.edu
  14. >>(Steve Allen) writes:
  15. >>This is the final summary of all gleaned wisdom on the topic of
  16. >>Pointers to Functions in Fortran 90.
  17. >...
  18. >There is a way to get the desired functionality using computed goto's.
  19. >Determine every possible function that might be assigned to the pointer.
  20. >Write a function which is called with the same arguments plus an index.
  21. >Store the index in an integer instead of the function in a pointer.
  22. [Example deleted.]
  23.  
  24. I have included below a few snippets of code that present another
  25. interesting example of a pointer to an array of functions.
  26. The original code comes from a digital simulation language
  27. called MIMIC that I had working on both a UNIVAC 1108 and
  28. an IBM mainframe.  Since I no longer use either machine,
  29. the code has gone to seed.
  30.  
  31. MIMIC is a fortran program that assembles machine language commands
  32. into an array based on a model input by the user on card images
  33. using fixed field format.  It would then transfer to the array
  34. and execute the simulation.  It makes use of some fortran
  35. functions and several of its own.  The array of function
  36. names are in the array LMJNAM while the labeled common /LMJLST/
  37. contained the actual machine language transfer commands, LMJCMD.
  38. The INTEGER FUNCTION GETLMJ(NAME) would return the appropriate transfer
  39. command for the function specified by the character argument NAME.
  40.  
  41. *   ************************************************************
  42.       Integer function getlmj(name)
  43.         Character name*(*)
  44. *
  45.       Common /lmjlst/ lmjcmd(16)
  46. *
  47.       Character lmjnam(16)*3
  48.         Data lmjnam/'LOG','ATN','COS','EXP','SIN','SQR','DMP','HDR',
  49.      &  'PAR','OUT','PLO','PFN','IMP','FUN','RNG','TDL'/
  50. *
  51.       izero = 0
  52.       j = 0
  53.  1035 continue
  54.         j = j + 1
  55.         If (lmjnam(j) .eq. name) goto 1075
  56.       If (j .lt. 16) goto 1035
  57.  1075 continue
  58. *
  59.       getlmj = or(izero,lmjcmd(j))
  60.       Return
  61.       End
  62.  
  63. The following is the snippet showing how the functions SQRT,
  64. SIN, and COS are assembled into UNIVAC machine code.
  65.  
  66. *   ************************************************************
  67.       If ((fctn.eq.'SQR').or.(fctn.eq.'SIN').or.(fctn.eq.'COS')) then
  68.         mf(if) = or(bla,loc(mf(if+5))) @ Stash LA   A0,(address pointer)
  69.         mf(if+1) = or(izero,blxi)      @ Stash LXI,U X11,0
  70.         mf(if+2) = getlmj(fctn)        @ Branch via LMJ X11,(Subroutine)
  71.         mf(if+3) = or(bj,aff+6)        @ Jump around parameter list
  72.         mf(if+4) = or(izero,aa)        @ Stash address of 1st operand
  73.         mf(if+5) = or(or(q1one,q2one),loc(mf(if+4))) @ No check,#ars,loc(arg1)
  74.         mf(if+6) = or(bnop,ifls)
  75.         mf(if+7) = or(bsa,ar)          @ Store address for result value
  76.         if = if + 8
  77.         goto 120
  78.       endif
  79.  
  80. The following snippet is the segment of UNIVAC assembly code that was
  81. used to capture the relocatable addresses of the functions that are
  82. needed by the loader.
  83.  
  84. *   ************************************************************
  85. $(1)     AXR$.
  86. fxz*       J          FF
  87. fxz5*      J          FF+5
  88. $(2)
  89. P     RES    95
  90. R     RES    2000
  91. S     RES    3000
  92. FF    RES   10000
  93.       INFO  4 2
  94. $(4)       axr$ .
  95.            ascii
  96.            LMJ        X11,FTN$ALOG
  97.            LMJ        X11,FTN$ATAN2
  98.            LMJ        X11,FTN$COS
  99.            LMJ        X11,FTN$EXP
  100.            LMJ        X11,FTN$SIN
  101.            LMJ        X11,FTN$SQRT
  102.            LMJ        X11,DMP
  103.            LMJ        X11,HDR
  104.            LMJ        X11,INP
  105.            LMJ        X11,OUT
  106.            LMJ        X11,PLO
  107.            LMJ        X11,SFN
  108.            LMJ        X11,IMP
  109.            LMJ        X11,MIMFN
  110.            LMJ        X11,MIMRN
  111.            LMJ        X11,MIMTD
  112. lmjlst     info  2 4
  113.            end
  114.  
  115. This is as close as I have come to working on compiler code.  It
  116. illustrates the lengths to which one would go to create "fast"
  117. looping code.
  118.  
  119. Regards,
  120. Albert Hybl (hybl@umbc3.umbc.edu)
  121.