Skip to content

Commit

Permalink
External mode compiler: Optimize negative integer constants
Browse files Browse the repository at this point in the history
  • Loading branch information
solardiz committed May 18, 2024
1 parent 6d2bdd7 commit f84f518
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,17 @@ static int c_expr(char term, struct c_ident *vars, char *token, int pop)

left = 1;
} else
if ((c >= '0' && c <= '9') || c == '\'') {
if ((c >= '0' && c <= '9') || c == '\'' || (c == '-' && !left)) {
if (c == '-') {
lookahead = c_getchar(0);
c_ungetchar(lookahead);
if (lookahead < '0' || lookahead > '9')
goto other;
token = c_gettoken();
}
value.imm = c_getint(token);
if (c == '-')
value.imm = -value.imm;
last = c_push(last, c_op_push_imm, &value);

left = 1; balance++;
Expand All @@ -552,6 +561,7 @@ static int c_expr(char term, struct c_ident *vars, char *token, int pop)
left = 0;
} else
if (c != ' ') {
other:
if (c_isident[ARCH_INDEX(c)])
var = c_find_ident(vars, NULL, token);
else
Expand Down

0 comments on commit f84f518

Please sign in to comment.