summaryrefslogtreecommitdiffhomepage
path: root/src/class.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/class.c')
-rw-r--r--src/class.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/class.c b/src/class.c
index 7533ac2b0..126ac0004 100644
--- a/src/class.c
+++ b/src/class.c
@@ -27,7 +27,8 @@ union mt_ptr {
struct mt_elem {
union mt_ptr ptr;
size_t func_p:1;
- mrb_sym key:sizeof(mrb_sym)*8-1;
+ size_t noarg_p:1;
+ mrb_sym key:sizeof(mrb_sym)*8-2;
};
/* method table structure */
@@ -51,7 +52,7 @@ mt_new(mrb_state *mrb)
return t;
}
-static struct mt_elem *mt_put(mrb_state *mrb, mt_tbl *t, mrb_sym sym, size_t func_p, union mt_ptr ptr);
+static struct mt_elem *mt_put(mrb_state *mrb, mt_tbl *t, mrb_sym sym, size_t func_p, size_t noarg_p, union mt_ptr ptr);
static void
mt_rehash(mrb_state *mrb, mt_tbl *t)
@@ -72,7 +73,7 @@ mt_rehash(mrb_state *mrb, mt_tbl *t)
/* key = 0 means empty or deleted */
if (slot->key != 0) {
- mt_put(mrb, t, slot->key, slot->func_p, slot->ptr);
+ mt_put(mrb, t, slot->key, slot->func_p, slot->noarg_p, slot->ptr);
}
}
mrb_free(mrb, old_table);
@@ -82,7 +83,7 @@ mt_rehash(mrb_state *mrb, mt_tbl *t)
/* Set the value for the symbol in the method table. */
static struct mt_elem*
-mt_put(mrb_state *mrb, mt_tbl *t, mrb_sym sym, size_t func_p, union mt_ptr ptr)
+mt_put(mrb_state *mrb, mt_tbl *t, mrb_sym sym, size_t func_p, size_t noarg_p, union mt_ptr ptr)
{
size_t hash, pos, start;
struct mt_elem *dslot = NULL;
@@ -97,6 +98,7 @@ mt_put(mrb_state *mrb, mt_tbl *t, mrb_sym sym, size_t func_p, union mt_ptr ptr)
if (slot->key == sym) {
slot->func_p = func_p;
+ slot->noarg_p = noarg_p;
slot->ptr = ptr;
return slot;
}
@@ -105,6 +107,7 @@ mt_put(mrb_state *mrb, mt_tbl *t, mrb_sym sym, size_t func_p, union mt_ptr ptr)
t->size++;
slot->key = sym;
slot->func_p = func_p;
+ slot->noarg_p = noarg_p;
slot->ptr = ptr;
return slot;
}
@@ -118,6 +121,7 @@ mt_put(mrb_state *mrb, mt_tbl *t, mrb_sym sym, size_t func_p, union mt_ptr ptr)
t->size++;
dslot->key = sym;
dslot->func_p = func_p;
+ dslot->noarg_p = noarg_p;
dslot->ptr = ptr;
return dslot;
}
@@ -203,7 +207,7 @@ mt_copy(mrb_state *mrb, mt_tbl *t)
struct mt_elem *slot = &t->table[i];
if (slot->key) {
- mt_put(mrb, t2, slot->key, slot->func_p, slot->ptr);
+ mt_put(mrb, t2, slot->key, slot->func_p, slot->noarg_p, slot->ptr);
}
}
return t2;
@@ -239,6 +243,9 @@ mrb_mt_foreach(mrb_state *mrb, struct RClass *c, mrb_mt_foreach_func *fn, void *
else {
MRB_METHOD_FROM_PROC(m, slot->ptr.proc);
}
+ if (slot->noarg_p) {
+ MRB_METHOD_NOARG_SET(m);
+ }
if (fn(mrb, slot->key, m, p) != 0)
return;
@@ -740,7 +747,7 @@ mrb_define_method_raw(mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_method_
else {
ptr.func = MRB_METHOD_FUNC(m);
}
- mt_put(mrb, h, mid, MRB_METHOD_FUNC_P(m), ptr);
+ mt_put(mrb, h, mid, MRB_METHOD_FUNC_P(m), MRB_METHOD_NOARG_P(m), ptr);
mc_clear(mrb);
}
@@ -809,7 +816,7 @@ mrb_get_argc(mrb_state *mrb)
mrb_int argc = mrb->c->ci->argc;
if (argc < 0) {
- struct RArray *a = mrb_ary_ptr(mrb->c->stack[1]);
+ struct RArray *a = mrb_ary_ptr(mrb->c->ci->stack[1]);
argc = ARY_LEN(a);
}
@@ -820,7 +827,7 @@ MRB_API const mrb_value*
mrb_get_argv(mrb_state *mrb)
{
mrb_int argc = mrb->c->ci->argc;
- mrb_value *array_argv = mrb->c->stack + 1;
+ mrb_value *array_argv = mrb->c->ci->stack + 1;
if (argc < 0) {
struct RArray *a = mrb_ary_ptr(*array_argv);
@@ -833,7 +840,7 @@ MRB_API mrb_value
mrb_get_arg1(mrb_state *mrb)
{
mrb_int argc = mrb->c->ci->argc;
- mrb_value *array_argv = mrb->c->stack + 1;
+ mrb_value *array_argv = mrb->c->ci->stack + 1;
if (argc < 0) {
struct RArray *a = mrb_ary_ptr(*array_argv);
@@ -888,7 +895,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
mrb_int i = 0;
va_list ap;
mrb_int argc = mrb->c->ci->argc;
- mrb_value *array_argv = mrb->c->stack+1;
+ mrb_value *array_argv = mrb->c->ci->stack+1;
mrb_bool argv_on_stack = argc >= 0;
mrb_bool opt = FALSE;
mrb_bool opt_skip = TRUE;
@@ -1201,10 +1208,10 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
p = va_arg(ap, mrb_value*);
if (mrb->c->ci->argc < 0) {
- bp = mrb->c->stack + 2;
+ bp = mrb->c->ci->stack + 2;
}
else {
- bp = mrb->c->stack + mrb->c->ci->argc + 1;
+ bp = mrb->c->ci->stack + mrb->c->ci->argc + 1;
}
if (altmode && mrb_nil_p(*bp)) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "no block given");
@@ -1748,6 +1755,9 @@ mrb_method_search_vm(mrb_state *mrb, struct RClass **cp, mrb_sym mid)
else {
MRB_METHOD_FROM_PROC(m, e->ptr.proc);
}
+ if (e->noarg_p) {
+ MRB_METHOD_NOARG_SET(m);
+ }
#ifndef MRB_NO_METHOD_CACHE
mc->c = oc;
mc->c0 = c;