-
-
Save headius/174583a14d0f24b55f58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/core/src/main/java/org/jruby/ir/interpreter/Interpreter.java b/core/src/main/java/org/jruby/ir/interpreter/Interpreter.java | |
index 9382072..29d847f 100644 | |
--- a/core/src/main/java/org/jruby/ir/interpreter/Interpreter.java | |
+++ b/core/src/main/java/org/jruby/ir/interpreter/Interpreter.java | |
@@ -19,6 +19,7 @@ import org.jruby.runtime.*; | |
import org.jruby.runtime.builtin.IRubyObject; | |
import org.jruby.runtime.ivars.VariableAccessor; | |
import org.jruby.runtime.opto.ConstantCache; | |
+import org.jruby.runtime.scope.ManyVarsDynamicScope; | |
import org.jruby.util.log.Logger; | |
import org.jruby.util.log.LoggerFactory; | |
@@ -721,7 +722,10 @@ public class Interpreter extends IRTranslator<IRubyObject, IRubyObject> { | |
} | |
// no binding, just eval in "current" frame (caller's frame) | |
- DynamicScope evalScope = context.getCurrentScope().getEvalScope(runtime); | |
+ | |
+ // new scope for every eval | |
+ DynamicScope parentScope = context.getCurrentScope(); | |
+ DynamicScope evalScope = new ManyVarsDynamicScope(runtime.getStaticScopeFactory().newEvalScope(parentScope.getStaticScope()), parentScope); | |
evalScope.getStaticScope().determineModule(); | |
RootNode node = (RootNode) runtime.parseEval(src.convertToString().getByteList(), file, evalScope, lineNumber); | |
@@ -744,8 +748,10 @@ public class Interpreter extends IRTranslator<IRubyObject, IRubyObject> { | |
throw new UnsupportedOperationException(); | |
} | |
- DynamicScope evalScope = binding.getEvalScope(runtime); | |
+ // new scope for every eval | |
+ DynamicScope evalScope = new ManyVarsDynamicScope(runtime.getStaticScopeFactory().newEvalScope(binding.getDynamicScope().getStaticScope()), binding.getDynamicScope()); | |
evalScope.setEvalType(EvalType.BINDING_EVAL); | |
+ | |
// FIXME: This determine module is in a strange location and should somehow be in block | |
evalScope.getStaticScope().determineModule(); | |
diff --git a/core/src/main/java/org/jruby/runtime/Binding.java b/core/src/main/java/org/jruby/runtime/Binding.java | |
index 899ef84..cd0af0e 100644 | |
--- a/core/src/main/java/org/jruby/runtime/Binding.java | |
+++ b/core/src/main/java/org/jruby/runtime/Binding.java | |
@@ -216,38 +216,4 @@ public class Binding { | |
return this.self == bOther.self && | |
this.dynamicScope == bOther.dynamicScope; | |
} | |
- | |
- public final DynamicScope getEvalScope(Ruby runtime) { | |
- // We create one extra dynamicScope on a binding so that when we 'eval "b=1", binding' the | |
- // 'b' will get put into this new dynamic scope. The original scope does not see the new | |
- // 'b' and successive evals with this binding will. I take it having the ability to have | |
- // succesive binding evals be able to share same scope makes sense from a programmers | |
- // perspective. One crappy outcome of this design is it requires Dynamic and Static | |
- // scopes to be mutable for this one case. | |
- | |
- // Note: In Ruby 1.9 all of this logic can go away since they will require explicit | |
- // bindings for evals. | |
- | |
- // We only define one special dynamic scope per 'logical' binding. So all bindings for | |
- // the same scope should share the same dynamic scope. This allows multiple evals with | |
- // different different bindings in the same scope to see the same stuff. | |
- | |
- // No eval scope set, so we create one | |
- if (evalScopeBinding.evalScope == null) { | |
- | |
- // 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.getParentScope(); | |
- | |
- if (parent != null && parent.getEvalScope(runtime) == dynamicScope) { | |
- evalScopeBinding.evalScope = dynamicScope; | |
- } else { | |
- // bindings scopes must always be ManyVars scopes since evals can grow them | |
- evalScopeBinding.evalScope = new ManyVarsDynamicScope(runtime.getStaticScopeFactory().newEvalScope(dynamicScope.getStaticScope()), dynamicScope); | |
- } | |
- } | |
- | |
- return evalScopeBinding.evalScope; | |
- } | |
} | |
diff --git a/core/src/main/java/org/jruby/runtime/DynamicScope.java b/core/src/main/java/org/jruby/runtime/DynamicScope.java | |
index a44c1db..6c115c8 100644 | |
--- a/core/src/main/java/org/jruby/runtime/DynamicScope.java | |
+++ b/core/src/main/java/org/jruby/runtime/DynamicScope.java | |
@@ -119,38 +119,6 @@ public abstract class DynamicScope { | |
return newDynamicScope(staticScope, null); | |
} | |
- public final DynamicScope getEvalScope(Ruby runtime) { | |
- // We create one extra dynamicScope on a binding so that when we 'eval "b=1", binding' the | |
- // 'b' will get put into this new dynamic scope. The original scope does not see the new | |
- // 'b' and successive evals with this binding will. I take it having the ability to have | |
- // succesive binding evals be able to share same scope makes sense from a programmers | |
- // perspective. One crappy outcome of this design is it requires Dynamic and Static | |
- // scopes to be mutable for this one case. | |
- | |
- // Note: In Ruby 1.9 all of this logic can go away since they will require explicit | |
- // bindings for evals. | |
- | |
- // We only define one special dynamic scope per 'logical' binding. So all bindings for | |
- // the same scope should share the same dynamic scope. This allows multiple evals with | |
- // different different bindings in the same scope to see the same stuff. | |
- | |
- // No binding scope so we should create one | |
- if (evalScope == null) { | |
- // 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 = getParentScope(); | |
- if (parent != null && parent.getEvalScope(runtime) == this) { | |
- evalScope = this; | |
- } else { | |
- // bindings scopes must always be ManyVars scopes since evals can grow them | |
- evalScope = new ManyVarsDynamicScope(runtime.getStaticScopeFactory().newEvalScope(getStaticScope()), this); | |
- } | |
- } | |
- | |
- return evalScope; | |
- } | |
- | |
/** | |
* Find the scope to use for flip-flops. Flip-flops live either in the | |
* topmost "method scope" or in their nearest containing "eval scope". |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment