ack/lang/m2/libm2/confarray.c

60 lines
1.4 KiB
C
Raw Normal View History

#include <m2_traps.h>
1987-10-30 18:32:14 +00:00
/* Runtime handling of "value" conformant arrays.
The routine that accepts the conformant array parameter first calls
the routine new_stackptr. This routine computes a new stack pointer
for the calling routine and returns it. The new space on the stack is
large enough to store the array.
Then, it calls copy_array to do the copying.
*/
1987-06-23 17:12:42 +00:00
struct descr {
char *addr;
int low;
unsigned int highminlow;
unsigned int size;
};
static struct descr *descrs[10];
static struct descr **ppdescr = descrs;
char *
_new_stackptr(pdescr, a)
register struct descr *pdescr;
{
1987-10-30 18:32:14 +00:00
/* The parameter "a" is not used and not supplied.
It's address is the old stack-pointer.
*/
1987-06-23 17:12:42 +00:00
unsigned int size = (((pdescr->highminlow + 1) * pdescr->size +
(EM_WSIZE - 1)) & ~(EM_WSIZE - 1));
if (ppdescr >= &descrs[10]) {
/* to many nested traps + handlers ! */
TRP(M2_TOOMANY);
1987-06-23 17:12:42 +00:00
}
*ppdescr++ = pdescr;
if ((char *) &a - (char *) &size > 0) {
/* stack grows downwards */
return (char *) &a - size;
}
else return (char *) &a + size;
}
_copy_array(p, a)
1987-10-30 18:32:14 +00:00
register int *p;
1987-06-23 17:12:42 +00:00
{
1987-10-30 18:32:14 +00:00
register int *q;
1987-06-23 17:12:42 +00:00
register unsigned int sz;
char dummy;
ppdescr--;
1987-10-30 18:32:14 +00:00
sz = (((*ppdescr)->highminlow + 1) * (*ppdescr)->size) / EM_WSIZE;
1987-06-23 17:12:42 +00:00
if ((char *) &a - (char *) &dummy > 0) {
1987-10-30 18:32:14 +00:00
(*ppdescr)->addr = (char *) (q = &a);
1987-06-23 17:12:42 +00:00
}
1987-10-30 18:32:14 +00:00
else (*ppdescr)->addr = (char *) (q = &a - sz);
1987-06-23 17:12:42 +00:00
while (sz--) *q++ = *p++;
}