home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.bin / pascal / src / flvalue.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-16  |  4.6 KB  |  140 lines

  1. /*-
  2.  * Copyright (c) 1980 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  */
  33.  
  34. #ifndef lint
  35. static char sccsid[] = "@(#)flvalue.c    5.2 (Berkeley) 4/16/91";
  36. #endif /* not lint */
  37.  
  38. #include "whoami.h"
  39. #include "0.h"
  40. #include "tree.h"
  41. #include "opcode.h"
  42. #include "objfmt.h"
  43. #include "tree_ty.h"
  44. #ifdef PC
  45. #   include "pc.h"
  46. #   include <pcc.h>
  47. #endif PC
  48. #include "tmps.h"
  49.  
  50.     /*
  51.      *    flvalue generates the code to either pass on a formal routine,
  52.      *    or construct the structure which is the environment for passing.
  53.      *    it tells the difference by looking at the tree it's given.
  54.      */
  55. struct nl *
  56. flvalue( r , formalp )
  57.     struct tnode *r;     /* T_VAR */
  58.     struct nl    *formalp;
  59.     {
  60.     struct nl    *p;
  61.     struct nl    *tempnlp;
  62.     char        *typename;
  63. #ifdef PC
  64.     char        extname[ BUFSIZ ];
  65. #endif PC
  66.  
  67.     if ( r == TR_NIL ) {
  68.         return NLNIL;
  69.     }
  70.     typename = formalp -> class == FFUNC ? "function":"procedure";
  71.     if ( r->tag != T_VAR ) {
  72.         error("Expression given, %s required for %s parameter %s" ,
  73.             typename , typename , formalp -> symbol );
  74.         return NLNIL;
  75.     }
  76.     p = lookup(r->var_node.cptr);
  77.     if (p == NLNIL) {
  78.         return NLNIL;
  79.     }
  80.     switch ( p -> class ) {
  81.         case FFUNC:
  82.         case FPROC:
  83.             if ( r->var_node.qual != TR_NIL ) {
  84.             error("Formal %s %s cannot be qualified" ,
  85.                 typename , p -> symbol );
  86.             return NLNIL;
  87.             }
  88. #            ifdef OBJ
  89.             (void) put(2, PTR_RV | bn << 8+INDX, (int)p->value[NL_OFFS]);
  90. #            endif OBJ
  91. #            ifdef PC
  92.             putRV( p -> symbol , bn , p -> value[ NL_OFFS ] , 
  93.                 p -> extra_flags ,
  94.                 p2type( p ) );
  95. #            endif PC
  96.             return p;
  97.         case FUNC:
  98.         case PROC:
  99.             if ( r->var_node.qual != TR_NIL ) {
  100.             error("%s %s cannot be qualified" , typename ,
  101.                 p -> symbol );
  102.             return NLNIL;
  103.             }
  104.             if (bn == 0) {
  105.             error("Built-in %s %s cannot be passed as a parameter" ,
  106.                 typename , p -> symbol );
  107.             return NLNIL;
  108.             }
  109.             /*
  110.              *    allocate space for the thunk
  111.              */
  112.             tempnlp = tmpalloc((long) (sizeof(struct formalrtn)), NLNIL, NOREG);
  113. #            ifdef OBJ
  114.             (void) put(2 , O_LV | cbn << 8 + INDX ,
  115.                 (int)tempnlp -> value[ NL_OFFS ] );
  116.             (void) put(2, O_FSAV | bn << 8, (long)p->value[NL_ENTLOC]);
  117. #            endif OBJ
  118. #            ifdef PC
  119.             putleaf( PCC_ICON , 0 , 0 ,
  120.                 PCCM_ADDTYPE( PCCTM_PTR , PCCM_ADDTYPE( PCCTM_FTN , PCCTM_PTR|PCCT_STRTY ) ) ,
  121.                 "_FSAV" );
  122.             sprintf( extname , "%s" , FORMALPREFIX );
  123.             sextname( &extname[ strlen( extname ) ] ,
  124.                     p -> symbol , bn );
  125.             putleaf( PCC_ICON , 0 , 0 , p2type( p ) , extname );
  126.             putleaf( PCC_ICON , bn , 0 , PCCT_INT , (char *) 0 );
  127.             putop( PCC_CM , PCCT_INT );
  128.             putLV( (char *) 0 , cbn , tempnlp -> value[NL_OFFS] ,
  129.                 tempnlp -> extra_flags , PCCT_STRTY );
  130.             putop( PCC_CM , PCCT_INT );
  131.             putop( PCC_CALL , PCCTM_PTR | PCCT_STRTY );
  132. #            endif PC
  133.             return p;
  134.         default:
  135.             error("Variable given, %s required for %s parameter %s" ,
  136.                 typename , typename , formalp -> symbol );
  137.             return NLNIL;
  138.     }
  139.     }
  140.