void p_patchContinue(SemVal *e) { e->continuelist = rss_realloc(e->continuelist, /* expand the continuelist */ (e->continuelen + 1) * sizeof(unsigned)); /* room for the jump-backpatch */ e->code = rss_realloc(e->code, e->codelen += sizeof(int16_t)); /* store jumpstart location */ e->continuelist[e->continuelen++] = e->codelen; }
void sc_changeFile(char *s) /* name of source file to open */ { register int slen; if (*s) /* any filename ? */ { if (!gs_fileSp--) /* no more entries ? */ rss_fatal(0, 0, "more than 10 nested #include directives"); /* save the name and line nr. of the file */ gs_fileStack[gs_fileSp].fname = rss_strdup(s); gs_fileStack[gs_fileSp].former_linenr = yylineno; gs_filenames = rss_realloc(gs_filenames, /* room for new filename */ filenames_len + (slen = strlen(s)) + 2); /* append name */ sprintf(gs_filenames + filenames_len, "%s\n", s); filenames_len += slen + 1; /* new length of string */ yylineno = 0; /* start at new file */ } util_setSourceName(gs_fileStack[gs_fileSp].fname); }
void p_pushDead() /* dead_sp: lastused, dead[0] = 0 */ { if (++gp_dead_sp >= size) /* too few elements ? then 5 more */ gp_dead = rss_realloc(gp_dead, (size += 5) * sizeof(unsigned)); gp_dead[gp_dead_sp] = gp_dead[gp_dead_sp - 1]; /* copy former element */ }
SemVal *p_catCode(SemVal *lval, SemVal *rval) { register unsigned l; register unsigned r; r = rval->codelen; /* sizeof rval code */ l = lval->codelen; /* sizeof lval code */ lval->code = rss_realloc(lval->code, /* room for new code */ (l + r) * sizeof(int8_t)); /* catenate the code */ memcpy(lval->code + l, rval->code, r * sizeof(int8_t)); lval->codelen += r; /* new size */ patchadd(l, &lval->truelist, &lval->truelen, rval->truelist, rval->truelen); patchadd(l, &lval->falselist, &lval->falselen, rval->falselist, rval->falselen); patchadd(l, &lval->continuelist, &lval->continuelen, rval->continuelist, rval->continuelen); lval->type |= rval->type; /* type of combined code */ /* (is ok with same types) */ p_discard(rval); /* free memory used by SemVal */ return (lval); /* return new frame */ }
SemVal *p_multipleArgs(SemVal *left, SemVal *right) { register size_t count; count = ++left->type; /* get/increase # of args */ /* room for extra SemVal */ left->code = rss_realloc(left->code, count * sizeof(SemVal)); p_expr2stack(right); /* argument is code now */ /* right expression in array */ *codestruc(left, count - 1) = *right; return (left); /* done */ }
void symtab_setFunParams() { FunInfo *info = st_lastFunInfo(); /* set the fun's # params */ info->nParams = gs_vars.nParams = gs_vars.varTab[1].nVars; /* room for the parameter types */ info->paramType = rss_realloc(NULL, gs_vars.nParams * sizeof(ExprType)); /* assign the parameter types */ for (unsigned idx = 0; idx != gs_vars.nParams; ++idx) info->paramType[idx] = st_paramType(idx); }
SemVal *p_insertArg(SemVal *insert, SemVal *mult) { register size_t count; count = ++mult->type; /* get/increase # of args */ /* room for extra SemVal */ mult->code = rss_realloc(mult->code, count * sizeof(SemVal)); memmove( /* shift up for new p_firstArg */ codestruc(mult, 1), codestruc(mult, 0), (count - 1) * sizeof(SemVal)); p_expr2stack(insert); /* argument is code now */ *codestruc(mult, 0) = *insert; /* insert expression in array */ return mult; /* done */ }
static void patchadd(register unsigned value, unsigned **dest, unsigned *dlen, unsigned *source, unsigned slen) { register unsigned idx; if (!*dlen) *dest = NULL; /* no memory for dest as yet */ for (idx = 0; idx < slen; idx++) /* all elements of source list: */ source[idx] += value; /* icrement addresses of targets */ /* expand the dest area */ *dest = rss_realloc(*dest, (*dlen + slen) * sizeof(unsigned)); /* append source list */ memcpy(*dest + *dlen, source, slen * sizeof(unsigned)); *dlen += slen; /* increment # element */ }