1: #include "../h/rt.h" 2: #ifdef VAX 3: /* 4: * ^x - return an entry block for co-expression x from the refresh block. 5: */ 6: 7: refresh(nargs, arg1, arg0) 8: int nargs; 9: struct descrip arg1, arg0; 10: { 11: register int *ap, *sp, *tp; 12: struct descrip *dp, *dsp; 13: register struct b_estack *ep; 14: register struct b_eblock *hp; 15: int na, nl, *r5, *newap; 16: extern struct b_estack *alcestk(); 17: extern interp(); 18: 19: SetBound; 20: DeRef(arg1) 21: if (QUAL(arg1) || TYPE(arg1) != T_ESTACK) 22: runerr(118, &arg1); 23: 24: /* 25: * Get a new co-expression stack and initialize activator, result 26: * count, stack base, and fresh block location. 27: */ 28: esneed(); 29: ep = alcestk(); 30: ep->activator = nulldesc; 31: ep->nresults = 0; 32: ep->freshblk = BLKLOC(arg1)->estack.freshblk; 33: ep->sbase = sp = (int *)ep; 34: /* 35: * Get number of arguments, number of locals, and a pointer to 36: * arg0 in the refresh block's argument list. 37: */ 38: hp = (struct b_eblock *) BLKLOC(ep->freshblk); 39: na = hp->numargs; 40: nl = hp->numlocals; 41: ap = (int *) hp->elems; 42: 43: /* 44: * Copy arguments into new stack and refresh block. 45: */ 46: dsp = (struct descrip *) sp; 47: dp = (struct descrip *) ap; 48: *--dsp = *dp++; 49: while (na-- > 0) { 50: *--dsp = *dp++; 51: } 52: sp = (int *) dsp; 53: ap = (int *) dp; 54: 55: /* 56: * Set up original procedure frame in new stack. 57: */ 58: *--sp = hp->numargs; /* nargs */ 59: *--sp = (hp->numargs*2) + 1; /* nwords */ 60: newap = sp; /* save address of nwords */ 61: *--sp = (int) interp; /* return pc */ 62: *--sp = 0; /* saved r5 (frame pointer) */ 63: *--sp = 0; /* saved ap */ 64: *--sp = 0; /* psw/reg. mask */ 65: *--sp = 0; /* condition handler */ 66: r5 = sp; /* (save its address) */ 67: *--sp = line; /* saved line number */ 68: *--sp = (int) file; /* saved file name */ 69: 70: /* 71: * Copy local variables into new stack. 72: */ 73: dsp = (struct descrip *) sp; 74: dp = (struct descrip *) ap; 75: while (nl-- > 0) { 76: *--dsp = *dp++; 77: } 78: sp = (int *) dsp; 79: ap = (int *) dp; 80: 81: /* 82: * Set up dummy call to coact. 83: */ 84: *--sp = nulldesc.type; /* place for result */ 85: *--sp = INTVAL(nulldesc); 86: *--sp = nulldesc.type; /* place for activate coexpr */ 87: *--sp = INTVAL(nulldesc); 88: *--sp = 1; /* nargs */ 89: *--sp = 3; /* nwords */ 90: tp = sp; /* save pointer to start of arg 91: list in this frame */ 92: *--sp = (int) hp->ep; /* saved r9 (coexpr entry point) */ 93: *--sp = (int) interp; /* return pc (entry point) */ 94: *--sp = (int) r5; /* saved r5 */ 95: *--sp = (int) newap; /* saved ap */ 96: *--sp = 0x02000000; /* psw/reg mask with bit set to 97: restore r9, the ipc */ 98: *--sp = 0; 99: ep->boundary = sp; /* (initial boundary) */ 100: *--sp = line; /* saved line number */ 101: *--sp = (int) file; /* saved file name */ 102: ep->sp = sp; /* initial stack pointer */ 103: ep->ap = tp; 104: 105: /* 106: * Return the new co-expression. 107: */ 108: arg0.type = D_ESTACK; 109: BLKLOC(arg0) = (union block *) ep; 110: ClearBound; 111: } 112: 113: Opblock(refresh,1,"^") 114: #endif VAX 115: 116: #ifdef PORT 117: refresh() 118: { 119: syserr("Attempt to refresh a co-expression"); 120: } 121: #endif PORT 122: #ifdef PDP11 123: /* 124: * ^x - return an entry block for co-expression x from the refresh block. 125: * NOTE: this code is highly dependent on stack frame layout. 126: */ 127: 128: refresh(nargs, arg1, arg0) 129: int nargs; 130: struct descrip arg1, arg0; 131: { 132: register int *ap, *sp; 133: register struct b_estack *ep; 134: register struct b_eblock *hp; 135: int na, nl, *r5; 136: extern struct b_estack *alcestk(); 137: extern interp(); 138: 139: DeRef(arg1) 140: if (QUAL(arg1) || TYPE(arg1) != T_ESTACK) 141: runerr(118, &arg1); 142: 143: esneed(); /* check for room in stack space */ 144: ep = alcestk(); /* allocate expression stack */ 145: ep->activator = nulldesc; 146: ep->nresults = 0; 147: ep->freshblk = BLKLOC(arg1)->estack.freshblk; 148: 149: ep->sbase = sp = (int *)ep; /* initialize new stack pointer */ 150: hp = BLKLOC(ep->freshblk); 151: na = hp->numargs; /* get value of nargs */ 152: nl = hp->numlocals; 153: ap = hp->elems; /* find arg0 of caller */ 154: 155: /* copy arguments into new stack and refresh block */ 156: *--(struct descrip *)sp = *(struct descrip *)ap; /* copy arg0 */ 157: while (na-- > 0) 158: *--(struct descrip *)sp = *++(struct descrip *)ap; 159: 160: /* set up original procedure frame in new stack */ 161: *--sp = hp->numargs; /* copy nargs */ 162: *--sp = 0; /* return pc */ 163: *--sp = 0; /* saved r5 */ 164: r5 = sp; /* (save its address) */ 165: *--sp = 0; /* saved r4 */ 166: *--sp = 0; /* saved r3 */ 167: *--sp = 0; /* saved r2 */ 168: *--sp = line; /* saved line number */ 169: *--sp = file; /* saved file name */ 170: 171: /* copy local variables into new stack */ 172: while (nl-- > 0) 173: *--(struct descrip *)sp = *++(struct descrip *)ap; 174: 175: /* set up dummy call to activate */ 176: *--(struct descrip *)sp = nulldesc; /* place for result */ 177: *--(struct descrip *)sp = nulldesc; /* place for activate coexpr */ 178: /* these values are the initial register state for the coexpression */ 179: *--sp = 1; /* nargs */ 180: *--sp = interp; /* return pc (entry point) */ 181: *--sp = r5; /* saved r5 */ 182: ep->boundary = sp; /* (initial boundary) */ 183: *--sp = 0; /* saved r4 */ 184: *--sp = 0; /* saved r3 */ 185: *--sp = hp->ep; /* saved r2 */ 186: *--sp = line; /* saved line number */ 187: *--sp = file; /* saved file name */ 188: ep->sp = sp; /* initial stack pointer */ 189: arg0.type = D_ESTACK; 190: BLKLOC(arg0) = ep; 191: } 192: Opblock(refresh,1,"^") 193: #endif PDP11