diff --git a/code.c b/code.c index 964797f..3c418b1 100644 --- a/code.c +++ b/code.c @@ -39,6 +39,12 @@ void code_push_statement(prog_section_statement *stmt, int linenum) vec_push(code_linenums, linenum); } +void code_pop_statement() +{ + vec_pop(code_statements); + vec_pop(code_linenums); +} + void code_init() { prog_section_function empty_function = {0,0,0,0,0,0,0,{0}}; prog_section_statement empty_statement = {0,{0},{0},{0}}; diff --git a/gmqcc.h b/gmqcc.h index b95bac4..df123c6 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -573,6 +573,7 @@ qcint code_alloc_field (size_t qcsize); /* this function is used to keep statements and linenumbers together */ void code_push_statement(prog_section_statement *stmt, int linenum); +void code_pop_statement(); /* * A shallow copy of a lex_file to remember where which ast node diff --git a/ir.c b/ir.c index 6bc766c..2375d55 100644 --- a/ir.c +++ b/ir.c @@ -2743,8 +2743,7 @@ tailcall: ontrue = tmp; } stidx = vec_size(code_statements); - if (stmt.o2.s1 != 1) - code_push_statement(&stmt, instr->context.line); + code_push_statement(&stmt, instr->context.line); /* on false we jump, so add ontrue-path */ if (!gen_blocks_recursive(func, ontrue)) return false; @@ -2754,6 +2753,12 @@ tailcall: if (onfalse->generated) { /* fixup the jump address */ code_statements[stidx].o2.s1 = (onfalse->code_start) - (stidx); + if (code_statements[stidx].o2.s1 == 1) { + code_statements[stidx] = code_statements[stidx+1]; + if (code_statements[stidx].o1.s1 < 0) + code_statements[stidx].o1.s1++; + code_pop_statement(); + } stmt.opcode = vec_last(code_statements).opcode; if (stmt.opcode == INSTR_GOTO || stmt.opcode == INSTR_IF || @@ -2773,6 +2778,12 @@ tailcall: code_push_statement(&stmt, instr->context.line); return true; } + else if (code_statements[stidx].o2.s1 == 1) { + code_statements[stidx] = code_statements[stidx+1]; + if (code_statements[stidx].o1.s1 < 0) + code_statements[stidx].o1.s1++; + code_pop_statement(); + } /* if not, generate now */ block = onfalse; goto tailcall;