예제 #1
0
파일: RubyThread.java 프로젝트: nahi/jruby
  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;
  }
예제 #2
0
  public static RubyClass createConverterClass(Ruby runtime) {
    RubyClass converterc =
        runtime.defineClassUnder(
            "Converter", runtime.getClass("Data"), CONVERTER_ALLOCATOR, runtime.getEncoding());
    runtime.setConverter(converterc);
    converterc.index = ClassIndex.CONVERTER;
    converterc.setReifiedClass(RubyConverter.class);
    converterc.kindOf = new RubyModule.JavaClassKindOf(RubyConverter.class);

    converterc.defineAnnotatedMethods(RubyConverter.class);
    return converterc;
  }
예제 #3
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;
  }
예제 #4
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;
  }
예제 #5
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;
  }