Skip to content

Commit

Permalink
[Truffle] Have a try at implementing a not fully compliant Bignum#coe…
Browse files Browse the repository at this point in the history
…rce.

* So it does not create Fixnum-range Bignums.
  • Loading branch information
eregon committed Feb 16, 2015
1 parent 05aad64 commit 535bc52
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
1 change: 0 additions & 1 deletion spec/truffle/tags/core/bignum/coerce_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:Bignum#coerce coerces other to a Bignum and returns [other, self] when passed a Fixnum
fails:Bignum#coerce raises a TypeError when passed a Float or String
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,47 @@ public Object abs(RubyBignum value) {

}

@CoreMethod(names = "coerce", required = 1)
public abstract static class CoerceNode extends CoreMethodNode {

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

public CoerceNode(CoerceNode prev) {
super(prev);
}

@Specialization
public RubyArray coerce(RubyBignum a, int b) {
notDesignedForCompilation();

// TODO (eregon, 16 Feb. 2015): This is NOT spec, but let's try to see if we can make it work.
// b is converted to a Bignum here in other implementations.
Object[] store = new Object[] { b, a };
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), store, store.length);
}

@Specialization
public RubyArray coerce(RubyBignum a, long b) {
notDesignedForCompilation();

// TODO (eregon, 16 Feb. 2015): This is NOT spec, but let's try to see if we can make it work.
// b is converted to a Bignum here in other implementations.
Object[] store = new Object[] { b, a };
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), store, store.length);
}

@Specialization
public RubyArray coerce(RubyBignum a, RubyBignum b) {
notDesignedForCompilation();

Object[] store = new Object[] { b, a };
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), store, store.length);
}

}

@CoreMethod(names = "divmod", required = 1)
public abstract static class DivModNode extends CoreMethodNode {

Expand Down

0 comments on commit 535bc52

Please sign in to comment.