示例#1
0
  LookupTable* LookupTable::duplicate(STATE) {
    size_t size, i;
    LookupTable *dup;

    size = bins_->to_native();
    dup = LookupTable::create(state, size);

    // Allow for subclassing.
    dup->klass(state, class_object(state));

    size_t num = entries_->to_native();

    Array* entries = all_entries(state);
    for(i = 0; i < num; i++) {
      LookupTableBucket* entry = as<LookupTableBucket>(entries->get(state, i));
      dup->store(state, entry->key(), entry->value());
    }
    return dup;
  }
示例#2
0
 /* The LookupTable.allocate primitive. */
 LookupTable* LookupTable::allocate(STATE, Object* self) {
   LookupTable* tbl = create(state, LOOKUPTABLE_MIN_SIZE);
   tbl->klass(state, as<Class>(self));
   return tbl;
 }
  void test_allocate() {
    Class* sub = state->memory()->new_class<Class>(state, G(lookup_table));
    LookupTable* tbl = LookupTable::allocate(state, sub);

    TS_ASSERT_EQUALS(tbl->klass(), sub);
  }
  void test_allocate() {
    Class* sub = ontology::new_class(state, "LookupTableSub", G(lookuptable), 0);
    LookupTable* tbl = LookupTable::allocate(state, sub);

    TS_ASSERT_EQUALS(tbl->klass(), sub);
  }
示例#5
0
  void test_allocate() {
    Class* sub = state->vm()->new_class("LookupTableSub", G(lookuptable), 0);
    LookupTable* tbl = LookupTable::allocate(state, sub);

    TS_ASSERT_EQUALS(tbl->klass(), sub);
  }