Exemplo n.º 1
0
Object* Class::set_superclass(STATE, Object* obj) {
    if(obj->nil_p()) {
        superclass(state, nil<Class>());
        return cNil;
    }

    Class* sup = try_as<Class>(obj);
    if(!sup) {
        return Primitives::failure();
    }

    if(try_as<SingletonClass>(sup)) {
        Exception::type_error(state, "cannot inherit from a singleton class");
    }

    superclass(state, sup);

    instance_type(state, sup->instance_type());
    if(sup->type_info()->type == PackedObject::type) {
        set_type_info(state->memory()->type_info[ObjectType]);
    } else {
        set_type_info(sup->type_info());
    }

    SingletonClass::attach(state, this, sup->singleton_class(state));

    sup->track_subclass(state, this);

    return cNil;
}
Exemplo n.º 2
0
 void Module::setup(STATE) {
   constant_table(state, ConstantTable::create(state));
   method_table(state, MethodTable::create(state));
   if(!superclass()->nil_p()) {
     superclass()->track_subclass(state, this);
   }
 }
Exemplo n.º 3
0
  Object* Class::set_superclass(STATE, Class* sup) {
    superclass(state, sup);
    instance_type(state, sup->instance_type());
    set_type_info(sup->type_info());

    return Qnil;
  }
Exemplo n.º 4
0
  Class* Class::true_superclass(STATE) {
    Module* super = superclass();

    while(kind_of<IncludedModule>(super)) {
      super = super->superclass();
    }

    return as<Class>(super);
  }
Exemplo n.º 5
0
  Object* Class::set_superclass(STATE, Object* obj) {
    if(obj->nil_p()) {
      superclass(state, (Class*)Qnil);
      return Qnil;
    }

    Class* sup;
    if((sup = try_as<Class>(obj)) == 0) {
      return Primitives::failure();
    }

    superclass(state, sup);

    instance_type(state, sup->instance_type());
    set_type_info(sup->type_info());

    packed_ivar_info(state, sup->packed_ivar_info());
    set_packed_size(sup->packed_size());

    MetaClass::attach(state, this, sup->metaclass(state));

    return Qnil;
  }
Exemplo n.º 6
0
void Parser::Classdef(ClassGenerationContext* cgenc) {
    cgenc->SetName(GetUniverse()->SymbolFor(text));
    expect(Identifier);

    expect(Equal);

    superclass(cgenc);

    expect(NewTerm);
    instanceFields(cgenc);
    while (symIsIdentifier() || sym == Keyword || sym == OperatorSequence ||
           symIn(binaryOpSyms)) {

        MethodGenerationContext mgenc;
        mgenc.SetHolder(cgenc);
        mgenc.AddArgument("self");

        method(&mgenc);

        if(mgenc.IsPrimitive())
            cgenc->AddInstanceMethod(mgenc.AssemblePrimitive(false));
        else
            cgenc->AddInstanceMethod(mgenc.Assemble());
    }

    if (accept(Separator)) {
        cgenc->SetClassSide(true);
        classFields(cgenc);
        while (symIsIdentifier() || sym == Keyword || sym == OperatorSequence ||
        symIn(binaryOpSyms)) {
            MethodGenerationContext mgenc;
            mgenc.SetHolder(cgenc);
            mgenc.AddArgument("self");

            method(&mgenc);

            if(mgenc.IsPrimitive())
                cgenc->AddClassMethod(mgenc.AssemblePrimitive(true));
            else
                cgenc->AddClassMethod(mgenc.Assemble());
        }
    }
    expect(EndTerm);
}