racc.patch

Dirkjan Bussink, 05/13/2013 05:37 AM

Download (4.71 KB)

View differences:

w/ext/racc/cparse/cparse.c
91 91
}
92 92

  
93 93
#define AREF(s, idx) \
94
    ((0 <= idx && idx < RARRAY_LEN(s)) ? RARRAY_PTR(s)[idx] : Qnil)
94
    ((0 <= idx && idx < RARRAY_LEN(s)) ? rb_ary_entry(s, idx) : Qnil)
95 95

  
96 96
/* -----------------------------------------------------------------------
97 97
                        Parser Stack Interfaces
......
105 105
{
106 106
    if (len < 0) return Qnil;  /* system error */
107 107
    if (len > RARRAY_LEN(stack)) len = RARRAY_LEN(stack);
108
    return rb_ary_new4(len, RARRAY_PTR(stack) + RARRAY_LEN(stack) - len);
108
    VALUE ret = rb_ary_new2(len);
109
    RB_GC_GUARD(ret);
110
    for(int i = 0; i < len; i++) {
111
        rb_ary_push(ret, rb_ary_entry(stack, RARRAY_LEN(stack) - len + i));
112
    }
113
    return ret;
109 114
}
110 115

  
111 116
static void
......
122 127
#define PUSH(s, i) rb_ary_store(s, RARRAY_LEN(s), i)
123 128
#define POP(s) rb_ary_pop(s)
124 129
#define LAST_I(s) \
125
    ((RARRAY_LEN(s) > 0) ? RARRAY_PTR(s)[RARRAY_LEN(s) - 1] : Qnil)
130
    ((RARRAY_LEN(s) > 0) ? rb_ary_entry(s, RARRAY_LEN(s) - 1) : Qnil)
126 131
#define GET_TAIL(s, len) get_stack_tail(s, len)
127 132
#define CUT_TAIL(s, len) cut_stack_tail(s, len)
128 133

  
......
334 339
    Check_Type(arg, T_ARRAY);
335 340
    if (!(13 <= RARRAY_LEN(arg) && RARRAY_LEN(arg) <= 14))
336 341
        rb_raise(RaccBug, "[Racc Bug] wrong arg.size %ld", RARRAY_LEN(arg));
337
    v->action_table   = assert_array  (RARRAY_PTR(arg)[ 0]);
338
    v->action_check   = assert_array  (RARRAY_PTR(arg)[ 1]);
339
    v->action_default = assert_array  (RARRAY_PTR(arg)[ 2]);
340
    v->action_pointer = assert_array  (RARRAY_PTR(arg)[ 3]);
341
    v->goto_table     = assert_array  (RARRAY_PTR(arg)[ 4]);
342
    v->goto_check     = assert_array  (RARRAY_PTR(arg)[ 5]);
343
    v->goto_default   = assert_array  (RARRAY_PTR(arg)[ 6]);
344
    v->goto_pointer   = assert_array  (RARRAY_PTR(arg)[ 7]);
345
    v->nt_base        = assert_integer(RARRAY_PTR(arg)[ 8]);
346
    v->reduce_table   = assert_array  (RARRAY_PTR(arg)[ 9]);
347
    v->token_table    = assert_hash   (RARRAY_PTR(arg)[10]);
348
    v->shift_n        = assert_integer(RARRAY_PTR(arg)[11]);
349
    v->reduce_n       = assert_integer(RARRAY_PTR(arg)[12]);
342
    v->action_table   = assert_array  (rb_ary_entry(arg,  0));
343
    v->action_check   = assert_array  (rb_ary_entry(arg,  1));
344
    v->action_default = assert_array  (rb_ary_entry(arg,  2));
345
    v->action_pointer = assert_array  (rb_ary_entry(arg,  3));
346
    v->goto_table     = assert_array  (rb_ary_entry(arg,  4));
347
    v->goto_check     = assert_array  (rb_ary_entry(arg,  5));
348
    v->goto_default   = assert_array  (rb_ary_entry(arg,  6));
349
    v->goto_pointer   = assert_array  (rb_ary_entry(arg,  7));
350
    v->nt_base        = assert_integer(rb_ary_entry(arg,  8));
351
    v->reduce_table   = assert_array  (rb_ary_entry(arg,  9));
352
    v->token_table    = assert_hash   (rb_ary_entry(arg, 10));
353
    v->shift_n        = assert_integer(rb_ary_entry(arg, 11));
354
    v->reduce_n       = assert_integer(rb_ary_entry(arg, 12));
350 355
    if (RARRAY_LEN(arg) > 13) {
351
        v->use_result_var = RTEST(RARRAY_PTR(arg)[13]);
356
        v->use_result_var = RTEST(rb_ary_entry(arg, 13));
352 357
    }
353 358
    else {
354 359
        v->use_result_var = TRUE;
......
564 569

  
565 570
  accept:
566 571
    if (v->debug) rb_funcall(v->parser, id_d_accept, 0);
567
    v->retval = RARRAY_PTR(v->vstack)[0];
572
    v->retval = rb_ary_entry(v->vstack, 0);
568 573
    v->fin = CP_FIN_ACCEPT;
569 574
    return;
570 575

  
......
693 698
    VALUE goto_state;
694 699

  
695 700
    Data_Get_Struct(data, struct cparse_params, v);
696
    reduce_len = RARRAY_PTR(v->reduce_table)[v->ruleno];
697
    reduce_to  = RARRAY_PTR(v->reduce_table)[v->ruleno+1];
698
    method_id  = RARRAY_PTR(v->reduce_table)[v->ruleno+2];
701
    reduce_len = rb_ary_entry(v->reduce_table, v->ruleno);
702
    reduce_to  = rb_ary_entry(v->reduce_table, v->ruleno+1);
703
    method_id  = rb_ary_entry(v->reduce_table, v->ruleno+2);
699 704
    len = NUM2LONG(reduce_len);
700 705
    mid = value_to_id(method_id);
701 706

  
......
710 715
    else {
711 716
        if (mid != id_noreduce) {
712 717
            tmp_v = GET_TAIL(v->vstack, len);
713
            tmp = RARRAY_PTR(tmp_v)[0];
718
            tmp = rb_ary_entry(tmp_v, 0);
714 719
        }
715 720
        else {
716
            tmp = RARRAY_PTR(v->vstack)[ RARRAY_LEN(v->vstack) - len ];
721
            tmp = rb_ary_entry(v->vstack, RARRAY_LEN(v->vstack) - len);
717 722
        }
718 723
        CUT_TAIL(v->vstack, len);
719 724
        if (v->debug) {