fixed an unexpected compiler bug caused by wrong ifdef while processing a lable at the end of a braced block

This commit is contained in:
hyunghwan.chung 2019-11-08 07:28:09 +00:00
parent 201b475133
commit 623c9b9198
2 changed files with 2 additions and 9 deletions

View File

@ -189,10 +189,10 @@ start:
[ self test_while_001 ], [ self test_while_001 ],
[ (if (1 > 2) { } else { }) == nil. ], [ (if (1 > 2) { } else { }) == nil. ],
[ (if (1 < 2) { } else { }) == nil. ], [ (if (1 < 2) { } else { }) == nil. ],
[ (if (1 > 2) { } else { goto A01. A01: }) == nil ], [ (if (1 > 2) { } else { goto A01. A01: nil }) == nil ],
// 25-29 // 25-29
[ (if (1 > 2) { } else { 9876. goto A02. A02: }) == 9876 ], [ (if (1 > 2) { } else { 9876. goto A02. A02: 9876. }) == 9876 ],
[ [ | a3 | a3:= 20. if (a3 == 21) { a3 := 4321. goto L03 } else { a3 := 1234. goto L03 }. a3 := 8888. L03: a3 ] value == 1234 ], [ [ | a3 | a3:= 20. if (a3 == 21) { a3 := 4321. goto L03 } else { a3 := 1234. goto L03 }. a3 := 8888. L03: a3 ] value == 1234 ],
[ [ | a4 | a4:= 21. if (a4 == 21) { a4 := 4321. goto L04 } else { a4 := 1234. goto L04 }. a4 := 8888. L04: a4 ] value == 4321 ] [ [ | a4 | a4:= 21. if (a4 == 21) { a4 := 4321. goto L04 } else { a4 := 1234. goto L04 }. a4 := 8888. L04: a4 ] value == 4321 ]
). ).

View File

@ -6472,19 +6472,12 @@ static int compile_braced_block (moo_t* moo)
MOO_ASSERT (moo, md->_label != MOO_NULL); MOO_ASSERT (moo, md->_label != MOO_NULL);
if (TOKEN_TYPE(moo) == MOO_IOTOK_RBRACE) if (TOKEN_TYPE(moo) == MOO_IOTOK_RBRACE)
{ {
#if 0
/* the last label inside {} must be followed by a valid statement */ /* the last label inside {} must be followed by a valid statement */
moo_oocs_t labname; moo_oocs_t labname;
labname.ptr = (moo_ooch_t*)(md->_label + 1); labname.ptr = (moo_ooch_t*)(md->_label + 1);
labname.len = moo_count_oocstr(labname.ptr); labname.len = moo_count_oocstr(labname.ptr);
moo_setsynerrbfmt (moo, MOO_SYNERR_LABELATEND, &md->_label->loc, &labname, "label at end of braced block"); moo_setsynerrbfmt (moo, MOO_SYNERR_LABELATEND, &md->_label->loc, &labname, "label at end of braced block");
return -1; return -1;
#else
/* unlike in [], a label can be placed at the back of the block.
* to keep the last evaluated value, eliminate the pop_stacktop instruction */
if (pop_stacktop_pos > 0) eliminate_instructions (moo, pop_stacktop_pos, pop_stacktop_pos);
break;
#endif
} }
} }
else if (n == 7777) else if (n == 7777)