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

Commits on Oct 7, 2016

  1. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    nomadium Miguel Landaeta
    Copy the full SHA
    41add42 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    nomadium Miguel Landaeta
    Copy the full SHA
    7916404 View commit details
  3. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    280cd66 View commit details
Original file line number Diff line number Diff line change
@@ -18,6 +18,8 @@
@GenerateNodeFactory
public abstract class PrimitiveNode extends RubyNode {

protected static final Object FAILURE = null;

public PrimitiveNode() {
}

94 changes: 7 additions & 87 deletions truffle/src/main/java/org/jruby/truffle/core/MathNodes.java
Original file line number Diff line number Diff line change
@@ -49,6 +49,8 @@
import org.jruby.truffle.builtins.CoreClass;
import org.jruby.truffle.builtins.CoreMethod;
import org.jruby.truffle.builtins.CoreMethodArrayArgumentsNode;
import org.jruby.truffle.builtins.Primitive;
import org.jruby.truffle.builtins.PrimitiveArrayArgumentsNode;
import org.jruby.truffle.language.NotProvided;
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.language.dispatch.CallDispatchHeadNode;
@@ -401,103 +403,21 @@ protected double doFunction(double a, double b) {

}

@CoreMethod(names = "ldexp", isModuleFunction = true, required = 2)
public abstract static class LdexpNode extends CoreMethodArrayArgumentsNode {

@Child private IsANode isANode;
@Child private CallDispatchHeadNode floatANode;
@Child private CallDispatchHeadNode integerBNode;

private final BranchProfile exceptionProfile = BranchProfile.create();

protected LdexpNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
isANode = IsANodeGen.create(context, sourceSection, null, null);
floatANode = DispatchHeadNodeFactory.createMethodCall(context, MissingBehavior.RETURN_MISSING);
integerBNode = DispatchHeadNodeFactory.createMethodCall(context, MissingBehavior.RETURN_MISSING);
}

@Specialization
public double function(int a, int b) {
return function((double) a, b);
}

@Specialization
public double function(int a, long b) {
return function((double) a, b);
}

@Specialization
public double function(int a, double b) {
return function((double) a, b);
}

@Specialization
public double function(long a, int b) {
return function((double) a, b);
}

@Specialization
public double function(long a, long b) {
return function((double) a, b);
}

@Specialization
public double function(long a, double b) {
return function((double) a, b);
}

@Specialization(guards = "isRubyBignum(a)")
public double function(DynamicObject a, int b) {
return function(Layouts.BIGNUM.getValue(a).doubleValue(), b);
}

@Specialization(guards = "isRubyBignum(a)")
public double function(DynamicObject a, long b) {
return function(Layouts.BIGNUM.getValue(a).doubleValue(), b);
}

@Specialization(guards = "isRubyBignum(a)")
public double function(DynamicObject a, double b) {
return function(Layouts.BIGNUM.getValue(a).doubleValue(), b);
}

@Specialization
public double function(double a, int b) {
return function(a, (double) b);
}
@Primitive(name = "math_ldexp", needsSelf = false)
public abstract static class LdexpNode extends PrimitiveArrayArgumentsNode {

@Specialization
public double function(double a, long b) {
return function(a, (double) b);
}

@Specialization
public double function(double a, double b) {
if (Double.isNaN(b)) {
exceptionProfile.enter();
throw new RaiseException(coreExceptions().rangeError("float", DoubleUtils.toString(b), "integer", this));
}

public double ldexp(double a, int b) {
return a * Math.pow(2, b);
}

@Fallback
public double function(VirtualFrame frame, Object a, Object b) {
if (!isANode.executeIsA(a, coreLibrary().getNumericClass())) {
exceptionProfile.enter();
throw new RaiseException(coreExceptions().typeErrorCantConvertInto(a, "Float", this));
}

return function(
floatANode.callFloat(frame, a, "to_f", null),
integerBNode.callLongFixnum(frame, b, "to_int", null));
public Object ldexp(Object a, Object b) {
return FAILURE;
}

}



@CoreMethod(names = "lgamma", isModuleFunction = true, required = 1)
public abstract static class LGammaNode extends CoreMethodArrayArgumentsNode {

Original file line number Diff line number Diff line change
@@ -89,28 +89,4 @@ public double callFloat(
}
}

public long callLongFixnum(
VirtualFrame frame,
Object receiverObject,
Object methodName,
DynamicObject blockObject,
Object... argumentsObjects) {
final Object value = dispatch(frame, receiverObject, methodName, blockObject, argumentsObjects);

if (value instanceof Integer) {
return (int) value;
}

if (value instanceof Long) {
return (long) value;
}

errorProfile.enter();
if (value == DispatchNode.MISSING) {
throw new RaiseException(context.getCoreExceptions().typeErrorCantConvertInto(receiverObject, "Fixnum", this));
} else {
throw new RaiseException(context.getCoreExceptions().typeErrorCantConvertTo(receiverObject, "Fixnum", (String) methodName, value, this));
}
}

}
9 changes: 9 additions & 0 deletions truffle/src/main/ruby/core/math.rb
Original file line number Diff line number Diff line change
@@ -13,4 +13,13 @@ module Math

DomainError = Errno::EDOM

module_function
def ldexp(fraction, exponent)
Truffle.primitive :math_ldexp
raise RangeError, "float NaN out of range of integer" if Float === exponent and exponent.nan?
ldexp(
Rubinius::Type.coerce_to_float(fraction),
Rubinius::Type.coerce_to_int(exponent))
end

end
21 changes: 21 additions & 0 deletions truffle/src/main/ruby/core/type.rb
Original file line number Diff line number Diff line change
@@ -410,6 +410,27 @@ def self.coerce_to_collection_length(length)
end
end

def self.coerce_to_int(obj)
if Integer === obj
obj
else
coerce_to(obj, Integer, :to_int)
end
end

def self.coerce_to_float(obj)
case obj
when Float
obj
when Numeric
coerce_to obj, Float, :to_f
when nil, true, false
raise TypeError, "can't convert #{obj.inspect} into Float"
else
raise TypeError, "can't convert #{obj.class} into Float"
end
end

def self.coerce_to_regexp(pattern, quote=false)
case pattern
when Regexp