Exemple #1
0
  public static RubyClass createThreadClass(Ruby runtime) {
    // FIXME: In order for Thread to play well with the standard 'new' behavior,
    // it must provide an allocator that can create empty object instances which
    // initialize then fills with appropriate data.
    RubyClass threadClass =
        runtime.defineClass(
            "Thread", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
    runtime.setThread(threadClass);

    threadClass.index = ClassIndex.THREAD;
    threadClass.setReifiedClass(RubyThread.class);

    threadClass.defineAnnotatedMethods(RubyThread.class);

    RubyThread rubyThread = new RubyThread(runtime, threadClass);
    // TODO: need to isolate the "current" thread from class creation
    rubyThread.threadImpl = new NativeThread(rubyThread, Thread.currentThread());
    runtime.getThreadService().setMainThread(Thread.currentThread(), rubyThread);

    // set to default thread group
    runtime.getDefaultThreadGroup().addDirectly(rubyThread);

    threadClass.setMarshal(ObjectMarshal.NOT_MARSHALABLE_MARSHAL);

    return threadClass;
  }
Exemple #2
0
  public static RubyClass createTimeClass(Ruby runtime) {
    RubyClass timeClass = runtime.defineClass("Time", runtime.getObject(), TIME_ALLOCATOR);

    timeClass.index = ClassIndex.TIME;
    timeClass.setReifiedClass(RubyTime.class);

    runtime.setTime(timeClass);

    timeClass.includeModule(runtime.getComparable());

    timeClass.defineAnnotatedMethods(RubyTime.class);

    return timeClass;
  }
Exemple #3
0
  public static RubyClass createEncodingClass(Ruby runtime) {
    RubyClass encodingc =
        runtime.defineClass(
            "Encoding", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
    runtime.setEncoding(encodingc);
    encodingc.index = ClassIndex.ENCODING;
    encodingc.setReifiedClass(RubyEncoding.class);
    encodingc.kindOf =
        new RubyModule.KindOf() {
          @Override
          public boolean isKindOf(IRubyObject obj, RubyModule type) {
            return obj instanceof RubyEncoding;
          }
        };

    encodingc.getSingletonClass().undefineMethod("allocate");
    encodingc.defineAnnotatedMethods(RubyEncoding.class);

    return encodingc;
  }
Exemple #4
0
  public static RubyClass createMatchDataClass(Ruby runtime) {
    RubyClass matchDataClass =
        runtime.defineClass("MatchData", runtime.getObject(), MATCH_DATA_ALLOCATOR);
    runtime.setMatchData(matchDataClass);

    matchDataClass.index = ClassIndex.MATCHDATA;
    matchDataClass.setReifiedClass(RubyMatchData.class);

    runtime.defineGlobalConstant("MatchingData", matchDataClass);
    matchDataClass.kindOf =
        new RubyModule.KindOf() {
          @Override
          public boolean isKindOf(IRubyObject obj, RubyModule type) {
            return obj instanceof RubyMatchData;
          }
        };

    matchDataClass.getMetaClass().undefineMethod("new");
    matchDataClass.defineAnnotatedMethods(RubyMatchData.class);
    return matchDataClass;
  }