Exemplo n.º 1
0
  @JRubyMethod(name = "initialize", frame = true, visibility = Visibility.PRIVATE)
  public IRubyObject initialize(ThreadContext context, Block procBlock) {
    if (!procBlock.isGiven()) {
      throw getRuntime().newArgumentError("tried to create Proc object without a block");
    }

    if (isLambda() && procBlock == null) {
      // TODO: warn "tried to create Proc object without a block"
    }

    block = procBlock.cloneBlock();

    if (isThread()) {
      // modify the block with a new backref/lastline-grabbing scope
      StaticScope oldScope = block.getBody().getStaticScope();
      StaticScope newScope =
          new BlockStaticScope(oldScope.getEnclosingScope(), oldScope.getVariables());
      newScope.setBackrefLastlineScope(true);
      newScope.setPreviousCRefScope(oldScope.getPreviousCRefScope());
      newScope.setModule(oldScope.getModule());
      block.getBody().setStaticScope(newScope);
    }

    block.type = type;
    block.setProcObject(this);

    file = context.getFile();
    line = context.getLine();
    return this;
  }
Exemplo n.º 2
0
  @Override
  public IRubyObject interpret(
      Ruby runtime, ThreadContext context, IRubyObject self, Block aBlock) {
    // Serialization killed our dynamic scope.  We can just create an empty one
    // since serialization cannot serialize an eval (which is the only thing
    // which is capable of having a non-empty dynamic scope).
    if (scope == null) {
      scope = DynamicScope.newDynamicScope(staticScope);
    }

    StaticScope theStaticScope = scope.getStaticScope();

    // Each root node has a top-level scope that we need to push
    context.preScopedBody(scope);

    if (theStaticScope.getModule() == null) {
      theStaticScope.setModule(runtime.getObject());
    }

    try {
      return bodyNode.interpret(runtime, context, self, aBlock);
    } finally {
      context.postScopedBody();
    }
  }
Exemplo n.º 3
0
 public void preCompiledClassDummyScope(RubyModule type, StaticScope staticScope) {
   pushRubyClass(type);
   pushFrameCopy();
   getCurrentFrame().setSelf(type);
   getCurrentFrame().setVisibility(Visibility.PUBLIC);
   staticScope.setModule(type);
   pushScope(staticScope.getDummyScope());
 }
Exemplo n.º 4
0
  // XXX: Again, screwy evaling under previous frame's scope
  public void preExecuteUnder(RubyModule executeUnderClass, Block block) {
    Frame frame = getCurrentFrame();

    pushRubyClass(executeUnderClass);
    DynamicScope scope = getCurrentScope();
    StaticScope sScope = new BlockStaticScope(scope.getStaticScope());
    sScope.setModule(executeUnderClass);
    pushScope(DynamicScope.newDynamicScope(sScope, scope));
    pushCallFrame(frame.getKlazz(), frame.getName(), frame.getSelf(), block);
    getCurrentFrame().setVisibility(getPreviousFrame().getVisibility());
  }