Exemplo n.º 1
0
  bool SendSite::fill(STATE, Module* klass, CallFrame* call_frame,
                                  SendSite::Internal* cache, bool priv,
                                  Module* lookup) {
    SendSite* ss = as<SendSite>(call_frame->cm->literals()->at(state, cache->literal));

    if(!lookup) lookup = klass;

    bool method_missing = false;

    if(find_method(state, lookup, ss->name(), priv, call_frame->self(),
                   &cache->method, &cache->module)) {
      cache->recv_class = klass;
      ss->write_barrier(state, cache->recv_class);
    } else {
      assert(find_method(state, lookup, G(sym_method_missing), true, call_frame->self(),
                         &cache->method, &cache->module));
      method_missing = true;
      cache->recv_class = 0; // Don't cache using method_missing
    }

    ss->write_barrier(state, cache->method);
    ss->write_barrier(state, cache->module);

    cache->execute = cache->method->execute;
    return method_missing;
  }
Exemplo n.º 2
0
  SendSite* SendSite::create(STATE, Object* name) {
    SendSite* ss = (SendSite*)state->new_struct(G(send_site), sizeof(SendSite));
    ss->name(state, (Symbol*)name);
    ss->sender(state, (CompiledMethod*)Qnil);
    ss->selector(state, Selector::lookup(state, name));

    ss->initialize(state);
    ss->selector()->associate(state, ss);

    return ss;
  }
Exemplo n.º 3
0
  void SendSite::Info::show(STATE, Object* self, int level) {
    SendSite* ss = as<SendSite>(self);

    class_header(state, self);
    indent_attribute(++level, "name"); ss->name()->show(state, level);
    indent_attribute(level, "sender"); class_info(state, ss->sender(), true);
    indent_attribute(level, "selector"); class_info(state, ss->selector(), true);
    indent_attribute(level, "hits"); std::cout << ss->hits << std::endl;
    indent_attribute(level, "misses"); std::cout << ss->misses << std::endl;
    indent_attribute(level, "module"); class_info(state, ss->module(), true);
    indent_attribute(level, "method"); class_info(state, ss->method(), true);
    indent_attribute(level, "recv_class"); class_info(state, ss->recv_class(), true);
    close_body(level);
  }
Exemplo n.º 4
0
  void test_create() {
    Object* sym = state->symbol("blah");
    SendSite* ss = SendSite::create(state, sym);
    TS_ASSERT_EQUALS(ss->name(), sym);
    TS_ASSERT_EQUALS(ss->sender(), Qnil);
    
    Selector* sel = Selector::lookup(state, sym);
    TS_ASSERT_EQUALS(ss->selector(), sel);

    TS_ASSERT(sel->includes_p(state, ss));

    TS_ASSERT_EQUALS(ss->method(), Qnil);
    TS_ASSERT_EQUALS(ss->module(), Qnil);
    TS_ASSERT_EQUALS(ss->recv_class(), Qnil);
  }