Skip to content

Instantly share code, notes, and snippets.

@shugo
Created February 25, 2012 11:18
Show Gist options
  • Save shugo/1907919 to your computer and use it in GitHub Desktop.
Save shugo/1907919 to your computer and use it in GitHub Desktop.
@n0kada このパッチあてるとbootstraptest/test_eval.rbの[ruby-core:25714]のテストから返って来ないのですが、何でかわかります?
diff --git a/parse.y b/parse.y
index 82eb3d4..c66f229 100644
--- a/parse.y
+++ b/parse.y
@@ -698,7 +698,7 @@ static void token_info_pop(struct parser_params*, const char *token);
%type <node> command_asgn mrhs superclass block_call block_command
%type <node> f_block_optarg f_block_opt
%type <node> f_arglist f_args f_arg f_arg_item f_optarg f_marg f_marg_list f_margs
-%type <node> assoc_list assocs assoc undef_list backref string_dvar for_var
+%type <node> assoc_list assocs assoc undef_list backref string_dvar
%type <node> block_param opt_block_param block_param_def f_opt
%type <node> f_kwarg f_kw f_block_kwarg f_block_kw
%type <node> bv_decls opt_bv_decl bvar
@@ -2885,10 +2885,32 @@ primary : literal
$$ = dispatch2(case, Qnil, $3);
%*/
}
- | k_for for_var keyword_in
- {COND_PUSH(1);}
+ | k_for
+ {
+ $<vars>1 = dyna_push();
+ /*%%%*/
+ $<num>$ = ruby_sourceline;
+ /*%
+ %*/
+ }
+ block_param keyword_in
+ {
+ COND_PUSH(1);
+ $<node>$ = NEW_NODE(NODE_MEMO, lvtbl->args, lvtbl->vars,
+ lvtbl->used);
+ lvtbl->args = lvtbl->args->prev;
+ lvtbl->vars = lvtbl->vars->prev;
+ if (lvtbl->used) {
+ lvtbl->used = lvtbl->used->prev;
+ }
+ }
expr_value do
- {COND_POP();}
+ {
+ lvtbl->args = (struct vtable *) $<node>5->u1.value;
+ lvtbl->vars = (struct vtable *) $<node>5->u2.value;
+ lvtbl->used = (struct vtable *) $<node>5->u3.value;
+ COND_POP();
+ }
compstmt
k_end
{
@@ -2902,54 +2924,13 @@ primary : literal
* #=>
* e.each{|x| a, = x}
*/
- ID id = internal_id();
- ID *tbl = ALLOC_N(ID, 2);
- NODE *m = NEW_ARGS_AUX(0, 0);
- NODE *args, *scope;
-
- if (nd_type($2) == NODE_MASGN) {
- /* if args.length == 1 && args[0].kind_of?(Array)
- * args = args[0]
- * end
- */
- NODE *one = NEW_LIST(NEW_LIT(INT2FIX(1)));
- NODE *zero = NEW_LIST(NEW_LIT(INT2FIX(0)));
- m->nd_next = block_append(
- NEW_IF(
- NEW_NODE(NODE_AND,
- NEW_CALL(NEW_CALL(NEW_DVAR(id), rb_intern("length"), 0),
- rb_intern("=="), one),
- NEW_CALL(NEW_CALL(NEW_DVAR(id), rb_intern("[]"), zero),
- rb_intern("kind_of?"), NEW_LIST(NEW_LIT(rb_cArray))),
- 0),
- NEW_DASGN_CURR(id,
- NEW_CALL(NEW_DVAR(id), rb_intern("[]"), zero)),
- 0),
- node_assign($2, NEW_DVAR(id)));
-
- args = new_args(m, 0, id, 0, 0, 0, 0);
- }
- else {
- if (nd_type($2) == NODE_LASGN ||
- nd_type($2) == NODE_DASGN ||
- nd_type($2) == NODE_DASGN_CURR) {
- $2->nd_value = NEW_DVAR(id);
- m->nd_plen = 1;
- m->nd_next = $2;
- args = new_args(m, 0, 0, 0, 0, 0, 0);
- }
- else {
- m->nd_next = node_assign(NEW_MASGN(NEW_LIST($2), 0), NEW_DVAR(id));
- args = new_args(m, 0, id, 0, 0, 0, 0);
- }
- }
- scope = NEW_NODE(NODE_SCOPE, tbl, $8, args);
- tbl[0] = 1; tbl[1] = id;
- $$ = NEW_FOR(0, $5, scope);
- fixpos($$, $2);
+ $$ = NEW_ITER($3, $9);
+ $$->nd_iter = NEW_CALL($6, rb_intern("each"), 0);
+ nd_set_line($$, $<num>2);
/*%
- $$ = dispatch3(for, $2, $5, $8);
+ $$ = dispatch3(for, $3, $6, $9);
%*/
+ dyna_pop($<vars>1);
}
| k_class cpath superclass
{
@@ -3223,10 +3204,6 @@ opt_else : none
}
;
-for_var : lhs
- | mlhs
- ;
-
f_marg : f_norm_arg
{
$$ = assignable($1, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment