Example #1
0
  Object* System::vm_attach_method(STATE, Symbol* name, CompiledMethod* method,
                                   StaticScope* scope, Object* recv) {
    Module* mod = recv->singleton_class(state);

    method->scope(state, scope);
    method->serial(state, Fixnum::from(0));
    mod->add_method(state, name, method);

    vm_reset_method_cache(state, name);

    return method;
  }
Example #2
0
  Object* System::vm_add_method(STATE, Symbol* name, CompiledMethod* method,
                                StaticScope* scope, Object* vis) {
    Module* mod = scope->for_method_definition();

    method->scope(state, scope);
    method->serial(state, Fixnum::from(0));
    mod->add_method(state, name, method);

    if(Class* cls = try_as<Class>(mod)) {
      if(!method->internalize(state)) {
        Exception::argument_error(state, "invalid bytecode method");
        return 0;
      }

      object_type type = (object_type)cls->instance_type()->to_native();
      TypeInfo* ti = state->om->type_info[type];
      if(ti) {
        method->specialize(state, ti);
      }
    }

    bool add_ivars = false;

    if(Class* cls = try_as<Class>(mod)) {
      add_ivars = !kind_of<SingletonClass>(cls) && cls->type_info()->type == Object::type;
    } else {
      add_ivars = true;
    }

    if(add_ivars) {
      Array* ary = mod->seen_ivars();
      if(ary->nil_p()) {
        ary = Array::create(state, 5);
        mod->seen_ivars(state, ary);
      }

      Tuple* lits = method->literals();
      for(native_int i = 0; i < lits->num_fields(); i++) {
        if(Symbol* sym = try_as<Symbol>(lits->at(state, i))) {
          if(RTEST(sym->is_ivar_p(state))) {
            if(!ary->includes_p(state, sym)) ary->append(state, sym);
          }
        }
      }
    }

    vm_reset_method_cache(state, name);

    return method;
  }
Example #3
0
  Object* System::vm_add_method(STATE, Symbol* name, CompiledMethod* method,
                                StaticScope* scope, Object* vis) {
    Module* mod = scope->for_method_definition();

    method->scope(state, scope);
    method->serial(state, Fixnum::from(0));
    mod->add_method(state, name, method);

    if(Class* cls = try_as<Class>(mod)) {
      method->formalize(state, false);

      object_type type = (object_type)cls->instance_type()->to_native();
      TypeInfo* ti = state->om->type_info[type];
      if(ti) {
        method->specialize(state, ti);
      }
    }

    vm_reset_method_cache(state, name);

    return method;
  }