emit: Minor fixes/adjustments

This commit is contained in:
Daniel_Cortez 2018-02-01 02:43:54 +07:00
parent a19b740a28
commit fdae3827f2
3 changed files with 25 additions and 24 deletions

View File

@ -137,7 +137,6 @@ static void dostate(void);
static void addwhile(int *ptr); static void addwhile(int *ptr);
static void delwhile(void); static void delwhile(void);
static int *readwhile(void); static int *readwhile(void);
static void doemit(void);
typedef void (SC_FASTCALL *OPCODE_PROC)(char *name); typedef void (SC_FASTCALL *OPCODE_PROC)(char *name);
typedef struct { typedef struct {
@ -5295,7 +5294,7 @@ static void statement(int *lastindent,int allow_decl)
lexclr(FALSE); lexclr(FALSE);
tok=lex(&val,&st); tok=lex(&val,&st);
} /* case */ } /* case */
/* drop through */ /* fallthrough */
default: /* non-empty expression */ default: /* non-empty expression */
sc_allowproccall=optproccall; sc_allowproccall=optproccall;
lexpush(); /* analyze token later */ lexpush(); /* analyze token later */
@ -5959,18 +5958,18 @@ static void SC_FASTCALL emit_param_any(emit_outval *p)
cell val,cidx; cell val,cidx;
symbol *sym; symbol *sym;
extern char *sc_tokens[]; extern char *sc_tokens[];
int tok,neg,ident,index; int tok,negate,ident,index;
neg=FALSE; negate=FALSE;
p->type=eotNUMBER; p->type=eotNUMBER;
fetchtok: fetchtok:
tok=lex(&val,&str); tok=lex(&val,&str);
switch (tok) { switch (tok) {
case tNUMBER: case tNUMBER:
p->value.ucell=(ucell)((neg!=FALSE) ? -val : val); p->value.ucell=(ucell)(negate ? -val : val);
break; break;
case tRATIONAL: case tRATIONAL:
p->value.ucell=(ucell)((neg!=FALSE) ? (val|((cell)1 << (PAWN_CELL_SIZE-1))) : val); p->value.ucell=(ucell)(negate ? (val|((cell)1 << (PAWN_CELL_SIZE-1))) : val);
break; break;
case tSYMBOL: case tSYMBOL:
sym=findloc(str); sym=findloc(str);
@ -5981,13 +5980,13 @@ fetchtok:
break; break;
} /* if */ } /* if */
if (sym->ident==iLABEL) { if (sym->ident==iLABEL) {
if (neg!=FALSE) if (negate)
goto invalid_token_neg; goto invalid_token_neg;
sym->usage|=uREAD; sym->usage|=uREAD;
p->type=eotLABEL; p->type=eotLABEL;
p->value.ucell=(ucell)sym->addr; p->value.ucell=(ucell)sym->addr;
} else if (sym->ident==iFUNCTN || sym->ident==iREFFUNC) { } else if (sym->ident==iFUNCTN || sym->ident==iREFFUNC) {
if (neg!=FALSE) if (negate)
goto invalid_token_neg; goto invalid_token_neg;
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++;
@ -5996,7 +5995,7 @@ fetchtok:
p->value.string=str; p->value.string=str;
} else { } else {
markusage(sym,uREAD | uWRITTEN); markusage(sym,uREAD | uWRITTEN);
p->value.ucell=(ucell)((neg!=FALSE) ? -sym->addr : sym->addr); p->value.ucell=(ucell)(negate ? -sym->addr : sym->addr);
} /* if */ } /* if */
break; break;
case '(': case '(':
@ -6012,11 +6011,11 @@ fetchtok:
if ((emit_flags & efEXPR)==0) if ((emit_flags & efEXPR)==0)
stgset(FALSE); stgset(FALSE);
needtoken(')'); needtoken(')');
p->value.ucell=(ucell)((neg!=FALSE) ? -val : val); p->value.ucell=(ucell)(negate ? -val : val);
break; break;
case '-': case '-':
if (neg==FALSE) { if (!negate) {
neg=TRUE; negate=TRUE;
goto fetchtok; goto fetchtok;
} else { } else {
char ival[sNAMEMAX+2]; char ival[sNAMEMAX+2];
@ -6120,18 +6119,18 @@ static void SC_FASTCALL emit_param_index(emit_outval *p,int isrange,const cell *
char *str; char *str;
symbol *sym; symbol *sym;
int tok,i,global; int tok,i,global;
int neg=FALSE; int negate=FALSE;
assert(isrange ? (numvalues==2) : (numvalues>0)); assert(isrange ? (numvalues==2) : (numvalues>0));
fetchtok: fetchtok:
tok=lex(&val,&str); tok=lex(&val,&str);
switch (tok) { switch (tok) {
case tNUMBER: case tNUMBER:
if (neg!=FALSE) if (negate)
val=-val; val=-val;
break; break;
case tRATIONAL: case tRATIONAL:
if (neg!=FALSE) if (negate)
val=val|((cell)1 << (PAWN_CELL_SIZE-1)); val=val|((cell)1 << (PAWN_CELL_SIZE-1));
break; break;
case tSYMBOL: case tSYMBOL:
@ -6160,14 +6159,14 @@ fetchtok:
goto invalid_token; goto invalid_token;
} /* switch */ } /* switch */
markusage(sym,uREAD); markusage(sym,uREAD);
val=(neg!=FALSE) ? -sym->addr : sym->addr; val=negate ? -sym->addr : sym->addr;
break; break;
case '-': case '-':
if (neg==FALSE) { if (!negate) {
neg=TRUE; negate=TRUE;
goto fetchtok; goto fetchtok;
} /* if */ } /* if */
/* drop through */ /* fallthrough */
default: default:
invalid_token: invalid_token:
emit_invalid_token(teNUMERIC,tok); emit_invalid_token(teNUMERIC,tok);
@ -6224,6 +6223,8 @@ static void SC_FASTCALL emit_param_nonneg(emit_outval *p)
goto invalid_token; goto invalid_token;
} /* switch */ } /* switch */
markusage(sym,uREAD); markusage(sym,uREAD);
val=sym->addr;
break;
default: default:
invalid_token: invalid_token:
emit_invalid_token(teNONNEG,tok); emit_invalid_token(teNONNEG,tok);
@ -6273,7 +6274,7 @@ static void SC_FASTCALL emit_param_function(emit_outval *p,int isnative)
} else { } else {
tok=(sym->ident==iCONSTEXPR) ? teNUMERIC : teDATA; tok=(sym->ident==iCONSTEXPR) ? teNUMERIC : teDATA;
} /* if */ } /* if */
/* drop through */ /* fallthrough */
default: default:
emit_invalid_token((isnative!=FALSE) ? teNATIVE : teFUNCTN,tok); emit_invalid_token((isnative!=FALSE) ? teNATIVE : teFUNCTN,tok);
return; return;