Ejemplo n.º 1
0
mrb_value
mrb_vm_const_get(mrb_state *mrb, mrb_sym sym)
{
  struct RClass *c = mrb->c->ci->proc->target_class;
  struct RClass *c2;
  mrb_value v;
  mrb_irep *irep;

  if (!c) c = mrb->c->ci->target_class;
  mrb_assert(c != NULL);

  if (c->iv && iv_get(mrb, c->iv, sym, &v)) {
    return v;
  }
  c2 = c;
  while (c2 && c2->tt == MRB_TT_SCLASS) {
    mrb_value klass;
    klass = mrb_obj_iv_get(mrb, (struct RObject *)c2,
                           mrb_intern_lit(mrb, "__attached__"));
    c2 = mrb_class_ptr(klass);
  }
  if (c2->tt == MRB_TT_CLASS || c2->tt == MRB_TT_MODULE) c = c2;
  mrb_assert(!MRB_PROC_CFUNC_P(mrb->c->ci->proc));
  irep = mrb->c->ci->proc->body.irep;
  while (irep) {
    if (irep->target_class) {
      c2 = irep->target_class;
      if (c2->iv && iv_get(mrb, c2->iv, sym, &v)) {
        return v;
      }
    }
    irep = irep->outer;
  }
  return const_get(mrb, c, sym);
}
Ejemplo n.º 2
0
mrb_value
mrb_vm_const_get(mrb_state *mrb, mrb_sym sym)
{
  struct RClass *c = mrb->c->ci->proc->target_class;

  if (!c) c = mrb->c->ci->target_class;
  if (c) {
    struct RClass *c2;
    mrb_value v;

    if (c->iv && iv_get(mrb, c->iv, sym, &v)) {
      return v;
    }
    if (c->tt == MRB_TT_SCLASS) {
      mrb_value klass;
      klass = mrb_obj_iv_get(mrb, (struct RObject *)c,
                             mrb_intern_lit(mrb, "__attached__"));
      c2 = mrb_class_ptr(klass);
      if (c2->tt == MRB_TT_CLASS)
        c = c2;
    }
    c2 = c;
    for (;;) {
      c2 = mrb_class_outer_module(mrb, c2);
      if (!c2) break;
      if (c2->iv && iv_get(mrb, c2->iv, sym, &v)) {
        return v;
      }
    }
  }
  return const_get(mrb, c, sym);
}
Ejemplo n.º 3
0
mrb_value
mrb_vm_const_get(mrb_state *mrb, mrb_sym sym)
{
  struct RClass *c;
  struct RClass *c2;
  mrb_value v;
  struct RProc *proc;

  c = MRB_PROC_TARGET_CLASS(mrb->c->ci->proc);
  if (iv_get(mrb, c->iv, sym, &v)) {
    return v;
  }
  c2 = c;
  while (c2 && c2->tt == MRB_TT_SCLASS) {
    mrb_value klass;

    if (!iv_get(mrb, c2->iv, mrb_intern_lit(mrb, "__attached__"), &klass)) {
      c2 = NULL;
      break;
    }
    c2 = mrb_class_ptr(klass);
  }
  if (c2 && (c2->tt == MRB_TT_CLASS || c2->tt == MRB_TT_MODULE)) c = c2;
  mrb_assert(!MRB_PROC_CFUNC_P(mrb->c->ci->proc));
  proc = mrb->c->ci->proc;
  while (proc) {
    c2 = MRB_PROC_TARGET_CLASS(proc);
    if (c2 && iv_get(mrb, c2->iv, sym, &v)) {
      return v;
    }
    proc = proc->upper;
  }
  return const_get(mrb, c, sym);
}
Ejemplo n.º 4
0
mrb_value
mrb_vm_const_get(mrb_state *mrb, mrb_sym sym)
{
  struct RClass *c = mrb->ci->proc->target_class;

  if (!c) c = mrb->ci->target_class;
  return const_get(mrb, c, sym);
}
Ejemplo n.º 5
0
    Module* open_module(STATE, CallFrame* call_frame, Module* under, Symbol* name) {
      Module* module;
      bool found;

      Object* obj = const_get(state, under, name, &found);

      if(found) {
        if(Autoload* autoload = try_as<Autoload>(obj)) {
          obj = autoload->resolve(state, call_frame);
        }

        return as<Module>(obj);
      }

      module = Module::create(state);

      module->set_name(state, under, name);
      under->set_const(state, name, module);

      return module;
    }
Ejemplo n.º 6
0
mrb_value
mrb_vm_const_get(mrb_state *mrb, mrb_sym sym)
{
    struct RClass *c = mrb->ci->proc->target_class;

    if (!c) c = mrb->ci->target_class;
    if (c) {
        struct RClass *c2 = c;
        mrb_value v;

        if (c->iv && iv_get(mrb, c->iv, sym, &v)) {
            return v;
        }
        c2 = c;
        for (;;) {
            c2 = mrb_class_outer_module(mrb, c2);
            if (!c2) break;
            if (c2->iv && iv_get(mrb, c2->iv, sym, &v)) {
                return v;
            }
        }
    }
    return const_get(mrb, c, sym);
}
Ejemplo n.º 7
0
mrb_value
mrb_const_get(mrb_state *mrb, mrb_value mod, mrb_sym sym)
{
    mod_const_check(mrb, mod);
    return const_get(mrb, mrb_class_ptr(mod), sym);
}