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: 7765d78a146a
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 06054b48c95a
Choose a head ref
  • 4 commits
  • 3 files changed
  • 1 contributor

Commits on Nov 6, 2014

  1. Copy the full SHA
    0096953 View commit details
  2. Copy the full SHA
    6eaebb7 View commit details
  3. Copy the full SHA
    5cf8a9f View commit details
  4. [Truffle] Avoid looking twice the same module.

    * And make LexicalScope fields private.
    eregon committed Nov 6, 2014
    Copy the full SHA
    06054b4 View commit details
Original file line number Diff line number Diff line change
@@ -12,8 +12,8 @@
import org.jruby.truffle.runtime.core.RubyModule;

public class LexicalScope {
final LexicalScope parent;
RubyModule liveModule;
private final LexicalScope parent;
private RubyModule liveModule;

public LexicalScope(LexicalScope parent, RubyModule liveModule) {
this.parent = parent;
24 changes: 18 additions & 6 deletions core/src/main/java/org/jruby/truffle/runtime/ModuleOperations.java
Original file line number Diff line number Diff line change
@@ -58,6 +58,11 @@ public static Map<String, RubyConstant> getAllConstants(RubyModule module) {
return constants;
}

/**
* @param lexicalScope The surrounding LexicalScope, null if it is ignored (as in Mod::Constant)
* @param module The receiver of the constant lookup.
* Identical to lexicalScope.getLiveModule() if there no qualifier (Constant).
*/
public static RubyConstant lookupConstant(LexicalScope lexicalScope, RubyModule module, String name) {
CompilerAsserts.neverPartOfCompilation();

@@ -74,14 +79,21 @@ public static RubyConstant lookupConstant(LexicalScope lexicalScope, RubyModule
final RubyContext context = module.getContext();
final RubyClass objectClass = context.getCoreLibrary().getObjectClass();

while (lexicalScope != null && lexicalScope != context.getRootLexicalScope()) { // TODO: looking twice self ?
constant = lexicalScope.getLiveModule().getConstants().get(name);

if (constant != null) {
return constant;
if (lexicalScope != null) {
if (lexicalScope.getLiveModule() == module && lexicalScope != context.getRootLexicalScope()) {
// Already looked in module.
lexicalScope = lexicalScope.getParent();
}

lexicalScope = lexicalScope.getParent();
while (lexicalScope != context.getRootLexicalScope()) {
constant = lexicalScope.getLiveModule().getConstants().get(name);

if (constant != null) {
return constant;
}

lexicalScope = lexicalScope.getParent();
}
}

// Look in ancestors
20 changes: 10 additions & 10 deletions core/src/main/java/org/jruby/truffle/translator/BodyTranslator.java
Original file line number Diff line number Diff line change
@@ -598,16 +598,6 @@ public RubyNode visitClassNode(org.jruby.ast.ClassNode node) {
return openModule(sourceSection, defineOrGetClass, name, node.getBodyNode());
}

private RubyNode translateCPath(SourceSection sourceSection, org.jruby.ast.Colon3Node node) {
if (node instanceof Colon2ImplicitNode) { // use current lexical scope
return new LexicalScopeNode(context, sourceSection, environment.getLexicalScope());
} else if (node instanceof Colon2ConstNode) { // A::B
return node.childNodes().get(0).accept(this);
} else { // Colon3Node: on top-level (Object)
return new ObjectLiteralNode(context, sourceSection, context.getCoreLibrary().getObjectClass());
}
}

@Override
public RubyNode visitClassVarAsgnNode(org.jruby.ast.ClassVarAsgnNode node) {
final SourceSection sourceSection = translate(node.getPosition());
@@ -655,6 +645,16 @@ public RubyNode visitColon3Node(org.jruby.ast.Colon3Node node) {
return new ReadConstantNode(context, sourceSection, node.getName(), root);
}

private RubyNode translateCPath(SourceSection sourceSection, org.jruby.ast.Colon3Node node) {
if (node instanceof Colon2ImplicitNode) { // use current lexical scope
return new LexicalScopeNode(context, sourceSection, environment.getLexicalScope());
} else if (node instanceof Colon2ConstNode) { // A::B
return node.childNodes().get(0).accept(this);
} else { // Colon3Node: on top-level (Object)
return new ObjectLiteralNode(context, sourceSection, context.getCoreLibrary().getObjectClass());
}
}

@Override
public RubyNode visitConstDeclNode(org.jruby.ast.ConstDeclNode node) {
final SourceSection sourceSection = translate(node.getPosition());