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

Commits on May 29, 2015

  1. Copy the full SHA
    ee0bb97 View commit details
  2. Copy the full SHA
    032cb72 View commit details
45 changes: 23 additions & 22 deletions truffle/src/main/java/org/jruby/truffle/nodes/RubyGuards.java
Original file line number Diff line number Diff line change
@@ -22,9 +22,7 @@

public abstract class RubyGuards {

public static boolean isNotProvided(Object value) {
return value instanceof NotProvided;
}
// Basic Java types

public static boolean isBoolean(Object value) {
return value instanceof Boolean;
@@ -42,22 +40,31 @@ public static boolean isDouble(Object value) {
return value instanceof Double;
}

// Ruby types

public static boolean isRubyBignum(Object value) {
return value instanceof RubyBignum;
}

public static boolean isRubyBigDecimal(RubyBasicObject value) {
return value.getDynamicObject().getShape().getObjectType() == BigDecimalNodes.BIG_DECIMAL_TYPE;
}

public static boolean isIntegerFixnumRange(Object value) {
return value instanceof RubyRange.IntegerFixnumRange;
}

public static boolean isRubyRange(Object value) {
return value instanceof RubyRange;
}

public static boolean isRubyArray(Object value) {
return (value instanceof RubyBasicObject) && isRubyArray((RubyBasicObject) value);
}

public static boolean isRubyArray(RubyBasicObject value) {
return value.getDynamicObject().getShape().getObjectType() == ArrayNodes.ARRAY_TYPE;
}

public static boolean isRubyBinding(Object value) {
return value instanceof RubyBinding;
}
@@ -78,10 +85,6 @@ public static boolean isRubyModule(Object value) {
return value instanceof RubyModule;
}

public static boolean isRubyRange(Object value) {
return value instanceof RubyRange;
}

public static boolean isRubyRegexp(Object value) {
return value instanceof RubyRegexp;
}
@@ -122,6 +125,8 @@ public static boolean isRubyBasicObject(Object value) {
return value instanceof RubyBasicObject;
}

// Internal types

public static boolean isThreadLocal(Object value) {
return value instanceof ThreadLocalObject;
}
@@ -130,28 +135,24 @@ public static boolean isForeignObject(Object object) {
return (object instanceof TruffleObject) && !(object instanceof RubyBasicObject);
}

public static boolean isTrue(boolean value) {
return value;
}
// Sentinels

public static boolean isNaN(double value) {
return Double.isNaN(value);
public static boolean wasProvided(Object value) {
return !(wasNotProvided(value));
}

public static boolean isInfinity(double value) {
return Double.isInfinite(value);
public static boolean wasNotProvided(Object value) {
return value instanceof NotProvided;
}

public static boolean isRubyBigDecimal(RubyBasicObject value) {
return value.getDynamicObject().getShape().getObjectType() == BigDecimalNodes.BIG_DECIMAL_TYPE;
}
// Values

public static boolean isNegative(int size) {
return size < 0;
public static boolean isNaN(double value) {
return Double.isNaN(value);
}

public static boolean isNegative(long size) {
return size < 0;
public static boolean isInfinity(double value) {
return Double.isInfinite(value);
}

}
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ public RubyBasicObject initialize(RubyException exception, NotProvided message)
return exception;
}

@Specialization(guards = "!isNotProvided(message)")
@Specialization(guards = "wasProvided(message)")
public RubyBasicObject initialize(RubyException exception, Object message) {
exception.initialize(message);
return exception;
Original file line number Diff line number Diff line change
@@ -606,7 +606,7 @@ public Object round(double n, NotProvided ndigits) {
return fixnumOrBignum.fixnumOrBignum(f);
}

@Specialization(guards = "!isNotProvided(ndigits)")
@Specialization(guards = "wasProvided(ndigits)")
public Object round(VirtualFrame frame, double n, Object ndigits) {
return ruby(frame, "round_internal(ndigits)", "ndigits", ndigits);
}
Original file line number Diff line number Diff line change
@@ -612,12 +612,12 @@ public Object classEval(VirtualFrame frame, RubyModule module, RubyString code,
return classEvalSource(frame, module, code, file.toString());
}

@Specialization(guards = "!isNotProvided(code)")
@Specialization(guards = "wasProvided(code)")
public Object classEval(VirtualFrame frame, RubyModule module, Object code, NotProvided file, NotProvided line, NotProvided block) {
return classEvalSource(frame, module, toStr(frame, code), file.toString());
}

@Specialization(guards = "!isNotProvided(file)")
@Specialization(guards = "wasProvided(file)")
public Object classEval(VirtualFrame frame, RubyModule module, RubyString code, Object file, NotProvided line, NotProvided block) {
return classEvalSource(frame, module, code, toStr(frame, file).toString());
}
@@ -648,7 +648,7 @@ public Object classEval(RubyModule self, NotProvided code, NotProvided file, Not
throw new RaiseException(getContext().getCoreLibrary().argumentError(0, 1, 2, this));
}

@Specialization(guards = "!isNotProvided(code)")
@Specialization(guards = "wasProvided(code)")
public Object classEval(RubyModule self, Object code, NotProvided file, NotProvided line, RubyProc block) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError(1, 0, this));
@@ -801,7 +801,7 @@ public RubyArray constants(RubyModule module, boolean inherit) {
return ArrayNodes.fromObjects(getContext().getCoreLibrary().getArrayClass(), constantsArray.toArray(new Object[constantsArray.size()]));
}

@Specialization(guards = "!isNotProvided(inherit)")
@Specialization(guards = "wasProvided(inherit)")
public RubyArray constants(VirtualFrame frame, RubyModule module, Object inherit) {
return constants(module, booleanCast(frame, inherit));
}
Original file line number Diff line number Diff line change
@@ -319,12 +319,12 @@ public Object step(VirtualFrame frame, RubyRange.LongFixnumRange range, int step
return range;
}

@Specialization(guards = { "!isStepValidInt(range, step, block)", "!isNotProvided(step)" })
@Specialization(guards = { "!isStepValidInt(range, step, block)", "wasProvided(step)" })
public Object stepFallback(VirtualFrame frame, RubyRange.IntegerFixnumRange range, Object step, RubyProc block) {
return ruby(frame, "step_internal(step, &block)", "step", step, "block", block);
}

@Specialization(guards = { "!isStepValidInt(range, step, block)", "!isNotProvided(step)" })
@Specialization(guards = { "!isStepValidInt(range, step, block)", "wasProvided(step)" })
public Object stepFallback(VirtualFrame frame, RubyRange.LongFixnumRange range, Object step, RubyProc block) {
return ruby(frame, "step_internal(step, &block)", "step", step, "block", block);
}
@@ -339,7 +339,7 @@ public Object step(VirtualFrame frame, RubyRange.IntegerFixnumRange range, NotPr
return ruby(frame, "step_internal(&block)", "block", block);
}

@Specialization(guards = { "!isInteger(step)", "!isLong(step)", "!isNotProvided(step)" })
@Specialization(guards = { "!isInteger(step)", "!isLong(step)", "wasProvided(step)" })
public Object step(VirtualFrame frame, RubyRange.IntegerFixnumRange range, Object step, NotProvided block) {
return ruby(frame, "step_internal(step)", "step", step);
}
@@ -354,12 +354,12 @@ public Object step(VirtualFrame frame, RubyRange.LongFixnumRange range, NotProvi
return ruby(frame, "step_internal(&block)", "block", block);
}

@Specialization(guards = "!isNotProvided(step)")
@Specialization(guards = "wasProvided(step)")
public Object step(VirtualFrame frame, RubyRange.LongFixnumRange range, Object step, NotProvided block) {
return ruby(frame, "step_internal(step)", "step", step);
}

@Specialization(guards = "!isNotProvided(step)")
@Specialization(guards = "wasProvided(step)")
public Object step(VirtualFrame frame, RubyRange.ObjectRange range, Object step, RubyProc block) {
return ruby(frame, "step_internal(step, &block)", "step", step, "block", block);
}
@@ -374,7 +374,7 @@ public Object step(VirtualFrame frame, RubyRange.ObjectRange range, NotProvided
return ruby(frame, "step_internal(&block)", "block", block);
}

@Specialization(guards = "!isNotProvided(step)")
@Specialization(guards = "wasProvided(step)")
public Object step(VirtualFrame frame, RubyRange.ObjectRange range, Object step, NotProvided block) {
return ruby(frame, "step_internal(step)", "step", step);
}
Original file line number Diff line number Diff line change
@@ -582,12 +582,12 @@ public Object slice(VirtualFrame frame, RubyString string, int start, int length
return getSubstringNode().execute(frame, string, start, length);
}

@Specialization(guards = "!isNotProvided(length)")
@Specialization(guards = "wasProvided(length)")
public Object slice(VirtualFrame frame, RubyString string, int start, Object length) {
return slice(frame, string, start, getToIntNode().doInt(frame, length));
}

@Specialization(guards = { "!isRubyRange(start)", "!isRubyRegexp(start)", "!isRubyString(start)", "!isNotProvided(length)" })
@Specialization(guards = { "!isRubyRange(start)", "!isRubyRegexp(start)", "!isRubyString(start)", "wasProvided(length)" })
public Object slice(VirtualFrame frame, RubyString string, Object start, Object length) {
return slice(frame, string, getToIntNode().doInt(frame, start), getToIntNode().doInt(frame, length));
}
@@ -597,7 +597,7 @@ public Object slice(VirtualFrame frame, RubyString string, RubyRegexp regexp, No
return slice(frame, string, regexp, 0);
}

@Specialization(guards = "!isNotProvided(capture)")
@Specialization(guards = "wasProvided(capture)")
public Object slice(VirtualFrame frame, RubyString string, RubyRegexp regexp, Object capture) {
// Extracted from Rubinius's definition of String#[].
return ruby(frame, "match, str = subpattern(index, other); Regexp.last_match = match; str", "index", regexp, "other", capture);
@@ -1281,7 +1281,7 @@ public RubyString initialize(RubyString self, RubyString from) {
return self;
}

@Specialization(guards = { "!isRubyString(from)", "!isNotProvided(from)" })
@Specialization(guards = { "!isRubyString(from)", "wasProvided(from)" })
public RubyString initialize(VirtualFrame frame, RubyString self, Object from) {
if (toStrNode == null) {
CompilerDirectives.transferToInterpreter();
@@ -2028,7 +2028,7 @@ public Object sum(VirtualFrame frame, RubyString string, NotProvided bits) {
return sum(frame, string, 16);
}

@Specialization(guards = { "!isInteger(bits)", "!isLong(bits)", "!isNotProvided(bits)" })
@Specialization(guards = { "!isInteger(bits)", "!isLong(bits)", "wasProvided(bits)" })
public Object sum(VirtualFrame frame, RubyString string, Object bits) {
return ruby(frame, "sum Rubinius::Type.coerce_to(bits, Fixnum, :to_int)", "bits", bits);
}
Loading