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

Commits on Oct 3, 2014

  1. Copy the full SHA
    38a1b25 View commit details
  2. Copy the full SHA
    c81d188 View commit details
  3. Copy the full SHA
    7d97cfc View commit details
27 changes: 8 additions & 19 deletions core/src/main/java/org/jruby/truffle/nodes/core/MainNodes.java
Original file line number Diff line number Diff line change
@@ -22,38 +22,27 @@ public abstract class MainNodes {
@CoreMethod(names = "include", isSplatted = true, minArgs = 1)
public abstract static class IncludeNode extends CoreMethodNode {

@Child protected DispatchHeadNode appendFeaturesNode;
@Child protected DispatchHeadNode includeNode;

public IncludeNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
appendFeaturesNode = new DispatchHeadNode(context);
includeNode = new DispatchHeadNode(context);

}

public IncludeNode(IncludeNode prev) {
super(prev);
appendFeaturesNode = prev.appendFeaturesNode;
includeNode = prev.includeNode;
}

@Specialization
public NilPlaceholder include(VirtualFrame frame, RubyObject main, Object[] args) {
public NilPlaceholder include(VirtualFrame frame, Object[] args) {
notDesignedForCompilation();

// TODO(cs): copied from Module - but where does this method really come from?

// Note that we traverse the arguments backwards

for (int n = args.length - 1; n >= 0; n--) {
if (args[n] instanceof RubyModule) {
final RubyModule included = (RubyModule) args[n];

// Note that we do appear to do full method lookup here
appendFeaturesNode.call(frame, included, "append_features", null, main.getSingletonClass(this));

// TODO(cs): call included hook
}
}
RubyClass object = getContext().getCoreLibrary().getObjectClass();

return NilPlaceholder.INSTANCE;
// TODO: MRI does this call statically
return (NilPlaceholder) includeNode.call(frame, object, "include", null, args);
}
}

33 changes: 32 additions & 1 deletion core/src/main/java/org/jruby/truffle/nodes/core/ModuleNodes.java
Original file line number Diff line number Diff line change
@@ -168,6 +168,37 @@ public RubyModule aliasMethod(RubyModule module, RubySymbol newName, RubySymbol
}
}

@CoreMethod(names = "ancestors", maxArgs = 0)
public abstract static class AncestorsNode extends CoreMethodNode {

public AncestorsNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public AncestorsNode(AncestorsNode prev) {
super(prev);
}

@Specialization
public RubyArray ancestors(RubyModule self) {
notDesignedForCompilation();

ModuleOperations.debugModuleChain(self);

final List<ModuleChain> ancestors = new ArrayList<>();

for (ModuleChain module = self; module != null; module = module.getParentModule()) {
if (module instanceof IncludedModule) {
ancestors.add(((IncludedModule) module).getIncludedModule());
} else {
ancestors.add(module);
}
}

return RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(), ancestors.toArray(new Object[ancestors.size()]));
}
}

@CoreMethod(names = "append_features", minArgs = 1, maxArgs = 1)
public abstract static class AppendFeaturesNode extends CoreMethodNode {

@@ -1167,7 +1198,7 @@ public RubyModule removeMethod(RubyModule module, RubySymbol name) {

}

@CoreMethod(names = "to_s", maxArgs = 0)
@CoreMethod(names = {"to_s", "inspect"}, maxArgs = 0)
public abstract static class ToSNode extends CoreMethodNode {

public ToSNode(RubyContext context, SourceSection sourceSection) {
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
import com.oracle.truffle.api.CompilerAsserts;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.core.RubyClass;
import org.jruby.truffle.runtime.core.RubyModule;
import org.jruby.truffle.runtime.methods.RubyMethod;

import java.util.Collection;
@@ -280,12 +281,13 @@ public static void debugModuleChain(ModuleChain module) {
while (module != null) {
System.err.print(module.getClass());

if (module instanceof RubyClass) {
System.err.print(" " + ((RubyClass) module).getName());
} else if (module instanceof IncludedModule) {
System.err.print(" " + ((IncludedModule) module).getIncludedModule().getName());
ModuleChain real = module;
if (module instanceof IncludedModule) {
real = ((IncludedModule) module).getIncludedModule();
}

System.err.print(" " + ((RubyModule) real).getName());

System.err.println();
module = module.getParentModule();
}