Пример #1
0
  public static IRubyObject INTERPRET_METHOD(
      ThreadContext context,
      InterpretedIRMethod irMethod,
      IRubyObject self,
      String name,
      IRubyObject[] args,
      Block block,
      Block.Type blockType,
      boolean isTraceable) {
    Ruby runtime = context.runtime;
    IRScope scope = irMethod.getIRMethod();
    RubyModule implClass = irMethod.getImplementationClass();
    Visibility viz = irMethod.getVisibility();
    boolean syntheticMethod = name == null || name.equals("");

    try {
      if (!syntheticMethod)
        ThreadContext.pushBacktrace(context, name, scope.getFileName(), context.getLine());
      if (isTraceable) methodPreTrace(runtime, context, name, implClass);
      return interpret(context, self, scope, viz, implClass, args, block, blockType);
    } finally {
      if (isTraceable) {
        try {
          methodPostTrace(runtime, context, name, implClass);
        } finally {
          if (!syntheticMethod) ThreadContext.popBacktrace(context);
        }
      } else {
        if (!syntheticMethod) ThreadContext.popBacktrace(context);
      }
    }
  }
Пример #2
0
  public static IRubyObject interpret(Ruby runtime, Node rootNode, IRubyObject self) {
    if (runtime.is1_9()) IRBuilder.setRubyVersion("1.9");

    IRScriptBody root =
        (IRScriptBody)
            IRBuilder.createIRBuilder(runtime, runtime.getIRManager())
                .buildRoot((RootNode) rootNode);

    // We get the live object ball rolling here.  This give a valid value for the top
    // of this lexical tree.  All new scope can then retrieve and set based on lexical parent.
    if (root.getStaticScope().getModule() == null) { // If an eval this may already be setup.
      root.getStaticScope().setModule(runtime.getObject());
    }

    RubyModule currModule = root.getStaticScope().getModule();

    // Scope state for root?
    IRStaticScopeFactory.newIRLocalScope(null).setModule(currModule);
    ThreadContext context = runtime.getCurrentContext();

    try {
      runBeginEndBlocks(
          root.getBeginBlocks(), context, self, null); // FIXME: No temp vars yet...not needed?
      InterpretedIRMethod method = new InterpretedIRMethod(root, currModule);
      IRubyObject rv = method.call(context, self, currModule, "(root)", IRubyObject.NULL_ARRAY);
      runBeginEndBlocks(
          root.getEndBlocks(), context, self, null); // FIXME: No temp vars yet...not needed?
      if ((IRRuntimeHelpers.isDebug() || IRRuntimeHelpers.inProfileMode())
          && interpInstrsCount > 10000) {
        LOG.info("-- Interpreted instructions: {}", interpInstrsCount);
        /*
        for (Operation o: opStats.keySet()) {
            System.out.println(o + " = " + opStats.get(o).count);
        }
        */
      }
      return rv;
    } catch (IRBreakJump bj) {
      throw IRException.BREAK_LocalJumpError.getException(context.runtime);
    }
  }
Пример #3
0
  public static IRubyObject interpretTop(Ruby runtime, IRScope scope, IRubyObject self) {
    assert scope instanceof IRScript : "Must be an IRScript scope at Top!!!";

    IRScript root = (IRScript) scope;

    // We get the live object ball rolling here.  This give a valid value for the top
    // of this lexical tree.  All new scope can then retrieve and set based on lexical parent.
    if (root.getStaticScope().getModule() == null) { // If an eval this may already be setup.
      root.getStaticScope().setModule(runtime.getObject());
    }

    RubyModule currModule = root.getStaticScope().getModule();
    IRMethod rootMethod = root.getRootClass().getRootMethod();
    InterpretedIRMethod method = new InterpretedIRMethod(rootMethod, currModule);
    ThreadContext context = runtime.getCurrentContext();

    IRubyObject rv = method.call(context, self, currModule, "", IRubyObject.NULL_ARRAY);
    if (isDebug()) LOG.debug("-- Interpreted instructions: {}", interpInstrsCount);

    return rv;
  }