Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove all traces of rubyclass stack from the codebase.
Browse files Browse the repository at this point in the history
* Removed klass arg from method calls.
* Remove the push/pop/get from thread-context and use sites.
* TODO: embed used to inject values into the current-module obtained
  from the rubyclass stack. That code needs investigation.
* Replaced the hacky if (klass==null) prepareSelf(binding) calls
  with information about actual execution context. The primary reason
  to use binding.self instead of self argument in blocks is when
  the block is being used in a binding-eval context. The same soln.
  is applicable in other contexts where this pattern was used (and
  currently marked with SSS FIXME annotations in code comments).
subbuss committed Jun 29, 2014
1 parent 92833b9 commit 525a110
Showing 35 changed files with 146 additions and 269 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -3224,7 +3224,7 @@ private IRubyObject sortInternal(final ThreadContext context, final Block block)
public int compare(Object o1, Object o2) {
IRubyObject obj1 = (IRubyObject) o1;
IRubyObject obj2 = (IRubyObject) o2;
IRubyObject ret = block.yieldArray(context, getRuntime().newArray(obj1, obj2), null, null);
IRubyObject ret = block.yieldArray(context, getRuntime().newArray(obj1, obj2), null);
//TODO: ary_sort_check should be done here
return RubyComparable.cmpint(context, ret, obj1, obj2);
}
7 changes: 3 additions & 4 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Original file line number Diff line number Diff line change
@@ -42,7 +42,6 @@

import org.jruby.anno.JRubyMethod;
import org.jruby.common.IRubyWarnings.ID;
import org.jruby.evaluator.ASTInterpreter;
import org.jruby.exceptions.JumpException;
import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.javasupport.JavaObject;
@@ -1621,10 +1620,10 @@ protected IRubyObject yieldUnder(final ThreadContext context, RubyModule under,
try {
if (args.length == 1) {
IRubyObject valueInYield = args[0];
return setupBlock(block, evalType).yieldNonArray(context, valueInYield, this, context.getRubyClass());
return setupBlock(block, evalType).yieldNonArray(context, valueInYield, this); // context.getRubyClass());
} else {
IRubyObject valueInYield = RubyArray.newArrayNoCopy(context.runtime, args);
return setupBlock(block, evalType).yieldArray(context, valueInYield, this, context.getRubyClass());
return setupBlock(block, evalType).yieldArray(context, valueInYield, this); // context.getRubyClass());
}
//TODO: Should next and return also catch here?
} catch (JumpException.BreakJump bj) {
@@ -1662,7 +1661,7 @@ protected IRubyObject yieldUnder(final ThreadContext context, RubyModule under,
block.getBinding().setVisibility(PUBLIC);

try {
return setupBlock(block, evalType).yieldNonArray(context, this, this, context.getRubyClass());
return setupBlock(block, evalType).yieldNonArray(context, this, this); // context.getRubyClass());
//TODO: Should next and return also catch here?
} catch (JumpException.BreakJump bj) {
return (IRubyObject) bj.getValue();
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/RubyEnumerable.java
Original file line number Diff line number Diff line change
@@ -763,7 +763,7 @@ public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
larg = RubyArray.newArrayNoCopy(ctx.runtime, largs);
}

IRubyObject value = newAry ? block.yieldArray(ctx, larg, null, null) : block.yield(ctx, larg);
IRubyObject value = newAry ? block.yieldArray(ctx, larg, null) : block.yield(ctx, larg);
synchronized (result) {
result.append(value);
}
@@ -828,7 +828,7 @@ public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
IRubyObject larg = packEnumValues(runtime, largs);
checkContext(localContext, ctx, "inject");
result[0] = result[0] == null ?
larg : block.yieldArray(ctx, runtime.newArray(result[0], larg), null, null);
larg : block.yieldArray(ctx, runtime.newArray(result[0], larg), null);

return runtime.getNil();
}
@@ -1135,7 +1135,7 @@ public IRubyObject call(ThreadContext ctx, IRubyObject[] largs, Block blk) {
IRubyObject larg = packEnumValues(runtime, largs);
checkContext(localContext, ctx, "max{}");
if (result[0] == null || RubyComparable.cmpint(ctx, block.yieldArray(ctx,
runtime.newArray(larg, result[0]), null, null), larg, result[0]) > 0) {
runtime.newArray(larg, result[0]), null), larg, result[0]) > 0) {
result[0] = larg;
}
return runtime.getNil();
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/RubyHash.java
Original file line number Diff line number Diff line change
@@ -1364,7 +1364,7 @@ public void visit(IRubyObject key, IRubyObject value) {
if (oneNine) {
block.yield(context, RubyArray.newArray(runtime, key, value));
} else {
block.yieldArray(context, RubyArray.newArray(runtime, key, value), null, null);
block.yieldArray(context, RubyArray.newArray(runtime, key, value), null);
}
}
});
@@ -1604,7 +1604,7 @@ public IRubyObject select19(final ThreadContext context, final Block block) {
iteratorVisitAll(new Visitor() {
@Override
public void visit(IRubyObject key, IRubyObject value) {
if (block.yieldArray(context, runtime.newArray(key, value), null, null).isTrue()) {
if (block.yieldArray(context, runtime.newArray(key, value), null).isTrue()) {
result.fastASet(key, value);
}
}
@@ -1624,7 +1624,7 @@ public RubyHash delete_ifInternal(final ThreadContext context, final Block block
iteratorVisitAll(new Visitor() {
@Override
public void visit(IRubyObject key, IRubyObject value) {
if (block.yieldArray(context, RubyArray.newArray(runtime, key, value), null, null).isTrue()) {
if (block.yieldArray(context, RubyArray.newArray(runtime, key, value), null).isTrue()) {
self.delete(context, key, Block.NULL_BLOCK);
}
}
1 change: 0 additions & 1 deletion core/src/main/java/org/jruby/RubyProc.java
Original file line number Diff line number Diff line change
@@ -146,7 +146,6 @@ private void setup(Block procBlock) {
oldBinding.getSelf(),
oldBinding.getFrame().duplicate(),
oldBinding.getVisibility(),
oldBinding.getKlass(),
oldBinding.getDynamicScope(),
oldBinding.getBacktrace().clone());
block = new Block(procBlock.getBody(), newBinding);
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyStruct.java
Original file line number Diff line number Diff line change
@@ -254,7 +254,7 @@ public DynamicMethod dup() {
if (block.isGiven()) {
// Struct bodies should be public by default, so set block visibility to public. JRUBY-1185.
block.getBinding().setVisibility(Visibility.PUBLIC);
block.yieldNonArray(runtime.getCurrentContext(), null, newStruct, newStruct);
block.yieldNonArray(runtime.getCurrentContext(), null, newStruct);
}

return newStruct;
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubySymbol.java
Original file line number Diff line number Diff line change
@@ -391,7 +391,7 @@ private IRubyObject yieldInner(ThreadContext context, RubyArray array, Block blo

@Override
public IRubyObject yield(ThreadContext context, IRubyObject[] args, IRubyObject self,
RubyModule klass, Binding binding, Block.Type type, Block block) {
Binding binding, Type type, Block block) {
RubyProc.prepareArgs(context, type, block.arity(), args);
return yieldInner(context, context.runtime.newArrayNoCopyLight(args), block);
}
@@ -408,7 +408,7 @@ protected IRubyObject doYield(ThreadContext context, IRubyObject value, Binding
}

@Override
protected IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self, RubyModule klass, Binding binding, Type type) {
protected IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self, Binding binding, Type type) {
return yieldInner(context, context.runtime.newArrayNoCopyLight(args), Block.NULL_BLOCK);
}

3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/embed/variable/Argv.java
Original file line number Diff line number Diff line change
@@ -128,7 +128,8 @@ public static boolean isValidName(Object name) {
public void inject() {
updateArgvByJavaObject();
RubyModule rubyModule = getRubyClass(receiver.getRuntime());
if (rubyModule == null) rubyModule = receiver.getRuntime().getCurrentContext().getRubyClass();
// SSS FIXME: With rubyclass stack gone, this needs a replacement
if (rubyModule == null) rubyModule = null; // receiver.getRuntime().getCurrentContext().getRubyClass();
if (rubyModule == null) return;

rubyModule.storeConstant(name, irubyObject);
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/embed/variable/Constant.java
Original file line number Diff line number Diff line change
@@ -218,7 +218,8 @@ public static boolean isValidName(Object name) {
public void inject() {
if (receiver == receiver.getRuntime().getTopSelf()) {
RubyModule rubyModule = getRubyClass(receiver.getRuntime());
if (rubyModule == null) rubyModule = receiver.getRuntime().getCurrentContext().getRubyClass();
// SSS FIXME: With rubyclass stack gone, this needs a replacement
if (rubyModule == null) rubyModule = null; // receiver.getRuntime().getCurrentContext().getRubyClass();
if (rubyModule == null) return;

rubyModule.storeConstant(name, irubyObject);
3 changes: 1 addition & 2 deletions core/src/main/java/org/jruby/ext/fiber/ThreadFiber.java
Original file line number Diff line number Diff line change
@@ -17,7 +17,6 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.Visibility;

import org.jruby.ir.runtime.IRBreakJump;
import org.jruby.ir.runtime.IRReturnJump;
@@ -225,7 +224,7 @@ public void run() {
if (init == NEVER) {
result = block.yieldSpecific(context);
} else {
result = block.yieldArray(context, init, null, null);
result = block.yieldArray(context, init, null);
}

data.prev.data.queue.push(context, result);
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@ public List<String[]> getParameterList() {
protected void post(ThreadContext context) {
// update call stacks (pop: ..)
context.popFrame();
context.popRubyClass();
context.popScope();
}

Original file line number Diff line number Diff line change
@@ -123,7 +123,6 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
protected void post(ThreadContext context) {
// update call stacks (pop: ..)
context.popFrame();
context.popRubyClass();
if (this.pushScope) {
context.popScope();
}
1 change: 0 additions & 1 deletion core/src/main/java/org/jruby/ir/IRScriptBody.java
Original file line number Diff line number Diff line change
@@ -116,7 +116,6 @@ public IRubyObject interpret(ThreadContext context, IRubyObject self) {
} catch (IRBreakJump bj) {
throw IRException.BREAK_LocalJumpError.getException(context.runtime);
} finally {
context.popRubyClass();
context.popScope();
}

Original file line number Diff line number Diff line change
@@ -393,7 +393,6 @@ private static void processBookKeepingOp(ThreadContext context, Instr instr, Ope
break;
case POP_FRAME:
context.popFrame();
context.popRubyClass();
break;
case POP_BINDING:
context.popScope();
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java
Original file line number Diff line number Diff line change
@@ -202,7 +202,7 @@ public static IRubyObject defCompiledIRMethod(ThreadContext context, MethodHandl
Ruby runtime = context.runtime;

// SSS FIXME: this has to be looked up at runtime now
RubyModule containingClass = context.getRubyClass();
RubyModule containingClass = null; // context.getRubyClass();
Visibility currVisibility = context.getCurrentVisibility();
Visibility newVisibility = Helpers.performNormalMethodChecksAndDetermineVisibility(runtime, containingClass, rubyName, currVisibility);

@@ -386,7 +386,7 @@ public static IRubyObject yield(ThreadContext context, Object blk, Object yieldA
if (blk instanceof RubyNil) blk = Block.NULL_BLOCK;
Block b = (Block)blk;
IRubyObject yieldVal = (IRubyObject)yieldArg;
return (unwrapArray && (yieldVal instanceof RubyArray)) ? b.yieldArray(context, yieldVal, null, null) : b.yield(context, yieldVal);
return (unwrapArray && (yieldVal instanceof RubyArray)) ? b.yieldArray(context, yieldVal, null) : b.yield(context, yieldVal);
}

public static IRubyObject yieldSpecific(ThreadContext context, Object blk) {
20 changes: 4 additions & 16 deletions core/src/main/java/org/jruby/runtime/Binding.java
Original file line number Diff line number Diff line change
@@ -49,7 +49,6 @@ public class Binding {
*/
private final Frame frame;
private final BacktraceElement backtrace;
private final RubyModule klass;

private Visibility visibility;
/**
@@ -80,37 +79,34 @@ public class Binding {
private Binding evalScopeBinding = this;

public Binding(IRubyObject self, Frame frame,
Visibility visibility, RubyModule klass, DynamicScope dynamicScope, BacktraceElement backtrace) {
Visibility visibility, DynamicScope dynamicScope, BacktraceElement backtrace) {
this.self = self;
this.frame = frame;
this.visibility = visibility;
this.klass = klass;
this.dynamicScope = dynamicScope;
this.backtrace = backtrace;
}

private Binding(IRubyObject self, Frame frame,
Visibility visibility, RubyModule klass, DynamicScope dynamicScope, BacktraceElement backtrace, DynamicScope dummyScope) {
Visibility visibility, DynamicScope dynamicScope, BacktraceElement backtrace, DynamicScope dummyScope) {
this.self = self;
this.frame = frame;
this.visibility = visibility;
this.klass = klass;
this.dynamicScope = dynamicScope;
this.backtrace = backtrace;
this.dummyScope = dummyScope;
}

public Binding(Frame frame, RubyModule bindingClass, DynamicScope dynamicScope, BacktraceElement backtrace) {
public Binding(Frame frame, DynamicScope dynamicScope, BacktraceElement backtrace) {
this.self = frame.getSelf();
this.frame = frame;
this.visibility = frame.getVisibility();
this.klass = bindingClass;
this.dynamicScope = dynamicScope;
this.backtrace = backtrace;
}

private Binding(Binding other) {
this(other.self, other.frame, other.visibility, other.klass, other.dynamicScope, other.backtrace, other.dummyScope);
this(other.self, other.frame, other.visibility, other.dynamicScope, other.backtrace, other.dummyScope);
}

/**
@@ -179,14 +175,6 @@ public Frame getFrame() {
return frame;
}

/**
* Gets the klass.
* @return Returns a RubyModule
*/
public RubyModule getKlass() {
return klass;
}

public BacktraceElement getBacktrace() {
return backtrace;
}
13 changes: 5 additions & 8 deletions core/src/main/java/org/jruby/runtime/Block.java
Original file line number Diff line number Diff line change
@@ -43,7 +43,6 @@

import org.jruby.EvalType;
import org.jruby.RubyArray;
import org.jruby.RubyModule;
import org.jruby.RubyProc;
import org.jruby.runtime.builtin.IRubyObject;

@@ -148,20 +147,18 @@ public IRubyObject yield(ThreadContext context, IRubyObject value) {
return body.yield(context, value, binding, type);
}

public IRubyObject yieldNonArray(ThreadContext context, IRubyObject value, IRubyObject self,
RubyModule klass) {
return body.yield(context, new IRubyObject[] { value }, self, klass, binding, type);
public IRubyObject yieldNonArray(ThreadContext context, IRubyObject value, IRubyObject self) {
return body.yield(context, new IRubyObject[] { value }, self, binding, type);
}

public IRubyObject yieldArray(ThreadContext context, IRubyObject value, IRubyObject self,
RubyModule klass) {
public IRubyObject yieldArray(ThreadContext context, IRubyObject value, IRubyObject self) {
IRubyObject[] args;
if (!(value instanceof RubyArray)) {
args = new IRubyObject[] { value };
} else {
args = value.convertToArray().toJavaArray();
}
return body.yield(context, args, self, klass, binding, type);
return body.yield(context, args, self, binding, type);
}

public Block cloneBlock() {
@@ -176,7 +173,7 @@ public Block cloneBlock() {
public Block cloneBlockAndFrame() {
Binding oldBinding = binding;
Binding binding = new Binding(
oldBinding.getSelf(), oldBinding.getFrame().duplicate(), oldBinding.getVisibility(), oldBinding.getKlass(), oldBinding.getDynamicScope(), oldBinding.getBacktrace());
oldBinding.getSelf(), oldBinding.getFrame().duplicate(), oldBinding.getVisibility(), oldBinding.getDynamicScope(), oldBinding.getBacktrace());

Block newBlock = new Block(body, binding);

29 changes: 14 additions & 15 deletions core/src/main/java/org/jruby/runtime/BlockBody.java
Original file line number Diff line number Diff line change
@@ -35,7 +35,6 @@

import org.jruby.EvalType;
import org.jruby.RubyArray;
import org.jruby.RubyModule;
import org.jruby.RubyProc;
import org.jruby.ast.IterNode;
import org.jruby.ast.MultipleAsgnNode;
@@ -69,24 +68,24 @@ public void setEvalType(EvalType evalType) {
public IRubyObject call(ThreadContext context, IRubyObject[] args, Binding binding, Block.Type type) {
args = prepareArgumentsForCall(context, args, type);

return yield(context, args, null, null, binding, type);
return yield(context, args, null, binding, type);
}

public IRubyObject call(ThreadContext context, IRubyObject[] args, Binding binding,
Block.Type type, Block block) {
args = prepareArgumentsForCall(context, args, type);

return yield(context, args, null, null, binding, type, block);
return yield(context, args, null, binding, type, block);
}

public final IRubyObject yield(ThreadContext context, IRubyObject value, Binding binding, Block.Type type) {
return doYield(context, value, binding, type);
}

public final IRubyObject yield(ThreadContext context, IRubyObject[] args, IRubyObject self,
RubyModule klass, Binding binding, Block.Type type) {
Binding binding, Block.Type type) {
IRubyObject[] preppedValue = RubyProc.prepareArgs(context, type, arity(), args);
return doYield(context, preppedValue, self, klass, binding, type);
return doYield(context, preppedValue, self, binding, type);
}

/**
@@ -100,17 +99,17 @@ public final IRubyObject yield(ThreadContext context, IRubyObject[] args, IRubyO
/**
* Subclass specific yield implementation.
* <p>
* Should not be called directly. Gets called by {@link #yield(ThreadContext, IRubyObject[], IRubyObject, RubyModule, Binding, Block.Type)}
* Should not be called directly. Gets called by {@link #yield(ThreadContext, org.jruby.runtime.builtin.IRubyObject[], org.jruby.runtime.builtin.IRubyObject, Binding, org.jruby.runtime.Block.Type)}
* after ensuring that all common yield logic is taken care of.
*/
protected abstract IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self,
RubyModule klass, Binding binding, Block.Type type);
Binding binding, Block.Type type);

// FIXME: This should be unified with the final versions above
// Here to allow incremental replacement. Overriden by subclasses which support it.
public IRubyObject yield(ThreadContext context, IRubyObject[] args, IRubyObject self,
RubyModule klass, Binding binding, Block.Type type, Block block) {
return yield(context, args, self, klass, binding, type);
Binding binding, Block.Type type, Block block) {
return yield(context, args, self, binding, type);
}

// FIXME: This should be unified with the final versions above
@@ -128,7 +127,7 @@ public IRubyObject call(ThreadContext context, Binding binding, Block.Type type)
IRubyObject[] args = IRubyObject.NULL_ARRAY;
args = prepareArgumentsForCall(context, args, type);

return yield(context, args, null, null, binding, type);
return yield(context, args, null, binding, type);
}
public IRubyObject call(ThreadContext context, Binding binding,
Block.Type type, Block unusedBlock) {
@@ -142,7 +141,7 @@ public IRubyObject call(ThreadContext context, IRubyObject arg0, Binding binding
IRubyObject[] args = new IRubyObject[] {arg0};
args = prepareArgumentsForCall(context, args, type);

return yield(context, args, null, null, binding, type);
return yield(context, args, null, binding, type);
}
public IRubyObject call(ThreadContext context, IRubyObject arg0, Binding binding,
Block.Type type, Block unusedBlock) {
@@ -156,29 +155,29 @@ public IRubyObject call(ThreadContext context, IRubyObject arg0, IRubyObject arg
IRubyObject[] args = new IRubyObject[] {arg0, arg1};
args = prepareArgumentsForCall(context, args, type);

return yield(context, args, null, null, binding, type);
return yield(context, args, null, binding, type);
}
public IRubyObject call(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Binding binding,
Block.Type type, Block unusedBlock) {
return call(context, arg0, arg1, binding, type);
}

public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Binding binding, Block.Type type) {
return yield(context, new IRubyObject[] { arg0, arg1 }, null, null, binding, type);
return yield(context, new IRubyObject[] { arg0, arg1 }, null, binding, type);
}
public IRubyObject call(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Binding binding, Block.Type type) {
IRubyObject[] args = new IRubyObject[] {arg0, arg1, arg2};
args = prepareArgumentsForCall(context, args, type);

return yield(context, args, null, null, binding, type);
return yield(context, args, null, binding, type);
}
public IRubyObject call(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Binding binding,
Block.Type type, Block unusedBlock) {
return call(context, arg0, arg1, arg2, binding, type);
}

public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Binding binding, Block.Type type) {
return yield(context, new IRubyObject[] { arg0, arg1, arg2 }, null, null, binding, type);
return yield(context, new IRubyObject[] { arg0, arg1, arg2 }, null, binding, type);
}


2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/runtime/CallBlock.java
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ protected IRubyObject doYield(ThreadContext context, IRubyObject value, Binding

@Override
protected IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self,
RubyModule klass, Binding binding, Block.Type type) {
Binding binding, Block.Type type) {
return callback.call(context, args, Block.NULL_BLOCK);
}

3 changes: 1 addition & 2 deletions core/src/main/java/org/jruby/runtime/CallBlock19.java
Original file line number Diff line number Diff line change
@@ -96,12 +96,11 @@ protected IRubyObject doYield(ThreadContext context, IRubyObject value, Binding
* @param context represents the current thread-specific data
* @param args The args to yield
* @param self The current self
* @param klass
* @return
*/
@Override
protected IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self,
RubyModule klass, Binding binding, Block.Type type) {
Binding binding, Block.Type type) {
return callback.call(context, args, Block.NULL_BLOCK);
}

20 changes: 9 additions & 11 deletions core/src/main/java/org/jruby/runtime/CompiledBlock.java
Original file line number Diff line number Diff line change
@@ -29,7 +29,6 @@

import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyModule;
import org.jruby.RubyProc;
import org.jruby.ast.util.ArgsUtil;
import org.jruby.common.IRubyWarnings.ID;
@@ -83,12 +82,12 @@ public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, Bindin

@Override
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Binding binding, Block.Type type) {
return yield(context, new IRubyObject[] { arg0, arg1 }, null, null, binding, type);
return yield(context, new IRubyObject[] { arg0, arg1 }, null, binding, type);
}

@Override
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Binding binding, Block.Type type) {
return yield(context, new IRubyObject[] { arg0, arg1, arg2 }, null, null, binding, type);
return yield(context, new IRubyObject[] { arg0, arg1, arg2 }, null, binding, type);
}

@Override
@@ -97,8 +96,8 @@ protected IRubyObject doYield(ThreadContext context, IRubyObject value, Binding
}

@Override
protected IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self, RubyModule klass, Binding binding, Block.Type type) {
return yield(context, args, self, klass, binding, type, Block.NULL_BLOCK);
protected IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self, Binding binding, Block.Type type) {
return yield(context, args, self, binding, type, Block.NULL_BLOCK);
}

// FIXME: These two duplicate overrides should go away
@@ -108,7 +107,7 @@ public IRubyObject yield(ThreadContext context, IRubyObject value, Binding bindi

IRubyObject realArg = setupBlockArg(context.runtime, value, self);
Visibility oldVis = binding.getFrame().getVisibility();
Frame lastFrame = pre(context, null, binding);
Frame lastFrame = pre(context, binding);

try {
return callback.call(context, self, realArg, block);
@@ -120,16 +119,15 @@ public IRubyObject yield(ThreadContext context, IRubyObject value, Binding bindi
}

@Override
public IRubyObject yield(ThreadContext context, IRubyObject[] args, IRubyObject self, RubyModule klass, Binding binding, Block.Type type, Block block) {
if (klass == null) {
self = prepareSelf(binding);
}
public IRubyObject yield(ThreadContext context, IRubyObject[] args, IRubyObject self, Binding binding, Block.Type type, Block block) {
// SSS FIXME: This is now being done unconditionally compared to if (klass == null) earlier
self = prepareSelf(binding);

IRubyObject[] preppedArgs = RubyProc.prepareArgs(context, type, arity, args);
RubyArray value = context.runtime.newArrayNoCopyLight(preppedArgs);
IRubyObject realArg = setupBlockArgs(context, value, self);
Visibility oldVis = binding.getFrame().getVisibility();
Frame lastFrame = pre(context, klass, binding);
Frame lastFrame = pre(context, binding);

try {
return callback.call(context, self, realArg, block);
22 changes: 10 additions & 12 deletions core/src/main/java/org/jruby/runtime/CompiledBlock19.java
Original file line number Diff line number Diff line change
@@ -28,7 +28,6 @@
package org.jruby.runtime;

import org.jruby.Ruby;
import org.jruby.RubyModule;
import org.jruby.RubyProc;
import org.jruby.exceptions.JumpException;
import org.jruby.parser.StaticScope;
@@ -80,12 +79,12 @@ public CompiledBlock19(Arity arity, StaticScope scope, CompiledBlockCallback19 c

@Override
public IRubyObject call(ThreadContext context, IRubyObject[] args, Binding binding, Block.Type type) {
return yield(context, args, null, null, binding, type, Block.NULL_BLOCK);
return yield(context, args, null, binding, type, Block.NULL_BLOCK);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject[] args, Binding binding, Block.Type type, Block block) {
return yield(context, args, null, null, binding, type, block);
return yield(context, args, null, binding, type, block);
}

@Override
@@ -112,7 +111,7 @@ private IRubyObject yieldSpecificInternal(ThreadContext context, IRubyObject[] a
IRubyObject self = prepareSelf(binding);

Visibility oldVis = binding.getFrame().getVisibility();
Frame lastFrame = pre(context, null, binding);
Frame lastFrame = pre(context, binding);

try {
return callback.call(context, self, args, Block.NULL_BLOCK);
@@ -128,7 +127,7 @@ protected IRubyObject doYield(ThreadContext context, IRubyObject value, Binding
IRubyObject self = prepareSelf(binding);

Visibility oldVis = binding.getFrame().getVisibility();
Frame lastFrame = pre(context, null, binding);
Frame lastFrame = pre(context, binding);

try {
IRubyObject[] realArgs = setupBlockArg(context.runtime, value, self, type);
@@ -141,18 +140,17 @@ protected IRubyObject doYield(ThreadContext context, IRubyObject value, Binding
}

@Override
protected IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self, RubyModule klass, Binding binding, Block.Type type) {
return yield(context, args, self, klass, binding, type, Block.NULL_BLOCK);
protected IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self, Binding binding, Block.Type type) {
return yield(context, args, self, binding, type, Block.NULL_BLOCK);
}

@Override
public IRubyObject yield(ThreadContext context, IRubyObject[] args, IRubyObject self, RubyModule klass, Binding binding, Block.Type type, Block block) {
if (klass == null) {
self = prepareSelf(binding);
}
public IRubyObject yield(ThreadContext context, IRubyObject[] args, IRubyObject self, Binding binding, Block.Type type, Block block) {
// SSS FIXME: This is now being done unconditionally compared to if (klass == null) earlier
self = prepareSelf(binding);

Visibility oldVis = binding.getFrame().getVisibility();
Frame lastFrame = pre(context, klass, binding);
Frame lastFrame = pre(context, binding);

try {
IRubyObject[] preppedArgs = RubyProc.prepareArgs(context, type, arity, args);
5 changes: 2 additions & 3 deletions core/src/main/java/org/jruby/runtime/CompiledBlockLight.java
Original file line number Diff line number Diff line change
@@ -27,7 +27,6 @@
***** END LICENSE BLOCK *****/
package org.jruby.runtime;

import org.jruby.RubyModule;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.builtin.IRubyObject;

@@ -55,8 +54,8 @@ protected CompiledBlockLight(Arity arity, StaticScope scope, CompiledBlockCallba
}

@Override
protected Frame pre(ThreadContext context, RubyModule klass, Binding binding) {
return context.preYieldLightBlock(binding, binding.getDummyScope(scope), klass);
protected Frame pre(ThreadContext context, Binding binding) {
return context.preYieldLightBlock(binding, binding.getDummyScope(scope));
}

@Override
Original file line number Diff line number Diff line change
@@ -27,7 +27,6 @@
***** END LICENSE BLOCK *****/
package org.jruby.runtime;

import org.jruby.RubyModule;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.builtin.IRubyObject;

@@ -55,8 +54,8 @@ protected CompiledBlockLight19(Arity arity, StaticScope scope, CompiledBlockCall
}

@Override
protected Frame pre(ThreadContext context, RubyModule klass, Binding binding) {
return context.preYieldLightBlock(binding, binding.getDummyScope(scope), klass);
protected Frame pre(ThreadContext context, Binding binding) {
return context.preYieldLightBlock(binding, binding.getDummyScope(scope));
}

@Override
14 changes: 4 additions & 10 deletions core/src/main/java/org/jruby/runtime/CompiledIRBlockBody.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package org.jruby.runtime;

import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyModule;
import org.jruby.common.IRubyWarnings;
import org.jruby.ir.IRClosure;
import org.jruby.ir.interpreter.Interpreter;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Block.Type;
import org.jruby.runtime.builtin.IRubyObject;
@@ -27,7 +20,7 @@ public CompiledIRBlockBody(StaticScope staticScope, String[] parameterList, Stri
this.sharedScope = sharedScope;
}

protected IRubyObject commonYieldPath(ThreadContext context, IRubyObject[] args, IRubyObject self, RubyModule klass, Binding binding, Type type, Block block) {
protected IRubyObject commonYieldPath(ThreadContext context, IRubyObject[] args, IRubyObject self, Binding binding, Type type, Block block) {
// SSS: Important! Use getStaticScope() to use a copy of the static-scope stored in the block-body.
// Do not use 'closure.getStaticScope()' -- that returns the original copy of the static scope.
// This matters because blocks created for Thread bodies modify the static-scope field of the block-body
@@ -36,8 +29,9 @@ protected IRubyObject commonYieldPath(ThreadContext context, IRubyObject[] args,
// FIXME: Rather than modify static-scope, it seems we ought to set a field in block-body which is then
// used to tell dynamic-scope that it is a dynamic scope for a thread body. Anyway, to be revisited later!
Visibility oldVis = binding.getFrame().getVisibility();
Frame prevFrame = context.preYieldNoScope(binding, klass);
if (klass == null) self = prepareSelf(binding);
Frame prevFrame = context.preYieldNoScope(binding);
// SSS FIXME: This is now being done unconditionally compared to if (klass == null) earlier
self = prepareSelf(binding);
try {
DynamicScope prevScope = binding.getDynamicScope();
DynamicScope newScope = sharedScope ? prevScope : DynamicScope.newDynamicScope(getStaticScope(), prevScope);
Original file line number Diff line number Diff line change
@@ -27,7 +27,6 @@
***** END LICENSE BLOCK *****/
package org.jruby.runtime;

import org.jruby.RubyModule;
import org.jruby.runtime.builtin.IRubyObject;

/**
@@ -49,8 +48,8 @@ private CompiledSharedScopeBlock(Arity arity, DynamicScope containingScope, Comp
}

@Override
protected Frame pre(ThreadContext context, RubyModule klass, Binding binding) {
return context.preForBlock(binding, klass);
protected Frame pre(ThreadContext context, Binding binding) {
return context.preForBlock(binding);
}

@Override
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jruby.runtime;

import org.jruby.RubyModule;
import org.jruby.parser.StaticScope;

/**
@@ -20,8 +19,8 @@ public ContextAwareBlockBody(StaticScope scope, Arity arity, int argumentType) {
this.arity = arity;
}

protected Frame pre(ThreadContext context, RubyModule klass, Binding binding) {
return context.preYieldSpecificBlock(binding, scope, klass);
protected Frame pre(ThreadContext context, Binding binding) {
return context.preYieldSpecificBlock(binding, scope);
}

protected void post(ThreadContext context, Binding binding, Visibility vis, Frame lastFrame) {
12 changes: 5 additions & 7 deletions core/src/main/java/org/jruby/runtime/Helpers.java
Original file line number Diff line number Diff line change
@@ -298,14 +298,13 @@ public static IRubyObject def(ThreadContext context, IRubyObject self, Object sc
Class compiledClass = scriptObject.getClass();
Ruby runtime = context.runtime;

RubyModule containingClass = context.getRubyClass();
Visibility currVisibility = context.getCurrentVisibility();
Visibility newVisibility = performNormalMethodChecksAndDetermineVisibility(runtime, containingClass, rubyName, currVisibility);
Visibility newVisibility = performNormalMethodChecksAndDetermineVisibility(runtime, null, rubyName, currVisibility);

MethodFactory factory = MethodFactory.createFactory(compiledClass.getClassLoader());
DynamicMethod method = constructNormalMethod(
factory, javaName,
rubyName, containingClass, new SimpleSourcePosition(filename, line), arity, scope, newVisibility, scriptObject,
rubyName, null, new SimpleSourcePosition(filename, line), arity, scope, newVisibility, scriptObject,
callConfig,
parameterDesc,
methodNodes);
@@ -316,7 +315,7 @@ rubyName, containingClass, new SimpleSourcePosition(filename, line), arity, scop
((CompiledMethod) method).unsafeSetMethodNodes(methodNodes);
}

return addInstanceMethod(containingClass, rubyName, method, currVisibility, context, runtime);
return addInstanceMethod(null, rubyName, method, currVisibility, context, runtime);
}

public static IRubyObject defs(ThreadContext context, IRubyObject self, IRubyObject receiver, Object scriptObject, String rubyName, String javaName, StaticScope scope,
@@ -1639,8 +1638,7 @@ public static RubyHash constructSmallHash(Ruby runtime,
}

public static IRubyObject undefMethod(ThreadContext context, Object nameArg) {
RubyModule module = context.getRubyClass();

RubyModule module = null; // context.getRubyClass();
String name = (nameArg instanceof String) ?
(String) nameArg : nameArg.toString();

@@ -1655,7 +1653,7 @@ public static IRubyObject undefMethod(ThreadContext context, Object nameArg) {

public static IRubyObject defineAlias(ThreadContext context, IRubyObject self, Object newNameArg, Object oldNameArg) {
Ruby runtime = context.runtime;
RubyModule module = context.getRubyClass();
RubyModule module = null; // context.getRubyClass();

if (module == null || self instanceof RubyFixnum || self instanceof RubySymbol){
throw runtime.newTypeError("no class to make alias");
21 changes: 9 additions & 12 deletions core/src/main/java/org/jruby/runtime/IRBlockBody.java
Original file line number Diff line number Diff line change
@@ -3,10 +3,7 @@
import org.jruby.EvalType;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyModule;
import org.jruby.common.IRubyWarnings.ID;
import org.jruby.ir.IRClosure;
import org.jruby.ir.interpreter.Interpreter;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Block.Type;
@@ -66,7 +63,7 @@ public IRubyObject call(ThreadContext context, IRubyObject[] args, Binding bindi

@Override
public IRubyObject call(ThreadContext context, IRubyObject[] args, Binding binding, Type type, Block block) {
return commonYieldPath(context, prepareArgumentsForCall(context, args, type), null, null, binding, type, block);
return commonYieldPath(context, prepareArgumentsForCall(context, args, type), null, binding, type, block);
}

@Override
@@ -75,7 +72,7 @@ public IRubyObject yieldSpecific(ThreadContext context, Binding binding, Type ty
if (type == Type.LAMBDA) {
arity().checkArity(context.runtime, args);
}
return commonYieldPath(context, args, null, null, binding, type, Block.NULL_BLOCK);
return commonYieldPath(context, args, null, binding, type, Block.NULL_BLOCK);
}

@Override
@@ -89,7 +86,7 @@ public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, Bindin
} else {
args = IRRuntimeHelpers.convertValueIntoArgArray(context, arg0, arity, true, true);
}
return commonYieldPath(context, args, null, null, binding, type, Block.NULL_BLOCK);
return commonYieldPath(context, args, null, binding, type, Block.NULL_BLOCK);
} else {
return yield(context, arg0, binding, type);
}
@@ -106,7 +103,7 @@ private IRubyObject yieldSpecificMultiArgsCommon(ThreadContext context, IRubyObj
args = new IRubyObject[] { RubyArray.newArrayNoCopy(context.runtime, args) };
}
}
return commonYieldPath(context, args, null, null, binding, type, Block.NULL_BLOCK);
return commonYieldPath(context, args, null, binding, type, Block.NULL_BLOCK);
}

@Override
@@ -137,26 +134,26 @@ public IRubyObject doYield(ThreadContext context, IRubyObject value, Binding bin
args = ((RubyArray)val0).toJavaArray();
}
}
return commonYieldPath(context, args, null, null, binding, type, Block.NULL_BLOCK);
return commonYieldPath(context, args, null, binding, type, Block.NULL_BLOCK);
}

@Override
public IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self, RubyModule klass, Binding binding, Type type) {
public IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self, Binding binding, Type type) {
args = (args == null) ? IRubyObject.NULL_ARRAY : args;
if (type == Type.LAMBDA) {
arity().checkArity(context.runtime, args);
}
return commonYieldPath(context, args, self, klass, binding, type, Block.NULL_BLOCK);
return commonYieldPath(context, args, self, binding, type, Block.NULL_BLOCK);
}

protected IRubyObject prepareSelf(Binding binding) {
protected IRubyObject useBindingSelf(Binding binding) {
IRubyObject self = binding.getSelf();
binding.getFrame().setSelf(self);

return self;
}

protected abstract IRubyObject commonYieldPath(ThreadContext context, IRubyObject[] args, IRubyObject self, RubyModule klass, Binding binding, Type type, Block block);
protected abstract IRubyObject commonYieldPath(ThreadContext context, IRubyObject[] args, IRubyObject self, Binding binding, Type type, Block block);

protected void blockArgWarning(Ruby ruby, int length) {
ruby.getWarnings().warn(ID.MULTIPLE_VALUES_FOR_BLOCK, "multiple values for a block parameter (" +
26 changes: 11 additions & 15 deletions core/src/main/java/org/jruby/runtime/Interpreted19Block.java
Original file line number Diff line number Diff line change
@@ -28,9 +28,7 @@
package org.jruby.runtime;

import org.jruby.Ruby;
import org.jruby.RubyModule;
import org.jruby.RubyProc;
import org.jruby.ast.ArgsNoArgNode;
import org.jruby.ast.ArgsNode;
import org.jruby.ast.IterNode;
import org.jruby.ast.LambdaNode;
@@ -117,12 +115,12 @@ public Interpreted19Block(LambdaNode lambdaNode) {

@Override
public IRubyObject call(ThreadContext context, IRubyObject[] args, Binding binding, Block.Type type) {
return yield(context, args, null, null, binding, type, Block.NULL_BLOCK);
return yield(context, args, null, binding, type, Block.NULL_BLOCK);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject[] args, Binding binding, Block.Type type, Block block) {
return yield(context, args, null, null, binding, type, block);
return yield(context, args, null, binding, type, block);
}

@Override
@@ -137,20 +135,20 @@ public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, Bindin

@Override
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Binding binding, Block.Type type) {
return yield(context, new IRubyObject[] { arg0, arg1 }, null, null, binding, type);
return yield(context, new IRubyObject[] { arg0, arg1 }, null, binding, type);
}

@Override
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Binding binding, Block.Type type) {
return yield(context, new IRubyObject[] { arg0, arg1, arg2 }, null, null, binding, type);
return yield(context, new IRubyObject[] { arg0, arg1, arg2 }, null, binding, type);
}

@Override
protected IRubyObject doYield(ThreadContext context, IRubyObject value, Binding binding, Block.Type type) {
IRubyObject self = prepareSelf(binding);

Visibility oldVis = binding.getFrame().getVisibility();
Frame lastFrame = pre(context, null, binding);
Frame lastFrame = pre(context, binding);

try {
setupBlockArg(context, value, self, Block.NULL_BLOCK, type);
@@ -169,25 +167,23 @@ protected IRubyObject doYield(ThreadContext context, IRubyObject value, Binding
* @param context represents the current thread-specific data
* @param args The args for yield
* @param self The current self
* @param klass
* @return
*/
@Override
protected IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self,
RubyModule klass, Binding binding, Block.Type type) {
return yield(context, args, self, klass, binding, type, Block.NULL_BLOCK);
Binding binding, Block.Type type) {
return yield(context, args, self, binding, type, Block.NULL_BLOCK);

}

@Override
public IRubyObject yield(ThreadContext context, IRubyObject[] args, IRubyObject self,
RubyModule klass, Binding binding, Block.Type type, Block block) {
if (klass == null) {
self = prepareSelf(binding);
}
Binding binding, Block.Type type, Block block) {
// SSS FIXME: This is now being done unconditionally compared to if (klass == null) earlier
self = prepareSelf(binding);

Visibility oldVis = binding.getFrame().getVisibility();
Frame lastFrame = pre(context, klass, binding);
Frame lastFrame = pre(context, binding);

try {
IRubyObject[] preppedArgs = RubyProc.prepareArgs(context, type, arity, args);
11 changes: 7 additions & 4 deletions core/src/main/java/org/jruby/runtime/InterpretedIRBlockBody.java
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.ir.IRClosure;
import org.jruby.ir.interpreter.Interpreter;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.runtime.Block.Type;
import org.jruby.runtime.builtin.IRubyObject;

@@ -19,7 +18,7 @@ public InterpretedIRBlockBody(IRClosure closure, Arity arity, int argumentType)
this.closure = closure;
}

protected IRubyObject commonYieldPath(ThreadContext context, IRubyObject[] args, IRubyObject self, RubyModule klass, Binding binding, Type type, Block block) {
protected IRubyObject commonYieldPath(ThreadContext context, IRubyObject[] args, IRubyObject self, Binding binding, Type type, Block block) {
// SSS: Important! Use getStaticScope() to use a copy of the static-scope stored in the block-body.
// Do not use 'closure.getStaticScope()' -- that returns the original copy of the static scope.
// This matters because blocks created for Thread bodies modify the static-scope field of the block-body
@@ -28,8 +27,12 @@ protected IRubyObject commonYieldPath(ThreadContext context, IRubyObject[] args,
// FIXME: Rather than modify static-scope, it seems we ought to set a field in block-body which is then
// used to tell dynamic-scope that it is a dynamic scope for a thread body. Anyway, to be revisited later!
Visibility oldVis = binding.getFrame().getVisibility();
Frame prevFrame = context.preYieldNoScope(binding, klass);
if (klass == null) self = prepareSelf(binding);
Frame prevFrame = context.preYieldNoScope(binding);

// SSS FIXME: Why is self null in non-binding-eval contexts?
if (self == null || this.evalType == EvalType.BINDING_EVAL) {
self = useBindingSelf(binding);
}
DynamicScope newScope = null;
try {
DynamicScope prevScope = binding.getDynamicScope();
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@
package org.jruby.runtime;

import org.jruby.Ruby;
import org.jruby.RubyModule;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Block.Type;
import org.jruby.runtime.builtin.IRubyObject;
@@ -49,13 +48,13 @@ private void threadCheck(ThreadContext yieldingContext) {

@Override
public IRubyObject call(ThreadContext context, IRubyObject[] args, Binding binding, Block.Type type) {
return yield(context, args, null, null, binding, type);
return yield(context, args, null, binding, type);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject[] args, Binding binding,
Block.Type type, Block block) {
return yield(context, args, null, null, binding, type, block);
return yield(context, args, null, binding, type, block);
}

@Override
@@ -66,7 +65,7 @@ protected IRubyObject doYield(ThreadContext context, IRubyObject value, Binding
}

@Override
protected IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self, RubyModule klass, Binding binding, Type type) {
protected IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self, Binding binding, Type type) {
threadCheck(context);

return yield(context, args);
35 changes: 19 additions & 16 deletions core/src/main/java/org/jruby/runtime/MethodBlock.java
Original file line number Diff line number Diff line change
@@ -59,7 +59,6 @@ public static Block createMethodBlock(ThreadContext context, IRubyObject self, D

Binding binding = new Binding(
frame,
module,
dynamicScope,
new BacktraceElement(method.getMethodName(), body.getFile(), body.getLine()));

@@ -80,17 +79,17 @@ public MethodBlock(RubyMethod method, StaticScope staticScope) {

@Override
public IRubyObject call(ThreadContext context, IRubyObject[] args, Binding binding, Block.Type type) {
return yield(context, args, null, null, binding, type, Block.NULL_BLOCK);
return yield(context, args, null, binding, type, Block.NULL_BLOCK);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject[] args, Binding binding, Block.Type type, Block block) {
return yield(context, args, null, null, binding, type, block);
return yield(context, args, null, binding, type, block);
}

@Override
protected Frame pre(ThreadContext context, RubyModule klass, Binding binding) {
return context.preYieldNoScope(binding, klass);
protected Frame pre(ThreadContext context, Binding binding) {
return context.preYieldNoScope(binding);
}

@Override
@@ -110,12 +109,12 @@ public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, Bindin

@Override
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Binding binding, Block.Type type) {
return yield(context, new IRubyObject[] { arg0, arg1 }, null, null, binding, type);
return yield(context, new IRubyObject[] { arg0, arg1 }, null, binding, type);
}

@Override
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Binding binding, Block.Type type) {
return yield(context, new IRubyObject[] { arg0, arg1, arg2 }, null, null, binding, type);
return yield(context, new IRubyObject[] { arg0, arg1, arg2 }, null, binding, type);
}

@Override
@@ -130,8 +129,15 @@ public IRubyObject yield(ThreadContext context, IRubyObject value, Binding bindi

@Override
protected IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self,
RubyModule klass, Binding binding, Block.Type type) {
return yield(context, args, self, klass, binding, type, Block.NULL_BLOCK);
Binding binding, Block.Type type) {
return yield(context, args, self, binding, type, Block.NULL_BLOCK);
}

protected IRubyObject prepareSelf(Binding binding) {
IRubyObject self = binding.getSelf();
binding.getFrame().setSelf(self);

return self;
}

/**
@@ -140,18 +146,15 @@ protected IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyOb
* @param context represents the current thread-specific data
* @param args The args for yield
* @param self The current self
* @param klass
* @return
*/
@Override
public IRubyObject yield(ThreadContext context, IRubyObject[] args, IRubyObject self,
RubyModule klass, Binding binding, Block.Type type, Block block) {
if (klass == null) {
self = binding.getSelf();
binding.getFrame().setSelf(self);
}
Binding binding, Block.Type type, Block block) {
// SSS FIXME: This is now being done unconditionally compared to if (klass == null) earlier
self = prepareSelf(binding);

Frame lastFrame = pre(context, klass, binding);
Frame lastFrame = pre(context, binding);

try {
// This while loop is for restarting the block call in case a 'redo' fires.
3 changes: 1 addition & 2 deletions core/src/main/java/org/jruby/runtime/NullBlockBody.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.jruby.runtime;

import org.jruby.RubyLocalJumpError;
import org.jruby.RubyModule;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Block.Type;
import org.jruby.runtime.builtin.IRubyObject;
@@ -55,7 +54,7 @@ protected IRubyObject doYield(ThreadContext context, IRubyObject value, Binding
}

@Override
protected IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self, RubyModule klass, Binding binding, Type type) {
protected IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self, Binding binding, Type type) {
throw context.runtime.newLocalJumpError(RubyLocalJumpError.Reason.NOREASON, args[0], "yield called out of block");
}

112 changes: 15 additions & 97 deletions core/src/main/java/org/jruby/runtime/ThreadContext.java
Original file line number Diff line number Diff line change
@@ -50,7 +50,6 @@
import org.jruby.ir.IRScopeType;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.parser.IRStaticScope;
import org.jruby.parser.StaticScope;
import org.jruby.parser.IRStaticScope;
import org.jruby.runtime.backtrace.BacktraceElement;
@@ -103,10 +102,7 @@ public static ThreadContext newContext(Ruby runtime) {
private ThreadFiber rootFiber; // hard anchor for root threads' fibers
// Cache format string because it is expensive to create on demand
private RubyDateFormatter dateFormatter;

private RubyModule[] parentStack = new RubyModule[INITIAL_SIZE];
private int parentIndex = -1;


private Frame[] frameStack = new Frame[INITIAL_FRAMES_SIZE];
private int frameIndex = -1;

@@ -286,16 +282,7 @@ private Frame[] fillNewFrameStack(Frame[] newFrameStack, int newSize) {

return newFrameStack;
}

private void expandParentStack() {
int newSize = parentStack.length * 2;
RubyModule[] newParentStack = new RubyModule[newSize];

System.arraycopy(parentStack, 0, newParentStack, 0, parentStack.length);

parentStack = newParentStack;
}

public void pushScope(DynamicScope scope) {
int index = ++scopeIndex;
DynamicScope[] stack = scopeStack;
@@ -681,41 +668,6 @@ public void trace(RubyEvent event, String name, RubyModule implClass) {
public void trace(RubyEvent event, String name, RubyModule implClass, String file, int line) {
runtime.callEventHooks(this, event, file, line, name, implClass);
}

public void pushRubyClass(RubyModule currentModule) {
// FIXME: this seems like a good assertion, but it breaks compiled code and the code seems
// to run without it...
//assert currentModule != null : "Can't push null RubyClass";
// int index = ++parentIndex;
// RubyModule[] stack = parentStack;
// stack[index] = currentModule;
// if (index + 1 == stack.length) {
// expandParentStack();
// }
}

public RubyModule popRubyClass() {
// int index = parentIndex;
// RubyModule[] stack = parentStack;
// RubyModule ret = stack[index];
// stack[index] = null;
// parentIndex = index - 1;
// return ret;
return null;
}

public RubyModule getRubyClass() {
// assert parentIndex != -1 : "Trying to get RubyClass from empty stack";
// RubyModule parentModule = parentStack[parentIndex];
// return parentModule.getNonIncludedClass();
return null;
}

public RubyModule getPreviousRubyClass() {
assert parentIndex != 0 : "Trying to getService RubyClass from too-shallow stack";
RubyModule parentModule = parentStack[parentIndex - 1];
return parentModule.getNonIncludedClass();
}

@Deprecated
public boolean getConstantDefined(String internedName) {
@@ -969,24 +921,20 @@ private Frame pushFrameForEval(Binding binding) {

public void preAdoptThread() {
pushFrame();
pushRubyClass(runtime.getObject());
getCurrentFrame().setSelf(runtime.getTopSelf());
}

public void preExtensionLoad(IRubyObject self) {
pushFrame();
pushRubyClass(runtime.getObject());
getCurrentFrame().setSelf(self);
getCurrentFrame().setVisibility(Visibility.PUBLIC);
}

public void postExtensionLoad() {
popFrame();
popRubyClass();
}

public void preCompiledClass(RubyModule type, StaticScope staticScope) {
pushRubyClass(type);
pushFrameCopy();
getCurrentFrame().setSelf(type);
getCurrentFrame().setVisibility(Visibility.PUBLIC);
@@ -995,7 +943,6 @@ public void preCompiledClass(RubyModule type, StaticScope staticScope) {
}

public void preCompiledClassDummyScope(RubyModule type, StaticScope staticScope) {
pushRubyClass(type);
pushFrameCopy();
getCurrentFrame().setSelf(type);
getCurrentFrame().setVisibility(Visibility.PUBLIC);
@@ -1005,7 +952,6 @@ public void preCompiledClassDummyScope(RubyModule type, StaticScope staticScope)

public void postCompiledClass() {
popScope();
popRubyClass();
popFrame();
}

@@ -1018,7 +964,6 @@ public void postScopeNode() {
}

public void preClassEval(StaticScope staticScope, RubyModule type) {
pushRubyClass(type);
pushFrameCopy();
getCurrentFrame().setSelf(type);
getCurrentFrame().setVisibility(Visibility.PUBLIC);
@@ -1029,7 +974,6 @@ public void preClassEval(StaticScope staticScope, RubyModule type) {

public void postClassEval() {
popScope();
popRubyClass();
popFrame();
}

@@ -1048,14 +992,12 @@ public void preMethodFrameAndClass(RubyModule implClass, String name, IRubyObjec
RubyModule ssModule = staticScope.getModule();
// FIXME: This is currently only here because of some problems with IOOutputStream writing to a "bare" runtime without a proper scope
if (ssModule == null) ssModule = implClass;
pushRubyClass(ssModule);
pushCallFrame(implClass, name, self, block);
}

// FIXME: This may not be correct for RubyClass in all cases
public void preMethodFrameAndClass(String name, IRubyObject self, Block block, StaticScope staticScope) {
RubyModule ssModule = staticScope.getModule();
pushRubyClass(ssModule);
pushCallFrame(ssModule, name, self, block);
}

@@ -1068,7 +1010,6 @@ public void preMethodFrameAndScope(RubyModule clazz, String name, IRubyObject se
}
pushCallFrame(clazz, name, self, block);
pushScope(DynamicScope.newDynamicScope(staticScope));
pushRubyClass(implementationClass);
}

public void preMethodFrameAndDummyScope(RubyModule clazz, String name, IRubyObject self, Block block,
@@ -1080,7 +1021,6 @@ public void preMethodFrameAndDummyScope(RubyModule clazz, String name, IRubyObje
}
pushCallFrame(clazz, name, self, block);
pushScope(staticScope.getDummyScope());
pushRubyClass(implementationClass);
}

public void preMethodNoFrameAndDummyScope(RubyModule clazz, StaticScope staticScope) {
@@ -1090,23 +1030,19 @@ public void preMethodNoFrameAndDummyScope(RubyModule clazz, StaticScope staticSc
implementationClass = clazz;
}
pushScope(staticScope.getDummyScope());
pushRubyClass(implementationClass);
}

public void postMethodFrameAndScope() {
popRubyClass();
popScope();
popFrame();
}

public void preMethodFrameOnly(RubyModule clazz, String name, IRubyObject self, Block block) {
pushRubyClass(clazz);
pushCallFrame(clazz, name, self, block);
}

public void postMethodFrameOnly() {
popFrame();
popRubyClass();
}

public void preMethodScopeOnly(RubyModule clazz, StaticScope staticScope) {
@@ -1116,11 +1052,9 @@ public void preMethodScopeOnly(RubyModule clazz, StaticScope staticScope) {
implementationClass = clazz;
}
pushScope(DynamicScope.newDynamicScope(staticScope));
pushRubyClass(implementationClass);
}

public void postMethodScopeOnly() {
popRubyClass();
popScope();
}

@@ -1142,49 +1076,40 @@ public void preMethodBacktraceDummyScope(RubyModule clazz, String name, StaticSc
implementationClass = clazz;
}
pushScope(staticScope.getDummyScope());
pushRubyClass(implementationClass);
}

public void postMethodBacktraceOnly() {
}

public void postMethodBacktraceDummyScope() {
popRubyClass();
popScope();
}

public void prepareTopLevel(RubyClass objectClass, IRubyObject topSelf) {
pushFrame();
setCurrentVisibility(Visibility.PRIVATE);

pushRubyClass(objectClass);

Frame frame = getCurrentFrame();
frame.setSelf(topSelf);

getCurrentScope().getStaticScope().setModule(objectClass);
}

public void preNodeEval(RubyModule rubyClass, IRubyObject self, String name) {
pushRubyClass(rubyClass);
pushEvalFrame(self);
}

public void preNodeEval(RubyModule rubyClass, IRubyObject self) {
pushRubyClass(rubyClass);
pushEvalFrame(self);
}

public void postNodeEval() {
popFrame();
popRubyClass();
}

// 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 = runtime.getStaticScopeFactory().newBlockScope(scope.getStaticScope());
sScope.setModule(executeUnderClass);
@@ -1196,7 +1121,6 @@ public void preExecuteUnder(RubyModule executeUnderClass, Block block) {
public void postExecuteUnder() {
popFrame();
popScope();
popRubyClass();
}

public void preMproc() {
@@ -1217,28 +1141,27 @@ public void postTrace() {
setWithinTrace(false);
}

public Frame preForBlock(Binding binding, RubyModule klass) {
Frame lastFrame = preYieldNoScope(binding, klass);
public Frame preForBlock(Binding binding) {
Frame lastFrame = preYieldNoScope(binding);
pushScope(binding.getDynamicScope());
return lastFrame;
}

public Frame preYieldSpecificBlock(Binding binding, StaticScope scope, RubyModule klass) {
Frame lastFrame = preYieldNoScope(binding, klass);
public Frame preYieldSpecificBlock(Binding binding, StaticScope scope) {
Frame lastFrame = preYieldNoScope(binding);
// new scope for this invocation of the block, based on parent scope
pushScope(DynamicScope.newDynamicScope(scope, binding.getDynamicScope()));
return lastFrame;
}

public Frame preYieldLightBlock(Binding binding, DynamicScope emptyScope, RubyModule klass) {
Frame lastFrame = preYieldNoScope(binding, klass);
public Frame preYieldLightBlock(Binding binding, DynamicScope emptyScope) {
Frame lastFrame = preYieldNoScope(binding);
// just push the same empty scope, since we won't use one
pushScope(emptyScope);
return lastFrame;
}

public Frame preYieldNoScope(Binding binding, RubyModule klass) {
pushRubyClass((klass != null) ? klass : binding.getKlass());
public Frame preYieldNoScope(Binding binding) {
return pushFrameForBlock(binding);
}

@@ -1252,30 +1175,25 @@ public void postEvalScriptlet() {

public Frame preEvalWithBinding(Binding binding) {
Frame lastFrame = pushFrameForEval(binding);
pushRubyClass(binding.getKlass());
return lastFrame;
}

public void postEvalWithBinding(Binding binding, Frame lastFrame) {
popFrameReal(lastFrame);
popRubyClass();
}

public void postYield(Binding binding, Frame lastFrame) {
popScope();
popFrameReal(lastFrame);
popRubyClass();
}

public void postYieldLight(Binding binding, Frame lastFrame) {
popScope();
popFrameReal(lastFrame);
popRubyClass();
}

public void postYieldNoScope(Frame lastFrame) {
popFrameReal(lastFrame);
popRubyClass();
}

public void preScopedBody(DynamicScope scope) {
@@ -1312,7 +1230,7 @@ public void setWithinTrace(boolean isWithinTrace) {
*/
public Binding currentBinding() {
Frame frame = getCurrentFrame().capture();
return new Binding(frame, parentIndex < 0 ? frame.getKlazz() : getRubyClass(), getCurrentScope(), backtrace[backtraceIndex].clone());
return new Binding(frame, getCurrentScope(), backtrace[backtraceIndex].clone());
}

/**
@@ -1322,7 +1240,7 @@ public Binding currentBinding() {
*/
public Binding currentBinding(IRubyObject self) {
Frame frame = getCurrentFrame().capture();
return new Binding(self, frame, frame.getVisibility(), getRubyClass(), getCurrentScope(), backtrace[backtraceIndex].clone());
return new Binding(self, frame, frame.getVisibility(), getCurrentScope(), backtrace[backtraceIndex].clone());
}

/**
@@ -1334,7 +1252,7 @@ public Binding currentBinding(IRubyObject self) {
*/
public Binding currentBinding(IRubyObject self, Visibility visibility) {
Frame frame = getCurrentFrame().capture();
return new Binding(self, frame, visibility, getRubyClass(), getCurrentScope(), backtrace[backtraceIndex].clone());
return new Binding(self, frame, visibility, getCurrentScope(), backtrace[backtraceIndex].clone());
}

/**
@@ -1346,7 +1264,7 @@ public Binding currentBinding(IRubyObject self, Visibility visibility) {
*/
public Binding currentBinding(IRubyObject self, DynamicScope scope) {
Frame frame = getCurrentFrame().capture();
return new Binding(self, frame, frame.getVisibility(), getRubyClass(), scope, backtrace[backtraceIndex].clone());
return new Binding(self, frame, frame.getVisibility(), scope, backtrace[backtraceIndex].clone());
}

/**
@@ -1361,7 +1279,7 @@ public Binding currentBinding(IRubyObject self, DynamicScope scope) {
*/
public Binding currentBinding(IRubyObject self, Visibility visibility, DynamicScope scope) {
Frame frame = getCurrentFrame().capture();
return new Binding(self, frame, visibility, getRubyClass(), scope, backtrace[backtraceIndex].clone());
return new Binding(self, frame, visibility, scope, backtrace[backtraceIndex].clone());
}

/**
@@ -1371,7 +1289,7 @@ public Binding currentBinding(IRubyObject self, Visibility visibility, DynamicSc
@Deprecated
public Binding previousBinding() {
Frame frame = getPreviousFrame();
return new Binding(frame, getPreviousRubyClass(), getCurrentScope(), backtrace[backtraceIndex].clone());
return new Binding(frame, getCurrentScope(), backtrace[backtraceIndex].clone());
}

/**
@@ -1382,7 +1300,7 @@ public Binding previousBinding() {
@Deprecated
public Binding previousBinding(IRubyObject self) {
Frame frame = getPreviousFrame();
return new Binding(self, frame, frame.getVisibility(), getPreviousRubyClass(), getCurrentScope(), backtrace[backtraceIndex].clone());
return new Binding(self, frame, frame.getVisibility(), getCurrentScope(), backtrace[backtraceIndex].clone());
}

/**

0 comments on commit 525a110

Please sign in to comment.