}
int
-sc_addconstant(char *name, cell value, int tag)
+sc_addconstant(char *name, cell val, int tag)
{
errorset(sFORCESET); /* make sure error engine is silenced */
sc_status = statIDLE;
- add_constant(name, value, sGLOBAL, tag);
+ add_constant(name, val, sGLOBAL, tag);
return 1;
}
decl_enum(int vclass)
{
char enumname[sNAMEMAX + 1], constname[sNAMEMAX + 1];
- cell val, value, size;
+ cell lexval, enumvalue, size;
char *str;
int tok, tag, explicittag;
cell increment, multiplier;
* explicit tag was passed, even if that explicit tag was "_:", so we
* cannot call sc_addtag() here
*/
- if (lex(&val, &str) == tLABEL)
+ if (lex(&lexval, &str) == tLABEL)
{
tag = sc_addtag(str);
explicittag = TRUE;
/* get optional enum name (also serves as a tag if no explicit
* tag was set) */
- if (lex(&val, &str) == tSYMBOL)
+ if (lex(&lexval, &str) == tSYMBOL)
{ /* read in (new) token */
strcpy(enumname, str); /* save enum name (last constant) */
if (!explicittag)
}
else if (matchtoken(taSHL))
{
- constexpr(&val, NULL);
- while (val-- > 0)
+ constexpr(&lexval, NULL);
+ while (lexval-- > 0)
multiplier *= 2;
} /* if */
needtoken(')');
needtoken('{');
/* go through all constants */
- value = 0; /* default starting value */
+ enumvalue = 0; /* default starting value */
do
{
if (matchtoken('}'))
lexpush();
break;
} /* if */
- tok = lex(&val, &str); /* read in (new) token */
+ tok = lex(&lexval, &str); /* read in (new) token */
if (tok != tSYMBOL && tok != tLABEL)
error(20, str); /* invalid symbol name */
strcpy(constname, str); /* save symbol name */
if (tok == tLABEL || matchtoken(':'))
constexpr(&size, NULL); /* get size */
if (matchtoken('='))
- constexpr(&value, NULL); /* get value */
+ constexpr(&enumvalue, NULL); /* get value */
/* add_constant() checks whether a variable (global or local) or
* a constant with the same name already exists */
- add_constant(constname, value, vclass, tag);
+ add_constant(constname, enumvalue, vclass, tag);
if (multiplier == 1)
- value += size;
+ enumvalue += size;
else
- value *= size * multiplier;
+ enumvalue *= size * multiplier;
}
while (matchtoken(','));
needtoken('}'); /* terminates the constant list */
/* set the enum name to the last value plus one */
if (enumname[0] != '\0')
- add_constant(enumname, value, vclass, tag);
+ add_constant(enumname, enumvalue, vclass, tag);
}
/*
if (needtoken(tSYMBOL))
{
/* save the name of the argument whose size id to take */
- char *name;
+ char *argname;
cell val;
- tokeninfo(&val, &name);
- if (!(arg->defvalue.size.symname = strdup(name)))
+ tokeninfo(&val, &argname);
+ if (!(arg->defvalue.size.symname = strdup(argname)))
error(103); /* insufficient memory */
arg->defvalue.size.level = 0;
if (size_tag_token == uSIZEOF)
* Global references: intest (altered, but restored upon termination)
*/
static void
-test(int label, int parens, int invert)
+test(int label, int parens, int inv)
{
int idx, tok;
cell cidx;
} /* if */
if (lval.tag != 0 && lval.tag != sc_addtag("bool"))
if (check_userop(lneg, lval.tag, 0, 1, NULL, &lval.tag))
- invert = !invert; /* user-defined ! operator inverted result */
- if (invert)
+ inv = !inv; /* user-defined ! operator inverted result */
+ if (inv)
jmp_ne0(label); /* jump to label if true (different from 0) */
else
jmp_eq0(label); /* jump to label if false (equal to 0) */
}
static void
-check_empty(char *lptr)
+check_empty(const char *sptr)
{
/* verifies that the string contains only whitespace */
- while (*lptr <= ' ' && *lptr != '\0')
- lptr++;
- if (*lptr != '\0')
+ while (*sptr <= ' ' && *sptr != '\0')
+ sptr++;
+ if (*sptr != '\0')
error(38); /* extra characters on line */
}
readline(char *line)
{
int i, num, cont;
- char *ptr;
if (lptr == term_expr)
return;
}
else
{
+ char *ptr;
/* check whether to erase leading spaces */
if (cont)
{
- char *ptr = line;
+ char *sptr = line;
- while (*ptr == ' ' || *ptr == '\t')
- ptr++;
- if (ptr != line)
- memmove(line, ptr, strlen(ptr) + 1);
+ while (*sptr == ' ' || *sptr == '\t')
+ sptr++;
+ if (sptr != line)
+ memmove(line, sptr, strlen(sptr) + 1);
} /* if */
cont = FALSE;
/* check whether a full line was read */
number(cell * val, char *curptr)
{
int i;
- cell value;
+ cell curval;
- if ((i = btoi(&value, curptr)) != 0 /* binary? */
- || (i = htoi(&value, curptr)) != 0 /* hexadecimal? */
- || (i = dtoi(&value, curptr)) != 0) /* decimal? */
+ if ((i = btoi(&curval, curptr)) != 0 /* binary? */
+ || (i = htoi(&curval, curptr)) != 0 /* hexadecimal? */
+ || (i = dtoi(&curval, curptr)) != 0) /* decimal? */
{
- *val = value;
+ *val = curval;
return i;
}
else
}
else if (strcmp(str, "compress") == 0)
{
- cell val;
+ cell compval;
- preproc_expr(&val, NULL);
- sc_compress = (int)val; /* switch code packing on/off */
+ preproc_expr(&compval, NULL);
+ sc_compress = (int)compval; /* switch code packing on/off */
}
else if (strcmp(str, "dynamic") == 0)
{
}
else if (strcmp(str, "pack") == 0)
{
- cell val;
+ cell packval;
- preproc_expr(&val, NULL); /* default = packed/unpacked */
- sc_packstr = (int)val;
+ preproc_expr(&packval, NULL); /* default = packed/unpacked */
+ sc_packstr = (int)packval;
}
else if (strcmp(str, "rational") == 0)
{
}
else if (strcmp(str, "semicolon") == 0)
{
- cell val;
+ cell semicolval;
- preproc_expr(&val, NULL);
- sc_needsemicolon = (int)val;
+ preproc_expr(&semicolval, NULL);
+ sc_needsemicolon = (int)semicolval;
}
else if (strcmp(str, "tabsize") == 0)
{
- cell val;
+ cell tabsizeval;
- preproc_expr(&val, NULL);
- sc_tabsize = (int)val;
+ preproc_expr(&tabsizeval, NULL);
+ sc_tabsize = (int)tabsizeval;
}
else if (strcmp(str, "align") == 0)
{
{
int prefixlen;
char *p, *s, *e, *args[10];
- int match, arg, len;
+ int is_match, arg, len;
memset(args, 0, sizeof args);
*/
s = line + prefixlen;
p = pattern + prefixlen;
- match = TRUE; /* so far, pattern matches */
- while (match && *s != '\0' && *p != '\0')
+ is_match = TRUE; /* so far, pattern matches */
+ while (is_match && *s != '\0' && *p != '\0')
{
if (*p == '%')
{
else
{
assert(*e == '\0' || *e == '\n');
- match = FALSE;
+ is_match = FALSE;
s = e;
} /* if */
p++;
}
else
{
- match = FALSE;
+ is_match = FALSE;
} /* if */
}
else if (*p == ';' && *(p + 1) == '\0' && !sc_needsemicolon)
while (*s <= ' ' && *s != '\0')
s++; /* skip white space */
if (*s != ';' && *s != '\0')
- match = FALSE;
+ is_match = FALSE;
p++; /* skip the semicolon in the pattern */
}
else
s++; /* skip white space */
ch = litchar(&p, FALSE); /* this increments "p" */
if (*s != ch)
- match = FALSE;
+ is_match = FALSE;
else
s++; /* this character matches */
} /* if */
} /* while */
- if (match && *p == '\0')
+ if (is_match && *p == '\0')
{
/* if the last character to match is an alphanumeric character, the
* current character in the source may not be alphanumeric
*/
assert(p > pattern);
if (alphanum(*(p - 1)) && alphanum(*s))
- match = FALSE;
+ is_match = FALSE;
} /* if */
- if (match)
+ if (is_match)
{
/* calculate the length of the substituted string */
for (e = substitution, len = 0; *e != '\0'; e++)
if (args[arg])
free(args[arg]);
- return match;
+ return is_match;
}
static void
}
static char *
-unpackedstring(char *lptr, int rawstring)
+unpackedstring(char *sptr, int rawstring)
{
- while (*lptr != '\0')
+ while (*sptr != '\0')
{
/* check for doublequotes indicating the end of the string */
- if (*lptr == '\"')
+ if (*sptr == '\"')
{
/* check whether there's another pair of quotes following.
* If so, paste the two strings together, thus
* "pants""off" becomes "pantsoff"
*/
- if (*(lptr + 1) == '\"')
- lptr += 2;
+ if (*(sptr + 1) == '\"')
+ sptr += 2;
else
break;
}
- if (*lptr == '\a')
+ if (*sptr == '\a')
{ /* ignore '\a' (which was inserted at a line concatenation) */
- lptr++;
+ sptr++;
continue;
} /* if */
- stowlit(litchar(&lptr, rawstring)); /* litchar() alters "lptr" */
+ stowlit(litchar(&sptr, rawstring)); /* litchar() alters "lptr" */
} /* while */
stowlit(0); /* terminate string */
- return lptr;
+ return sptr;
}
static char *
-packedstring(char *lptr, int rawstring)
+packedstring(char *sptr, int rawstring)
{
int i;
ucell val, c;
i = sizeof(ucell) - (charbits / 8); /* start at most significant byte */
val = 0;
- while (*lptr != '\0')
+ while (*sptr != '\0')
{
/* check for doublequotes indicating the end of the string */
- if (*lptr == '\"')
+ if (*sptr == '\"')
{
/* check whether there's another pair of quotes following.
* If so, paste the two strings together, thus
* "pants""off" becomes "pantsoff"
*/
- if (*(lptr + 1) == '\"')
- lptr += 2;
+ if (*(sptr + 1) == '\"')
+ sptr += 2;
else
break;
}
- if (*lptr == '\a')
+ if (*sptr == '\a')
{ /* ignore '\a' (which was inserted at a line concatenation) */
- lptr++;
+ sptr++;
continue;
} /* if */
- c = litchar(&lptr, rawstring); /* litchar() alters "lptr" */
+ c = litchar(&sptr, rawstring); /* litchar() alters "sptr" */
if (c >= (ucell) (1 << charbits))
error(43); /* character constant exceeds range */
val |= (c << 8 * i);
stowlit(val); /* at least one zero character in "val" */
else
stowlit(0); /* add full cell of zeros */
- return lptr;
+ return sptr;
}
/* lex(lexvalue,lexsym) Lexical Analysis
* litq (altered)
*/
void
-stowlit(cell value)
+stowlit(cell val)
{
if (litidx >= litmax)
{
litq = p;
} /* if */
assert(litidx < litmax);
- litq[litidx++] = value;
+ litq[litidx++] = val;
}
/* litchar
* but ddd must be decimal!
*/
static cell
-litchar(char **lptr, int rawmode)
+litchar(char **p_str, int rawmode)
{
cell c = 0;
unsigned char *cptr;
- cptr = (unsigned char *)*lptr;
+ cptr = (unsigned char *)*p_str;
if (rawmode || *cptr != sc_ctrlchar)
{ /* no escape character */
c = *cptr;
} /* switch */
} /* if */
} /* if */
- *lptr = (char *)cptr;
+ *p_str = (char *)cptr;
assert(c >= 0 && c < 256);
return c;
}
}
static symbol *
-find_symbol(symbol * root, char *name, int fnumber)
+find_symbol(symbol * root, char *name, int fnum)
{
symbol *ptr = root->next;
unsigned long hash = namehash(name);
{
if (hash == ptr->hash && strcmp(name, ptr->name) == 0
&& !ptr->parent && (ptr->fnumber < 0
- || ptr->fnumber == fnumber))
+ || ptr->fnumber == fnum))
return ptr;
ptr = ptr->next;
} /* while */
}
int
-expression(int *constant, cell * val, int *tag, int chkfuncresult)
+expression(int *is_constant, cell * val, int *tag, int chkfuncresult)
{
value lval = { NULL, 0, 0, 0, 0, NULL };
rvalue(&lval);
if (lval.ident == iCONSTEXPR)
{ /* constant expression */
- *constant = TRUE;
+ *is_constant = TRUE;
*val = lval.constval;
}
else
{
- *constant = FALSE;
+ *is_constant = FALSE;
*val = 0;
} /* if */
if (tag)
/* check the sizes of all sublevels too */
symbol *sym1 = lval3.sym;
symbol *sym2 = lval2.sym;
- int i;
+ int clvl;
assert(sym1 != NULL && sym2 != NULL);
/* ^^^ sym2 must be valid, because only variables can be
* sym1 must be valid because it must be an lvalue
*/
assert(exactmatch);
- for (i = 0; i < level; i++)
+ for (clvl = 0; clvl < level; clvl++)
{
sym1 = finddepend(sym1);
sym2 = finddepend(sym2);
}
else
{
- symbol *sym = lval.sym;
+ symbol *lsym = lval.sym;
short level = 0;
- assert(sym != NULL);
- if (sym->dim.array.level + 1 != arg[argidx].numdim)
+ assert(lsym != NULL);
+ if (lsym->dim.array.level + 1 != arg[argidx].numdim)
error(48); /* array dimensions must match */
/* the lengths for all dimensions must match, unless the dimension
* length was defined at zero (which means "undefined")
*/
- while (sym->dim.array.level > 0)
+ while (lsym->dim.array.level > 0)
{
assert(level < sDIMEN_MAX);
if (arg[argidx].dim[level] != 0
- && sym->dim.array.length !=
+ && lsym->dim.array.length !=
arg[argidx].dim[level])
error(47); /* array sizes must match */
append_constval(&arrayszlst, arg[argidx].name,
- sym->dim.array.length, level);
- sym = finddepend(sym);
- assert(sym != NULL);
+ lsym->dim.array.length, level);
+ lsym = finddepend(lsym);
+ assert(lsym != NULL);
level++;
} /* if */
/* the last dimension is checked too, again, unless it is zero */
assert(level < sDIMEN_MAX);
- assert(sym != NULL);
+ assert(lsym != NULL);
if (arg[argidx].dim[level] != 0
- && sym->dim.array.length !=
+ && lsym->dim.array.length !=
arg[argidx].dim[level])
error(47); /* array sizes must match */
append_constval(&arrayszlst, arg[argidx].name,
- sym->dim.array.length, level);
+ lsym->dim.array.length, level);
} /* if */
/* address already in PRI */
if (!checktag
}
else
{
- symbol *sym;
+ symbol *lsym;
assert((arg[argidx].hasdefault & uTAGOF) != 0);
- sym = findloc(arg[argidx].defvalue.size.symname);
- if (!sym)
- sym = findglb(arg[argidx].defvalue.size.symname);
- array_sz = (sym) ? sym->tag : 0;
+ lsym = findloc(arg[argidx].defvalue.size.symname);
+ if (!lsym)
+ lsym = findglb(arg[argidx].defvalue.size.symname);
+ array_sz = (lsym) ? lsym->tag : 0;
exporttag(array_sz);
} /* if */
const1(array_sz);
static int
constant(value * lval)
{
- int tok, idx, constant;
+ int tok, idx, is_constant;
cell val, item, cidx;
char *st;
symbol *sym;
* on at this point */
assert(staging);
stgget(&idx, &cidx); /* mark position in code generator */
- expression(&constant, &item, &tag, FALSE);
+ expression(&is_constant, &item, &tag, FALSE);
stgdel(idx, cidx); /* scratch generated code */
- if (constant == 0)
+ if (is_constant == 0)
error(8); /* must be constant expression */
if (lasttag < 0)
lasttag = tag;
}
void
-setactivefile(int fnumber)
+setactivefile(int fnum)
{
stgwrite("curfile ");
- outval(fnumber, TRUE);
+ outval(fnum, TRUE);
}
cell
replacesequence(char *pattern, char symbols[_maxoptvars][_aliasmax + 1],
int *repl_length)
{
- char *lptr;
+ char *sptr;
int var;
char *buffer;
*/
assert(repl_length != NULL);
*repl_length = 0;
- lptr = pattern;
- while (*lptr)
+ sptr = pattern;
+ while (*sptr)
{
- switch (*lptr)
+ switch (*sptr)
{
case '%':
- lptr++; /* skip '%' */
- assert(sc_isdigit(*lptr));
- var = atoi(lptr) - 1;
+ sptr++; /* skip '%' */
+ assert(sc_isdigit(*sptr));
+ var = atoi(sptr) - 1;
assert(var >= 0 && var < _maxoptvars);
assert(symbols[var][0] != '\0'); /* variable should be defined */
*repl_length += strlen(symbols[var]);
default:
*repl_length += 1;
} /* switch */
- lptr++;
+ sptr++;
} /* while */
/* allocate a buffer to replace the sequence in */
}
/* replace the pattern into this temporary buffer */
- lptr = buffer;
- *lptr++ = '\t'; /* the "replace" patterns do not have tabs */
+ sptr = buffer;
+ *sptr++ = '\t'; /* the "replace" patterns do not have tabs */
while (*pattern)
{
- assert((int)(lptr - buffer) < *repl_length);
+ assert((int)(sptr - buffer) < *repl_length);
switch (*pattern)
{
case '%':
var = atoi(pattern) - 1;
assert(var >= 0 && var < _maxoptvars);
assert(symbols[var][0] != '\0'); /* variable should be defined */
- strcpy(lptr, symbols[var]);
- lptr += strlen(symbols[var]);
+ strcpy(sptr, symbols[var]);
+ sptr += strlen(symbols[var]);
break;
case '!':
/* finish the line, optionally start the next line with an indent */
- *lptr++ = '\n';
- *lptr++ = '\0';
+ *sptr++ = '\n';
+ *sptr++ = '\0';
if (*(pattern + 1) != '\0')
- *lptr++ = '\t';
+ *sptr++ = '\t';
break;
default:
- *lptr++ = *pattern;
+ *sptr++ = *pattern;
} /* switch */
pattern++;
} /* while */
- assert((int)(lptr - buffer) == *repl_length);
+ assert((int)(sptr - buffer) == *repl_length);
return buffer;
}