emit/__emit: Allow for leading '-' to negate symbol values in emit_param_num()

Now it should be possible to do this:
    const SOME_VAL = 1;
    emit const.pri -SOME_VAL

or this:
    static some_array[] = { 0, 1, 2, 3, 4, 5 };
    static some_var;
    emit { const.pri some_var };
    new some_var_offset = emit { add.c -some_array };
This commit is contained in:
Daniel_Cortez 2017-11-17 22:54:10 +07:00
parent 912376b658
commit 5eb18c4eec

View File

@ -5850,12 +5850,18 @@ static void emit_param_num(ucell *p,int size)
int tok; int tok;
extern char *sc_tokens[]; extern char *sc_tokens[];
int curp=0; int curp=0;
int neg;
do { do {
switch (tok=lex(&val,&str)) { neg=0;
case tRATIONAL: fetchtok:
tok=lex(&val,&str);
switch (tok) {
case tNUMBER: case tNUMBER:
p[curp]=val; p[curp]=(neg!=0) ? -val : val;
break;
case tRATIONAL:
p[curp]=(neg!=0) ? (val|((cell)1 << (PAWN_CELL_SIZE-1))) : val;
break; break;
case tSYMBOL: case tSYMBOL:
sym=findloc(str); sym=findloc(str);
@ -5863,28 +5869,26 @@ static void emit_param_num(ucell *p,int size)
sym=findglb(str,sSTATEVAR); sym=findglb(str,sSTATEVAR);
if (sym==NULL || (sym->ident!=iFUNCTN && sym->ident!=iREFFUNC && (sym->usage & uDEFINE)==0) || sym->ident==iLABEL) { if (sym==NULL || (sym->ident!=iFUNCTN && sym->ident!=iREFFUNC && (sym->usage & uDEFINE)==0) || sym->ident==iLABEL) {
error(17,str); /* undefined symbol */ error(17,str); /* undefined symbol */
} else if (sym->ident==iFUNCTN || sym->ident==iREFFUNC) { break;
} /* if */
if (sym->ident==iFUNCTN || sym->ident==iREFFUNC) {
if ((sym->usage & uNATIVE)!=0 && (sym->usage & uREAD)==0 && sym->addr>=0) if ((sym->usage & uNATIVE)!=0 && (sym->usage & uREAD)==0 && sym->addr>=0)
sym->addr=ntv_funcid++; sym->addr=ntv_funcid++;
p[curp]=sym->addr;
markusage(sym,uREAD); markusage(sym,uREAD);
} else { } else {
p[curp]=sym->addr;
markusage(sym,uREAD|uWRITTEN); markusage(sym,uREAD|uWRITTEN);
} /* if */ } /* if */
p[curp]=(neg!=0) ? -sym->addr : sym->addr;
break; break;
default: default:
if ((char)tok=='-') { if (tok==(int)'-') {
tok=lex(&val,&str); if (neg==0) {
if (tok==tNUMBER) { neg=1;
p[curp]=-val; goto fetchtok;
} else if (tok==tRATIONAL) { } /* if */
p[curp]=val|((cell)1 << (PAWN_CELL_SIZE-1));
} else {
char ival[sNAMEMAX+2]="-"; char ival[sNAMEMAX+2]="-";
strcpy(ival+1,str); strcpy(ival+1,str);
error(1,sc_tokens[tSYMBOL-tFIRST],ival); error(1,sc_tokens[tSYMBOL-tFIRST],ival);
} /* if */
} else { } else {
emit_invalid_token(teNUMBER,tok); emit_invalid_token(teNUMBER,tok);
} /* if */ } /* if */