Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 54960e7bd5da
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9e2f3d1cab1c
Choose a head ref
  • 2 commits
  • 5 files changed
  • 1 contributor

Commits on Sep 24, 2014

  1. Change getNextCapturedScope to getParentScope (aligns with getNthPare…

    …ntScope name and it makes more sense as a name).
    enebo committed Sep 24, 2014
    Copy the full SHA
    3565ea5 View commit details
  2. Copy the full SHA
    9e2f3d1 View commit details
3 changes: 1 addition & 2 deletions core/src/main/java/org/jruby/RubyFileTest.java
Original file line number Diff line number Diff line change
@@ -277,9 +277,8 @@ public static IRubyObject sticky_p(IRubyObject recv, IRubyObject filename) {
@JRubyMethod(name = "symlink?", required = 1, module = true)
public static RubyBoolean symlink_p(IRubyObject recv, IRubyObject filename) {
Ruby runtime = recv.getRuntime();
FileResource file = fileResource(filename);

IRubyObject oldExc = runtime.getGlobalVariables().get("$!");

try {
// Note: We can't use file.exists() to check whether the symlink
// exists or not, because that method returns false for existing
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ public Object interpret(ThreadContext context, StaticScope currScope, DynamicSco
// CON FIXME: Does this need to be done every time?
int i = 0, offset = 0;
while (!argsDynScope.getStaticScope().isArgumentScope()) {
argsDynScope = argsDynScope.getNextCapturedScope();
argsDynScope = argsDynScope.getParentScope();
offset += argCounts[i];
i++;
}
25 changes: 11 additions & 14 deletions core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java
Original file line number Diff line number Diff line change
@@ -80,7 +80,7 @@ public static IRubyObject initiateNonLocalReturn(ThreadContext context, DynamicS
break;
}
}
dynScope = dynScope.getNextCapturedScope();
dynScope = dynScope.getParentScope();
}

// SSS FIXME: Why is scopeType empty? Looks like this static-scope
@@ -132,7 +132,7 @@ public static IRubyObject initiateBreak(ThreadContext context, DynamicScope dynS
throw IRException.BREAK_LocalJumpError.getException(context.runtime);
}

IRBreakJump bj = IRBreakJump.create(dynScope.getNextCapturedScope(), breakValue);
IRBreakJump bj = IRBreakJump.create(dynScope.getParentScope(), breakValue);
if (scopeType == IRScopeType.EVAL_SCRIPT) {
// If we are in an eval, record it so we can account for it
bj.breakInEval = true;
@@ -674,35 +674,31 @@ public static IRubyObject mergeKeywordArguments(ThreadContext context, IRubyObje
public static RubyModule findInstanceMethodContainer(ThreadContext context, DynamicScope currDynScope, IRubyObject self) {
boolean inBindingEval = currDynScope.inBindingEval();

if (!inBindingEval && self == context.runtime.getTopSelf()) {
// Top-level-scripts are special
// but, not if binding-evals are in force!
return self.getType();
}
// Top-level-scripts are special but, not if binding-evals are in force!
if (!inBindingEval && self == context.runtime.getTopSelf()) return self.getType();

DynamicScope ds = currDynScope;
while (ds != null) {
for (DynamicScope ds = currDynScope; ds != null; ) {
IRScopeType scopeType = ds.getStaticScope().getScopeType();
switch (ds.getEvalType()) {
case MODULE_EVAL : return (RubyModule)self;
case MODULE_EVAL : return (RubyModule) self;
case INSTANCE_EVAL: return self.getSingletonClass();
case BINDING_EVAL : ds = ds.getNextCapturedScope(); break;
case BINDING_EVAL : ds = ds.getParentScope(); break;
case NONE:
if (scopeType == null || scopeType.isClosureType()) {
ds = ds.getNextCapturedScope();
ds = ds.getParentScope();
} else if (inBindingEval) {
// Binding evals are special!
return ds.getStaticScope().getModule();
} else if (scopeType == IRScopeType.CLASS_METHOD) {
return (RubyModule)self;
return (RubyModule) self;
} else if (scopeType == IRScopeType.INSTANCE_METHOD) {
return self.getMetaClass();
} else {
switch (scopeType) {
case MODULE_BODY:
case CLASS_BODY:
case METACLASS_BODY:
return (RubyModule)self;
return (RubyModule) self;

default:
throw new RuntimeException("Should not get here!");
@@ -711,6 +707,7 @@ public static RubyModule findInstanceMethodContainer(ThreadContext context, Dyna
break;
}
}

throw new RuntimeException("Should not get here!");
}

3 changes: 1 addition & 2 deletions core/src/main/java/org/jruby/runtime/Binding.java
Original file line number Diff line number Diff line change
@@ -34,7 +34,6 @@

import org.jruby.Ruby;
import org.jruby.runtime.backtrace.BacktraceElement;
import org.jruby.RubyModule;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.scope.ManyVarsDynamicScope;
@@ -239,7 +238,7 @@ public final DynamicScope getEvalScope(Ruby runtime) {
// If the next scope out has the same binding scope as this scope it means
// we are evaling within an eval and in that case we should be sharing the same
// binding scope.
DynamicScope parent = dynamicScope.getNextCapturedScope();
DynamicScope parent = dynamicScope.getParentScope();

if (parent != null && parent.getEvalScope(runtime) == dynamicScope) {
evalScopeBinding.evalScope = dynamicScope;
28 changes: 12 additions & 16 deletions core/src/main/java/org/jruby/runtime/DynamicScope.java
Original file line number Diff line number Diff line change
@@ -91,6 +91,15 @@ public static DynamicScope newDummyScope(StaticScope staticScope, DynamicScope p
return new DummyDynamicScope(staticScope, parent);
}

/**
* Get parent (capturing) scope. This is used by eval and closures to
* walk up to hard lexical boundary.
*
*/
public final DynamicScope getParentScope() {
return parent;
}

/**
* Returns the n-th parent scope of this scope.
* May return <code>null</code>.
@@ -100,11 +109,8 @@ public static DynamicScope newDummyScope(StaticScope staticScope, DynamicScope p
public DynamicScope getNthParentScope(int n) {
DynamicScope scope = this;
for (int i = 0; i < n; i++) {
if (scope != null) {
scope = scope.getNextCapturedScope();
} else {
break;
}
if (scope == null) break;
scope = scope.getParentScope();
}
return scope;
}
@@ -133,7 +139,7 @@ public final DynamicScope getEvalScope(Ruby runtime) {
// If the next scope out has the same binding scope as this scope it means
// we are evaling within an eval and in that case we should be sharing the same
// binding scope.
DynamicScope parent = getNextCapturedScope();
DynamicScope parent = getParentScope();
if (parent != null && parent.getEvalScope(runtime) == this) {
evalScope = this;
} else {
@@ -159,16 +165,6 @@ public DynamicScope getFlipScope() {
}
}

/**
* Get next 'captured' scope.
*
* @return the scope captured by this scope for implementing closures
*
*/
public final DynamicScope getNextCapturedScope() {
return parent;
}

/**
* Get the static scope associated with this DynamicScope.
*