parent
4937b8dd25
commit
44a33d1f1d
|
@ -67,7 +67,6 @@ static int declargs(symbol * sym);
|
||||||
static void doarg(char *name, int ident, int offset,
|
static void doarg(char *name, int ident, int offset,
|
||||||
int tags[], int numtags,
|
int tags[], int numtags,
|
||||||
int fpublic, int fconst, arginfo * arg);
|
int fpublic, int fconst, arginfo * arg);
|
||||||
static void dump_referrers(symbol * root, FILE * log, char *sourcefile);
|
|
||||||
static void reduce_referrers(symbol * root);
|
static void reduce_referrers(symbol * root);
|
||||||
static int testsymbols(symbol * root, int level,
|
static int testsymbols(symbol * root, int level,
|
||||||
int testlabs, int testconst);
|
int testlabs, int testconst);
|
||||||
|
@ -581,11 +580,11 @@ initglobals(void)
|
||||||
litmax = sDEF_LITMAX; /* current size of the literal table */
|
litmax = sDEF_LITMAX; /* current size of the literal table */
|
||||||
errnum = 0; /* number of errors */
|
errnum = 0; /* number of errors */
|
||||||
warnnum = 0; /* number of warnings */
|
warnnum = 0; /* number of warnings */
|
||||||
/* // sc_debug=sCHKBOUNDS; /* by default: bounds checking+assertions */
|
/* sc_debug=sCHKBOUNDS; by default: bounds checking+assertions */
|
||||||
sc_debug = 0; /* by default: no debug */
|
sc_debug = 0; /* by default: no debug */
|
||||||
charbits = 8; /* a "char" is 8 bits */
|
charbits = 8; /* a "char" is 8 bits */
|
||||||
sc_packstr = FALSE; /* strings are unpacked by default */
|
sc_packstr = FALSE; /* strings are unpacked by default */
|
||||||
/* // sc_compress=TRUE; /* compress output bytecodes */
|
/* sc_compress=TRUE; compress output bytecodes */
|
||||||
sc_compress = FALSE; /* compress output bytecodes */
|
sc_compress = FALSE; /* compress output bytecodes */
|
||||||
sc_needsemicolon = FALSE; /* semicolon required to terminate
|
sc_needsemicolon = FALSE; /* semicolon required to terminate
|
||||||
* expressions? */
|
* expressions? */
|
||||||
|
@ -651,35 +650,6 @@ set_extension(char *filename, char *extension, int force)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
toggle_option(char *optptr, int option)
|
|
||||||
{
|
|
||||||
switch (*(optptr + 1))
|
|
||||||
{
|
|
||||||
case '\0':
|
|
||||||
option = !option;
|
|
||||||
break;
|
|
||||||
case '-':
|
|
||||||
option = FALSE;
|
|
||||||
break;
|
|
||||||
case '+':
|
|
||||||
option = TRUE;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
about();
|
|
||||||
} /* switch */
|
|
||||||
return option;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Parsing command line options is indirectly recursive: parseoptions()
|
|
||||||
* calls parserespf() to handle options in a a response file and
|
|
||||||
* parserespf() calls parseoptions() at its turn after having created
|
|
||||||
* an "option list" from the contents of the file.
|
|
||||||
*/
|
|
||||||
static void parserespf(char *filename, char *iname,
|
|
||||||
char *oname, char *ename,
|
|
||||||
char *pname, char *rname);
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
parseoptions(int argc, char **argv, char *iname, char *oname,
|
parseoptions(int argc, char **argv, char *iname, char *oname,
|
||||||
char *ename, char *pname, char *rname)
|
char *ename, char *pname, char *rname)
|
||||||
|
@ -901,12 +871,6 @@ setconfig(char *root)
|
||||||
} /* if */
|
} /* if */
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
waitkey(void)
|
|
||||||
{
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
setcaption(void)
|
setcaption(void)
|
||||||
{
|
{
|
||||||
|
@ -1423,7 +1387,7 @@ declloc(int fstatic)
|
||||||
* of a global variable or to that of a local variable at a lower
|
* of a global variable or to that of a local variable at a lower
|
||||||
* level might indicate a bug.
|
* level might indicate a bug.
|
||||||
*/
|
*/
|
||||||
if ((sym = findloc(name)) != NULL && sym->compound != nestlevel
|
if (((sym = findloc(name)) != NULL && sym->compound != nestlevel)
|
||||||
|| findglb(name) != NULL)
|
|| findglb(name) != NULL)
|
||||||
error(219, name); /* variable shadows another symbol */
|
error(219, name); /* variable shadows another symbol */
|
||||||
while (matchtoken('['))
|
while (matchtoken('['))
|
||||||
|
@ -2114,7 +2078,7 @@ operatoradjust(int opertok, symbol * sym, char *opername, int resulttag)
|
||||||
} /* switch */
|
} /* switch */
|
||||||
|
|
||||||
if (tags[0] == 0
|
if (tags[0] == 0
|
||||||
&& (opertok != '=' && tags[1] == 0 || opertok == '=' && resulttag == 0))
|
&& ((opertok != '=' && tags[1] == 0) || (opertok == '=' && resulttag == 0)))
|
||||||
error(64); /* cannot change predefined operators */
|
error(64); /* cannot change predefined operators */
|
||||||
|
|
||||||
/* change the operator name */
|
/* change the operator name */
|
||||||
|
@ -2298,7 +2262,7 @@ funcstub(int native)
|
||||||
if (native)
|
if (native)
|
||||||
{
|
{
|
||||||
if (tok == tPUBLIC || tok == tSTOCK || tok == tSTATIC ||
|
if (tok == tPUBLIC || tok == tSTOCK || tok == tSTATIC ||
|
||||||
tok == tSYMBOL && *str == PUBLIC_CHAR)
|
(tok == tSYMBOL && *str == PUBLIC_CHAR))
|
||||||
error(42); /* invalid combination of class specifiers */
|
error(42); /* invalid combination of class specifiers */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -2426,7 +2390,7 @@ newfunc(char *firstname, int firsttag, int fpublic, int fstatic, int stock)
|
||||||
tag = (firsttag >= 0) ? firsttag : sc_addtag(NULL);
|
tag = (firsttag >= 0) ? firsttag : sc_addtag(NULL);
|
||||||
tok = lex(&val, &str);
|
tok = lex(&val, &str);
|
||||||
assert(!fpublic);
|
assert(!fpublic);
|
||||||
if (tok == tNATIVE || tok == tPUBLIC && stock)
|
if (tok == tNATIVE || (tok == tPUBLIC && stock))
|
||||||
error(42); /* invalid combination of class specifiers */
|
error(42); /* invalid combination of class specifiers */
|
||||||
if (tok == tOPERATOR)
|
if (tok == tOPERATOR)
|
||||||
{
|
{
|
||||||
|
@ -2798,7 +2762,7 @@ declargs(symbol * sym)
|
||||||
error(10); /* illegal function or declaration */
|
error(10); /* illegal function or declaration */
|
||||||
} /* switch */
|
} /* switch */
|
||||||
}
|
}
|
||||||
while (tok == '&' || tok == tLABEL || tok == tCONST || tok != tELLIPS && matchtoken(',')); /* more? */
|
while (tok == '&' || tok == tLABEL || tok == tCONST || (tok != tELLIPS && matchtoken(','))); /* more? */
|
||||||
/* if the next token is not ",", it should be ")" */
|
/* if the next token is not ",", it should be ")" */
|
||||||
needtoken(')');
|
needtoken(')');
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
|
@ -1176,9 +1176,9 @@ command(void)
|
||||||
sym = findloc(str);
|
sym = findloc(str);
|
||||||
if (sym == NULL)
|
if (sym == NULL)
|
||||||
sym = findglb(str);
|
sym = findglb(str);
|
||||||
if (sym == NULL || sym->ident != iFUNCTN
|
if (sym == NULL || (sym->ident != iFUNCTN
|
||||||
&& sym->ident != iREFFUNC
|
&& sym->ident != iREFFUNC
|
||||||
&& (sym->usage & uDEFINE) == 0)
|
&& (sym->usage & uDEFINE) == 0))
|
||||||
{
|
{
|
||||||
error(17, str); /* undefined symbol */
|
error(17, str); /* undefined symbol */
|
||||||
}
|
}
|
||||||
|
@ -1974,7 +1974,7 @@ lex(cell * lexvalue, char **lexsym)
|
||||||
lptr += 1; /* skip colon */
|
lptr += 1; /* skip colon */
|
||||||
} /* if */
|
} /* if */
|
||||||
}
|
}
|
||||||
else if (*lptr == '\"' || *lptr == sc_ctrlchar && *(lptr + 1) == '\"')
|
else if (*lptr == '\"' || (*lptr == sc_ctrlchar && *(lptr + 1) == '\"'))
|
||||||
{ /* unpacked string literal */
|
{ /* unpacked string literal */
|
||||||
_lextok = tSTRING;
|
_lextok = tSTRING;
|
||||||
rawstring = (*lptr == sc_ctrlchar);
|
rawstring = (*lptr == sc_ctrlchar);
|
||||||
|
@ -1990,10 +1990,10 @@ lex(cell * lexvalue, char **lexsym)
|
||||||
else
|
else
|
||||||
error(37); /* invalid (non-terminated) string */
|
error(37); /* invalid (non-terminated) string */
|
||||||
}
|
}
|
||||||
else if (*lptr == '!' && *(lptr + 1) == '\"'
|
else if ((*lptr == '!' && *(lptr + 1) == '\"')
|
||||||
|| *lptr == '!' && *(lptr + 1) == sc_ctrlchar && *(lptr + 2) == '\"'
|
|| (*lptr == '!' && *(lptr + 1) == sc_ctrlchar && *(lptr + 2) == '\"')
|
||||||
|| *lptr == sc_ctrlchar && *(lptr + 1) == '!'
|
|| (*lptr == sc_ctrlchar && *(lptr + 1) == '!'
|
||||||
&& *(lptr + 2) == '\"')
|
&& *(lptr + 2) == '\"'))
|
||||||
{ /* packed string literal */
|
{ /* packed string literal */
|
||||||
_lextok = tSTRING;
|
_lextok = tSTRING;
|
||||||
rawstring = (*lptr == sc_ctrlchar || *(lptr + 1) == sc_ctrlchar);
|
rawstring = (*lptr == sc_ctrlchar || *(lptr + 1) == sc_ctrlchar);
|
||||||
|
@ -2082,7 +2082,7 @@ matchtoken(int token)
|
||||||
int tok;
|
int tok;
|
||||||
|
|
||||||
tok = lex(&val, &str);
|
tok = lex(&val, &str);
|
||||||
if (tok == token || token == tTERM && (tok == ';' || tok == tENDEXPR))
|
if (tok == token || (token == tTERM && (tok == ';' || tok == tENDEXPR)))
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1002,7 +1002,7 @@ hier14(value * lval1)
|
||||||
if (lval3.sym->dim.array.level != level)
|
if (lval3.sym->dim.array.level != level)
|
||||||
return error(48); /* array dimensions must match */
|
return error(48); /* array dimensions must match */
|
||||||
else if (lval3.sym->dim.array.length < val
|
else if (lval3.sym->dim.array.length < val
|
||||||
|| exactmatch && lval3.sym->dim.array.length > val)
|
|| (exactmatch && lval3.sym->dim.array.length > val))
|
||||||
return error(47); /* array sizes must match */
|
return error(47); /* array sizes must match */
|
||||||
if (level > 0)
|
if (level > 0)
|
||||||
{
|
{
|
||||||
|
@ -1544,8 +1544,8 @@ hier1(value * lval1)
|
||||||
if (close == ']')
|
if (close == ']')
|
||||||
{
|
{
|
||||||
/* normal array index */
|
/* normal array index */
|
||||||
if (lval2.constval < 0 || sym->dim.array.length != 0
|
if (lval2.constval < 0 || (sym->dim.array.length != 0
|
||||||
&& sym->dim.array.length <= lval2.constval)
|
&& sym->dim.array.length <= lval2.constval))
|
||||||
error(32, sym->name); /* array index out of bounds */
|
error(32, sym->name); /* array index out of bounds */
|
||||||
if (lval2.constval != 0)
|
if (lval2.constval != 0)
|
||||||
{
|
{
|
||||||
|
@ -1561,10 +1561,10 @@ hier1(value * lval1)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* character index */
|
/* character index */
|
||||||
if (lval2.constval < 0 || sym->dim.array.length != 0
|
if (lval2.constval < 0 || (sym->dim.array.length != 0
|
||||||
&& sym->dim.array.length * ((8 * sizeof(cell)) /
|
&& sym->dim.array.length * ((8 * sizeof(cell)) /
|
||||||
charbits) <=
|
charbits) <=
|
||||||
(ucell) lval2.constval)
|
(ucell) lval2.constval))
|
||||||
error(32, sym->name); /* array index out of bounds */
|
error(32, sym->name); /* array index out of bounds */
|
||||||
if (lval2.constval != 0)
|
if (lval2.constval != 0)
|
||||||
{
|
{
|
||||||
|
@ -2094,11 +2094,11 @@ callfunction(symbol * sym)
|
||||||
* function argument; a literal string may be smaller than
|
* function argument; a literal string may be smaller than
|
||||||
* the function argument.
|
* the function argument.
|
||||||
*/
|
*/
|
||||||
if (lval.constval > 0
|
if ((lval.constval > 0
|
||||||
&& arg[argidx].dim[0] != lval.constval
|
&& arg[argidx].dim[0] != lval.constval)
|
||||||
|| lval.constval < 0
|
|| (lval.constval < 0
|
||||||
&& arg[argidx].dim[0] <
|
&& arg[argidx].dim[0] <
|
||||||
-lval.constval)
|
-lval.constval))
|
||||||
error(47); /* array sizes must match */
|
error(47); /* array sizes must match */
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
|
@ -1023,8 +1023,8 @@ assemble(FILE * fout, FILE * fin)
|
||||||
instr = skipwhitespace(line);
|
instr = skipwhitespace(line);
|
||||||
/* ignore empty lines and labels (labels have a special syntax, so these
|
/* ignore empty lines and labels (labels have a special syntax, so these
|
||||||
* must be parsed separately) */
|
* must be parsed separately) */
|
||||||
if (*instr == '\0' || tolower(*instr) == 'l'
|
if (*instr == '\0' || (tolower(*instr) == 'l'
|
||||||
&& *(instr + 1) == '.')
|
&& *(instr + 1) == '.'))
|
||||||
continue;
|
continue;
|
||||||
/* get to the end of the instruction (make use of the '\n' that fgets()
|
/* get to the end of the instruction (make use of the '\n' that fgets()
|
||||||
* added at the end of the line; this way we will *always* drop on a
|
* added at the end of the line; this way we will *always* drop on a
|
||||||
|
|
|
@ -490,18 +490,18 @@ matchsequence(char *start, char *end, char *pattern,
|
||||||
case ' ':
|
case ' ':
|
||||||
if (*start != '\t' && *start != ' ')
|
if (*start != '\t' && *start != ' ')
|
||||||
return FALSE;
|
return FALSE;
|
||||||
while (start < end && *start == '\t' || *start == ' ')
|
while ((start < end && *start == '\t') || *start == ' ')
|
||||||
start++;
|
start++;
|
||||||
break;
|
break;
|
||||||
case '!':
|
case '!':
|
||||||
while (start < end && *start == '\t' || *start == ' ')
|
while ((start < end && *start == '\t') || *start == ' ')
|
||||||
start++; /* skip trailing white space */
|
start++; /* skip trailing white space */
|
||||||
if (*start != '\n')
|
if (*start != '\n')
|
||||||
return FALSE;
|
return FALSE;
|
||||||
assert(*(start + 1) == '\0');
|
assert(*(start + 1) == '\0');
|
||||||
start += 2; /* skip '\n' and '\0' */
|
start += 2; /* skip '\n' and '\0' */
|
||||||
if (*(pattern + 1) != '\0')
|
if (*(pattern + 1) != '\0')
|
||||||
while (start < end && *start == '\t' || *start == ' ')
|
while ((start < end && *start == '\t') || *start == ' ')
|
||||||
start++; /* skip leading white space of next instruction */
|
start++; /* skip leading white space of next instruction */
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -239,7 +239,7 @@ adjustindex(char c)
|
||||||
{
|
{
|
||||||
stringpair *cur;
|
stringpair *cur;
|
||||||
|
|
||||||
assert(c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c == '_');
|
assert((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_');
|
||||||
assert('A' < '_' && '_' < 'z');
|
assert('A' < '_' && '_' < 'z');
|
||||||
|
|
||||||
for (cur = substpair.next; cur != NULL && cur->first[0] != c;
|
for (cur = substpair.next; cur != NULL && cur->first[0] != c;
|
||||||
|
@ -270,7 +270,7 @@ find_subst(char *name, int length)
|
||||||
|
|
||||||
assert(name != NULL);
|
assert(name != NULL);
|
||||||
assert(length > 0);
|
assert(length > 0);
|
||||||
assert(*name >= 'A' && *name <= 'Z' || *name >= 'a' && *name <= 'z'
|
assert((*name >= 'A' && *name <= 'Z') || (*name >= 'a' && *name <= 'z')
|
||||||
|| *name == '_');
|
|| *name == '_');
|
||||||
item = substindex[(int)*name - 'A'];
|
item = substindex[(int)*name - 'A'];
|
||||||
if (item != NULL)
|
if (item != NULL)
|
||||||
|
@ -285,7 +285,7 @@ delete_subst(char *name, int length)
|
||||||
|
|
||||||
assert(name != NULL);
|
assert(name != NULL);
|
||||||
assert(length > 0);
|
assert(length > 0);
|
||||||
assert(*name >= 'A' && *name <= 'Z' || *name >= 'a' && *name <= 'z'
|
assert((*name >= 'A' && *name <= 'Z') || (*name >= 'a' && *name <= 'z')
|
||||||
|| *name == '_');
|
|| *name == '_');
|
||||||
item = substindex[(int)*name - 'A'];
|
item = substindex[(int)*name - 'A'];
|
||||||
if (item != NULL)
|
if (item != NULL)
|
||||||
|
|
|
@ -130,7 +130,6 @@ exported_printf(Embryo_Program *ep, Embryo_Cell *params)
|
||||||
static Embryo_Cell
|
static Embryo_Cell
|
||||||
exported_rec(Embryo_Program *ep, Embryo_Cell *params)
|
exported_rec(Embryo_Program *ep, Embryo_Cell *params)
|
||||||
{
|
{
|
||||||
Embryo_Cell *cptr;
|
|
||||||
Embryo_Function fn;
|
Embryo_Function fn;
|
||||||
Embryo_Cell ret, arg1, arg2;
|
Embryo_Cell ret, arg1, arg2;
|
||||||
|
|
||||||
|
|
|
@ -23,32 +23,11 @@
|
||||||
|
|
||||||
#define JUMPABS(base, ip) ((Embryo_Cell *)(code + (*ip)))
|
#define JUMPABS(base, ip) ((Embryo_Cell *)(code + (*ip)))
|
||||||
|
|
||||||
static void _embryo_byte_swap_16 (unsigned short *v);
|
|
||||||
static void _embryo_byte_swap_32 (unsigned int *v);
|
|
||||||
static int _embryo_native_call (Embryo_Program *ep, Embryo_Cell index, Embryo_Cell *result, Embryo_Cell *params);
|
static int _embryo_native_call (Embryo_Program *ep, Embryo_Cell index, Embryo_Cell *result, Embryo_Cell *params);
|
||||||
static int _embryo_func_get (Embryo_Program *ep, int index, char *funcname);
|
static int _embryo_func_get (Embryo_Program *ep, int index, char *funcname);
|
||||||
static int _embryo_var_get (Embryo_Program *ep, int index, char *varname, Embryo_Cell *ep_addr);
|
static int _embryo_var_get (Embryo_Program *ep, int index, char *varname, Embryo_Cell *ep_addr);
|
||||||
static int _embryo_program_init (Embryo_Program *ep, void *code);
|
static int _embryo_program_init (Embryo_Program *ep, void *code);
|
||||||
|
|
||||||
static void
|
|
||||||
_embryo_byte_swap_16(unsigned short *v)
|
|
||||||
{
|
|
||||||
unsigned char *s, t;
|
|
||||||
|
|
||||||
s = (unsigned char *)v;
|
|
||||||
t = s[0]; s[0] = s[1]; s[1] = t;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
_embryo_byte_swap_32(unsigned int *v)
|
|
||||||
{
|
|
||||||
unsigned char *s, t;
|
|
||||||
|
|
||||||
s = (unsigned char *)v;
|
|
||||||
t = s[0]; s[0] = s[3]; s[3] = t;
|
|
||||||
t = s[1]; s[1] = s[2]; s[2] = t;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_embryo_native_call(Embryo_Program *ep, Embryo_Cell index, Embryo_Cell *result, Embryo_Cell *params)
|
_embryo_native_call(Embryo_Program *ep, Embryo_Cell index, Embryo_Cell *result, Embryo_Cell *params)
|
||||||
{
|
{
|
||||||
|
@ -1555,7 +1534,7 @@ embryo_program_run(Embryo_Program *ep, Embryo_Function fn)
|
||||||
break;
|
break;
|
||||||
case EMBRYO_OP_SWITCH:
|
case EMBRYO_OP_SWITCH:
|
||||||
{
|
{
|
||||||
Embryo_Cell *cptr, *tbl;
|
Embryo_Cell *cptr;
|
||||||
|
|
||||||
/* +1, to skip the "casetbl" opcode */
|
/* +1, to skip the "casetbl" opcode */
|
||||||
cptr = (Embryo_Cell *)(code + (*cip)) + 1;
|
cptr = (Embryo_Cell *)(code + (*cip)) + 1;
|
||||||
|
|
Loading…
Reference in New Issue