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

Commits on Oct 6, 2015

  1. Copy the full SHA
    7292d31 View commit details
  2. Copy the full SHA
    50ce6bf View commit details
  3. Copy the full SHA
    39d6355 View commit details
  4. Copy the full SHA
    813a0cd View commit details
7 changes: 0 additions & 7 deletions spec/truffle/tags/core/bignum/comparison_tags.txt

This file was deleted.

3 changes: 2 additions & 1 deletion test/truffle/pe/core/binding_pe.rb
Original file line number Diff line number Diff line change
@@ -13,7 +13,8 @@
example "x = 14; binding.local_variable_get(:x) * 2", 28

# Proc#binding
example "x = 14; p = Proc.new { }; p.binding.local_variable_get(:x)", 14
tagged_example "x = 14; p = Proc.new { }; p.binding.local_variable_get(:x)", 14
example "x = 14; p = Proc.new { }; p.binding.local_variable_get(:x) * 2", 28

# set + get
tagged_example "b = binding; b.local_variable_set(:x, 14); b.local_variable_get(:x)", 14
Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.BranchProfile;
import com.oracle.truffle.api.utilities.ConditionProfile;
import org.jcodings.specific.USASCIIEncoding;
import org.jruby.truffle.nodes.cast.BooleanCastNode;
import org.jruby.truffle.nodes.cast.BooleanCastNodeGen;
@@ -313,35 +312,6 @@ public boolean equal(VirtualFrame frame, DynamicObject a, DynamicObject b) {
}
}

@CoreMethod(names = "<=>", required = 1)
public abstract static class CompareNode extends CoreMethodArrayArgumentsNode {

private final ConditionProfile negativeInfinityProfile = ConditionProfile.createBinaryProfile();

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

@Specialization
public int compare(DynamicObject a, long b) {
return Layouts.BIGNUM.getValue(a).compareTo(BigInteger.valueOf(b));
}

@Specialization
public int compare(DynamicObject a, double b) {
if (negativeInfinityProfile.profile(Double.isInfinite(b) && b < 0)) {
return 1;
} else {
return Double.compare(Layouts.BIGNUM.getValue(a).doubleValue(), b);
}
}

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

@CoreMethod(names = ">=", required = 1)
public abstract static class GreaterEqualNode extends CoreMethodArrayArgumentsNode {

Original file line number Diff line number Diff line change
@@ -9,11 +9,14 @@
*/
package org.jruby.truffle.nodes.rubinius;

import java.math.BigInteger;

import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.ConditionProfile;

import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.layouts.Layouts;

@@ -22,6 +25,44 @@
*/
public abstract class BignumPrimitiveNodes {

@RubiniusPrimitive(name = "bignum_compare")
public abstract static class BignumCompareNode extends RubiniusPrimitiveNode {

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

@Specialization
public int compare(DynamicObject a, long b) {
return Layouts.BIGNUM.getValue(a).compareTo(BigInteger.valueOf(b));
}

@Specialization(guards = "!isInfinity(b)")
public int compare(DynamicObject a, double b) {
return Double.compare(Layouts.BIGNUM.getValue(a).doubleValue(), b);
}

@Specialization(guards = "isInfinity(b)")
public int compareInfinity(DynamicObject a, double b) {
if (b < 0) {
return +1;
} else {
return -1;
}
}

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

@Specialization(guards = "!isRubyBignum(b)")
public Object compareFallback(DynamicObject a, DynamicObject b) {
return null; // Primitive failure
}

}

@RubiniusPrimitive(name = "bignum_pow")
public static abstract class BignumPowPrimitiveNode extends RubiniusPrimitiveNode {

2 changes: 1 addition & 1 deletion truffle/src/main/ruby/core.rb
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ def self.omit(reason)
#require_relative 'core/rubinius/bootstrap/array_mirror'
#require_relative 'core/rubinius/bootstrap/array'
#require_relative 'core/rubinius/bootstrap/atomic'
#require_relative 'core/rubinius/bootstrap/bignum'
require_relative 'core/rubinius/bootstrap/bignum'
#require_relative 'core/rubinius/bootstrap/block_environment'
#require_relative 'core/rubinius/bootstrap/byte_array'
#require_relative 'core/rubinius/bootstrap/call_site'
44 changes: 44 additions & 0 deletions truffle/src/main/ruby/core/rubinius/bootstrap/bignum.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of Rubinius nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Only part of Rubinius' bignum.rb

class Bignum < Integer
def <=>(other)
Rubinius.primitive :bignum_compare

# We do not use redo_compare here because Ruby does not
# raise if any part of the coercion or comparison raises
# an exception.
begin
coerced = other.coerce self
return nil unless coerced
coerced[0] <=> coerced[1]
rescue
return nil
end
end
end