From 8fcf66f4be06e680ff32eeeaacbfa6105b4700de Mon Sep 17 00:00:00 2001 From: "jeffdyer@acm.org" Date: Sat, 1 Sep 2007 17:34:17 -0700 Subject: [PATCH] small fix to switch --HG-- branch : com.mozilla.es4.smlnj extra : convert_revision : f605dd37c16a259220c45f3279c48fca55cd402f --- comp-esc1.sh | 2 +- tests/self/cogen-stmt.es | 34 ++++++++++++++++++---------------- tests/self/parse-ident.es | 3 --- tests/self/t.es | 5 ++++- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/comp-esc1.sh b/comp-esc1.sh index e72461e8..94f6dd6c 100755 --- a/comp-esc1.sh +++ b/comp-esc1.sh @@ -23,7 +23,7 @@ #./esc.sh tests/self/ast.es #./esc.sh tests/self/lex-char.es #./esc.sh tests/self/lex-token.es -./esc.sh tests/self/lex-scan.es +#./esc.sh tests/self/lex-scan.es #./esc.sh tests/self/parse-util.es #./esc.sh tests/self/parse-ident.es #./esc.sh tests/self/parse-lhsexpr.es diff --git a/tests/self/cogen-stmt.es b/tests/self/cogen-stmt.es index e4d051eb..1da165f7 100644 --- a/tests/self/cogen-stmt.es +++ b/tests/self/cogen-stmt.es @@ -217,43 +217,45 @@ var hasBreak = false; for ( let i=0 ; i < cases.length ; i++ ) { let c = cases[i]; - if (c.expr == null) + + if (c.expr == null) { + assert (Ldefault===null); Ldefault = asm.I_label(); // label default pos + } if (Lnext !== null) { - asm.I_label(Lnext); // label next pos - print ("case label"); + asm.I_label(Lnext); // label next pos Lnext = null; } - if (c.expr !== null) { - cgExpr(nctx, c.expr); // check for match + if (c.expr != null) { + cgExpr(nctx, c.expr); // check for match asm.I_getlocal(t); asm.I_strictequals(); - Lnext = asm.I_iffalse(); // if no match jump to next label - if (Lfall !== null) { // label fall through pos - asm.I_label(Lfall); - print ("fall through label"); - Lfall = null; - } + Lnext = asm.I_iffalse(); // if no match jump to next label + } + + if (Lfall !== null) { // label fall through pos + asm.I_label(Lfall); + Lfall = null; } let stmts = c.stmts; for ( let j=0 ; j < stmts.length ; j++ ) { - if (stmts[j] is BreakStmt) { + if (stmts[j] is BreakStmt) { // FIXME might be nested in if var hasBreak=true; } - cgStmt(nctx, stmts[j] ); } - if (!hasBreak) { // if no break then jump past - Lfall = asm.I_jump (); // next test + + if (!hasBreak) { // if no break then jump past + Lfall = asm.I_jump (); // next test } } if (Lnext !== null) asm.I_label(Lnext); if (Lfall !== null) - asm.I_jump(Lfall); + asm.I_label(Lfall); if (Ldefault !== null) asm.I_jump(Ldefault); asm.I_label(Lbreak); diff --git a/tests/self/parse-ident.es b/tests/self/parse-ident.es index 41571801..88d4bda9 100644 --- a/tests/self/parse-ident.es +++ b/tests/self/parse-ident.es @@ -76,11 +76,8 @@ use namespace Release; var str = ""; // fixme: evaluator isn't happy if this is inside of the switch - - switch (hd (ts)) { case Token::Identifier: - print("ident found"); case Token::Call: case Token::Cast: case Token::Const: diff --git a/tests/self/t.es b/tests/self/t.es index f64f877b..0eaa56cc 100644 --- a/tests/self/t.es +++ b/tests/self/t.es @@ -6,6 +6,7 @@ print(a.length) print(a) */ +/* function f (x) { switch (x) { case 10: @@ -15,7 +16,6 @@ print(20); break; case 30: print(30); -break; default: print('default'); break; @@ -25,3 +25,6 @@ f(10) // 10 20 f(20) // 20 f(30) // 30 f(40) // default +*/ + +print ("hello world") \ No newline at end of file