Skip to content

Commit

Permalink
[Truffle] Uniform guards for type.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Dec 5, 2014
1 parent c1bf2b6 commit 6127af9
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 48 deletions.
194 changes: 160 additions & 34 deletions core/src/main/java/org/jruby/truffle/nodes/RubyNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package org.jruby.truffle.nodes;

import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.dsl.ImportGuards;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.VirtualFrame;
Expand Down Expand Up @@ -214,72 +215,197 @@ public static void notDesignedForCompilation() {
CompilerAsserts.neverPartOfCompilation();
}

public static boolean isNil(Object o) {
return o instanceof RubyNilClass;
public boolean isTrue(boolean value) {
return value;
}

public static boolean isTrue(boolean b) {
return b;
public RubyBignum bignum(int value) {
return bignum((long) value);
}

public static boolean isModule(RubyBasicObject o) {
return o instanceof RubyModule;
public RubyBignum bignum(long value) {
return bignum(BigInteger.valueOf(value));
}

public static boolean isArray(Object o) {
return o instanceof RubyArray;
public RubyBignum bignum(BigInteger value) {
return new RubyBignum(getContext().getCoreLibrary().getBignumClass(), value);
}

public static boolean isFixnum(Object o) {
return o instanceof Integer || o instanceof Long;
// Copied from RubyTypesGen

@SuppressWarnings("static-method")
public boolean isDispatchAction(Object value) {
return value instanceof Dispatch.DispatchAction;
}

public static boolean isBignum(Object o) {
return o instanceof RubyBignum;
@SuppressWarnings("static-method")
public boolean isLexicalScope(Object value) {
return value instanceof LexicalScope;
}

public static boolean isFloat(Object o) {
return o instanceof Double;
@SuppressWarnings("static-method")
public boolean isUndefinedPlaceholder(Object value) {
return value instanceof UndefinedPlaceholder;
}

public static boolean isFirstFixnum(Object o) {
return o instanceof Integer || o instanceof Long;
@SuppressWarnings("static-method")
public boolean isBoolean(Object value) {
return value instanceof Boolean;
}

public static boolean isFirstBignum(Object o) {
return o instanceof RubyBignum;
@SuppressWarnings("static-method")
public boolean isInteger(Object value) {
return value instanceof Integer;
}

public static boolean isFirstFloat(Object o) {
return o instanceof Double;
@SuppressWarnings("static-method")
public boolean isLong(Object value) {
return value instanceof Long;
}

public static boolean isSecondFixnum(Object a, Object b) {
return b instanceof Integer || b instanceof Long;
@SuppressWarnings("static-method")
public boolean isDouble(Object value) {
return value instanceof Double;
}

public static boolean isSecondBignum(Object a, Object b) {
return b instanceof RubyBignum;
@SuppressWarnings("static-method")
public boolean isString(Object value) {
return value instanceof String;
}

public static boolean isSecondFloat(Object a, Object b) {
return b instanceof Double;
@SuppressWarnings("static-method")
public boolean isRubyBignum(Object value) {
return value instanceof RubyBignum;
}

public static boolean isString(Object o) {
return o instanceof RubyString;
@SuppressWarnings("static-method")
public boolean isIntegerFixnumRange(Object value) {
return value instanceof RubyRange.IntegerFixnumRange;
}

public RubyBignum bignum(int value) {
return bignum((long) value);
@SuppressWarnings("static-method")
public boolean isLongFixnumRange(Object value) {
return value instanceof RubyRange.LongFixnumRange;
}

public RubyBignum bignum(long value) {
return bignum(BigInteger.valueOf(value));
@SuppressWarnings("static-method")
public boolean isObjectRange(Object value) {
return value instanceof RubyRange.ObjectRange;
}

public RubyBignum bignum(BigInteger value) {
return new RubyBignum(getContext().getCoreLibrary().getBignumClass(), value);
@SuppressWarnings("static-method")
public boolean isRubyArray(Object value) {
return value instanceof RubyArray;
}

@SuppressWarnings("static-method")
public boolean isRubyBinding(Object value) {
return value instanceof RubyBinding;
}

@SuppressWarnings("static-method")
public boolean isRubyClass(Object value) {
return value instanceof RubyClass;
}

@SuppressWarnings("static-method")
public boolean isRubyException(Object value) {
return value instanceof RubyException;
}

@SuppressWarnings("static-method")
public boolean isRubyFiber(Object value) {
return value instanceof RubyFiber;
}

@SuppressWarnings("static-method")
public boolean isRubyFile(Object value) {
return value instanceof RubyFile;
}

@SuppressWarnings("static-method")
public boolean isRubyHash(Object value) {
return value instanceof RubyHash;
}

@SuppressWarnings("static-method")
public boolean isRubyMatchData(Object value) {
return value instanceof RubyMatchData;
}

@SuppressWarnings("static-method")
public boolean isRubyModule(Object value) {
return value instanceof RubyModule;
}

@SuppressWarnings("static-method")
public boolean isRubyNilClass(Object value) {
return value instanceof RubyNilClass;
}

@SuppressWarnings("static-method")
public boolean isRubyProc(Object value) {
return value instanceof RubyProc;
}

@SuppressWarnings("static-method")
public boolean isRubyRange(Object value) {
return value instanceof RubyRange;
}

@SuppressWarnings("static-method")
public boolean isRubyRegexp(Object value) {
return value instanceof RubyRegexp;
}

@SuppressWarnings("static-method")
public boolean isRubyString(Object value) {
return value instanceof RubyString;
}

@SuppressWarnings("static-method")
public boolean isRubyEncoding(Object value) {
return value instanceof RubyEncoding;
}

@SuppressWarnings("static-method")
public boolean isRubySymbol(Object value) {
return value instanceof RubySymbol;
}

@SuppressWarnings("static-method")
public boolean isRubyThread(Object value) {
return value instanceof RubyThread;
}

@SuppressWarnings("static-method")
public boolean isRubyTime(Object value) {
return value instanceof RubyTime;
}

@SuppressWarnings("static-method")
public boolean isRubiniusChannel(Object value) {
return value instanceof RubiniusChannel;
}

@SuppressWarnings("static-method")
public boolean isRubiniusByteArray(Object value) {
return value instanceof RubiniusByteArray;
}

@SuppressWarnings("static-method")
public boolean isRubyEncodingConverter(Object value) {
return value instanceof RubyEncodingConverter;
}

@SuppressWarnings("static-method")
public boolean isRubyBasicObject(Object value) {
return value instanceof RubyBasicObject;
}

@SuppressWarnings("static-method")
public boolean isObjectArray(Object value) {
return value instanceof Object[];
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public RubyNilClass cast(RubyNilClass nil) {
return nil;
}

@Specialization(guards = {"!isNil", "!isArray"})
@Specialization(guards = {"!isRubyNilClass", "!isRubyArray"})
public Object cast(VirtualFrame frame, RubyBasicObject object) {
notDesignedForCompilation();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public boolean doFloat(double value) {
return true;
}

@Specialization(guards = "!isNil")
@Specialization(guards = "!isRubyNilClass")
public boolean doBasicObject(RubyBasicObject object) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public RubyArray splat(RubyArray array) {
return array;
}

@Specialization(guards = {"!isNil", "!isArray"})
@Specialization(guards = {"!isRubyNilClass", "!isRubyArray"})
public RubyArray splat(VirtualFrame frame, Object object) {
notDesignedForCompilation();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public boolean orXor(RubyNilClass other) {
return false;
}

@Specialization(guards = "!isNil")
@Specialization(guards = "!isRubyNilClass")
public boolean orXor(RubyBasicObject other) {
return true;
}
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/java/org/jruby/truffle/nodes/core/FloatNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public boolean less(double a, RubyBignum b) {
return a < b.doubleValue();
}

@Specialization(guards = "!isBignum(arguments[1])")
@Specialization(guards = "!isRubyBignum(arguments[1])")
public boolean less(@SuppressWarnings("unused") double a, RubyBasicObject other) {
throw new RaiseException(new RubyException(
getContext().getCoreLibrary().getArgumentErrorClass(),
Expand Down Expand Up @@ -344,7 +344,7 @@ public boolean lessEqual(double a, RubyBignum b) {
return a <= b.doubleValue();
}

@Specialization(guards = "!isBignum(arguments[1])")
@Specialization(guards = "!isRubyBignum(arguments[1])")
public boolean less(@SuppressWarnings("unused") double a, RubyBasicObject other) {
throw new RaiseException(new RubyException(
getContext().getCoreLibrary().getArgumentErrorClass(),
Expand Down Expand Up @@ -385,7 +385,7 @@ public boolean equal(double a, RubyBignum b) {
return a == b.doubleValue();
}

@Specialization(guards = "!isBignum(arguments[1])")
@Specialization(guards = "!isRubyBignum(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;
Expand Down Expand Up @@ -440,7 +440,7 @@ public boolean greaterEqual(double a, RubyBignum b) {
return a >= b.doubleValue();
}

@Specialization(guards = "!isBignum(arguments[1])")
@Specialization(guards = "!isRubyBignum(arguments[1])")
public boolean less(@SuppressWarnings("unused") double a, RubyBasicObject other) {
throw new RaiseException(new RubyException(
getContext().getCoreLibrary().getArgumentErrorClass(),
Expand Down Expand Up @@ -481,7 +481,7 @@ public boolean equal(double a, RubyBignum b) {
return a > b.doubleValue();
}

@Specialization(guards = "!isBignum(arguments[1])")
@Specialization(guards = "!isRubyBignum(arguments[1])")
public boolean less(@SuppressWarnings("unused") double a, RubyBasicObject other) {
throw new RaiseException(new RubyException(
getContext().getCoreLibrary().getArgumentErrorClass(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,7 @@ public RubyClass singletonClass(RubyBignum self) {
throw new RaiseException(getContext().getCoreLibrary().typeErrorCantDefineSingleton(this));
}

@Specialization(guards = "!isBignum")
@Specialization(guards = "!isRubyBignum")
public RubyClass singletonClass(RubyBasicObject self) {
notDesignedForCompilation();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public boolean orXor(RubyNilClass other) {
return false;
}

@Specialization(guards = "!isNil")
@Specialization(guards = "!isRubyNilClass")
public boolean orXor(RubyBasicObject other) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public boolean and(RubyNilClass other) {
return false;
}

@Specialization(guards = "!isNil")
@Specialization(guards = "!isRubyNilClass")
public boolean and(RubyBasicObject other) {
return true;
}
Expand Down Expand Up @@ -82,7 +82,7 @@ public boolean xor(RubyNilClass other) {
return true;
}

@Specialization(guards = "!isNil")
@Specialization(guards = "!isRubyNilClass")
public boolean xor(RubyBasicObject other) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public Object alias(RubyModule module) {
return null;
}

@Specialization(guards = "!isModule")
@Specialization(guards = {"!isRubyModule", "!isRubyBignum"})
public Object alias(RubyBasicObject object) {
notDesignedForCompilation();

Expand Down

0 comments on commit 6127af9

Please sign in to comment.