Commit 779251de authored by KOBAYASHI Shuji's avatar KOBAYASHI Shuji

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

parent 4261ba94
...@@ -657,8 +657,30 @@ mrb_mod_s_constants(mrb_state *mrb, mrb_value mod) ...@@ -657,8 +657,30 @@ mrb_mod_s_constants(mrb_state *mrb, mrb_value mod)
return mrb_nil_value(); /* not reached */ return mrb_nil_value(); /* not reached */
} }
/* implementation of Module.nesting */ mrb_value
mrb_value mrb_mod_s_nesting(mrb_state*, 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 void
mrb_mruby_metaprog_gem_init(mrb_state* mrb) mrb_mruby_metaprog_gem_init(mrb_state* mrb)
......
...@@ -830,31 +830,6 @@ mrb_yield_cont(mrb_state *mrb, mrb_value b, mrb_value self, mrb_int argc, const ...@@ -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); 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* static struct RBreak*
break_new(mrb_state *mrb, struct RProc *p, mrb_value val) break_new(mrb_state *mrb, struct RProc *p, mrb_value val)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment