From 623c9b91987629d60fa71790b5db0a8f804b1122 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Fri, 8 Nov 2019 07:28:09 +0000 Subject: [PATCH] fixed an unexpected compiler bug caused by wrong ifdef while processing a lable at the end of a braced block --- moo/kernel/test-003.moo | 4 ++-- moo/lib/comp.c | 7 ------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/moo/kernel/test-003.moo b/moo/kernel/test-003.moo index 072b956..6cbbb14 100644 --- a/moo/kernel/test-003.moo +++ b/moo/kernel/test-003.moo @@ -189,10 +189,10 @@ start: [ self test_while_001 ], [ (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 - [ (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 ], [ [ | a4 | a4:= 21. if (a4 == 21) { a4 := 4321. goto L04 } else { a4 := 1234. goto L04 }. a4 := 8888. L04: a4 ] value == 4321 ] ). diff --git a/moo/lib/comp.c b/moo/lib/comp.c index 8dbfa72..0608d25 100644 --- a/moo/lib/comp.c +++ b/moo/lib/comp.c @@ -6472,19 +6472,12 @@ static int compile_braced_block (moo_t* moo) MOO_ASSERT (moo, md->_label != MOO_NULL); if (TOKEN_TYPE(moo) == MOO_IOTOK_RBRACE) { - #if 0 /* the last label inside {} must be followed by a valid statement */ moo_oocs_t labname; labname.ptr = (moo_ooch_t*)(md->_label + 1); labname.len = moo_count_oocstr(labname.ptr); moo_setsynerrbfmt (moo, MOO_SYNERR_LABELATEND, &md->_label->loc, &labname, "label at end of braced block"); 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)