From 8645250f3d8a823e0e9a1d264bd1b7936ba1f2c6 Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 9 Jan 2003 06:16:43 +0000 Subject: * parse.y (stmt): NODE_NOT elimitation for if/unless/while/until node. * parse.y (primary): ditto. * eval.c (rb_eval): reduce recursive rb_eval() call by using sort of continuation passing style. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@3314 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- parse.y | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'parse.y') diff --git a/parse.y b/parse.y index 0309b41ff..67da74313 100644 --- a/parse.y +++ b/parse.y @@ -407,11 +407,21 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem { $$ = NEW_IF(cond($3), $1, 0); fixpos($$, $3); + if (nd_type($$->nd_cond) == NODE_NOT) { + $$->nd_cond = $$->nd_cond->nd_body; + $$->nd_else = $$->nd_body; + $$->nd_body = 0; + } } | stmt kUNLESS_MOD expr_value { $$ = NEW_UNLESS(cond($3), $1, 0); fixpos($$, $3); + if (nd_type($$->nd_cond) == NODE_NOT) { + $$->nd_cond = $$->nd_cond->nd_body; + $$->nd_body = $$->nd_else; + $$->nd_else = 0; + } } | stmt kWHILE_MOD expr_value { @@ -421,6 +431,10 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem else { $$ = NEW_WHILE(cond($3), $1, 1); } + if (nd_type($$->nd_cond) == NODE_NOT) { + $$->nd_cond = $$->nd_cond->nd_body; + nd_set_type($$, NODE_UNTIL); + } } | stmt kUNTIL_MOD expr_value { @@ -430,6 +444,10 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem else { $$ = NEW_UNTIL(cond($3), $1, 1); } + if (nd_type($$->nd_cond) == NODE_NOT) { + $$->nd_cond = $$->nd_cond->nd_body; + nd_set_type($$, NODE_WHILE); + } } | klBEGIN { @@ -1440,6 +1458,12 @@ primary : literal { $$ = NEW_IF(cond($2), $4, $5); fixpos($$, $2); + if (nd_type($$->nd_cond) == NODE_NOT) { + NODE *tmp = $$->nd_body; + $$->nd_cond = $$->nd_cond->nd_body; + $$->nd_body = $$->nd_else; + $$->nd_else = tmp; + } } | kUNLESS expr_value then compstmt @@ -1448,6 +1472,12 @@ primary : literal { $$ = NEW_UNLESS(cond($2), $4, $5); fixpos($$, $2); + if (nd_type($$->nd_cond) == NODE_NOT) { + NODE *tmp = $$->nd_body; + $$->nd_cond = $$->nd_cond->nd_body; + $$->nd_body = $$->nd_else; + $$->nd_else = tmp; + } } | kWHILE {COND_PUSH(1);} expr_value do {COND_POP();} compstmt @@ -1455,6 +1485,10 @@ primary : literal { $$ = NEW_WHILE(cond($3), $6, 1); fixpos($$, $3); + if (nd_type($$->nd_cond) == NODE_NOT) { + $$->nd_cond = $$->nd_cond->nd_body; + nd_set_type($$, NODE_UNTIL); + } } | kUNTIL {COND_PUSH(1);} expr_value do {COND_POP();} compstmt @@ -1462,6 +1496,10 @@ primary : literal { $$ = NEW_UNTIL(cond($3), $6, 1); fixpos($$, $3); + if (nd_type($$->nd_cond) == NODE_NOT) { + $$->nd_cond = $$->nd_cond->nd_body; + nd_set_type($$, NODE_WHILE); + } } | kCASE expr_value opt_terms case_body -- cgit