@Override
  public Object interpret(
      ThreadContext context,
      DynamicScope currDynScope,
      IRubyObject self,
      Object[] temp,
      Block block) {
    // SSS FIXME: This is ugly and needs fixing.  Is there another way of capturing this info?
    RubyModule containerModule =
        (candidateScope == null) ? null : candidateScope.getStaticScope().getModule();
    if (containerModule == null)
      containerModule = ASTInterpreter.getClassVariableBase(context, context.getRuntime());
    if (containerModule == null && object != null) {
      IRubyObject arg = (IRubyObject) object.retrieve(context, self, currDynScope, temp);
      // SSS: What is the right thing to do here?
      containerModule =
          arg
              .getMetaClass(); // (arg instanceof RubyClass) ? ((RubyClass)arg).getRealClass() :
                               // arg.getType();
    }

    if (containerModule == null)
      throw context.getRuntime().newTypeError("no class/module to define class variable");

    return containerModule;
  }
Example #2
0
  @Override
  public IRubyObject call(
      ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0) {
    Ruby runtime = context.getRuntime();
    int callNumber = context.callNumber;

    try {
      pre(context, name, self, Block.NULL_BLOCK, runtime);
      argsNode.checkArgCount(runtime, name, 1);
      argsNode.prepare(context, runtime, self, arg0, Block.NULL_BLOCK);

      return ASTInterpreter.INTERPRET_METHOD(
          runtime,
          context,
          file,
          line,
          getImplementationClass(),
          body,
          name,
          self,
          Block.NULL_BLOCK,
          isTraceable());
    } catch (JumpException.ReturnJump rj) {
      return handleReturn(context, rj, callNumber);
    } catch (JumpException.RedoJump rj) {
      return handleRedo(runtime);
    } catch (JumpException.BreakJump bj) {
      return handleBreak(context, runtime, bj, callNumber);
    } finally {
      post(runtime, context, name);
    }
  }
Example #3
0
 private IRubyObject evalBlockBody(ThreadContext context, Binding binding, IRubyObject self) {
   // This while loop is for restarting the block call in case a 'redo' fires.
   while (true) {
     try {
       return ASTInterpreter.INTERPRET_BLOCK(
           context.runtime,
           context,
           file,
           line,
           bodyNode,
           binding.getMethod(),
           self,
           Block.NULL_BLOCK);
     } catch (JumpException.RedoJump rj) {
       context.pollThreadEvents();
       // do nothing, allow loop to redo
     } catch (StackOverflowError soe) {
       throw context.runtime.newSystemStackError("stack level too deep", soe);
     }
   }
 }