Project

General

Profile

Feature #15897 ยป mame_its_proposal.patch

Benoit_Tigeot (Benoit Tigeot), 07/02/2019 11:45 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;
......
421 422
static NODE *new_hash_pattern_tail(struct parser_params *p, NODE *kw_args, ID kw_rest_arg, const YYLTYPE *loc);
422 423

  
423 424
static NODE *new_kw_arg(struct parser_params *p, NODE *k, const YYLTYPE *loc);
424
static NODE *args_with_numbered(struct parser_params*,NODE*,int);
425
static NODE *args_with_numbered(struct parser_params*,NODE*,int,ID);
425 426

  
426 427
static VALUE negate_lit(struct parser_params*, VALUE);
427 428
static NODE *ret_args(struct parser_params*,NODE*);
......
720 721
}
721 722

  
722 723
static inline VALUE
723
args_with_numbered(struct parser_params *p, VALUE args, int max_numparam)
724
args_with_numbered(struct parser_params *p, VALUE args, int max_numparam, ID it_id)
724 725
{
725 726
    return args;
726 727
}
......
3405 3406
			$<num>$ = p->max_numparam;
3406 3407
			p->max_numparam = 0;
3407 3408
		    }
3409
		    {
3410
			$<id>$ = p->it_id;
3411
			p->it_id = 0;
3412
		    }
3408 3413
		  f_larglist
3409 3414
		    {
3410 3415
			CMDARG_PUSH(0);
......
3412 3417
		  lambda_body
3413 3418
		    {
3414 3419
			int max_numparam = p->max_numparam;
3420
			ID it_id = p->it_id;
3415 3421
			p->lex.lpar_beg = $<num>2;
3416 3422
			p->max_numparam = $<num>3;
3423
			p->it_id = $<id>4;
3417 3424
			CMDARG_POP();
3418
			$4 = args_with_numbered(p, $4, max_numparam);
3425
			$5 = args_with_numbered(p, $5, max_numparam, it_id);
3419 3426
		    /*%%%*/
3420 3427
                        {
3421
                            YYLTYPE loc = code_loc_gen(&@4, &@6);
3422
                            $$ = NEW_LAMBDA($4, $6, &loc);
3423
                            nd_set_line($$->nd_body, @6.end_pos.lineno);
3424
                            nd_set_line($$, @4.end_pos.lineno);
3428
                            YYLTYPE loc = code_loc_gen(&@5, &@7);
3429
                            $$ = NEW_LAMBDA($5, $7, &loc);
3430
                            nd_set_line($$->nd_body, @7.end_pos.lineno);
3431
                            nd_set_line($$, @5.end_pos.lineno);
3425 3432
                        }
3426 3433
		    /*% %*/
3427
		    /*% ripper: lambda!($4, $6) %*/
3434
		    /*% ripper: lambda!($5, $7) %*/
3428 3435
			dyna_pop(p, $<vars>1);
3429 3436
		    }
3430 3437
		;
......
3603 3610
			$<num>$ = p->max_numparam;
3604 3611
			p->max_numparam = 0;
3605 3612
		    }
3613
		    {
3614
			$<id>$ = p->it_id;
3615
			p->it_id = 0;
3616
		    }
3606 3617
		  opt_block_param compstmt
3607 3618
		    {
3608 3619
			int max_numparam = p->max_numparam;
3620
			ID it_id = p->it_id;
3609 3621
			p->max_numparam = $<num>2;
3610
			$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);
3611 3624
		    /*%%%*/
3612
			$$ = NEW_ITER($3, $4, &@$);
3625
			$$ = NEW_ITER($4, $5, &@$);
3613 3626
		    /*% %*/
3614
		    /*% ripper: brace_block!(escape_Qundef($3), $4) %*/
3627
		    /*% ripper: brace_block!(escape_Qundef($4), $5) %*/
3615 3628
			dyna_pop(p, $<vars>1);
3616 3629
		    }
3617 3630
		;
......
3622 3635
			p->max_numparam = 0;
3623 3636
			CMDARG_PUSH(0);
3624 3637
		    }
3638
		    {
3639
			$<id>$ = p->it_id;
3640
			p->it_id = 0;
3641
		    }
3625 3642
		  opt_block_param bodystmt
3626 3643
		    {
3627 3644
			int max_numparam = p->max_numparam;
3645
			ID it_id = p->it_id;
3628 3646
			p->max_numparam = $<num>2;
3629
			$3 = args_with_numbered(p, $3, max_numparam);
3647
			p->it_id = $<id>3;
3648
			$4 = args_with_numbered(p, $4, max_numparam, it_id);
3630 3649
		    /*%%%*/
3631
			$$ = NEW_ITER($3, $4, &@$);
3650
			$$ = NEW_ITER($4, $5, &@$);
3632 3651
		    /*% %*/
3633
		    /*% ripper: do_block!(escape_Qundef($3), $4) %*/
3652
		    /*% ripper: do_block!(escape_Qundef($4), $5) %*/
3634 3653
			CMDARG_POP();
3635 3654
			dyna_pop(p, $<vars>1);
3636 3655
		    }
......
9778 9797
	}
9779 9798
# endif
9780 9799
	/* method call without arguments */
9800
	if (dyna_in_block(p) && id == rb_intern("it") && !(DVARS_TERMINAL_P(p->lvtbl->args) || DVARS_TERMINAL_P(p->lvtbl->args->prev))) {
9801
	    if (p->max_numparam < 0) {
9802
		compile_error(p, "ordinary parameter is defined");
9803
		return 0;
9804
	    }
9805
	    if (!p->it_id) {
9806
		p->it_id = internal_id(p);
9807
		vtable_add(p->lvtbl->args, p->it_id);
9808
	    }
9809
	    return NEW_DVAR(p->it_id, loc);
9810
	}
9781 9811
	return NEW_VCALL(id, loc);
9782 9812
      case ID_GLOBAL:
9783 9813
	return NEW_GVAR(id, loc);
......
11168 11198
}
11169 11199

  
11170 11200
static NODE *
11171
args_with_numbered(struct parser_params *p, NODE *args, int max_numparam)
11201
args_with_numbered(struct parser_params *p, NODE *args, int max_numparam, ID it_id)
11172 11202
{
11173 11203
    if (max_numparam > 0) {
11174 11204
	if (!args) args = new_args_tail(p, 0, 0, 0, 0);
11175 11205
	args->nd_ainfo->pre_args_num = max_numparam;
11176 11206
	args->nd_ainfo->rest_arg = NODE_SPECIAL_EXCESSIVE_COMMA;
11177 11207
    }
11208
    else if (it_id) {
11209
	if (!args) args = new_args_tail(p, 0, 0, 0, 0);
11210
	args->nd_ainfo->pre_args_num = 1;
11211
	args->nd_ainfo->rest_arg = 0;
11212
    }
11178 11213
    return args;
11179 11214
}
11180 11215

  
11181
-