Project

General

Profile

Feature #15915 ยป local_variable_get-for-numparam.patch

mame (Yusuke Endoh), 08/23/2019 04:40 AM

View differences:

internal.h
1970 1970
PUREFUNC(int rb_is_local_sym(VALUE sym));
1971 1971
PUREFUNC(int rb_is_method_sym(VALUE sym));
1972 1972
PUREFUNC(int rb_is_junk_sym(VALUE sym));
1973
int rb_is_numparam_id(ID id);
1974
int rb_is_numparam_name(VALUE name);
1973 1975
ID rb_make_internal_id(void);
1974 1976
void rb_gc_free_dsymbol(VALUE);
1975 1977
ID rb_id_attrget(ID id);
proc.c
471 471
	}
472 472
    }
473 473
    else {
474
        int num = rb_is_numparam_name(name);
475
        if (num >= 0) {
476
	    *pname = INT2FIX(num);
477
	    return -1;
478
	}
474 479
	if (!rb_is_local_name(name)) {
475 480
	    rb_name_err_raise("wrong local variable name `%1$s' for %2$s",
476 481
			      bindval, name);
......
538 543

  
539 544
    GetBindingPtr(bindval, bind);
540 545

  
546
    if (lid == (ID)-1) {
547
	int numparam = FIX2INT(sym);
548
	env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
549
	if (!VM_ENV_FLAGS(env->ep, VM_FRAME_FLAG_CFRAME)) {
550
	    const rb_iseq_t *iseq = env->iseq;
551
	    if (numparam <= iseq->body->param.lead_num) {
552
                if (rb_is_junk_id(iseq->body->local_table[numparam - 1])) {
553
		    return env->env[numparam - 1];
554
		}
555
		else {
556
		    rb_name_err_raise("numbered parameter is not used in this block", bindval, sym);
557
		}
558
	    }
559
	}
560
	goto undefined;
561
    }
562

  
541 563
    env = VM_ENV_ENVVAL_PTR(vm_block_ep(&bind->block));
542 564
    if ((ptr = get_local_variable_ptr(&env, lid)) == NULL) {
543 565
	sym = ID2SYM(lid);
symbol.c
261 261
	    ++m;
262 262
	    type = ID_CLASS;
263 263
	}
264
        if (ISDIGIT(*m)) {
265
            if (!m[1] || (ISDIGIT(m[1]) && !m[2])) {
266
                return ID_NUMPARAM;
267
            }
268
        }
264 269
	goto id;
265 270

  
266 271
      case '<':
......
915 920
    return is_junk_id(id);
916 921
}
917 922

  
923
int
924
rb_is_numparam_id(ID id)
925
{
926
    return is_numparam_id(id);
927
}
928

  
918 929
int
919 930
rb_is_const_sym(VALUE sym)
920 931
{
......
1187 1198
    return rb_str_symname_type(name, IDSET_ATTRSET_FOR_SYNTAX) == -1;
1188 1199
}
1189 1200

  
1201
int
1202
rb_is_numparam_name(VALUE name)
1203
{
1204
    if (rb_str_symname_type(name, 0) == ID_NUMPARAM) {
1205
        const char *ptr = StringValuePtr(name);
1206
        return atoi(ptr+1);
1207
    }
1208
    return -1;
1209
}
1190 1210
#include "id_table.c"
symbol.h
40 40
#define is_const_id(id) (id_type(id)==ID_CONST)
41 41
#define is_class_id(id) (id_type(id)==ID_CLASS)
42 42
#define is_junk_id(id) (id_type(id)==ID_JUNK)
43
#define is_numparam_id(id) (id_type(id)==ID_NUMPARAM)
43 44

  
44 45
static inline int
45 46
id_type(ID id)
template/id.h.tmpl
24 24
    RUBY_ID_STATIC_SYM  = 0x01,
25 25
    RUBY_ID_LOCAL       = 0x00,
26 26
    RUBY_ID_INSTANCE    = (0x01<<1),
27
    RUBY_ID_NUMPARAM    = (0x02<<1),
27 28
    RUBY_ID_GLOBAL      = (0x03<<1),
28 29
    RUBY_ID_ATTRSET     = (0x04<<1),
29 30
    RUBY_ID_CONST       = (0x05<<1),
......
43 44
#define ID_ATTRSET     RUBY_ID_ATTRSET
44 45
#define ID_CONST       RUBY_ID_CONST
45 46
#define ID_CLASS       RUBY_ID_CLASS
47
#define ID_NUMPARAM    RUBY_ID_NUMPARAM
46 48
#define ID_JUNK        RUBY_ID_JUNK
47 49
#define ID_INTERNAL    RUBY_ID_INTERNAL
48 50