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

Commits on Oct 13, 2015

  1. Copy the full SHA
    15c16da View commit details
  2. Copy the full SHA
    e2d7206 View commit details
  3. Copy the full SHA
    7d8367c View commit details
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
class Symbol
alias :to_str :to_s
end
bundler.rb: "module Bundler; def self.setup; end; end"
# mock method_source gem
method_source.rb: nil
@@ -25,3 +26,6 @@
:run:
:require:
- shims
- date
- bigdecimal
- rubygems
Original file line number Diff line number Diff line change
@@ -41,7 +41,6 @@
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.StringOperations;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.util.StringSupport;

import java.math.BigDecimal;
import java.math.BigInteger;
@@ -214,8 +213,9 @@ protected RoundingMode getRoundMode(VirtualFrame frame) {
setupRoundModeCall();
setupRoundModeIntegerCast();

return toRoundingMode(roundModeIntegerCast.executeCastInt(// TODO (pitr 21-Jun-2015): read the actual constant
roundModeCall.call(frame, getBigDecimalClass(), "mode", null, 256)));
return toRoundingMode(roundModeIntegerCast.executeCastInt(
// TODO (pitr 21-Jun-2015): read the actual constant
roundModeCall.call(frame, getBigDecimalClass(), "mode", null, 256)));
}

protected DynamicObject getBigDecimalClass() {
@@ -338,6 +338,20 @@ public DynamicObject createString(VirtualFrame frame, DynamicObject value, Dynam
return executeInitialize(frame, getValueFromString(value.toString(), digits), self, digits);
}

@Specialization(guards = { "!isRubyBignum(value)", "!isRubyBigDecimal(value)", "!isRubyString(value)" })
public DynamicObject create(VirtualFrame frame, DynamicObject value, DynamicObject self, int digits) {
final Object castedValue = bigDecimalCast.executeObject(frame, value);
if (castedValue == nil()) {
throw new RaiseException(getContext().getCoreLibrary().typeError("could not be casted to BigDecimal", this));
}

setBigDecimalValue(
self,
((BigDecimal) castedValue).round(new MathContext(digits, getRoundMode(frame))));

return self;
}

// TODO (pitr 21-Jun-2015): raise on underflow

private DynamicObject createWithMode(VirtualFrame frame, Type value, DynamicObject self,
@@ -2054,6 +2068,19 @@ public BigDecimal doBigDecimal(DynamicObject value) {
return Layouts.BIG_DECIMAL.getValue(value);
}

@Specialization(guards = {"!isRubyBignum(value)", "!isRubyBigDecimal(value)"})
public Object doOther(VirtualFrame frame, DynamicObject value) {
final Object result = ruby(
frame,
"value.is_a?(Rational) ? value.to_f : nil",
"value", value);
if (result != nil()) {
return new BigDecimal((double) result);
} else {
return result;
}
}

@Fallback
public Object doBigDecimalFallback(Object value) {
return nil();
@@ -2096,7 +2123,7 @@ protected DynamicObject createBigDecimal(VirtualFrame frame, Object value) {
public abstract DynamicObject executeBigDecimal(VirtualFrame frame, Object value);

@Specialization
public Object doBigDecimal(VirtualFrame frame, Object value, BigDecimal cast) {
public DynamicObject doBigDecimal(VirtualFrame frame, Object value, BigDecimal cast) {
return createBigDecimal(frame, cast);
}

@@ -2123,5 +2150,4 @@ public DynamicObject allocate(DynamicObject rubyClass) {

}


}
Original file line number Diff line number Diff line change
@@ -12,8 +12,6 @@
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Field;
import java.security.AccessController;
import java.security.PrivilegedAction;

public abstract class MethodHandleUtils {