Skip to content
Permalink
Browse files
Merge branch 'master' into truffle-head
  • Loading branch information
chrisseaton committed Dec 2, 2014
2 parents 42d8c43 + b083103 commit 7a21fc490250e8919344af0291c8d8ce80d3714d
Showing with 333 additions and 41 deletions.
  1. +1 −0 .gitignore
  2. +4 −0 core/src/main/java/org/jruby/RubyIO.java
  3. +5 −0 core/src/main/java/org/jruby/RubyThread.java
  4. +1 −10 core/src/main/java/org/jruby/truffle/nodes/cast/BooleanCastNode.java
  5. +41 −10 core/src/main/java/org/jruby/truffle/nodes/core/BasicObjectNodes.java
  6. +43 −0 core/src/main/java/org/jruby/truffle/nodes/core/FloatNodes.java
  7. +37 −0 core/src/main/java/org/jruby/truffle/nodes/core/HashNodes.java
  8. +6 −1 core/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java
  9. +52 −0 core/src/main/java/org/jruby/truffle/nodes/core/NilClassNodes.java
  10. +18 −1 core/src/main/java/org/jruby/truffle/nodes/core/ObjectSpaceNodes.java
  11. +12 −1 core/src/main/java/org/jruby/truffle/nodes/core/YieldingCoreMethodNode.java
  12. +77 −4 core/src/main/java/org/jruby/truffle/runtime/ObjectIDOperations.java
  13. +1 −3 core/src/main/java/org/jruby/truffle/runtime/RubyContext.java
  14. +0 −1 core/src/main/java/org/jruby/util/cli/OutputStrings.java
  15. +1 −1 spec/compiler/general_spec.rb
  16. 0 spec/regression/{GH-1726_File_read_raises_an_enoent.rb → GH-1726_File_read_raises_an_enoent_spec.rb}
  17. +1 −1 ...nlocal_return_in_define_method_block.rb → GH-1960_nonlocal_return_in_define_method_block_spec.rb}
  18. +0 −1 spec/truffle/tags/core/float/equal_value_tags.txt
  19. +0 −1 spec/truffle/tags/core/hash/default_tags.txt
  20. +0 −1 spec/truffle/tags/core/nil/dup_tags.txt
  21. +0 −1 spec/truffle/tags/core/nil/to_a_tags.txt
  22. +0 −2 spec/truffle/tags/core/nil/to_f_tags.txt
  23. +0 −1 spec/truffle/tags/core/nil/to_h_tags.txt
  24. +0 −1 spec/truffle/tags/core/nil/to_i_tags.txt
  25. +33 −0 test/truffle/test_methods_parity.rb
@@ -66,6 +66,7 @@ target
test/prawn
test/rails
test/testapp/testapp
test/truffle/*.methods
tool/nailgun/Makefile
tool/nailgun/config.log
tool/nailgun/config.status
@@ -3446,6 +3446,10 @@ public static IRubyObject ioOpen(ThreadContext context, IRubyObject filename, IR
int perm;
IRubyObject cmd;

if ((filename instanceof RubyString) && ((RubyString) filename).isEmpty()) {
throw context.getRuntime().newErrnoENOENTError();
}

Object pm = EncodingUtils.vmodeVperm(vmode, vperm);

IOEncodable convconfig = new IOEncodable.ConvConfig();
@@ -1258,7 +1258,12 @@ public <Data, Return> Return executeTask(ThreadContext context, Data data, Task<
try {
this.unblockFunc = task;
this.unblockArg = data;

enterSleep();

// check for interrupt before going into blocking call
context.pollThreadEvents();

return task.run(context, data);
} finally {
exitSleep();
@@ -52,25 +52,16 @@ public boolean doLongFixnum(long value) {
return true;
}

@Specialization
public boolean doBignum(RubyBignum value) {
return true;
}

@Specialization
public boolean doFloat(double value) {
return true;
}

@Specialization(guards = "neitherNilNorFalse")
@Specialization(guards = "!isNil")
public boolean doBasicObject(RubyBasicObject object) {
return true;
}

protected boolean neitherNilNorFalse(RubyBasicObject object) {
return object != getContext().getCoreLibrary().getNilObject();
}

@Override
public abstract boolean executeBoolean(VirtualFrame frame);

@@ -12,10 +12,13 @@
import java.util.*;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.ExactMath;
import com.oracle.truffle.api.source.*;
import com.oracle.truffle.api.dsl.*;
import com.oracle.truffle.api.frame.VirtualFrame;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.cast.BooleanCastNodeFactory;
import org.jruby.truffle.nodes.dispatch.Dispatch;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.nodes.yield.YieldDispatchHeadNode;
@@ -38,9 +41,15 @@ public NotNode(NotNode prev) {
super(prev);
}

@CreateCast("arguments") public RubyNode[] createCast(RubyNode[] arguments) {
return new RubyNode[] {
BooleanCastNodeFactory.create(getContext(), getSourceSection(), arguments[0])
};
}

@Specialization
public boolean not(Object value) {
return !getContext().getCoreLibrary().isTruthy(value);
public boolean not(boolean value) {
return !value;
}

}
@@ -95,25 +104,48 @@ public int objectIDFalse(boolean value) {

@Specialization
public long objectID(int value) {
return ObjectIDOperations.fixnumToID(value);
return ObjectIDOperations.smallFixnumToID(value);
}

@Specialization(rewriteOn = ArithmeticException.class)
public long objectIDSmallFixnumOverflow(long value) {
return ObjectIDOperations.smallFixnumToIDOverflow(value);
}

/* TODO: Ideally we would have this instead of the code below to speculate better. [GRAAL-903]
@Specialization(guards = "isSmallFixnum")
public long objectIDSmallFixnum(long value) {
return ObjectIDOperations.smallFixnumToID(value);
}
@Specialization(guards = "!isSmallFixnum")
public Object objectIDLargeFixnum(long value) {
return ObjectIDOperations.largeFixnumToID(getContext(), value);
} */

@Specialization
public long objectID(long value) {
return ObjectIDOperations.fixnumToID(value);
public Object objectID(long value) {
if (isSmallFixnum(value)) {
return ObjectIDOperations.smallFixnumToID(value);
} else {
return ObjectIDOperations.largeFixnumToID(getContext(), value);
}
}

@Specialization
public long objectID(double value) {
CompilerDirectives.transferToInterpreter();
throw new UnsupportedOperationException("No ID for Float yet");
public RubyBignum objectID(double value) {
return ObjectIDOperations.floatToID(getContext(), value);
}

@Specialization
public long objectID(RubyBasicObject object) {
return object.getObjectID();
}

protected boolean isSmallFixnum(long fixnum) {
return ObjectIDOperations.isSmallFixnum(fixnum);
}

}

@CoreMethod(names = {"equal?", "=="}, required = 1)
@@ -127,8 +159,7 @@ public ReferenceEqualNode(ReferenceEqualNode prev) {
super(prev);
}

// The @CreateCast is not applied when using this, so the caller needs to unbox itself.
protected abstract boolean executeEqualWithUnboxed(VirtualFrame frame, Object a, Object b);
protected abstract boolean executeReferenceEqual(VirtualFrame frame, Object a, Object b);

@Specialization public boolean equal(boolean a, boolean b) { return a == b; }
@Specialization public boolean equal(int a, int b) { return a == b; }
@@ -16,6 +16,7 @@
import com.oracle.truffle.api.dsl.*;
import com.oracle.truffle.api.utilities.BranchProfile;
import org.jruby.truffle.runtime.*;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.*;
import org.jruby.truffle.runtime.core.RubyArray;

@@ -301,6 +302,15 @@ public boolean less(double a, double b) {
public boolean less(double a, RubyBignum b) {
return a < b.doubleValue();
}

@Specialization(guards = "!isBignum(arguments[1])")
public boolean less(@SuppressWarnings("unused") double a, RubyBasicObject other) {
throw new RaiseException(new RubyException(
getContext().getCoreLibrary().getArgumentErrorClass(),
getContext().makeString(String.format("comparison of Float with %s failed", other.getLogicalClass().getName())),
RubyCallStack.getBacktrace(this)
));
}
}

@CoreMethod(names = "<=", required = 1)
@@ -333,6 +343,15 @@ public boolean lessEqual(double a, double b) {
public boolean lessEqual(double a, RubyBignum b) {
return a <= b.doubleValue();
}

@Specialization(guards = "!isBignum(arguments[1])")
public boolean less(@SuppressWarnings("unused") double a, RubyBasicObject other) {
throw new RaiseException(new RubyException(
getContext().getCoreLibrary().getArgumentErrorClass(),
getContext().makeString(String.format("comparison of Float with %s failed", other.getLogicalClass().getName())),
RubyCallStack.getBacktrace(this)
));
}
}

@CoreMethod(names = "==", required = 1)
@@ -365,6 +384,12 @@ public boolean equal(double a, double b) {
public boolean equal(double a, RubyBignum b) {
return a == b.doubleValue();
}

@Specialization(guards = "!isBignum(arguments[1])")
public boolean less(@SuppressWarnings("unused") double a, RubyBasicObject other) {
// TODO (nirvdrum Dec. 1, 2014): This is a stub. There is one case where this should return 'true', but it's not a trivial fix.
return false;
}
}

@CoreMethod(names = "<=>", required = 1)
@@ -414,6 +439,15 @@ public boolean greaterEqual(double a, double b) {
public boolean greaterEqual(double a, RubyBignum b) {
return a >= b.doubleValue();
}

@Specialization(guards = "!isBignum(arguments[1])")
public boolean less(@SuppressWarnings("unused") double a, RubyBasicObject other) {
throw new RaiseException(new RubyException(
getContext().getCoreLibrary().getArgumentErrorClass(),
getContext().makeString(String.format("comparison of Float with %s failed", other.getLogicalClass().getName())),
RubyCallStack.getBacktrace(this)
));
}
}

@CoreMethod(names = ">", required = 1)
@@ -446,6 +480,15 @@ public boolean equal(double a, double b) {
public boolean equal(double a, RubyBignum b) {
return a > b.doubleValue();
}

@Specialization(guards = "!isBignum(arguments[1])")
public boolean less(@SuppressWarnings("unused") double a, RubyBasicObject other) {
throw new RaiseException(new RubyException(
getContext().getCoreLibrary().getArgumentErrorClass(),
getContext().makeString(String.format("comparison of Float with %s failed", other.getLogicalClass().getName())),
RubyCallStack.getBacktrace(this)
));
}
}

@CoreMethod(names = "abs")
@@ -18,6 +18,7 @@
import com.oracle.truffle.api.frame.*;
import com.oracle.truffle.api.utilities.BranchProfile;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.RubyRootNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.nodes.yield.YieldDispatchHeadNode;
@@ -1004,6 +1005,42 @@ public RubyHash mergeObjectArrayObjectArray(VirtualFrame frame, RubyHash hash, R

}

@CoreMethod(names = "default", optional = 1)
public abstract static class DefaultNode extends HashCoreMethodNode {

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

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

@Specialization
public Object defaultElement(VirtualFrame frame, RubyHash hash, UndefinedPlaceholder undefined) {
Object ret = hash.getDefaultValue();

// TODO (nirvdrum Dec. 1, 2014): This needs to evaluate the defaultProc if it exists before it tries defaultValue.
if (ret != null) {
return ret;
} else {
return getContext().getCoreLibrary().getNilObject();
}
}

@Specialization
public Object defaultElement(VirtualFrame frame, RubyHash hash, Object key) {
Object ret = hash.getDefaultValue();

// TODO (nirvdrum Dec. 1, 2014): This really needs to do something with the key. Dummy stub for now.
if (ret != null) {
return ret;
} else {
return getContext().getCoreLibrary().getNilObject();
}
}
}

@CoreMethod(names = "size")
public abstract static class SizeNode extends HashCoreMethodNode {

@@ -65,7 +65,7 @@ protected boolean areSame(VirtualFrame frame, Object left, Object right) {
CompilerDirectives.transferToInterpreterAndInvalidate();
referenceEqualNode = insert(BasicObjectNodesFactory.ReferenceEqualNodeFactory.create(getContext(), getSourceSection(), new RubyNode[]{null, null}));
}
return referenceEqualNode.executeEqualWithUnboxed(frame, left, right);
return referenceEqualNode.executeReferenceEqual(frame, left, right);
}

protected boolean areEqual(VirtualFrame frame, Object left, Object right) {
@@ -377,6 +377,11 @@ public RubyClass getClass(@SuppressWarnings("unused") int value) {
return getContext().getCoreLibrary().getFixnumClass();
}

@Specialization
public RubyClass getClass(@SuppressWarnings("unused") long value) {
return getContext().getCoreLibrary().getFixnumClass();
}

@Specialization
public RubyClass getClass(@SuppressWarnings("unused") RubyBignum value) {
return getContext().getCoreLibrary().getBignumClass();
@@ -12,6 +12,7 @@
import com.oracle.truffle.api.source.*;
import com.oracle.truffle.api.dsl.*;
import org.jruby.truffle.runtime.*;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.*;

@CoreClass(name = "NilClass")
@@ -85,6 +86,23 @@ public int toI() {
}
}

@CoreMethod(names = "to_f", needsSelf = false)
public abstract static class ToFNode extends CoreMethodNode {

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

public ToFNode(ToINode prev) {
super(prev);
}

@Specialization
public double toF() {
return 0.0f;
}
}

@CoreMethod(names = "to_s", needsSelf = false)
public abstract static class ToSNode extends CoreMethodNode {

@@ -102,6 +120,40 @@ public RubyString toS() {
}
}

@CoreMethod(names = "to_h", needsSelf = false)
public abstract static class ToHNode extends CoreMethodNode {

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

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

@Specialization
public RubyHash toH() {
return new RubyHash(getContext().getCoreLibrary().getHashClass(), null, getContext().getCoreLibrary().getNilObject(), null, 0);
}
}

@CoreMethod(names = "dup", needsSelf = false)
public abstract static class DupNode extends CoreMethodNode {

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

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

@Specialization
public RubyString dup() {
throw new RaiseException(getContext().getCoreLibrary().typeError("can't dup NilClass", this));
}
}

@CoreMethod(names = "&", needsSelf = false, required = 1)
public abstract static class AndNode extends CoreMethodNode {

0 comments on commit 7a21fc4

Please sign in to comment.