|
|
1.1 ! root 1: /* Copyright (c) 1980 Regents of the University of California */ ! 2: ! 3: static char sccsid[] = "@(#)flvalue.c 1.2 10/2/80"; ! 4: ! 5: #include "whoami.h" ! 6: #include "0.h" ! 7: #include "tree.h" ! 8: #include "opcode.h" ! 9: #include "objfmt.h" ! 10: #ifdef PC ! 11: # include "pc.h" ! 12: # include "pcops.h" ! 13: #endif PC ! 14: #ifdef OBJ ! 15: /* ! 16: * define the display structure for purposes of allocating ! 17: * a temporary ! 18: */ ! 19: struct dispsave { ! 20: char *ptr; ! 21: }; ! 22: #endif OBJ ! 23: ! 24: /* ! 25: * flvalue generates the code to either pass on a formal routine, ! 26: * or construct the structure which is the environment for passing. ! 27: * it tells the difference by looking at the tree it's given. ! 28: */ ! 29: struct nl * ! 30: flvalue( r , formalp ) ! 31: int *r; ! 32: struct nl *formalp; ! 33: { ! 34: struct nl *p; ! 35: long tempoff; ! 36: char *typename; ! 37: ! 38: if ( r == NIL ) { ! 39: return NIL; ! 40: } ! 41: typename = formalp -> class == FFUNC ? "function":"procedure"; ! 42: if ( r[0] != T_VAR ) { ! 43: error("Expression given, %s required for %s parameter %s" , ! 44: typename , typename , formalp -> symbol ); ! 45: return NIL; ! 46: } ! 47: p = lookup(r[2]); ! 48: if (p == NIL) { ! 49: return NIL; ! 50: } ! 51: switch ( p -> class ) { ! 52: case FFUNC: ! 53: case FPROC: ! 54: if ( r[3] != NIL ) { ! 55: error("Formal %s %s cannot be qualified" , ! 56: typename , p -> symbol ); ! 57: return NIL; ! 58: } ! 59: # ifdef OBJ ! 60: put( 2 , PTR_RV | bn << 8+INDX , p -> value[NL_OFFS] ); ! 61: # endif OBJ ! 62: # ifdef PC ! 63: putRV( p -> symbol , bn , p -> value[ NL_OFFS ] , ! 64: p2type( p ) ); ! 65: # endif PC ! 66: return p -> type; ! 67: case FUNC: ! 68: case PROC: ! 69: if ( r[3] != NIL ) { ! 70: error("%s %s cannot be qualified" , typename , ! 71: p -> symbol ); ! 72: return NIL; ! 73: } ! 74: if (bn == 0) { ! 75: error("Built-in %s %s cannot be passed as a parameter" , ! 76: typename , p -> symbol ); ! 77: return NIL; ! 78: } ! 79: /* ! 80: * formal routine structure: ! 81: * ! 82: * struct formalrtn { ! 83: * long (*entryaddr)(); ! 84: * long cbn; ! 85: * struct dispsave disp[2*MAXLVL]; ! 86: * }; ! 87: */ ! 88: sizes[ cbn ].om_off -= sizeof (long (*)()) ! 89: + sizeof (long) ! 90: + 2*bn*sizeof (struct dispsave); ! 91: tempoff = sizes[ cbn ].om_off; ! 92: if ( sizes[ cbn ].om_off < sizes[ cbn ].om_max ) { ! 93: sizes[ cbn ].om_max = tempoff; ! 94: } ! 95: # ifdef OBJ ! 96: put( 2 , O_LV | cbn << 8 + INDX , tempoff ); ! 97: put( 2 , O_FSAV | bn << 8 + INDX , p -> entloc ); ! 98: # endif OBJ ! 99: # ifdef PC ! 100: putlbracket( ftnno , -tempoff ); ! 101: putleaf( P2ICON , 0 , 0 , ! 102: ADDTYPE( P2PTR , ADDTYPE( P2FTN , P2PTR|P2STRTY ) ) , ! 103: "_FSAV" ); ! 104: { ! 105: char extname[ BUFSIZ ]; ! 106: char *starthere; ! 107: int i; ! 108: ! 109: starthere = &extname[0]; ! 110: for ( i = 1 ; i < bn ; i++ ) { ! 111: sprintf( starthere , EXTFORMAT , enclosing[ i ] ); ! 112: starthere += strlen( enclosing[ i ] ) + 1; ! 113: } ! 114: sprintf( starthere , EXTFORMAT , p -> symbol ); ! 115: starthere += strlen( p -> symbol ) + 1; ! 116: if ( starthere >= &extname[ BUFSIZ ] ) { ! 117: panic( "flvalue namelength" ); ! 118: } ! 119: putleaf( P2ICON , 0 , 0 , p2type( p ) , extname ); ! 120: } ! 121: putleaf( P2ICON , bn , 0 , P2INT , 0 ); ! 122: putop( P2LISTOP , P2INT ); ! 123: putLV( 0 , cbn , tempoff , P2STRTY ); ! 124: putop( P2LISTOP , P2INT ); ! 125: putop( P2CALL , P2PTR | P2STRTY ); ! 126: # endif PC ! 127: return p -> type; ! 128: default: ! 129: error("Variable given, %s required for %s parameter %s" , ! 130: typename , typename , formalp -> symbol ); ! 131: return NIL; ! 132: } ! 133: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.