Skip to content

Commit

Permalink
[Truffle] No need for a FixnumOrBignumNode for ObjectIDOperations.
Browse files Browse the repository at this point in the history
* They produce Bignums on purpose.
  • Loading branch information
eregon committed Feb 16, 2015
1 parent 535bc52 commit 04f85be
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,12 @@ public abstract class ObjectPrimitiveNodes {
@RubiniusPrimitive(name = "object_id")
public abstract static class ObjectIDPrimitiveNode extends RubiniusPrimitiveNode {

@Child private FixnumOrBignumNode fixnumOrBignum;

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

public ObjectIDPrimitiveNode(ObjectIDPrimitiveNode prev) {
super(prev);
fixnumOrBignum = prev.fixnumOrBignum;
}

public abstract Object executeObjectID(VirtualFrame frame, Object value);
Expand Down Expand Up @@ -83,23 +80,13 @@ public Object objectID(long value) {
if (isSmallFixnum(value)) {
return ObjectIDOperations.smallFixnumToID(value);
} else {
if (fixnumOrBignum == null) {
CompilerDirectives.transferToInterpreter();
fixnumOrBignum = insert(new FixnumOrBignumNode(getContext(), getSourceSection()));
}

return fixnumOrBignum.fixnumOrBignum(ObjectIDOperations.largeFixnumToID(value));
return ObjectIDOperations.largeFixnumToID(getContext(), value);
}
}

@Specialization
public Object objectID(double value) {
if (fixnumOrBignum == null) {
CompilerDirectives.transferToInterpreter();
fixnumOrBignum = insert(new FixnumOrBignumNode(getContext(), getSourceSection()));
}

return fixnumOrBignum.fixnumOrBignum(ObjectIDOperations.floatToID(value));
return ObjectIDOperations.floatToID(getContext(), value);
}

@Specialization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ public static long smallFixnumToID(long fixnum) {
return fixnum * 2 + 1;
}

public static BigInteger largeFixnumToID(long fixnum) {
public static RubyBignum largeFixnumToID(RubyContext context, long fixnum) {
assert !isSmallFixnum(fixnum);
return BigInteger.valueOf(fixnum).or(LARGE_FIXNUM_FLAG);
return new RubyBignum(context.getCoreLibrary().getBignumClass(), BigInteger.valueOf(fixnum).or(LARGE_FIXNUM_FLAG));
}

public static BigInteger floatToID(double value) {
public static RubyBignum floatToID(RubyContext context, double value) {
long bits = Double.doubleToRawLongBits(value);
return BigInteger.valueOf(bits).or(FLOAT_FLAG);
return new RubyBignum(context.getCoreLibrary().getBignumClass(), BigInteger.valueOf(bits).or(FLOAT_FLAG));
}

// ID => primitive
Expand Down

0 comments on commit 04f85be

Please sign in to comment.