fix prefix and div-assign

This commit is contained in:
Yaossg 2024-12-08 15:40:44 +08:00
parent 9a2a1b00be
commit a9054f0a64

18
boot.c
View File

@ -427,7 +427,7 @@ void next_token() {
int ch2 = getchar();
if (ch2 == '=') {
token_type = TOKEN_DIV_ASSIGN;
} if (ch2 == '/') {
} else if (ch2 == '/') {
do ch = getchar(); while (ch != -1 && ch != '\n');
next_token();
return;
@ -1253,7 +1253,7 @@ int parse_postfix_expr() {
int parse_prefix_expr() {
next_token();
if (token_type == TOKEN_AND) {
int reg = parse_postfix_expr();
int reg = parse_prefix_expr();
int type = reg_type[reg];
if (type & TYPE_PTR_MASK) {
fprintf(stderr, "cannot take address of a pointer\n");
@ -1261,7 +1261,7 @@ int parse_prefix_expr() {
}
return addressof(reg);
} else if (token_type == TOKEN_MUL) {
int reg = parse_postfix_expr();
int reg = parse_prefix_expr();
int type = reg_type[reg];
if (!(type & TYPE_PTR_MASK)) {
fprintf(stderr, "cannot dereference a non-pointer\n");
@ -1273,20 +1273,20 @@ int parse_prefix_expr() {
}
return dereference(reg);
} else if (token_type == TOKEN_SUB) {
int reg = parse_postfix_expr();
int reg = parse_prefix_expr();
return asm_r_arith("neg", reg);
} else if (token_type == TOKEN_COMPL) {
int reg = parse_postfix_expr();
int reg = parse_prefix_expr();
return asm_r_arith("not", reg);
} else if (token_type == TOKEN_NOT) {
int reg = parse_postfix_expr();
int reg = parse_prefix_expr();
return asm_r(TYPE_INT, "seqz", reg);
} else if (token_type == TOKEN_INC) {
int reg = parse_postfix_expr();
int reg = parse_prefix_expr();
_asm_ri("addi", reg, reg, step_of(reg_type[reg]));
return reg;
} else if (token_type == TOKEN_DEC) {
int reg = parse_postfix_expr();
int reg = parse_prefix_expr();
_asm_ri("addi", reg, reg, -step_of(reg_type[reg]));
return reg;
} else {
@ -1989,8 +1989,6 @@ void dump_string_table() {
printf("\\t");
} else if (ch == '\r') {
printf("\\r");
} else if (ch == '\0') {
printf("\\0");
} else if (ch == '\\') {
printf("\\\\");
} else if (ch == '\'') {