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

Commits on Dec 11, 2014

  1. Copy the full SHA
    a02aea3 View commit details
  2. [Truffle] Implement Kernel#to_s for all objects and use it in ToSNode.

    * Fix fallback to use Kernel#to_s on object, not its class.
    * Use the lazy pattern for the kernelToSNode since it should be rarely used.
    eregon committed Dec 11, 2014
    5
    Copy the full SHA
    cf3ca08 View commit details
19 changes: 12 additions & 7 deletions core/src/main/java/org/jruby/truffle/nodes/cast/ToSNode.java
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
*/
package org.jruby.truffle.nodes.cast;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
@@ -26,21 +27,25 @@
public abstract class ToSNode extends RubyNode {

@Child protected DispatchHeadNode callToSNode;
@Child protected KernelNodes.ClassNode classNode;
@Child protected KernelNodes.ToSNode toSNode;
@Child protected KernelNodes.ToSNode kernelToSNode;

public ToSNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
callToSNode = new DispatchHeadNode(context, true);
classNode = KernelNodesFactory.ClassNodeFactory.create(context, sourceSection, new RubyNode[]{null});
toSNode = KernelNodesFactory.ToSNodeFactory.create(context, sourceSection, new RubyNode[]{null});
}

protected RubyString kernelToS(VirtualFrame frame, Object object) {
if (kernelToSNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
kernelToSNode = insert(KernelNodesFactory.ToSNodeFactory.create(getContext(), getSourceSection(), new RubyNode[] {null}));
}
return kernelToSNode.executeToS(frame, object);
}


public ToSNode(ToSNode prev) {
super(prev);
callToSNode = prev.callToSNode;
classNode = prev.classNode;
toSNode = prev.toSNode;
}

@Override
@@ -63,7 +68,7 @@ public RubyString toSFallback(VirtualFrame frame, Object object) {
if (value instanceof RubyString) {
return (RubyString) value;
} else {
return toSNode.toS(classNode.executeGetClass(frame, object));
return kernelToS(frame, object);
}
}
}
Original file line number Diff line number Diff line change
@@ -84,6 +84,8 @@ public IDNode(IDNode prev) {
super(prev);
}

public abstract Object executeObjectID(VirtualFrame frame, Object value);

@Specialization
public int objectID(RubyNilClass nil) {
return ObjectIDOperations.NIL;
25 changes: 20 additions & 5 deletions core/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java
Original file line number Diff line number Diff line change
@@ -1982,19 +1982,34 @@ public Object doThrow(Object tag, Object value) {
@CoreMethod(names = {"to_s", "inspect"})
public abstract static class ToSNode extends CoreMethodNode {

@Child protected ClassNode classNode;
@Child protected BasicObjectNodes.IDNode idNode;

public ToSNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
classNode = KernelNodesFactory.ClassNodeFactory.create(context, sourceSection, new RubyNode[]{null});
idNode = BasicObjectNodesFactory.IDNodeFactory.create(context, sourceSection, new RubyNode[]{null});
}

public ToSNode(ToSNode prev) {
super(prev);
}
public abstract RubyString executeToS(VirtualFrame frame, Object self);

@Specialization
public RubyString toS(RubyBasicObject self) {
public RubyString toS(VirtualFrame frame, Object self) {
notDesignedForCompilation();

return getContext().makeString("#<" + self.getLogicalClass().getName() + ":0x" + Long.toHexString(self.getObjectID()) + ">");
String className = classNode.executeGetClass(frame, self).getName();

Object id = idNode.executeObjectID(frame, self);
String hexID;
if (id instanceof Integer || id instanceof Long) {
hexID = Long.toHexString((long) id);
} else if (id instanceof RubyBignum) {
hexID = ((RubyBignum) id).toHexString();
} else {
throw new UnsupportedOperationException();
}

return getContext().makeString("#<" + className + ":0x" + hexID + ">");
}

}
Original file line number Diff line number Diff line change
@@ -145,17 +145,17 @@ public int compareTo(double other) {

@CompilerDirectives.SlowPath
public boolean isEqualTo(int b) {
return value.compareTo(BigInteger.valueOf(b)) == 0;
return value.equals(BigInteger.valueOf(b));
}

@CompilerDirectives.SlowPath
public boolean isEqualTo(long b) {
return value.compareTo(BigInteger.valueOf(b)) == 0;
return value.equals(BigInteger.valueOf(b));
}

@CompilerDirectives.SlowPath
public boolean isEqualTo(RubyBignum b) {
return value.compareTo(b.value) == 0;
return value.equals(b.value);
}

@CompilerDirectives.SlowPath
@@ -208,6 +208,11 @@ public boolean isZero() {
return value.equals(BigInteger.ZERO);
}

@CompilerDirectives.SlowPath
public String toHexString() {
return value.toString(16);
}

@CompilerDirectives.SlowPath
public double doubleValue() {
return value.doubleValue();