From:	SMTP%"system@bolam5.lamel.bo.cnr.it" 12-JAN-1995 10:03:49.16
To:	EVERHART
CC:	
Subj:	Re: AXP FORTRAN argument list (variable)

From: system@bolam5.lamel.bo.cnr.it (Maurizio Impronta)
X-Newsgroups: comp.os.vms
Subject: Re: AXP FORTRAN argument list (variable)
Date: 12 Jan 1995 11:33:54 GMT
Organization: CNR-LAMEL Institute - Bologna - Italy
Lines: 109
Sender: system@bolam5 (Maurizio Impronta)
Distribution: world
Message-ID: <3f3432$e5q@sirio.cineca.it>
Reply-To: system@bolam5.lamel.bo.cnr.it (Maurizio Impronta)
NNTP-Posting-Host: bolam5.lamel.bo.cnr.it
X-Newsreader: mxrn 6.18-16
To: Info-VAX@Mvb.Saic.Com
X-Gateway-Source-Info: USENET


In article <3euicl$8jo@jac.zko.dec.com> lionel@quark.enet.dec.com
(Steve Lionel) answers:
>
>In article <3eudc8$am2@sirio.cineca.it>, system@bolam5.lamel.bo.cnr.it 
>(Maurizio Impronta) writes:
>|>
>|>We used on VAX extensively a very short MACRO routine, 
>|>which traverses the call stack frame list, to obtain 
>|>informations about a variable argument list in a FORTRAN 
>|>routine: it was very useful to know at run time in a 
>|>FORTRAN routine the actual argument count and to arrange 
>|>for default argument values if needed.
>|>
>|>Fortunately in DEC-FORTRAN V6.2 there are the new library 
>|>routines IARGCOUNT and IARGPTR that partially - with some 
>|>optimization problem on dummy (and/or omitted) arguments - 
>|>solve this problem.
>|>
>|>*******************
>|>The question now should be: ** why do DEC not introduce a 
>|>FORTRAN compiler option to force "homing" the unoptimized 
>|>argument list on the stack frame ** as i.e. in AXP MACRO-32 ?
>|>*******************
>
>There's no real purpose in doing so, given that there is now a supported
>method of obtaining the argument count and pointer to the homed argument
>list ...
-- 

Maybe there is some misunderstanding in my question.
I have appreciated greatly the IARGCOUNT and IARGPTR routines, but
actually I have on VAX hundreds of routines with code like (simplified):
	PROGRAM MAIN
	....
	CALL SUB(a1,,c1)
	...
	SUBROUTINE SUB(a,b,c,d)		! **really DUMMY** arguments
	INTEGER LSTARG			! my MACRO routine
	IF (LSTARG(2).GT.0) THEN	! returns address of 2nd arg i.e.
		b2=b			! if 2nd argument is passed
	ELSE
		b2=b_default		! default value if NOT passed
	ENDIF
	....
LSTARG(nvar) is my VAX MACRO integer function which:
1_ goes backward in the call chain to read SUB argument list
2_ returns the address of nvar-th argument if passed by the calling
   procedure (MAIN i.e.), or
3_ returns 0 if nvar-th argument is defaulted (i.e. 'b' or 'd')

To do the same on the AXP I have to code IARGCOUNT and IARGPTR like:
	SUBROUTINE SUB(a,b,c,d)	! **really DUMMY** arguments
	POINTER (ap,list)	! ap contains the address of arg 'list'
	POINTER (avar,var)	! avar contains the address of 'var'
	IF (IARGCOUNT( ).GT.2) THEN	! test 2nd argument i.e.
		ap=IARGPTR( )+2*SIZEOF(ap)
		avar=list		! get address of 2nd arg
		IF (avar.GT.0) THEN
			b2=var		! passed value ('b' i.e.)
		ELSE	
			b2=b_default	! defaulted value
		ENDIF
	ELSE
		b2=b_default		! defaulted value
	ENDIF
********** I must modify ALL routines to do this ! ********
(note that from some preliminary test only the presence of a
call to IARGPTR "home" the argument list, not IARGCOUNT alone)
**********
Alternatively, **if I could assume homed** arglist (by compiler option
i.e.), I can rewrite on AXP **ONLY my function LSTARG - using some
documented utility - like (simplified):
	INTEGER FUNCTION LSTARG(nvar)
	INCLUDE '($LIBICB)'
	INCLUDE '($PDSCDEF)'
	RECORD /INVO_CONTEXT_BLOCK/ invo
	RECORD /PDSCDEF/ pdsc		! stack frame procedure descriptor
	RECORD /PDSC_LKPDEF/ pdsc_lkp	! needed ?? WARNING in compilation !
	RECORD /LKPDEF/ lkp
	POINTER (p_pdcs,pdcs)		! prodecure description block
	POINTER (ap,list)		! argument pointer to arglist
	CALL LIB$GET_CURR_INVO_CONTEXT(invo)	! see OpenVMS Calling Standard
	istat=LIB$GET_PREV_INVO_CONTEXT(invo)	! backward in call chain
	fp=invo.LIBICB$Q_IREG(29)	! frame pointer R29
	p_pdsc=invo.LIBICB$PH_PROCEDURE_DESCRIPTOR	! address of pdsc	
	size=pdsc.PDSC$L_SIZE		! size of frame
	ap=fp+size-SIZEOF(ap)*7		! argument pointer for homed list
	narg=list			! 1st in list = number of arguments
	IF (nvar.LE.narg) THEN
		ap=ap+SIZEOF(ap)*nvar	! address of nvar-th in arglist
		LSTARG=list		! address of nvar-th argument
	ELSE
		LSTARG=0
	ENDIF
	RETURN
Thus my suggestion to give a compiler option to effectively "home"
the argument list in DEC FORTRAN.
I hope this clear, thank very much for Your answers.
Maurizio Impronta
------------------------------------------------------------------------
           Consiglio Nazionale delle Ricerche - Istituto di 
  Chimica e Tecnologia dei Materiali e dei Componenti per l' Elettronica
 ------------------------------------------------------------------------
    CNR - LAMEL Institute     |   fax   : +39 51 639 9216
     Via P. Gobetti, 101      |
   I 40129 Bologna (Italy)    |   e-mail: system@bolam5.lamel.bo.cnr.it
 ------------------------------------------------------------------------

