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

Commits on Jun 4, 2015

  1. Copy the full SHA
    8156e58 View commit details
  2. Copy the full SHA
    c3cc29e View commit details
  3. Copy the full SHA
    0398913 View commit details
  4. Copy the full SHA
    87ac2e4 View commit details
  5. Copy the full SHA
    87a43f2 View commit details
  6. Copy the full SHA
    cfa7caf View commit details
  7. Copy the full SHA
    8dc3582 View commit details
  8. Copy the full SHA
    f267801 View commit details
  9. Copy the full SHA
    b2f6b33 View commit details
  10. [Truffle] jt: add --jexception[s] to print java exceptions

    * both test and run
    * --jdebug has now alias --debug
    pitr-ch committed Jun 4, 2015
    Copy the full SHA
    19590ae View commit details
  11. [Truffle] jt: print cmd being called

    useful for copying to `jt run ...` and tweaking
    pitr-ch committed Jun 4, 2015
    Copy the full SHA
    5b04676 View commit details
  12. Copy the full SHA
    a24087b View commit details
  13. Copy the full SHA
    6b7d2b4 View commit details
  14. Copy the full SHA
    40cc598 View commit details
  15. Copy the full SHA
    7379991 View commit details
  16. Copy the full SHA
    d40f7b0 View commit details
  17. [Truffle] fix typo

    pitr-ch committed Jun 4, 2015
    Copy the full SHA
    dd87239 View commit details
  18. [Truffle] BigDecimal: safe cast to int in :split method

    * add IntegerCastNode for safe int casting
    pitr-ch committed Jun 4, 2015
    Copy the full SHA
    b628851 View commit details
Showing with 552 additions and 217 deletions.
  1. +1 −0 lib/ruby/truffle/truffle/bigdecimal.rb
  2. +0 −2 spec/truffle/tags/library/bigdecimal/abs_tags.txt
  3. +0 −6 spec/truffle/tags/library/bigdecimal/case_compare_tags.txt
  4. +0 −5 spec/truffle/tags/library/bigdecimal/divide_tags.txt
  5. +0 −5 spec/truffle/tags/library/bigdecimal/equal_value_tags.txt
  6. +0 −3 spec/truffle/tags/library/bigdecimal/exponent_tags.txt
  7. +0 −3 spec/truffle/tags/library/bigdecimal/gte_tags.txt
  8. +0 −3 spec/truffle/tags/library/bigdecimal/lt_tags.txt
  9. +0 −3 spec/truffle/tags/library/bigdecimal/lte_tags.txt
  10. +0 −7 spec/truffle/tags/library/bigdecimal/quo_tags.txt
  11. +0 −7 spec/truffle/tags/library/bigdecimal/split_tags.txt
  12. +0 −2 spec/truffle/tags/library/bigdecimal/to_i_tags.txt
  13. +0 −2 spec/truffle/tags/library/bigdecimal/to_int_tags.txt
  14. +33 −10 tool/jt.rb
  15. +0 −4 truffle/src/main/java/org/jruby/truffle/nodes/cast/BooleanCastNode.java
  16. +1 −1 truffle/src/main/java/org/jruby/truffle/nodes/cast/HashCastNode.java
  17. +56 −0 truffle/src/main/java/org/jruby/truffle/nodes/cast/IntegerCastNode.java
  18. +348 −50 truffle/src/main/java/org/jruby/truffle/nodes/core/BigDecimalNodes.java
  19. +29 −7 truffle/src/main/java/org/jruby/truffle/nodes/core/BignumNodes.java
  20. +29 −15 truffle/src/main/java/org/jruby/truffle/nodes/core/FloatNodes.java
  21. +10 −42 truffle/src/main/java/org/jruby/truffle/nodes/core/MathNodes.java
  22. +29 −8 truffle/src/main/java/org/jruby/truffle/nodes/core/fixnum/FixnumNodes.java
  23. +16 −14 truffle/src/main/java/org/jruby/truffle/nodes/dispatch/CallDispatchHeadNode.java
  24. +0 −18 truffle/src/main/java/org/jruby/truffle/nodes/dispatch/UseMethodMissingException.java
1 change: 1 addition & 0 deletions lib/ruby/truffle/truffle/bigdecimal.rb
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ def ==(o)
end

alias_method :eql?, :==
alias_method :===, :==

def coerce(other)
[BigDecimal(other), self]
2 changes: 0 additions & 2 deletions spec/truffle/tags/library/bigdecimal/abs_tags.txt

This file was deleted.

6 changes: 0 additions & 6 deletions spec/truffle/tags/library/bigdecimal/case_compare_tags.txt

This file was deleted.

5 changes: 0 additions & 5 deletions spec/truffle/tags/library/bigdecimal/divide_tags.txt

This file was deleted.

5 changes: 0 additions & 5 deletions spec/truffle/tags/library/bigdecimal/equal_value_tags.txt

This file was deleted.

3 changes: 0 additions & 3 deletions spec/truffle/tags/library/bigdecimal/exponent_tags.txt
Original file line number Diff line number Diff line change
@@ -6,6 +6,3 @@ fails:BigDecimal#** other powers of 0 are 0
fails:BigDecimal#** returns NaN if self is NaN
fails:BigDecimal#** returns 0.0 if self is infinite and argument is negative
fails:BigDecimal#** returns infinite if self is infinite and argument is positive
fails:BigDecimal#exponent returns an Integer
fails:BigDecimal#exponent is n if number can be represented as 0.xxx*10**n
fails:BigDecimal#exponent returns 0 if self is 0
3 changes: 0 additions & 3 deletions spec/truffle/tags/library/bigdecimal/gte_tags.txt

This file was deleted.

3 changes: 0 additions & 3 deletions spec/truffle/tags/library/bigdecimal/lt_tags.txt

This file was deleted.

3 changes: 0 additions & 3 deletions spec/truffle/tags/library/bigdecimal/lte_tags.txt

This file was deleted.

7 changes: 0 additions & 7 deletions spec/truffle/tags/library/bigdecimal/quo_tags.txt

This file was deleted.

7 changes: 0 additions & 7 deletions spec/truffle/tags/library/bigdecimal/split_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/library/bigdecimal/to_i_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/library/bigdecimal/to_int_tags.txt

This file was deleted.

43 changes: 33 additions & 10 deletions tool/jt.rb
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
# Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
#
# Eclipse Public License version 1.0
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1
@@ -18,6 +18,7 @@

JDEBUG_PORT = 51819
JDEBUG = "-J-agentlib:jdwp=transport=dt_socket,server=y,address=#{JDEBUG_PORT},suspend=y"
JEXCEPTION = "-Xtruffle.exceptions.print_java=true"

# wait for sub-processes to handle the interrupt
trap(:INT) {}
@@ -111,13 +112,26 @@ module ShellUtils
private

def raw_sh(*args)
puts "$ #{printable_cmd(args) * ' '}"
result = system(*args)
unless result
$stderr.puts "FAILED (#{$?}): #{args * ' '}"
$stderr.puts "FAILED (#{$?}): #{printable_cmd(args) * ' '}"
exit $?.exitstatus
end
end

def printable_cmd(args)
if Hash === args[0]
if args[0].empty?
args[1..-1]
else
[args[0].map { |k, v| "#{k}=#{v}" }.join(' '), *args[1..-1]]
end
else
args
end
end

def sh(*args)
Dir.chdir(JRUBY_DIR) do
raw_sh(*args)
@@ -148,11 +162,12 @@ def help
puts 'jt irb irb'
puts 'jt rebuild clean and build'
puts 'jt run [options] args... run JRuby with -X+T and args'
puts ' --graal use Graal (set GRAAL_BIN or it will try to automagically find it)'
puts ' --asm show assembly (implies --graal)'
puts ' --server run an instrumentation server on port 8080'
puts ' --igv make sure IGV is running and dump Graal graphs after partial escape (implies --graal)'
puts ' --jdebug run a JDWP debug server on 8000'
puts ' --graal use Graal (set GRAAL_BIN or it will try to automagically find it)'
puts ' --asm show assembly (implies --graal)'
puts ' --server run an instrumentation server on port 8080'
puts ' --igv make sure IGV is running and dump Graal graphs after partial escape (implies --graal)'
puts ' --[j]debug run a JDWP debug server on 8000'
puts ' --jexception[s] print java exceptions'
puts 'jt e 14 + 2 evaluate an expression'
puts 'jt puts 14 + 2 evaluate and print an expression'
puts 'jt test run all mri tests and specs'
@@ -228,10 +243,14 @@ def run(*args)
jruby_args += %w[-J-XX:+UnlockDiagnosticVMOptions -J-XX:CompileCommand=print,*::callRoot]
end

if args.delete('--jdebug')
if args.delete('--jdebug') || args.delete('--debug')
jruby_args << JDEBUG
end

if args.delete('--jexception') || args.delete('--jexceptions')
jruby_args << JEXCEPTION
end

if args.delete('--server')
jruby_args += %w[-Xtruffle.instrumentation_server_port=8080 -Xtruffle.passalot=1]
end
@@ -301,7 +320,7 @@ def test_specs(*args)
env_vars = {}

options = %w[--excl-tag fails]

if args.first == 'fast'
args.shift
options += %w[--excl-tag slow]
@@ -312,10 +331,14 @@ def test_specs(*args)
options << '-T-J-server'
end

if args.delete('--jdebug')
if args.delete('--jdebug') || args.delete('--debug')
options << "-T#{JDEBUG}"
end

if args.delete('--jexception') || args.delete('--jexceptions')
options << "-T#{JEXCEPTION}"
end

mspec_env env_vars, 'run', *options, *args
end
private :test_specs
Original file line number Diff line number Diff line change
@@ -27,10 +27,6 @@ public BooleanCastNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public BooleanCastNode(BooleanCastNode copy) {
super(copy.getContext(), copy.getSourceSection());
}

public abstract boolean executeBoolean(VirtualFrame frame, Object value);

@Specialization(guards = "isNil(nil)")
Original file line number Diff line number Diff line change
@@ -83,7 +83,7 @@ public Object cast(VirtualFrame frame, RubyBasicObject object) {

if (!RubyGuards.isRubyHash(result)) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorShouldReturn(object.toString(), "to_hash", "HAsh", this));
throw new RaiseException(getContext().getCoreLibrary().typeErrorShouldReturn(object.toString(), "to_hash", "Hash", this));
}

return result;
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2013, 2015 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.nodes.cast;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;

/**
* Casts a value into an int.
*/
@ImportStatic(Integer.class)
@NodeChild(value = "value", type = RubyNode.class)
public abstract class IntegerCastNode extends RubyNode {

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

public abstract int executeInteger(VirtualFrame frame, Object value);

@Override
public abstract int executeInteger(VirtualFrame frame);

@Specialization
public int doIntegerFixnum(int value) {
return value;
}

@Specialization(guards = {"value >= MIN_VALUE", "value <= MAX_VALUE"})
public int doLongFixnum(long value) {
return (int) value;
}

@Fallback
public int doBasicObject(Object object) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().
typeErrorIsNotA(object.toString(), "Fixnum (fitting in int)", this));
}

}
398 changes: 348 additions & 50 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/BigDecimalNodes.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -247,9 +247,13 @@ public boolean less(RubyBasicObject a, RubyBasicObject b) {
return getBigIntegerValue(a).compareTo(getBigIntegerValue(b)) < 0;
}

@Specialization(guards = "!isRubyBignum(b)")
public Object lessCoerced(VirtualFrame frame, RubyBasicObject a, RubyBasicObject b) {
return ruby(frame, "redo_coerced :<, b", "b", b);
@Specialization(guards = {
"!isRubyBignum(b)",
"!isInteger(b)",
"!isLong(b)",
"!isDouble(b)"})
public Object lessCoerced(VirtualFrame frame, RubyBasicObject a, Object b) {
return ruby(frame, "b, a = math_coerce other, :compare_error; a < b", "other", b);
}

}
@@ -275,6 +279,15 @@ public boolean lessEqual(RubyBasicObject a, double b) {
public boolean lessEqual(RubyBasicObject a, RubyBasicObject b) {
return getBigIntegerValue(a).compareTo(getBigIntegerValue(b)) <= 0;
}

@Specialization(guards = {
"!isRubyBignum(b)",
"!isInteger(b)",
"!isLong(b)",
"!isDouble(b)"})
public Object lessEqualCoerced(VirtualFrame frame, RubyBasicObject a, Object b) {
return ruby(frame, "b, a = math_coerce other, :compare_error; a <= b", "other", b);
}
}

@CoreMethod(names = {"==", "eql?"}, required = 1)
@@ -375,6 +388,15 @@ public boolean greaterEqual(RubyBasicObject a, double b) {
public boolean greaterEqual(RubyBasicObject a, RubyBasicObject b) {
return getBigIntegerValue(a).compareTo(getBigIntegerValue(b)) >= 0;
}

@Specialization(guards = {
"!isRubyBignum(b)",
"!isInteger(b)",
"!isLong(b)",
"!isDouble(b)"})
public Object greaterEqualCoerced(VirtualFrame frame, RubyBasicObject a, Object b) {
return ruby(frame, "b, a = math_coerce other, :compare_error; a >= b", "other", b);
}
}

@CoreMethod(names = ">", required = 1)
@@ -400,12 +422,12 @@ public boolean greater(RubyBasicObject a, RubyBasicObject b) {
}

@Specialization(guards = {
"!isRubyBignum(b)",
"!isInteger(b)",
"!isLong(b)",
"!isDouble(b)",
"!isRubyBignum(b)"})
public Object compare(VirtualFrame frame, Object a, Object b) {
return ruby(frame, "b, a = math_coerce(other, :compare_error); a > b", "other", b);
"!isDouble(b)"})
public Object greaterCoerced(VirtualFrame frame, RubyBasicObject a, Object b) {
return ruby(frame, "b, a = math_coerce other, :compare_error; a > b", "other", b);
}
}

44 changes: 29 additions & 15 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/FloatNodes.java
Original file line number Diff line number Diff line change
@@ -295,10 +295,13 @@ public boolean lessBignum(double a, RubyBasicObject b) {
return a < BignumNodes.getBigIntegerValue(b).doubleValue();
}

@Specialization(guards = "!isRubyBignum(other)")
public boolean less(double a, RubyBasicObject other) {
throw new RaiseException(getContext().getCoreLibrary().argumentError(
String.format("comparison of Float with %s failed", other.getLogicalClass().getName()), this));
@Specialization(guards = {
"!isRubyBignum(b)",
"!isInteger(b)",
"!isLong(b)",
"!isDouble(b)"})
public Object lessCoerced(VirtualFrame frame, double a, Object b) {
return ruby(frame, "b, a = math_coerce other, :compare_error; a < b", "other", b);
}
}

@@ -324,10 +327,13 @@ public boolean lessEqual(double a, RubyBasicObject b) {
return a <= BignumNodes.getBigIntegerValue(b).doubleValue();
}

@Specialization(guards = "!isRubyBignum(other)")
public boolean less(double a, RubyBasicObject other) {
throw new RaiseException(getContext().getCoreLibrary().argumentError(
String.format("comparison of Float with %s failed", other.getLogicalClass().getName()), this));
@Specialization(guards = {
"!isRubyBignum(b)",
"!isInteger(b)",
"!isLong(b)",
"!isDouble(b)"})
public Object lessEqualCoerced(VirtualFrame frame, double a, Object b) {
return ruby(frame, "b, a = math_coerce other, :compare_error; a <= b", "other", b);
}
}

@@ -436,11 +442,15 @@ public boolean greaterEqual(double a, RubyBasicObject b) {
return a >= BignumNodes.getBigIntegerValue(b).doubleValue();
}

@Specialization(guards = "!isRubyBignum(other)")
public boolean less(double a, RubyBasicObject other) {
throw new RaiseException(getContext().getCoreLibrary().argumentError(
String.format("comparison of Float with %s failed", other.getLogicalClass().getName()), this));
@Specialization(guards = {
"!isRubyBignum(b)",
"!isInteger(b)",
"!isLong(b)",
"!isDouble(b)"})
public Object greaterEqualCoerced(VirtualFrame frame, double a, Object b) {
return ruby(frame, "b, a = math_coerce other, :compare_error; a >= b", "other", b);
}

}

@CoreMethod(names = ">", required = 1)
@@ -465,9 +475,13 @@ public boolean greater(double a, RubyBasicObject b) {
return a > BignumNodes.getBigIntegerValue(b).doubleValue();
}

@Specialization(guards = "!isRubyBignum(other)")
public Object greater(VirtualFrame frame, double a, RubyBasicObject other) {
return ruby(frame, "b, a = math_coerce(other, :compare_error); a > b", "other", other);
@Specialization(guards = {
"!isRubyBignum(b)",
"!isInteger(b)",
"!isLong(b)",
"!isDouble(b)"})
public Object greaterCoerced(VirtualFrame frame, double a, Object b) {
return ruby(frame, "b, a = math_coerce(other, :compare_error); a > b", "other", b);
}
}

52 changes: 10 additions & 42 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/MathNodes.java
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.nodes.dispatch.MissingBehavior;
import org.jruby.truffle.nodes.dispatch.UseMethodMissingException;
import org.jruby.truffle.runtime.NotProvided;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
@@ -364,12 +363,7 @@ public RubyBasicObject frexp(double a) {
@Fallback
public RubyBasicObject frexp(VirtualFrame frame, Object a) {
if (isANode.executeIsA(frame, a, getContext().getCoreLibrary().getNumericClass())) {
try {
return frexp(floatNode.callFloat(frame, a, "to_f", null));
} catch (UseMethodMissingException e) {
throw new RaiseException(getContext().getCoreLibrary().typeErrorCantConvertInto(
a, getContext().getCoreLibrary().getFloatClass(), this));
}
return frexp(floatNode.callFloat(frame, a, "to_f", null));
} else {
CompilerDirectives.transferToInterpreter();

@@ -529,14 +523,9 @@ public double function(double a, double b) {
@Fallback
public double function(VirtualFrame frame, Object a, Object b) {
if (isANode.executeIsA(frame, a, getContext().getCoreLibrary().getNumericClass())) {
try {
return function(
floatANode.callFloat(frame, a, "to_f", null),
integerBNode.callLongFixnum(frame, b, "to_int", null));
} catch (UseMethodMissingException e) {
throw new RaiseException(getContext().getCoreLibrary().typeErrorCantConvertInto(
a, getContext().getCoreLibrary().getIntegerClass(), this));
}
return function(
floatANode.callFloat(frame, a, "to_f", null),
integerBNode.callLongFixnum(frame, b, "to_int", null));
} else {
CompilerDirectives.transferToInterpreter();

@@ -593,12 +582,7 @@ public RubyBasicObject lgamma(double a) {
@Fallback
public RubyBasicObject lgamma(VirtualFrame frame, Object a) {
if (isANode.executeIsA(frame, a, getContext().getCoreLibrary().getNumericClass())) {
try {
return lgamma(floatNode.callFloat(frame, a, "to_f", null));
} catch (UseMethodMissingException e) {
throw new RaiseException(getContext().getCoreLibrary().typeErrorCantConvertInto(
a, getContext().getCoreLibrary().getFloatClass(), this));
}
return lgamma(floatNode.callFloat(frame, a, "to_f", null));
} else {
CompilerDirectives.transferToInterpreter();

@@ -639,13 +623,7 @@ public double function(double a, NotProvided b) {
@Specialization
public double function(VirtualFrame frame, Object a, NotProvided b) {
if (isANode.executeIsA(frame, a, getContext().getCoreLibrary().getNumericClass())) {
try {
return doFunction(
floatANode.callFloat(frame, a, "to_f", null));
} catch (UseMethodMissingException e) {
throw new RaiseException(getContext().getCoreLibrary().typeErrorCantConvertInto(
a, getContext().getCoreLibrary().getFloatClass(), this));
}
return doFunction(floatANode.callFloat(frame, a, "to_f", null));
} else {
CompilerDirectives.transferToInterpreter();

@@ -825,12 +803,7 @@ public double function(double a) {
@Fallback
public double function(VirtualFrame frame, Object a) {
if (isANode.executeIsA(frame, a, getContext().getCoreLibrary().getNumericClass())) {
try {
return doFunction(floatNode.callFloat(frame, a, "to_f", null));
} catch (UseMethodMissingException e) {
throw new RaiseException(getContext().getCoreLibrary().typeErrorCantConvertInto(
a, getContext().getCoreLibrary().getFloatClass(), this));
}
return doFunction(floatNode.callFloat(frame, a, "to_f", null));
} else {
CompilerDirectives.transferToInterpreter();

@@ -943,14 +916,9 @@ public double function(double a, double b) {
@Fallback
public double function(VirtualFrame frame, Object a, Object b) {
if (isANode.executeIsA(frame, a, getContext().getCoreLibrary().getNumericClass()) && isANode.executeIsA(frame, b, getContext().getCoreLibrary().getNumericClass())) {
try {
return doFunction(
floatANode.callFloat(frame, a, "to_f", null),
floatBNode.callFloat(frame, b, "to_f", null));
} catch (UseMethodMissingException e) {
throw new RaiseException(getContext().getCoreLibrary().typeErrorCantConvertInto(
a, getContext().getCoreLibrary().getFloatClass(), this));
}
return doFunction(
floatANode.callFloat(frame, a, "to_f", null),
floatBNode.callFloat(frame, b, "to_f", null));
} else {
CompilerDirectives.transferToInterpreter();

Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.BranchProfile;
import org.jruby.ext.bigdecimal.RubyBigDecimal;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.*;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
@@ -502,11 +503,14 @@ public boolean less(long a, RubyBasicObject b) {
return BigInteger.valueOf(a).compareTo(BignumNodes.getBigIntegerValue(b)) < 0;
}

@Specialization(guards = { "!isRubyBignum(b)", "!isInteger(b)", "!isLong(b)", "!isDouble(b)" })
public Object less(VirtualFrame frame, long a, Object b) {
@Specialization(guards = {
"!isRubyBignum(b)",
"!isInteger(b)",
"!isLong(b)",
"!isDouble(b)" })
public Object lessCoerced(VirtualFrame frame, long a, Object b) {
return ruby(frame, "b, a = math_coerce other, :compare_error; a < b", "other", b);
}

}

@CoreMethod(names = "<=", required = 1, unsupportedOperationBehavior = UnsupportedOperationBehavior.ARGUMENT_ERROR)
@@ -540,6 +544,15 @@ public boolean lessEqual(long a, double b) {
public boolean lessEqual(long a, RubyBasicObject b) {
return BigInteger.valueOf(a).compareTo(BignumNodes.getBigIntegerValue(b)) <= 0;
}

@Specialization(guards = {
"!isRubyBignum(b)",
"!isInteger(b)",
"!isLong(b)",
"!isDouble(b)" })
public Object lessEqualCoerced(VirtualFrame frame, long a, Object b) {
return ruby(frame, "b, a = math_coerce other, :compare_error; a <= b", "other", b);
}
}

@CoreMethod(names = {"==", "==="}, required = 1)
@@ -580,8 +593,7 @@ public boolean equal(long a, RubyBasicObject b) {
@Specialization(guards = {
"!isInteger(b)",
"!isLong(b)",
"!isRubyBignum(b)"
})
"!isRubyBignum(b)"})
public Object equal(VirtualFrame frame, Object a, Object b) {
return reverseCallNode.call(frame, b, "==", null, a);
}
@@ -662,6 +674,15 @@ public boolean greaterEqual(long a, double b) {
public boolean greaterEqual(long a, RubyBasicObject b) {
return BigInteger.valueOf(a).compareTo(BignumNodes.getBigIntegerValue(b)) >= 0;
}

@Specialization(guards = {
"!isRubyBignum(b)",
"!isInteger(b)",
"!isLong(b)",
"!isDouble(b)"})
public Object greaterEqualCoerced(VirtualFrame frame, long a, Object b) {
return ruby(frame, "b, a = math_coerce other, :compare_error; a >= b", "other", b);
}
}

@CoreMethod(names = ">", required = 1, unsupportedOperationBehavior = UnsupportedOperationBehavior.ARGUMENT_ERROR)
@@ -698,11 +719,11 @@ public boolean greater(long a, RubyBasicObject b) {
}

@Specialization(guards = {
"!isRubyBignum(b)",
"!isInteger(b)",
"!isLong(b)",
"!isDouble(b)",
"!isRubyBignum(b)"})
public Object compare(VirtualFrame frame, Object a, Object b) {
"!isDouble(b)"})
public Object greaterCoerced(VirtualFrame frame, long a, Object b) {
return ruby(frame, "b, a = math_coerce(other, :compare_error); a > b", "other", b);
}
}
Original file line number Diff line number Diff line change
@@ -59,34 +59,31 @@ public double callFloat(
Object receiverObject,
Object methodName,
RubyProc blockObject,
Object... argumentsObjects) throws UseMethodMissingException {
Object... argumentsObjects) {
final Object value = call(frame, receiverObject, methodName, blockObject, argumentsObjects);

if (missingBehavior == MissingBehavior.RETURN_MISSING && value == DispatchNode.MISSING) {
throw new UseMethodMissingException();
}

if (value instanceof Double) {
return (double) value;
}

CompilerDirectives.transferToInterpreter();
throw new RaiseException(context.getCoreLibrary().typeErrorCantConvertTo(
receiverObject, context.getCoreLibrary().getFloatClass(), (String) methodName, value, this));
if (value == DispatchNode.MISSING) {
throw new RaiseException(context.getCoreLibrary().typeErrorCantConvertInto(
receiverObject, context.getCoreLibrary().getFloatClass(), this));
} else {
throw new RaiseException(context.getCoreLibrary().typeErrorCantConvertTo(
receiverObject, context.getCoreLibrary().getFloatClass(), (String) methodName, value, this));
}
}

public long callLongFixnum(
VirtualFrame frame,
Object receiverObject,
Object methodName,
RubyProc blockObject,
Object... argumentsObjects) throws UseMethodMissingException {
Object... argumentsObjects) {
final Object value = call(frame, receiverObject, methodName, blockObject, argumentsObjects);

if (missingBehavior == MissingBehavior.RETURN_MISSING && value == DispatchNode.MISSING) {
throw new UseMethodMissingException();
}

if (value instanceof Integer) {
return (int) value;
}
@@ -96,8 +93,13 @@ public long callLongFixnum(
}

CompilerDirectives.transferToInterpreter();
throw new RaiseException(context.getCoreLibrary().typeErrorCantConvertTo(
receiverObject, context.getCoreLibrary().getFixnumClass(), (String) methodName, value, this));
if (value == DispatchNode.MISSING) {
throw new RaiseException(context.getCoreLibrary().typeErrorCantConvertInto(
receiverObject, context.getCoreLibrary().getFixnumClass(), this));
} else {
throw new RaiseException(context.getCoreLibrary().typeErrorCantConvertTo(
receiverObject, context.getCoreLibrary().getFixnumClass(), (String) methodName, value, this));
}
}

}

This file was deleted.