diff options
author | Tucker Evans <tuckerevans24@gmail.com> | 2019-10-09 09:33:44 -0400 |
---|---|---|
committer | Tucker Evans <tuckerevans24@gmail.com> | 2019-10-09 09:33:44 -0400 |
commit | a7369d623535c0ced7e84f9bb41f988de9e00312 (patch) | |
tree | 1bb1749c5a1500c03e100729e094f6c4002b3dab | |
parent | 1280836201150aa0097d7338459f6b142a962f82 (diff) |
Fix gen label to deal with NEG
-rw-r--r-- | gen_code.c | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -19,7 +19,7 @@ scope *cur_scope; else yyerror("CAN'T POP");} #define REG_PUSH {if (reg_cnt < 13) reg_ptr--, reg_cnt++;\ else yyerror("CAN'T PUSH");} -#define GEN_EXPR(x) {gen_label(x); gen_expr(x);} +#define GEN_EXPR(x) {(x)->label = gen_label(x); gen_expr(x);} char **reg_stack, **reg_ptr; int reg_cnt; @@ -65,7 +65,7 @@ ptree *t; { int tmp; - if (!(t->l && t->r)) { + if (!(t->l || t->r)) { t->label = 0; return 0; } @@ -77,16 +77,18 @@ ptree *t; yyerror("GEN_LABEL: left child NULL, shouldn't happen!\n"); if (t->r) - t->r->label = gen_label(t->r); + tmp = t->r->label = gen_label(t->r); else - t->r->label = 0; + tmp = 0; - if (t->r->label == t->l->label) { + + if (tmp == t->l->label) { return 1 + t->l->label; } else { - return t->r->label > t->l->label ? t->r->label : t->l->label; + return tmp > t->l->label ? tmp : t->l->label; } +} } |