Move mrb_mod_s_nesting() to mruby-metaprog gem from the core

This commit is contained in:
KOBAYASHI Shuji
2019-05-26 20:32:04 +09:00
parent 4261ba9443
commit 779251de64
2 changed files with 24 additions and 27 deletions
+24 -2
View File
@@ -657,8 +657,30 @@ mrb_mod_s_constants(mrb_state *mrb, mrb_value mod)
return mrb_nil_value(); /* not reached */
}
/* implementation of Module.nesting */
mrb_value mrb_mod_s_nesting(mrb_state*, mrb_value);
mrb_value
mrb_mod_s_nesting(mrb_state *mrb, mrb_value mod)
{
struct RProc *proc;
mrb_value ary;
struct RClass *c = NULL;
mrb_get_args(mrb, "");
ary = mrb_ary_new(mrb);
proc = mrb->c->ci[-1].proc; /* callee proc */
mrb_assert(!MRB_PROC_CFUNC_P(proc));
while (proc) {
if (MRB_PROC_SCOPE_P(proc)) {
struct RClass *c2 = MRB_PROC_TARGET_CLASS(proc);
if (c2 != c) {
c = c2;
mrb_ary_push(mrb, ary, mrb_obj_value(c));
}
}
proc = proc->upper;
}
return ary;
}
void
mrb_mruby_metaprog_gem_init(mrb_state* mrb)
-25
View File
@@ -830,31 +830,6 @@ mrb_yield_cont(mrb_state *mrb, mrb_value b, mrb_value self, mrb_int argc, const
return mrb_exec_irep(mrb, self, p);
}
mrb_value
mrb_mod_s_nesting(mrb_state *mrb, mrb_value mod)
{
struct RProc *proc;
mrb_value ary;
struct RClass *c = NULL;
mrb_get_args(mrb, "");
ary = mrb_ary_new(mrb);
proc = mrb->c->ci[-1].proc; /* callee proc */
mrb_assert(!MRB_PROC_CFUNC_P(proc));
while (proc) {
if (MRB_PROC_SCOPE_P(proc)) {
struct RClass *c2 = MRB_PROC_TARGET_CLASS(proc);
if (c2 != c) {
c = c2;
mrb_ary_push(mrb, ary, mrb_obj_value(c));
}
}
proc = proc->upper;
}
return ary;
}
static struct RBreak*
break_new(mrb_state *mrb, struct RProc *p, mrb_value val)
{