Example #1
0
    inline bool find_const(STATE, CallFrame* call_frame, intptr_t literal) {
      Module* under = as<Module>(stack_pop());

      ConstantCache* cache = reinterpret_cast<ConstantCache*>(literal);

      Object* res = cache->retrieve(state, under, call_frame->lexical_scope());

      if(!res) {
        ConstantMissingReason reason;

        Symbol* sym = cache->name();
        res = Helpers::const_get_under(state, under, sym, &reason);

        if(reason == vFound) {
          OnStack<3> os(state, cache, under, res);
          if(Autoload* autoload = try_as<Autoload>(res)) {
            res = autoload->resolve(state, under);
          }

          if(res) {
            ConstantCache* update = ConstantCache::create(state, cache, res, under, call_frame->lexical_scope());
            cache->update_constant_cache(state, update);
          }
        } else {
          res = Helpers::const_missing_under(state, under, sym);
        }
      }

      CHECK_AND_PUSH(res);
    }
Example #2
0
  ConstantCache* ConstantCache::empty(STATE, Symbol* name, Executable* executable, int ip) {
    ConstantCache* cache = state->new_object_dirty<ConstantCache>(G(constant_cache));

    cache->name(state, name);
    cache->executable(state, executable);
    cache->ip_ = ip;
    cache->value(state, cNil);
    cache->under(state, nil<Module>());
    cache->scope(state, nil<ConstantScope>());
    cache->serial_ = -1;
    return cache;
  }
Example #3
0
  ConstantCache* ConstantCache::create(STATE, ConstantCache* existing, Object* value, Module* under,
                                             ConstantScope* scope) {
    ConstantCache* cache = state->new_object_dirty<ConstantCache>(G(constant_cache));

    cache->name(state, existing->name());
    cache->executable(state, existing->executable());
    cache->ip_ = existing->ip();
    cache->value(state, value);
    cache->under(state, under);
    cache->scope(state, scope);
    cache->serial_ = state->shared().global_serial();
    return cache;
  }