Project

General

Profile

Feature #15897 ยป its.patch

mame (Yusuke Endoh), 06/04/2019 05:07 AM

View differences:

parse.y
248 248
    int node_id;
249 249

  
250 250
    int max_numparam;
251
    ID it_id;
251 252

  
252 253
    unsigned int command_start:1;
253 254
    unsigned int eofp: 1;
......
424 425
static NODE *new_hash_pattern_tail(struct parser_params *p, NODE *kw_args, ID kw_rest_arg, const YYLTYPE *loc);
425 426

  
426 427
static NODE *new_kw_arg(struct parser_params *p, NODE *k, const YYLTYPE *loc);
427
static NODE *args_with_numbered(struct parser_params*,NODE*,int);
428
static NODE *args_with_numbered(struct parser_params*,NODE*,int,ID);
428 429

  
429 430
static VALUE negate_lit(struct parser_params*, VALUE);
430 431
static NODE *ret_args(struct parser_params*,NODE*);
......
723 724
}
724 725

  
725 726
static inline VALUE
726
args_with_numbered(struct parser_params *p, VALUE args, int max_numparam)
727
args_with_numbered(struct parser_params *p, VALUE args, int max_numparam, ID it_id)
727 728
{
728 729
    return args;
729 730
}
......
3380 3381
			$<num>$ = p->max_numparam;
3381 3382
			p->max_numparam = 0;
3382 3383
		    }
3384
		    {
3385
			$<id>$ = p->it_id;
3386
			p->it_id = 0;
3387
		    }
3383 3388
		  f_larglist
3384 3389
		    {
3385 3390
			CMDARG_PUSH(0);
......
3387 3392
		  lambda_body
3388 3393
		    {
3389 3394
			int max_numparam = p->max_numparam;
3395
			ID it_id = p->it_id;
3390 3396
			p->lex.lpar_beg = $<num>2;
3391 3397
			p->max_numparam = $<num>3;
3398
			p->it_id = $<id>4;
3392 3399
			CMDARG_POP();
3393
			$4 = args_with_numbered(p, $4, max_numparam);
3400
			$5 = args_with_numbered(p, $5, max_numparam, it_id);
3394 3401
		    /*%%%*/
3395 3402
                        {
3396
                            YYLTYPE loc = code_loc_gen(&@4, &@6);
3397
                            $$ = NEW_LAMBDA($4, $6, &loc);
3398
                            nd_set_line($$->nd_body, @6.end_pos.lineno);
3399
                            nd_set_line($$, @4.end_pos.lineno);
3403
                            YYLTYPE loc = code_loc_gen(&@5, &@7);
3404
                            $$ = NEW_LAMBDA($5, $7, &loc);
3405
                            nd_set_line($$->nd_body, @7.end_pos.lineno);
3406
                            nd_set_line($$, @5.end_pos.lineno);
3400 3407
                        }
3401 3408
		    /*% %*/
3402
		    /*% ripper: lambda!($4, $6) %*/
3409
		    /*% ripper: lambda!($5, $7) %*/
3403 3410
			dyna_pop(p, $<vars>1);
3404 3411
		    }
3405 3412
		;
......
3578 3585
			$<num>$ = p->max_numparam;
3579 3586
			p->max_numparam = 0;
3580 3587
		    }
3588
		    {
3589
			$<id>$ = p->it_id;
3590
			p->it_id = 0;
3591
		    }
3581 3592
		  opt_block_param compstmt
3582 3593
		    {
3583 3594
			int max_numparam = p->max_numparam;
3595
			ID it_id = p->it_id;
3584 3596
			p->max_numparam = $<num>2;
3585
			$3 = args_with_numbered(p, $3, max_numparam);
3597
			p->it_id = $<id>3;
3598
			$4 = args_with_numbered(p, $4, max_numparam, it_id);
3586 3599
		    /*%%%*/
3587
			$$ = NEW_ITER($3, $4, &@$);
3600
			$$ = NEW_ITER($4, $5, &@$);
3588 3601
		    /*% %*/
3589
		    /*% ripper: brace_block!(escape_Qundef($3), $4) %*/
3602
		    /*% ripper: brace_block!(escape_Qundef($4), $5) %*/
3590 3603
			dyna_pop(p, $<vars>1);
3591 3604
		    }
3592 3605
		;
......
3597 3610
			p->max_numparam = 0;
3598 3611
			CMDARG_PUSH(0);
3599 3612
		    }
3613
		    {
3614
			$<id>$ = p->it_id;
3615
			p->it_id = 0;
3616
		    }
3600 3617
		  opt_block_param bodystmt
3601 3618
		    {
3602 3619
			int max_numparam = p->max_numparam;
3620
			ID it_id = p->it_id;
3603 3621
			p->max_numparam = $<num>2;
3604
			$3 = args_with_numbered(p, $3, max_numparam);
3622
			p->it_id = $<id>3;
3623
			$4 = args_with_numbered(p, $4, max_numparam, it_id);
3605 3624
		    /*%%%*/
3606
			$$ = NEW_ITER($3, $4, &@$);
3625
			$$ = NEW_ITER($4, $5, &@$);
3607 3626
		    /*% %*/
3608
		    /*% ripper: do_block!(escape_Qundef($3), $4) %*/
3627
		    /*% ripper: do_block!(escape_Qundef($4), $5) %*/
3609 3628
			CMDARG_POP();
3610 3629
			dyna_pop(p, $<vars>1);
3611 3630
		    }
......
9748 9767
	}
9749 9768
# endif
9750 9769
	/* method call without arguments */
9770
	if (dyna_in_block(p) && id == rb_intern("it") && !(DVARS_TERMINAL_P(p->lvtbl->args) || DVARS_TERMINAL_P(p->lvtbl->args->prev))) {
9771
	    if (p->max_numparam < 0) {
9772
		compile_error(p, "ordinary parameter is defined");
9773
		return 0;
9774
	    }
9775
	    if (!p->it_id) {
9776
		p->it_id = internal_id(p);
9777
		vtable_add(p->lvtbl->args, p->it_id);
9778
	    }
9779
	    return NEW_DVAR(p->it_id, loc);
9780
	}
9751 9781
	return NEW_VCALL(id, loc);
9752 9782
      case ID_GLOBAL:
9753 9783
	return NEW_GVAR(id, loc);
......
11129 11159
}
11130 11160

  
11131 11161
static NODE *
11132
args_with_numbered(struct parser_params *p, NODE *args, int max_numparam)
11162
args_with_numbered(struct parser_params *p, NODE *args, int max_numparam, ID it_id)
11133 11163
{
11134 11164
    if (max_numparam > 0) {
11135 11165
	if (!args) args = new_args_tail(p, 0, 0, 0, 0);
11136 11166
	args->nd_ainfo->pre_args_num = max_numparam;
11137 11167
	args->nd_ainfo->rest_arg = excessed_comma;
11138 11168
    }
11169
    else if (it_id) {
11170
	if (!args) args = new_args_tail(p, 0, 0, 0, 0);
11171
	args->nd_ainfo->pre_args_num = 1;
11172
	args->nd_ainfo->rest_arg = 0;
11173
    }
11139 11174
    return args;
11140 11175
}
11141 11176