* internal.h: define struct MEMO.

* enum.c: use MEMO.
* enumerator.c: ditto.
* load.c: ditto.
* node.h: return (struct MEMO *) pointer.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49928 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2015-03-11 00:20:45 +00:00
Родитель 9f21759c53
Коммит 97e21517a3
6 изменённых файлов: 188 добавлений и 159 удалений

Просмотреть файл

@ -1,3 +1,15 @@
Wed Mar 11 09:15:21 2015 Koichi Sasada <ko1@atdot.net>
* internal.h: define struct MEMO.
* enum.c: use MEMO.
* enumerator.c: ditto.
* load.c: ditto.
* node.h: return (struct MEMO *) pointer.
Wed Mar 11 06:26:21 2015 Koichi Sasada <ko1@atdot.net> Wed Mar 11 06:26:21 2015 Koichi Sasada <ko1@atdot.net>
* vm_insnhelper.h (THROW_DATA_STATE): return int, not VALUE. * vm_insnhelper.h (THROW_DATA_STATE): return int, not VALUE.

304
enum.c
Просмотреть файл

@ -43,11 +43,11 @@ rb_enum_values_pack(int argc, const VALUE *argv)
static VALUE static VALUE
grep_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args)) grep_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args))
{ {
NODE *memo = RNODE(args); struct MEMO *memo = MEMO_CAST(args);
ENUM_WANT_SVALUE(); ENUM_WANT_SVALUE();
if (RTEST(rb_funcall(memo->u1.value, id_eqq, 1, i))) { if (RTEST(rb_funcall(memo->v1, id_eqq, 1, i))) {
rb_ary_push(memo->u2.value, i); rb_ary_push(memo->v2, i);
} }
return Qnil; return Qnil;
} }
@ -55,11 +55,11 @@ grep_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args))
static VALUE static VALUE
grep_iter_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args)) grep_iter_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args))
{ {
NODE *memo = RNODE(args); struct MEMO *memo = MEMO_CAST(args);
ENUM_WANT_SVALUE(); ENUM_WANT_SVALUE();
if (RTEST(rb_funcall(memo->u1.value, id_eqq, 1, i))) { if (RTEST(rb_funcall(memo->v1, id_eqq, 1, i))) {
rb_ary_push(memo->u2.value, rb_yield(i)); rb_ary_push(memo->v2, rb_yield(i));
} }
return Qnil; return Qnil;
} }
@ -86,7 +86,7 @@ static VALUE
enum_grep(VALUE obj, VALUE pat) enum_grep(VALUE obj, VALUE pat)
{ {
VALUE ary = rb_ary_new(); VALUE ary = rb_ary_new();
NODE *memo = NEW_MEMO(pat, ary, 0); struct MEMO *memo = NEW_MEMO(pat, ary, 0);
rb_block_call(obj, id_each, 0, 0, rb_block_given_p() ? grep_iter_i : grep_i, (VALUE)memo); rb_block_call(obj, id_each, 0, 0, rb_block_given_p() ? grep_iter_i : grep_i, (VALUE)memo);
@ -96,11 +96,11 @@ enum_grep(VALUE obj, VALUE pat)
static VALUE static VALUE
count_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memop)) count_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memop))
{ {
NODE *memo = RNODE(memop); struct MEMO *memo = MEMO_CAST(memop);
ENUM_WANT_SVALUE(); ENUM_WANT_SVALUE();
if (rb_equal(i, memo->u1.value)) { if (rb_equal(i, memo->v1)) {
memo->u3.cnt++; memo->u3.cnt++;
} }
return Qnil; return Qnil;
@ -109,7 +109,7 @@ count_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memop))
static VALUE static VALUE
count_iter_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memop)) count_iter_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memop))
{ {
NODE *memo = RNODE(memop); struct MEMO *memo = MEMO_CAST(memop);
if (RTEST(enum_yield(argc, argv))) { if (RTEST(enum_yield(argc, argv))) {
memo->u3.cnt++; memo->u3.cnt++;
@ -120,7 +120,7 @@ count_iter_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memop))
static VALUE static VALUE
count_all_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memop)) count_all_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memop))
{ {
NODE *memo = RNODE(memop); struct MEMO *memo = MEMO_CAST(memop);
memo->u3.cnt++; memo->u3.cnt++;
return Qnil; return Qnil;
@ -148,7 +148,7 @@ static VALUE
enum_count(int argc, VALUE *argv, VALUE obj) enum_count(int argc, VALUE *argv, VALUE obj)
{ {
VALUE item = Qnil; VALUE item = Qnil;
NODE *memo; struct MEMO *memo;
rb_block_call_func *func; rb_block_call_func *func;
if (argc == 0) { if (argc == 0) {
@ -178,8 +178,8 @@ find_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memop))
ENUM_WANT_SVALUE(); ENUM_WANT_SVALUE();
if (RTEST(rb_yield(i))) { if (RTEST(rb_yield(i))) {
NODE *memo = RNODE(memop); struct MEMO *memo = MEMO_CAST(memop);
memo->u1.value = i; memo->v1 = i;
memo->u3.cnt = 1; memo->u3.cnt = 1;
rb_iter_break(); rb_iter_break();
} }
@ -208,7 +208,7 @@ find_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memop))
static VALUE static VALUE
enum_find(int argc, VALUE *argv, VALUE obj) enum_find(int argc, VALUE *argv, VALUE obj)
{ {
NODE *memo; struct MEMO *memo;
VALUE if_none; VALUE if_none;
rb_scan_args(argc, argv, "01", &if_none); rb_scan_args(argc, argv, "01", &if_none);
@ -216,7 +216,7 @@ enum_find(int argc, VALUE *argv, VALUE obj)
memo = NEW_MEMO(Qundef, 0, 0); memo = NEW_MEMO(Qundef, 0, 0);
rb_block_call(obj, id_each, 0, 0, find_i, (VALUE)memo); rb_block_call(obj, id_each, 0, 0, find_i, (VALUE)memo);
if (memo->u3.cnt) { if (memo->u3.cnt) {
return memo->u1.value; return memo->v1;
} }
if (!NIL_P(if_none)) { if (!NIL_P(if_none)) {
return rb_funcallv(if_none, id_call, 0, 0); return rb_funcallv(if_none, id_call, 0, 0);
@ -227,12 +227,12 @@ enum_find(int argc, VALUE *argv, VALUE obj)
static VALUE static VALUE
find_index_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memop)) find_index_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memop))
{ {
NODE *memo = RNODE(memop); struct MEMO *memo = MEMO_CAST(memop);
ENUM_WANT_SVALUE(); ENUM_WANT_SVALUE();
if (rb_equal(i, memo->u2.value)) { if (rb_equal(i, memo->v2)) {
memo->u1.value = UINT2NUM(memo->u3.cnt); memo->v1 = UINT2NUM(memo->u3.cnt);
rb_iter_break(); rb_iter_break();
} }
memo->u3.cnt++; memo->u3.cnt++;
@ -242,10 +242,10 @@ find_index_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memop))
static VALUE static VALUE
find_index_iter_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memop)) find_index_iter_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memop))
{ {
NODE *memo = RNODE(memop); struct MEMO *memo = MEMO_CAST(memop);
if (RTEST(enum_yield(argc, argv))) { if (RTEST(enum_yield(argc, argv))) {
memo->u1.value = UINT2NUM(memo->u3.cnt); memo->v1 = UINT2NUM(memo->u3.cnt);
rb_iter_break(); rb_iter_break();
} }
memo->u3.cnt++; memo->u3.cnt++;
@ -274,7 +274,7 @@ find_index_iter_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memop))
static VALUE static VALUE
enum_find_index(int argc, VALUE *argv, VALUE obj) enum_find_index(int argc, VALUE *argv, VALUE obj)
{ {
NODE *memo; /* [return value, current index, ] */ struct MEMO *memo; /* [return value, current index, ] */
VALUE condition_value = Qnil; VALUE condition_value = Qnil;
rb_block_call_func *func; rb_block_call_func *func;
@ -292,7 +292,7 @@ enum_find_index(int argc, VALUE *argv, VALUE obj)
memo = NEW_MEMO(Qnil, condition_value, 0); memo = NEW_MEMO(Qnil, condition_value, 0);
rb_block_call(obj, id_each, 0, 0, func, (VALUE)memo); rb_block_call(obj, id_each, 0, 0, func, (VALUE)memo);
return memo->u1.value; return memo->v1;
} }
static VALUE static VALUE
@ -566,15 +566,15 @@ enum_to_h(int argc, VALUE *argv, VALUE obj)
static VALUE static VALUE
inject_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, p)) inject_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, p))
{ {
NODE *memo = RNODE(p); struct MEMO *memo = MEMO_CAST(p);
ENUM_WANT_SVALUE(); ENUM_WANT_SVALUE();
if (memo->u1.value == Qundef) { if (memo->v1 == Qundef) {
memo->u1.value = i; memo->v1 = i;
} }
else { else {
memo->u1.value = rb_yield_values(2, memo->u1.value, i); memo->v1 = rb_yield_values(2, memo->v1, i);
} }
return Qnil; return Qnil;
} }
@ -582,23 +582,23 @@ inject_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, p))
static VALUE static VALUE
inject_op_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, p)) inject_op_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, p))
{ {
NODE *memo = RNODE(p); struct MEMO *memo = MEMO_CAST(p);
VALUE name; VALUE name;
ENUM_WANT_SVALUE(); ENUM_WANT_SVALUE();
if (memo->u1.value == Qundef) { if (memo->v1 == Qundef) {
memo->u1.value = i; memo->v1 = i;
} }
else if (SYMBOL_P(name = memo->u3.value)) { else if (SYMBOL_P(name = memo->u3.value)) {
const ID mid = SYM2ID(name); const ID mid = SYM2ID(name);
memo->u1.value = rb_funcall(memo->u1.value, mid, 1, i); memo->v1 = rb_funcall(memo->v1, mid, 1, i);
} }
else { else {
VALUE args[2]; VALUE args[2];
args[0] = name; args[0] = name;
args[1] = i; args[1] = i;
memo->u1.value = rb_f_send(numberof(args), args, memo->u1.value); memo->v1 = rb_f_send(numberof(args), args, memo->v1);
} }
return Qnil; return Qnil;
} }
@ -649,7 +649,7 @@ inject_op_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, p))
static VALUE static VALUE
enum_inject(int argc, VALUE *argv, VALUE obj) enum_inject(int argc, VALUE *argv, VALUE obj)
{ {
NODE *memo; struct MEMO *memo;
VALUE init, op; VALUE init, op;
rb_block_call_func *iter = inject_i; rb_block_call_func *iter = inject_i;
ID id; ID id;
@ -678,22 +678,22 @@ enum_inject(int argc, VALUE *argv, VALUE obj)
} }
memo = NEW_MEMO(init, Qnil, op); memo = NEW_MEMO(init, Qnil, op);
rb_block_call(obj, id_each, 0, 0, iter, (VALUE)memo); rb_block_call(obj, id_each, 0, 0, iter, (VALUE)memo);
if (memo->u1.value == Qundef) return Qnil; if (memo->v1 == Qundef) return Qnil;
return memo->u1.value; return memo->v1;
} }
static VALUE static VALUE
partition_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, arys)) partition_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, arys))
{ {
NODE *memo = RNODE(arys); struct MEMO *memo = MEMO_CAST(arys);
VALUE ary; VALUE ary;
ENUM_WANT_SVALUE(); ENUM_WANT_SVALUE();
if (RTEST(rb_yield(i))) { if (RTEST(rb_yield(i))) {
ary = memo->u1.value; ary = memo->v1;
} }
else { else {
ary = memo->u2.value; ary = memo->v2;
} }
rb_ary_push(ary, i); rb_ary_push(ary, i);
return Qnil; return Qnil;
@ -717,14 +717,14 @@ partition_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, arys))
static VALUE static VALUE
enum_partition(VALUE obj) enum_partition(VALUE obj)
{ {
NODE *memo; struct MEMO *memo;
RETURN_SIZED_ENUMERATOR(obj, 0, 0, enum_size); RETURN_SIZED_ENUMERATOR(obj, 0, 0, enum_size);
memo = NEW_MEMO(rb_ary_new(), rb_ary_new(), 0); memo = NEW_MEMO(rb_ary_new(), rb_ary_new(), 0);
rb_block_call(obj, id_each, 0, 0, partition_i, (VALUE)memo); rb_block_call(obj, id_each, 0, 0, partition_i, (VALUE)memo);
return rb_assoc_new(memo->u1.value, memo->u2.value); return rb_assoc_new(memo->v1, memo->v2);
} }
static VALUE static VALUE
@ -779,10 +779,10 @@ enum_group_by(VALUE obj)
static VALUE static VALUE
first_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, params)) first_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, params))
{ {
NODE *memo = RNODE(params); struct MEMO *memo = MEMO_CAST(params);
ENUM_WANT_SVALUE(); ENUM_WANT_SVALUE();
memo->u1.value = i; memo->v1 = i;
rb_iter_break(); rb_iter_break();
UNREACHABLE; UNREACHABLE;
@ -809,7 +809,7 @@ static VALUE enum_take(VALUE obj, VALUE n);
static VALUE static VALUE
enum_first(int argc, VALUE *argv, VALUE obj) enum_first(int argc, VALUE *argv, VALUE obj)
{ {
NODE *memo; struct MEMO *memo;
rb_check_arity(argc, 0, 1); rb_check_arity(argc, 0, 1);
if (argc > 0) { if (argc > 0) {
return enum_take(obj, argv[0]); return enum_take(obj, argv[0]);
@ -817,7 +817,7 @@ enum_first(int argc, VALUE *argv, VALUE obj)
else { else {
memo = NEW_MEMO(Qnil, 0, 0); memo = NEW_MEMO(Qnil, 0, 0);
rb_block_call(obj, id_each, 0, 0, first_i, (VALUE)memo); rb_block_call(obj, id_each, 0, 0, first_i, (VALUE)memo);
return memo->u1.value; return memo->v1;
} }
} }
@ -855,7 +855,7 @@ struct sort_by_data {
static VALUE static VALUE
sort_by_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, _data)) sort_by_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, _data))
{ {
struct sort_by_data *data = (struct sort_by_data *)&RNODE(_data)->u1; struct sort_by_data *data = (struct sort_by_data *)&MEMO_CAST(_data)->v1;
VALUE ary = data->ary; VALUE ary = data->ary;
VALUE v; VALUE v;
@ -972,7 +972,7 @@ static VALUE
enum_sort_by(VALUE obj) enum_sort_by(VALUE obj)
{ {
VALUE ary, buf; VALUE ary, buf;
NODE *memo; struct MEMO *memo;
long i; long i;
struct sort_by_data *data; struct sort_by_data *data;
@ -989,7 +989,7 @@ enum_sort_by(VALUE obj)
rb_ary_store(buf, SORT_BY_BUFSIZE*2-1, Qnil); rb_ary_store(buf, SORT_BY_BUFSIZE*2-1, Qnil);
memo = NEW_MEMO(0, 0, 0); memo = NEW_MEMO(0, 0, 0);
OBJ_INFECT(memo, obj); OBJ_INFECT(memo, obj);
data = (struct sort_by_data *)&memo->u1; data = (struct sort_by_data *)&memo->v1;
data->ary = ary; data->ary = ary;
data->buf = buf; data->buf = buf;
data->n = 0; data->n = 0;
@ -1021,27 +1021,27 @@ enum_sort_by(VALUE obj)
#define ENUMFUNC(name) rb_block_given_p() ? name##_iter_i : name##_i #define ENUMFUNC(name) rb_block_given_p() ? name##_iter_i : name##_i
#define DEFINE_ENUMFUNCS(name) \ #define DEFINE_ENUMFUNCS(name) \
static VALUE enum_##name##_func(VALUE result, NODE *memo); \ static VALUE enum_##name##_func(VALUE result, struct MEMO *memo); \
\ \
static VALUE \ static VALUE \
name##_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memo)) \ name##_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memo)) \
{ \ { \
return enum_##name##_func(rb_enum_values_pack(argc, argv), RNODE(memo)); \ return enum_##name##_func(rb_enum_values_pack(argc, argv), MEMO_CAST(memo)); \
} \ } \
\ \
static VALUE \ static VALUE \
name##_iter_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memo)) \ name##_iter_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memo)) \
{ \ { \
return enum_##name##_func(enum_yield(argc, argv), RNODE(memo)); \ return enum_##name##_func(enum_yield(argc, argv), MEMO_CAST(memo)); \
} \ } \
\ \
static VALUE \ static VALUE \
enum_##name##_func(VALUE result, NODE *memo) enum_##name##_func(VALUE result, struct MEMO *memo)
DEFINE_ENUMFUNCS(all) DEFINE_ENUMFUNCS(all)
{ {
if (!RTEST(result)) { if (!RTEST(result)) {
memo->u1.value = Qfalse; memo->v1 = Qfalse;
rb_iter_break(); rb_iter_break();
} }
return Qnil; return Qnil;
@ -1067,15 +1067,15 @@ DEFINE_ENUMFUNCS(all)
static VALUE static VALUE
enum_all(VALUE obj) enum_all(VALUE obj)
{ {
NODE *memo = NEW_MEMO(Qtrue, 0, 0); struct MEMO *memo = NEW_MEMO(Qtrue, 0, 0);
rb_block_call(obj, id_each, 0, 0, ENUMFUNC(all), (VALUE)memo); rb_block_call(obj, id_each, 0, 0, ENUMFUNC(all), (VALUE)memo);
return memo->u1.value; return memo->v1;
} }
DEFINE_ENUMFUNCS(any) DEFINE_ENUMFUNCS(any)
{ {
if (RTEST(result)) { if (RTEST(result)) {
memo->u1.value = Qtrue; memo->v1 = Qtrue;
rb_iter_break(); rb_iter_break();
} }
return Qnil; return Qnil;
@ -1101,19 +1101,19 @@ DEFINE_ENUMFUNCS(any)
static VALUE static VALUE
enum_any(VALUE obj) enum_any(VALUE obj)
{ {
NODE *memo = NEW_MEMO(Qfalse, 0, 0); struct MEMO *memo = NEW_MEMO(Qfalse, 0, 0);
rb_block_call(obj, id_each, 0, 0, ENUMFUNC(any), (VALUE)memo); rb_block_call(obj, id_each, 0, 0, ENUMFUNC(any), (VALUE)memo);
return memo->u1.value; return memo->v1;
} }
DEFINE_ENUMFUNCS(one) DEFINE_ENUMFUNCS(one)
{ {
if (RTEST(result)) { if (RTEST(result)) {
if (memo->u1.value == Qundef) { if (memo->v1 == Qundef) {
memo->u1.value = Qtrue; memo->v1 = Qtrue;
} }
else if (memo->u1.value == Qtrue) { else if (memo->v1 == Qtrue) {
memo->u1.value = Qfalse; memo->v1 = Qfalse;
rb_iter_break(); rb_iter_break();
} }
} }
@ -1344,11 +1344,11 @@ nmin_run(VALUE obj, VALUE num, int by, int rev)
static VALUE static VALUE
enum_one(VALUE obj) enum_one(VALUE obj)
{ {
NODE *memo = NEW_MEMO(Qundef, 0, 0); struct MEMO *memo = NEW_MEMO(Qundef, 0, 0);
VALUE result; VALUE result;
rb_block_call(obj, id_each, 0, 0, ENUMFUNC(one), (VALUE)memo); rb_block_call(obj, id_each, 0, 0, ENUMFUNC(one), (VALUE)memo);
result = memo->u1.value; result = memo->v1;
if (result == Qundef) return Qfalse; if (result == Qundef) return Qfalse;
return result; return result;
} }
@ -1356,7 +1356,7 @@ enum_one(VALUE obj)
DEFINE_ENUMFUNCS(none) DEFINE_ENUMFUNCS(none)
{ {
if (RTEST(result)) { if (RTEST(result)) {
memo->u1.value = Qfalse; memo->v1 = Qfalse;
rb_iter_break(); rb_iter_break();
} }
return Qnil; return Qnil;
@ -1380,26 +1380,26 @@ DEFINE_ENUMFUNCS(none)
static VALUE static VALUE
enum_none(VALUE obj) enum_none(VALUE obj)
{ {
NODE *memo = NEW_MEMO(Qtrue, 0, 0); struct MEMO *memo = NEW_MEMO(Qtrue, 0, 0);
rb_block_call(obj, id_each, 0, 0, ENUMFUNC(none), (VALUE)memo); rb_block_call(obj, id_each, 0, 0, ENUMFUNC(none), (VALUE)memo);
return memo->u1.value; return memo->v1;
} }
static VALUE static VALUE
min_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args)) min_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args))
{ {
VALUE cmp; VALUE cmp;
NODE *memo = RNODE(args); struct MEMO *memo = MEMO_CAST(args);
ENUM_WANT_SVALUE(); ENUM_WANT_SVALUE();
if (memo->u1.value == Qundef) { if (memo->v1 == Qundef) {
memo->u1.value = i; memo->v1 = i;
} }
else { else {
cmp = rb_funcall(i, id_cmp, 1, memo->u1.value); cmp = rb_funcall(i, id_cmp, 1, memo->v1);
if (rb_cmpint(cmp, i, memo->u1.value) < 0) { if (rb_cmpint(cmp, i, memo->v1) < 0) {
memo->u1.value = i; memo->v1 = i;
} }
} }
return Qnil; return Qnil;
@ -1409,17 +1409,17 @@ static VALUE
min_ii(RB_BLOCK_CALL_FUNC_ARGLIST(i, args)) min_ii(RB_BLOCK_CALL_FUNC_ARGLIST(i, args))
{ {
VALUE cmp; VALUE cmp;
NODE *memo = RNODE(args); struct MEMO *memo = MEMO_CAST(args);
ENUM_WANT_SVALUE(); ENUM_WANT_SVALUE();
if (memo->u1.value == Qundef) { if (memo->v1 == Qundef) {
memo->u1.value = i; memo->v1 = i;
} }
else { else {
cmp = rb_yield_values(2, i, memo->u1.value); cmp = rb_yield_values(2, i, memo->v1);
if (rb_cmpint(cmp, i, memo->u1.value) < 0) { if (rb_cmpint(cmp, i, memo->v1) < 0) {
memo->u1.value = i; memo->v1 = i;
} }
} }
return Qnil; return Qnil;
@ -1452,7 +1452,7 @@ min_ii(RB_BLOCK_CALL_FUNC_ARGLIST(i, args))
static VALUE static VALUE
enum_min(int argc, VALUE *argv, VALUE obj) enum_min(int argc, VALUE *argv, VALUE obj)
{ {
NODE *memo = NEW_MEMO(Qundef, 0, 0); struct MEMO *memo = NEW_MEMO(Qundef, 0, 0);
VALUE result; VALUE result;
VALUE num; VALUE num;
@ -1467,7 +1467,7 @@ enum_min(int argc, VALUE *argv, VALUE obj)
else { else {
rb_block_call(obj, id_each, 0, 0, min_i, (VALUE)memo); rb_block_call(obj, id_each, 0, 0, min_i, (VALUE)memo);
} }
result = memo->u1.value; result = memo->v1;
if (result == Qundef) return Qnil; if (result == Qundef) return Qnil;
return result; return result;
} }
@ -1475,18 +1475,18 @@ enum_min(int argc, VALUE *argv, VALUE obj)
static VALUE static VALUE
max_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args)) max_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args))
{ {
NODE *memo = RNODE(args); struct MEMO *memo = MEMO_CAST(args);
VALUE cmp; VALUE cmp;
ENUM_WANT_SVALUE(); ENUM_WANT_SVALUE();
if (memo->u1.value == Qundef) { if (memo->v1 == Qundef) {
memo->u1.value = i; memo->v1 = i;
} }
else { else {
cmp = rb_funcall(i, id_cmp, 1, memo->u1.value); cmp = rb_funcall(i, id_cmp, 1, memo->v1);
if (rb_cmpint(cmp, i, memo->u1.value) > 0) { if (rb_cmpint(cmp, i, memo->v1) > 0) {
memo->u1.value = i; memo->v1 = i;
} }
} }
return Qnil; return Qnil;
@ -1495,18 +1495,18 @@ max_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args))
static VALUE static VALUE
max_ii(RB_BLOCK_CALL_FUNC_ARGLIST(i, args)) max_ii(RB_BLOCK_CALL_FUNC_ARGLIST(i, args))
{ {
NODE *memo = RNODE(args); struct MEMO *memo = MEMO_CAST(args);
VALUE cmp; VALUE cmp;
ENUM_WANT_SVALUE(); ENUM_WANT_SVALUE();
if (memo->u1.value == Qundef) { if (memo->v1 == Qundef) {
memo->u1.value = i; memo->v1 = i;
} }
else { else {
cmp = rb_yield_values(2, i, memo->u1.value); cmp = rb_yield_values(2, i, memo->v1);
if (rb_cmpint(cmp, i, memo->u1.value) > 0) { if (rb_cmpint(cmp, i, memo->v1) > 0) {
memo->u1.value = i; memo->v1 = i;
} }
} }
return Qnil; return Qnil;
@ -1538,7 +1538,7 @@ max_ii(RB_BLOCK_CALL_FUNC_ARGLIST(i, args))
static VALUE static VALUE
enum_max(int argc, VALUE *argv, VALUE obj) enum_max(int argc, VALUE *argv, VALUE obj)
{ {
NODE *memo = NEW_MEMO(Qundef, 0, 0); struct MEMO *memo = NEW_MEMO(Qundef, 0, 0);
VALUE result; VALUE result;
VALUE num; VALUE num;
@ -1553,7 +1553,7 @@ enum_max(int argc, VALUE *argv, VALUE obj)
else { else {
rb_block_call(obj, id_each, 0, 0, max_i, (VALUE)memo); rb_block_call(obj, id_each, 0, 0, max_i, (VALUE)memo);
} }
result = memo->u1.value; result = memo->v1;
if (result == Qundef) return Qnil; if (result == Qundef) return Qnil;
return result; return result;
} }
@ -1590,7 +1590,7 @@ minmax_i_update(VALUE i, VALUE j, struct minmax_t *memo)
static VALUE static VALUE
minmax_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, _memo)) minmax_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, _memo))
{ {
struct minmax_t *memo = (struct minmax_t *)&RNODE(_memo)->u1.value; struct minmax_t *memo = (struct minmax_t *)&MEMO_CAST(_memo)->v1;
int n; int n;
VALUE j; VALUE j;
@ -1642,7 +1642,7 @@ minmax_ii_update(VALUE i, VALUE j, struct minmax_t *memo)
static VALUE static VALUE
minmax_ii(RB_BLOCK_CALL_FUNC_ARGLIST(i, _memo)) minmax_ii(RB_BLOCK_CALL_FUNC_ARGLIST(i, _memo))
{ {
struct minmax_t *memo = (struct minmax_t *)&RNODE(_memo)->u1.value; struct minmax_t *memo = (struct minmax_t *)&MEMO_CAST(_memo)->v1;
int n; int n;
VALUE j; VALUE j;
@ -1688,8 +1688,8 @@ minmax_ii(RB_BLOCK_CALL_FUNC_ARGLIST(i, _memo))
static VALUE static VALUE
enum_minmax(VALUE obj) enum_minmax(VALUE obj)
{ {
NODE *memo = NEW_MEMO(Qundef, Qundef, Qundef); struct MEMO *memo = NEW_MEMO(Qundef, Qundef, Qundef);
struct minmax_t *m = (struct minmax_t *)&memo->u1.value; struct minmax_t *m = (struct minmax_t *)&memo->v1;
VALUE ary = rb_ary_new3(2, Qnil, Qnil); VALUE ary = rb_ary_new3(2, Qnil, Qnil);
m->min = Qundef; m->min = Qundef;
@ -1714,19 +1714,19 @@ enum_minmax(VALUE obj)
static VALUE static VALUE
min_by_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args)) min_by_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args))
{ {
NODE *memo = RNODE(args); struct MEMO *memo = MEMO_CAST(args);
VALUE v; VALUE v;
ENUM_WANT_SVALUE(); ENUM_WANT_SVALUE();
v = rb_yield(i); v = rb_yield(i);
if (memo->u1.value == Qundef) { if (memo->v1 == Qundef) {
memo->u1.value = v; memo->v1 = v;
memo->u2.value = i; memo->v2 = i;
} }
else if (rb_cmpint(rb_funcall(v, id_cmp, 1, memo->u1.value), v, memo->u1.value) < 0) { else if (rb_cmpint(rb_funcall(v, id_cmp, 1, memo->v1), v, memo->v1) < 0) {
memo->u1.value = v; memo->v1 = v;
memo->u2.value = i; memo->v2 = i;
} }
return Qnil; return Qnil;
} }
@ -1756,7 +1756,7 @@ min_by_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args))
static VALUE static VALUE
enum_min_by(int argc, VALUE *argv, VALUE obj) enum_min_by(int argc, VALUE *argv, VALUE obj)
{ {
NODE *memo; struct MEMO *memo;
VALUE num; VALUE num;
rb_scan_args(argc, argv, "01", &num); rb_scan_args(argc, argv, "01", &num);
@ -1768,25 +1768,25 @@ enum_min_by(int argc, VALUE *argv, VALUE obj)
memo = NEW_MEMO(Qundef, Qnil, 0); memo = NEW_MEMO(Qundef, Qnil, 0);
rb_block_call(obj, id_each, 0, 0, min_by_i, (VALUE)memo); rb_block_call(obj, id_each, 0, 0, min_by_i, (VALUE)memo);
return memo->u2.value; return memo->v2;
} }
static VALUE static VALUE
max_by_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args)) max_by_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args))
{ {
NODE *memo = RNODE(args); struct MEMO *memo = MEMO_CAST(args);
VALUE v; VALUE v;
ENUM_WANT_SVALUE(); ENUM_WANT_SVALUE();
v = rb_yield(i); v = rb_yield(i);
if (memo->u1.value == Qundef) { if (memo->v1 == Qundef) {
memo->u1.value = v; memo->v1 = v;
memo->u2.value = i; memo->v2 = i;
} }
else if (rb_cmpint(rb_funcall(v, id_cmp, 1, memo->u1.value), v, memo->u1.value) > 0) { else if (rb_cmpint(rb_funcall(v, id_cmp, 1, memo->v1), v, memo->v1) > 0) {
memo->u1.value = v; memo->v1 = v;
memo->u2.value = i; memo->v2 = i;
} }
return Qnil; return Qnil;
} }
@ -1861,7 +1861,7 @@ max_by_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args))
static VALUE static VALUE
enum_max_by(int argc, VALUE *argv, VALUE obj) enum_max_by(int argc, VALUE *argv, VALUE obj)
{ {
NODE *memo; struct MEMO *memo;
VALUE num; VALUE num;
rb_scan_args(argc, argv, "01", &num); rb_scan_args(argc, argv, "01", &num);
@ -1873,7 +1873,7 @@ enum_max_by(int argc, VALUE *argv, VALUE obj)
memo = NEW_MEMO(Qundef, Qnil, 0); memo = NEW_MEMO(Qundef, Qnil, 0);
rb_block_call(obj, id_each, 0, 0, max_by_i, (VALUE)memo); rb_block_call(obj, id_each, 0, 0, max_by_i, (VALUE)memo);
return memo->u2.value; return memo->v2;
} }
struct minmax_by_t { struct minmax_by_t {
@ -1985,10 +1985,10 @@ enum_minmax_by(VALUE obj)
static VALUE static VALUE
member_i(RB_BLOCK_CALL_FUNC_ARGLIST(iter, args)) member_i(RB_BLOCK_CALL_FUNC_ARGLIST(iter, args))
{ {
NODE *memo = RNODE(args); struct MEMO *memo = MEMO_CAST(args);
if (rb_equal(rb_enum_values_pack(argc, argv), memo->u1.value)) { if (rb_equal(rb_enum_values_pack(argc, argv), memo->v1)) {
memo->u2.value = Qtrue; memo->v2 = Qtrue;
rb_iter_break(); rb_iter_break();
} }
return Qnil; return Qnil;
@ -2010,16 +2010,16 @@ member_i(RB_BLOCK_CALL_FUNC_ARGLIST(iter, args))
static VALUE static VALUE
enum_member(VALUE obj, VALUE val) enum_member(VALUE obj, VALUE val)
{ {
NODE *memo = NEW_MEMO(val, Qfalse, 0); struct MEMO *memo = NEW_MEMO(val, Qfalse, 0);
rb_block_call(obj, id_each, 0, 0, member_i, (VALUE)memo); rb_block_call(obj, id_each, 0, 0, member_i, (VALUE)memo);
return memo->u2.value; return memo->v2;
} }
static VALUE static VALUE
each_with_index_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memo)) each_with_index_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memo))
{ {
long n = RNODE(memo)->u3.cnt++; long n = MEMO_CAST(memo)->u3.cnt++;
return rb_yield_values(2, rb_enum_values_pack(argc, argv), INT2NUM(n)); return rb_yield_values(2, rb_enum_values_pack(argc, argv), INT2NUM(n));
} }
@ -2046,7 +2046,7 @@ each_with_index_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memo))
static VALUE static VALUE
enum_each_with_index(int argc, VALUE *argv, VALUE obj) enum_each_with_index(int argc, VALUE *argv, VALUE obj)
{ {
NODE *memo; struct MEMO *memo;
RETURN_SIZED_ENUMERATOR(obj, argc, argv, enum_size); RETURN_SIZED_ENUMERATOR(obj, argc, argv, enum_size);
@ -2138,13 +2138,12 @@ enum_each_entry(int argc, VALUE *argv, VALUE obj)
} }
#define dont_recycle_block_arg(arity) ((arity) == 1 || (arity) < 0) #define dont_recycle_block_arg(arity) ((arity) == 1 || (arity) < 0)
#define nd_no_recycle u2.value
static VALUE static VALUE
each_slice_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, m)) each_slice_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, m))
{ {
NODE *memo = RNODE(m); struct MEMO *memo = MEMO_CAST(m);
VALUE ary = memo->u1.value; VALUE ary = memo->v1;
VALUE v = Qnil; VALUE v = Qnil;
long size = memo->u3.cnt; long size = memo->u3.cnt;
ENUM_WANT_SVALUE(); ENUM_WANT_SVALUE();
@ -2154,8 +2153,8 @@ each_slice_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, m))
if (RARRAY_LEN(ary) == size) { if (RARRAY_LEN(ary) == size) {
v = rb_yield(ary); v = rb_yield(ary);
if (memo->nd_no_recycle) { if (memo->v2) {
memo->u1.value = rb_ary_new2(size); memo->v1 = rb_ary_new2(size);
} }
else { else {
rb_ary_clear(ary); rb_ary_clear(ary);
@ -2200,7 +2199,7 @@ enum_each_slice(VALUE obj, VALUE n)
{ {
long size = NUM2LONG(n); long size = NUM2LONG(n);
VALUE ary; VALUE ary;
NODE *memo; struct MEMO *memo;
int arity; int arity;
if (size <= 0) rb_raise(rb_eArgError, "invalid slice size"); if (size <= 0) rb_raise(rb_eArgError, "invalid slice size");
@ -2210,7 +2209,7 @@ enum_each_slice(VALUE obj, VALUE n)
arity = rb_block_arity(); arity = rb_block_arity();
memo = NEW_MEMO(ary, dont_recycle_block_arg(arity), size); memo = NEW_MEMO(ary, dont_recycle_block_arg(arity), size);
rb_block_call(obj, id_each, 0, 0, each_slice_i, (VALUE)memo); rb_block_call(obj, id_each, 0, 0, each_slice_i, (VALUE)memo);
ary = memo->u1.value; ary = memo->v1;
if (RARRAY_LEN(ary) > 0) rb_yield(ary); if (RARRAY_LEN(ary) > 0) rb_yield(ary);
return Qnil; return Qnil;
@ -2219,8 +2218,8 @@ enum_each_slice(VALUE obj, VALUE n)
static VALUE static VALUE
each_cons_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args)) each_cons_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args))
{ {
NODE *memo = RNODE(args); struct MEMO *memo = MEMO_CAST(args);
VALUE ary = memo->u1.value; VALUE ary = memo->v1;
VALUE v = Qnil; VALUE v = Qnil;
long size = memo->u3.cnt; long size = memo->u3.cnt;
ENUM_WANT_SVALUE(); ENUM_WANT_SVALUE();
@ -2230,7 +2229,7 @@ each_cons_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args))
} }
rb_ary_push(ary, i); rb_ary_push(ary, i);
if (RARRAY_LEN(ary) == size) { if (RARRAY_LEN(ary) == size) {
if (memo->nd_no_recycle) { if (memo->v2) {
ary = rb_ary_dup(ary); ary = rb_ary_dup(ary);
} }
v = rb_yield(ary); v = rb_yield(ary);
@ -2277,7 +2276,7 @@ static VALUE
enum_each_cons(VALUE obj, VALUE n) enum_each_cons(VALUE obj, VALUE n)
{ {
long size = NUM2LONG(n); long size = NUM2LONG(n);
NODE *memo; struct MEMO *memo;
int arity; int arity;
if (size <= 0) rb_raise(rb_eArgError, "invalid size"); if (size <= 0) rb_raise(rb_eArgError, "invalid size");
@ -2324,9 +2323,9 @@ enum_each_with_object(VALUE obj, VALUE memo)
static VALUE static VALUE
zip_ary(RB_BLOCK_CALL_FUNC_ARGLIST(val, memoval)) zip_ary(RB_BLOCK_CALL_FUNC_ARGLIST(val, memoval))
{ {
NODE *memo = (NODE *)memoval; struct MEMO *memo = (struct MEMO *)memoval;
volatile VALUE result = memo->u1.value; volatile VALUE result = memo->v1;
volatile VALUE args = memo->u2.value; volatile VALUE args = memo->v2;
long n = memo->u3.cnt++; long n = memo->u3.cnt++;
volatile VALUE tmp; volatile VALUE tmp;
int i; int i;
@ -2367,9 +2366,9 @@ call_stop(VALUE *v)
static VALUE static VALUE
zip_i(RB_BLOCK_CALL_FUNC_ARGLIST(val, memoval)) zip_i(RB_BLOCK_CALL_FUNC_ARGLIST(val, memoval))
{ {
NODE *memo = (NODE *)memoval; struct MEMO *memo = (struct MEMO *)memoval;
volatile VALUE result = memo->u1.value; volatile VALUE result = memo->v1;
volatile VALUE args = memo->u2.value; volatile VALUE args = memo->v2;
volatile VALUE tmp; volatile VALUE tmp;
int i; int i;
@ -2429,7 +2428,7 @@ enum_zip(int argc, VALUE *argv, VALUE obj)
{ {
int i; int i;
ID conv; ID conv;
NODE *memo; struct MEMO *memo;
VALUE result = Qnil; VALUE result = Qnil;
VALUE args = rb_ary_new4(argc, argv); VALUE args = rb_ary_new4(argc, argv);
int allary = TRUE; int allary = TRUE;
@ -2456,8 +2455,9 @@ enum_zip(int argc, VALUE *argv, VALUE obj)
if (!rb_block_given_p()) { if (!rb_block_given_p()) {
result = rb_ary_new(); result = rb_ary_new();
} }
/* use NODE_DOT2 as memo(v, v, -) */
memo = rb_node_newnode(NODE_DOT2, result, args, 0); /* TODO: use NODE_DOT2 as memo(v, v, -) */
memo = NEW_MEMO(result, args, 0);
rb_block_call(obj, id_each, 0, 0, allary ? zip_ary : zip_i, (VALUE)memo); rb_block_call(obj, id_each, 0, 0, allary ? zip_ary : zip_i, (VALUE)memo);
return result; return result;
@ -2466,8 +2466,8 @@ enum_zip(int argc, VALUE *argv, VALUE obj)
static VALUE static VALUE
take_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args)) take_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args))
{ {
NODE *memo = RNODE(args); struct MEMO *memo = MEMO_CAST(args);
rb_ary_push(memo->u1.value, rb_enum_values_pack(argc, argv)); rb_ary_push(memo->v1, rb_enum_values_pack(argc, argv));
if (--memo->u3.cnt == 0) rb_iter_break(); if (--memo->u3.cnt == 0) rb_iter_break();
return Qnil; return Qnil;
} }
@ -2487,7 +2487,7 @@ take_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args))
static VALUE static VALUE
enum_take(VALUE obj, VALUE n) enum_take(VALUE obj, VALUE n)
{ {
NODE *memo; struct MEMO *memo;
VALUE result; VALUE result;
long len = NUM2LONG(n); long len = NUM2LONG(n);
@ -2540,9 +2540,9 @@ enum_take_while(VALUE obj)
static VALUE static VALUE
drop_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args)) drop_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args))
{ {
NODE *memo = RNODE(args); struct MEMO *memo = MEMO_CAST(args);
if (memo->u3.cnt == 0) { if (memo->u3.cnt == 0) {
rb_ary_push(memo->u1.value, rb_enum_values_pack(argc, argv)); rb_ary_push(memo->v1, rb_enum_values_pack(argc, argv));
} }
else { else {
memo->u3.cnt--; memo->u3.cnt--;
@ -2566,7 +2566,7 @@ static VALUE
enum_drop(VALUE obj, VALUE n) enum_drop(VALUE obj, VALUE n)
{ {
VALUE result; VALUE result;
NODE *memo; struct MEMO *memo;
long len = NUM2LONG(n); long len = NUM2LONG(n);
if (len < 0) { if (len < 0) {
@ -2583,14 +2583,14 @@ enum_drop(VALUE obj, VALUE n)
static VALUE static VALUE
drop_while_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args)) drop_while_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args))
{ {
NODE *memo = RNODE(args); struct MEMO *memo = MEMO_CAST(args);
ENUM_WANT_SVALUE(); ENUM_WANT_SVALUE();
if (!memo->u3.state && !RTEST(rb_yield(i))) { if (!memo->u3.state && !RTEST(rb_yield(i))) {
memo->u3.state = TRUE; memo->u3.state = TRUE;
} }
if (memo->u3.state) { if (memo->u3.state) {
rb_ary_push(memo->u1.value, i); rb_ary_push(memo->v1, i);
} }
return Qnil; return Qnil;
} }
@ -2615,7 +2615,7 @@ static VALUE
enum_drop_while(VALUE obj) enum_drop_while(VALUE obj)
{ {
VALUE result; VALUE result;
NODE *memo; struct MEMO *memo;
RETURN_ENUMERATOR(obj, 0, 0); RETURN_ENUMERATOR(obj, 0, 0);
result = rb_ary_new(); result = rb_ary_new();

Просмотреть файл

@ -494,9 +494,9 @@ enumerator_each(int argc, VALUE *argv, VALUE obj)
static VALUE static VALUE
enumerator_with_index_i(RB_BLOCK_CALL_FUNC_ARGLIST(val, m)) enumerator_with_index_i(RB_BLOCK_CALL_FUNC_ARGLIST(val, m))
{ {
NODE *memo = (NODE *)m; struct MEMO *memo = (struct MEMO *)m;
VALUE idx = memo->u1.value; VALUE idx = memo->v1;
memo->u1.value = rb_int_succ(idx); memo->v1 = rb_int_succ(idx);
if (argc <= 1) if (argc <= 1)
return rb_yield_values(2, val, idx); return rb_yield_values(2, val, idx);

Просмотреть файл

@ -596,6 +596,23 @@ CREF_OMOD_SHARED_UNSET(rb_cref_t *cref)
cref->flags &= ~NODE_FL_CREF_OMOD_SHARED_; cref->flags &= ~NODE_FL_CREF_OMOD_SHARED_;
} }
/* MEMO */
struct MEMO {
VALUE flags;
VALUE reserved;
VALUE v1;
VALUE v2;
union {
long cnt;
long state;
VALUE value;
VALUE (*func)(ANYARGS);
} u3;
};
#define MEMO_CAST(m) ((struct MEMO *)m)
struct vtm; /* defined by timev.h */ struct vtm; /* defined by timev.h */
/* array.c */ /* array.c */

6
load.c
Просмотреть файл

@ -729,8 +729,8 @@ load_lock(const char *ftptr)
return (char *)ftptr; return (char *)ftptr;
} }
else if (RB_TYPE_P((VALUE)data, T_NODE) && nd_type((VALUE)data) == NODE_MEMO) { else if (RB_TYPE_P((VALUE)data, T_NODE) && nd_type((VALUE)data) == NODE_MEMO) {
NODE *memo = RNODE(data); struct MEMO *memo = MEMO_CAST(data);
void (*init)(void) = (void (*)(void))memo->nd_cfnc; void (*init)(void) = (void (*)(void))memo->u3.func;
data = (st_data_t)rb_thread_shield_new(); data = (st_data_t)rb_thread_shield_new();
st_insert(loading_tbl, (st_data_t)ftptr, data); st_insert(loading_tbl, (st_data_t)ftptr, data);
(*init)(); (*init)();
@ -1078,7 +1078,7 @@ register_init_ext(st_data_t *key, st_data_t *value, st_data_t init, int existing
rb_warn("%s is already registered", name); rb_warn("%s is already registered", name);
} }
else { else {
*value = (st_data_t)NEW_MEMO(init, 0, 0); *value = (st_data_t)NEW_MEMO(0, 0, init);
*key = (st_data_t)ruby_strdup(name); *key = (st_data_t)ruby_strdup(name);
} }
return ST_CONTINUE; return ST_CONTINUE;

2
node.h
Просмотреть файл

@ -461,7 +461,7 @@ typedef struct RNode {
#define NEW_BMETHOD(b) NEW_NODE(NODE_BMETHOD,0,0,b) #define NEW_BMETHOD(b) NEW_NODE(NODE_BMETHOD,0,0,b)
#define NEW_ATTRASGN(r,m,a) NEW_NODE(NODE_ATTRASGN,r,m,a) #define NEW_ATTRASGN(r,m,a) NEW_NODE(NODE_ATTRASGN,r,m,a)
#define NEW_PRELUDE(p,b) NEW_NODE(NODE_PRELUDE,p,b,0) #define NEW_PRELUDE(p,b) NEW_NODE(NODE_PRELUDE,p,b,0)
#define NEW_MEMO(a,b,c) NEW_NODE(NODE_MEMO,a,b,c) #define NEW_MEMO(a,b,c) ((struct MEMO *)NEW_NODE(NODE_MEMO,a,b,c))
#define roomof(x, y) ((sizeof(x) + sizeof(y) - 1) / sizeof(y)) #define roomof(x, y) ((sizeof(x) + sizeof(y) - 1) / sizeof(y))
#define MEMO_FOR(type, value) ((type *)RARRAY_PTR(value)) #define MEMO_FOR(type, value) ((type *)RARRAY_PTR(value))