Skip to content

Commit

Permalink
Merge branch 'master' into truffle-head
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Dec 2, 2014
2 parents 42d8c43 + b083103 commit 7a21fc4
Show file tree
Hide file tree
Showing 25 changed files with 333 additions and 41 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/RubyIO.java
Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/org/jruby/RubyThread.java
Expand Up @@ -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();
Expand Down
Expand Up @@ -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);

Expand Down
Expand Up @@ -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;
Expand All @@ -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;
}

}
Expand Down Expand Up @@ -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)
Expand All @@ -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; }
Expand Down
43 changes: 43 additions & 0 deletions core/src/main/java/org/jruby/truffle/nodes/core/FloatNodes.java
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
37 changes: 37 additions & 0 deletions core/src/main/java/org/jruby/truffle/nodes/core/HashNodes.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {

Expand Down
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
52 changes: 52 additions & 0 deletions core/src/main/java/org/jruby/truffle/nodes/core/NilClassNodes.java
Expand Up @@ -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")
Expand Down Expand Up @@ -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 {

Expand All @@ -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 {

Expand Down

0 comments on commit 7a21fc4

Please sign in to comment.