|
14 | 14 | import com.oracle.truffle.api.object.Property;
|
15 | 15 | import org.truffleruby.Layouts;
|
16 | 16 | import org.truffleruby.RubyContext;
|
| 17 | +import org.truffleruby.cext.ValueWrapperManager; |
17 | 18 | import org.truffleruby.core.numeric.BignumOperations;
|
18 | 19 | import org.truffleruby.language.objects.shared.SharedObjects;
|
19 | 20 |
|
| 21 | +import static org.truffleruby.cext.ValueWrapperManager.FALSE_HANDLE; |
| 22 | +import static org.truffleruby.cext.ValueWrapperManager.MAX_FIXNUM_VALUE; |
| 23 | +import static org.truffleruby.cext.ValueWrapperManager.MIN_FIXNUM_VALUE; |
| 24 | +import static org.truffleruby.cext.ValueWrapperManager.NIL_HANDLE; |
| 25 | +import static org.truffleruby.cext.ValueWrapperManager.TRUE_HANDLE; |
| 26 | + |
20 | 27 | import java.math.BigInteger;
|
21 | 28 |
|
22 | 29 | /**
|
|
41 | 48 | */
|
42 | 49 | public abstract class ObjectIDOperations {
|
43 | 50 |
|
44 |
| - public static final long FALSE = 0; |
45 |
| - public static final long TRUE = 2; |
46 |
| - public static final long NIL = 4; |
47 |
| - public static final long FIRST_OBJECT_ID = 6; |
| 51 | + public static final long FALSE = FALSE_HANDLE; |
| 52 | + public static final long TRUE = TRUE_HANDLE; |
| 53 | + public static final long NIL = NIL_HANDLE; |
48 | 54 |
|
49 | 55 | private static final BigInteger LARGE_FIXNUM_FLAG = BigInteger.ONE.shiftLeft(64);
|
50 | 56 | private static final BigInteger FLOAT_FLAG = BigInteger.ONE.shiftLeft(65);
|
51 | 57 |
|
52 |
| - private static final long SMALL_FIXNUM_MIN = -(1L << 62); |
53 |
| - private static final long SMALL_FIXNUM_MAX = (1L << 62) - 1; |
54 |
| - |
55 | 58 | // primitive => ID
|
56 | 59 |
|
57 | 60 | public static boolean isSmallFixnum(long fixnum) {
|
58 | 61 | // TODO: optimize
|
59 |
| - return SMALL_FIXNUM_MIN <= fixnum && fixnum <= SMALL_FIXNUM_MAX; |
| 62 | + return MIN_FIXNUM_VALUE <= fixnum && fixnum <= MAX_FIXNUM_VALUE; |
60 | 63 | }
|
61 | 64 |
|
62 | 65 | public static long smallFixnumToIDOverflow(long fixnum) throws ArithmeticException {
|
@@ -99,7 +102,7 @@ public static boolean isFloatID(BigInteger id) {
|
99 | 102 | }
|
100 | 103 |
|
101 | 104 | public static boolean isBasicObjectID(long id) {
|
102 |
| - return id >= FIRST_OBJECT_ID && id % 2 == 0; |
| 105 | + return id != 0 && (id & ValueWrapperManager.TAG_MASK) == 0; |
103 | 106 | }
|
104 | 107 |
|
105 | 108 | private static BigInteger unsignedBigInteger(long value) {
|
|
0 commit comments