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

Commits on Jan 8, 2015

  1. Copy the full SHA
    e5c85a3 View commit details
  2. Copy the full SHA
    ac02d42 View commit details
  3. [Truffle] Fixnum#coerce

    chrisseaton committed Jan 8, 2015
    Copy the full SHA
    8454ba8 View commit details
Showing with 334 additions and 84 deletions.
  1. +4 −0 core/src/main/java/org/jruby/truffle/nodes/RubyNode.java
  2. +20 −0 core/src/main/java/org/jruby/truffle/nodes/core/CoreMethodNode.java
  3. +18 −15 core/src/main/java/org/jruby/truffle/nodes/core/CoreMethodNodeManager.java
  4. +10 −0 core/src/main/java/org/jruby/truffle/nodes/core/EncodingNodes.java
  5. +117 −6 core/src/main/java/org/jruby/truffle/nodes/core/FixnumNodes.java
  6. +7 −14 core/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
  7. +79 −0 core/src/main/java/org/jruby/truffle/nodes/rubinius/FixnumPrimitiveNodes.java
  8. +1 −0 core/src/main/java/org/jruby/truffle/nodes/rubinius/RubiniusPrimitiveManager.java
  9. +5 −0 core/src/main/java/org/jruby/truffle/runtime/core/CoreLibrary.java
  10. +2 −1 core/src/main/java/org/jruby/truffle/runtime/core/RubyString.java
  11. +1 −0 core/src/main/ruby/jruby/truffle/core.rb
  12. +36 −0 core/src/main/ruby/jruby/truffle/core/rubinius/kernel/common/fixnum.rb
  13. +14 −0 core/src/main/ruby/jruby/truffle/core/rubinius/kernel/common/integer.rb
  14. +4 −0 core/src/main/ruby/jruby/truffle/core/rubinius/kernel/common/numeric.rb
  15. +12 −0 core/src/main/ruby/jruby/truffle/core/shims.rb
  16. +1 −0 spec/truffle/tags/core/array/inspect_tags.txt
  17. +1 −0 spec/truffle/tags/core/array/join_tags.txt
  18. +1 −0 spec/truffle/tags/core/array/to_s_tags.txt
  19. +0 −1 spec/truffle/tags/core/fixnum/case_compare_tags.txt
  20. +0 −6 spec/truffle/tags/core/fixnum/coerce_tags.txt
  21. +0 −1 spec/truffle/tags/core/fixnum/comparison_tags.txt
  22. +0 −1 spec/truffle/tags/core/fixnum/div_tags.txt
  23. +0 −1 spec/truffle/tags/core/fixnum/divide_tags.txt
  24. +0 −7 spec/truffle/tags/core/fixnum/element_reference_tags.txt
  25. +0 −1 spec/truffle/tags/core/fixnum/equal_value_tags.txt
  26. +0 −5 spec/truffle/tags/core/fixnum/even_tags.txt
  27. +0 −1 spec/truffle/tags/core/fixnum/exponent_tags.txt
  28. +0 −10 spec/truffle/tags/core/fixnum/fdiv_tags.txt
  29. +0 −1 spec/truffle/tags/core/fixnum/magnitude_tags.txt
  30. +0 −2 spec/truffle/tags/core/fixnum/modulo_tags.txt
  31. +0 −5 spec/truffle/tags/core/fixnum/odd_tags.txt
  32. +0 −1 spec/truffle/tags/core/fixnum/plus_tags.txt
  33. +0 −1 spec/truffle/tags/core/fixnum/right_shift_tags.txt
  34. +0 −3 spec/truffle/tags/core/fixnum/succ_tags.txt
  35. +0 −1 spec/truffle/tags/core/fixnum/to_s_tags.txt
  36. +1 −0 spec/truffle/tags/language/predefined_tags.txt
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/truffle/nodes/RubyNode.java
Original file line number Diff line number Diff line change
@@ -438,4 +438,8 @@ public boolean isObjectArray(Object value) {
return value instanceof Object[];
}

public boolean isRubyNilObject(Object value) {
return value == getContext().getCoreLibrary().getNilObject();
}

}
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
*/
package org.jruby.truffle.nodes.core;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
@@ -17,12 +18,31 @@
@NodeChild(value = "arguments", type = RubyNode[].class)
public abstract class CoreMethodNode extends RubyNode {

@CompilerDirectives.CompilationFinal private String name;

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

public CoreMethodNode(CoreMethodNode prev) {
super(prev);
name = prev.name;
}

public String getName() {
if (name == null) {
throw new UnsupportedOperationException();
}

return name;
}

public void setName(String name) {
if (this.name != null) {
throw new UnsupportedOperationException();
}

this.name = name;
}

}
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.dsl.GeneratedBy;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.nodes.NodeUtil;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.CoreSourceSection;
import org.jruby.truffle.nodes.RubyNode;
@@ -80,9 +81,6 @@ private static void addMethod(RubyClass rubyObjectClass, MethodDetails methodDet
final List<String> names = Arrays.asList(anno.names());
assert names.size() >= 1;

final String canonicalName = names.get(0);
final List<String> aliases = names.subList(1, names.size());

final Visibility visibility = anno.visibility();

if (anno.isModuleFunction()) {
@@ -100,25 +98,30 @@ private static void addMethod(RubyClass rubyObjectClass, MethodDetails methodDet

final RubyRootNode rootNode = makeGenericMethod(context, methodDetails, needsSelf);

final RubyMethod method = new RubyMethod(rootNode.getSharedMethodInfo(), canonicalName, module, visibility, false,
Truffle.getRuntime().createCallTarget(rootNode), null);

if (anno.isModuleFunction()) {
addMethod(module, method, aliases, Visibility.PRIVATE);
addMethod(module.getSingletonClass(null), method, aliases, Visibility.PUBLIC);
addMethod(module, rootNode, names, Visibility.PRIVATE);
addMethod(module.getSingletonClass(null), rootNode, names, Visibility.PUBLIC);
} else if (anno.onSingleton()) {
addMethod(module.getSingletonClass(null), method, aliases, visibility);
addMethod(module.getSingletonClass(null), rootNode, names, visibility);
} else {
addMethod(module, method, aliases, visibility);
addMethod(module, rootNode, names, visibility);
}
}

private static void addMethod(RubyModule module, RubyMethod method, List<String> aliases, Visibility visibility) {
method = method.withVisibility(visibility);
private static void addMethod(RubyModule module, RubyRootNode rootNode, List<String> names, Visibility visibility) {
for (String name : names) {
final RubyRootNode rootNodeCopy = NodeUtil.cloneNode(rootNode);

final CoreMethodNode coreMethodNode = NodeUtil.findFirstNodeInstance(rootNodeCopy, CoreMethodNode.class);

if (coreMethodNode != null) {
coreMethodNode.setName(name);
}

final RubyMethod method = new RubyMethod(rootNodeCopy.getSharedMethodInfo(), name, module, visibility, false,
Truffle.getRuntime().createCallTarget(rootNodeCopy), null);

module.addMethod(null, method);
for (String alias : aliases) {
module.addMethod(null, method.withNewName(alias));
module.addMethod(null, method.withVisibility(visibility).withNewName(name));
}
}

10 changes: 10 additions & 0 deletions core/src/main/java/org/jruby/truffle/nodes/core/EncodingNodes.java
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyEncoding;
import org.jruby.truffle.runtime.core.RubyNilClass;
import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.util.ByteList;

@@ -122,6 +123,15 @@ public RubyEncoding defaultExternal(RubyEncoding encoding) {
return encoding;
}

@Specialization
public RubyNilClass defaultExternal(RubyNilClass encoding) {
notDesignedForCompilation();

getContext().getRuntime().setDefaultInternalEncoding(ASCIIEncoding.INSTANCE);

return encoding;
}

}

@CoreMethod(names = "find", onSingleton = true, required = 1)
123 changes: 117 additions & 6 deletions core/src/main/java/org/jruby/truffle/nodes/core/FixnumNodes.java
Original file line number Diff line number Diff line change
@@ -20,10 +20,12 @@
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.nodes.methods.UnsupportedOperationBehavior;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.UndefinedPlaceholder;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyBignum;
import org.jruby.truffle.runtime.core.RubyNilClass;
import org.jruby.truffle.runtime.core.RubyString;

import java.math.BigInteger;
@@ -567,6 +569,27 @@ public long mod(int a, long b) {
return mod((long) a, b);
}

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

@Specialization
public double mod(long a, double b) {
if (b == 0) {
return 0 / 0;
}

double mod = a % b;

if (mod < 0 && b > 0 || mod > 0 && b < 0) {
adjustProfile.enter();
mod += b;
}

return mod;
}

@Specialization
public long mod(long a, int b) {
return mod(a, (long) b);
@@ -761,12 +784,16 @@ public boolean lessEqual(long a, RubyBignum b) {
@CoreMethod(names = {"==", "==="}, required = 1)
public abstract static class EqualNode extends CoreMethodNode {

@Child protected DispatchHeadNode reverseCallNode;

public EqualNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
reverseCallNode = new DispatchHeadNode(context);
}

public EqualNode(EqualNode prev) {
super(prev);
reverseCallNode = prev.reverseCallNode;
}

@Specialization
@@ -809,10 +836,15 @@ public boolean equal(long a, RubyBignum b) {
return bignum(a).equals(b);
}

@Fallback
public boolean equal(Object a, Object b) {
return false;
@Specialization(guards = {
"!isInteger(arguments[1])",
"!isLong(arguments[1])",
"!isRubyBignum(arguments[1])"
})
public Object equal(VirtualFrame frame, Object a, Object b) {
return reverseCallNode.call(frame, b, getName(), null, a);
}

}

@CoreMethod(names = "<=>", required = 1)
@@ -865,6 +897,16 @@ public int compare(long a, double b) {
public int compare(long a, RubyBignum b) {
return bignum(a).compareTo(b);
}

@Specialization(guards = {
"!isInteger(arguments[1])",
"!isLong(arguments[1])",
"!isDouble(arguments[1])",
"!isRubyBignum(arguments[1])"})
public RubyNilClass compare(Object a, Object b) {
return getContext().getCoreLibrary().getNilObject();
}

}

@CoreMethod(names = ">=", required = 1, unsupportedOperationBehavior = UnsupportedOperationBehavior.ARGUMENT_ERROR)
@@ -1208,14 +1250,20 @@ static boolean isStrictlyNegative(int value) {
@CoreMethod(names = ">>", required = 1, lowerFixnumParameters = 0)
public abstract static class RightShiftNode extends CoreMethodNode {

@Child protected DispatchHeadNode toInt;

public RightShiftNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
toInt = new DispatchHeadNode(context);
}

public RightShiftNode(RightShiftNode prev) {
super(prev);
toInt = prev.toInt;
}

protected abstract Object executeRightShift(VirtualFrame frame, Object a, Object b);

@Specialization
public int rightShift(int a, int b) {
if (b > 0) {
@@ -1242,6 +1290,27 @@ public long rightShift(long a, int b) {
}
}

@Specialization
public int rightShift(int a, RubyBignum b) {
return 0;
}

@Specialization
public int rightShift(long a, RubyBignum b) {
return 0;
}

@Specialization(guards = {"!isInteger(arguments[1])", "!isLong(arguments[1])", "!isRubyBignum(arguments[1])"})
public Object rightShift(VirtualFrame frame, Object a, Object b) {
final Object coerced = toInt.call(frame, b, "to_int", null);

if (coerced instanceof Integer || coerced instanceof Long || coerced instanceof RubyBignum) {
return executeRightShift(frame, a, coerced);
} else {
throw new UnsupportedOperationException();
}
}

}

@CoreMethod(names = "abs")
@@ -1324,6 +1393,31 @@ public long floor(long n) {

}

@CoreMethod(names = "inspect")
public abstract static class InspectNode extends CoreMethodNode {

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

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

@CompilerDirectives.TruffleBoundary
@Specialization
public RubyString inspect(int n) {
return getContext().makeString(Integer.toString(n));
}

@CompilerDirectives.TruffleBoundary
@Specialization
public RubyString inspect(long n) {
return getContext().makeString(Long.toString(n));
}

}

@CoreMethod(names = "size", needsSelf = false)
public abstract static class SizeNode extends CoreMethodNode {

@@ -1365,7 +1459,7 @@ public double toF(long n) {

}

@CoreMethod(names = {"to_s", "inspect"})
@CoreMethod(names = "to_s", optional = 1)
public abstract static class ToSNode extends CoreMethodNode {

public ToSNode(RubyContext context, SourceSection sourceSection) {
@@ -1378,16 +1472,33 @@ public ToSNode(ToSNode prev) {

@CompilerDirectives.TruffleBoundary
@Specialization
public RubyString toS(int n) {
public RubyString toS(int n, UndefinedPlaceholder undefined) {
return getContext().makeString(Integer.toString(n));
}

@CompilerDirectives.TruffleBoundary
@Specialization
public RubyString toS(long n) {
public RubyString toS(long n, UndefinedPlaceholder undefined) {
return getContext().makeString(Long.toString(n));
}

@CompilerDirectives.TruffleBoundary
@Specialization
public RubyString toS(int n, int base) {
return toS((long) n, base);
}

@CompilerDirectives.TruffleBoundary
@Specialization
public RubyString toS(long n, int base) {
if (base < 2 || base > 36) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentErrorInvalidRadix(base, this));
}

return getContext().makeString(Long.toString(n, base));
}

}

@CoreMethod(names = "zero?")
21 changes: 7 additions & 14 deletions core/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
Original file line number Diff line number Diff line change
@@ -100,23 +100,14 @@ public EqualNode(EqualNode prev) {
super(prev);
}

@Specialization
public boolean equal(@SuppressWarnings("unused") RubyString a, @SuppressWarnings("unused") RubyNilClass b) {
return false;
}

@Specialization
public boolean equal(RubyString a, RubyString b) {
return a.equals(b.toString());
}

@Specialization
@Specialization(guards = "!isRubyString(arguments[1])")
public boolean equal(RubyString a, Object b) {
if (b instanceof RubyString) {
return equal(a, (RubyString) b);
} else {
return false;
}
return false;
}
}

@@ -1332,9 +1323,11 @@ public ToFNode(ToFNode prev) {

@Specialization
public double toF(RubyString string) {
notDesignedForCompilation();

return Double.parseDouble(string.toString());
try {
return Double.parseDouble(string.toString());
} catch (NumberFormatException e) {
return 0;
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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
*/
package org.jruby.truffle.nodes.rubinius;

import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.ConditionProfile;
import org.jruby.truffle.nodes.dispatch.DispatchAction;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.MissingBehavior;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.util.StringSupport;

/**
* Rubinius primitives associated with the Ruby {@code Fixnum} class.
*/
public abstract class FixnumPrimitiveNodes {

@RubiniusPrimitive(name = "fixnum_coerce")
public static abstract class FixnumCoercePrimitiveNode extends RubiniusPrimitiveNode {

@Child protected DispatchHeadNode toFRespond;
@Child protected DispatchHeadNode toF;

public FixnumCoercePrimitiveNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
toFRespond = new DispatchHeadNode(context, false, false, MissingBehavior.RETURN_MISSING, null, DispatchAction.RESPOND_TO_METHOD);
toF = new DispatchHeadNode(context);
}

public FixnumCoercePrimitiveNode(FixnumCoercePrimitiveNode prev) {
super(prev);
toFRespond = prev.toFRespond;
toF = prev.toF;
}

@Specialization
public RubyArray coerce(int a, int b) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), new int[]{b, a}, 2);
}

@Specialization
public RubyArray coerce(int a, RubyString b) {
try {
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), new double[]{Double.parseDouble(b.toString()), a}, 2);
} catch (NumberFormatException e) {
throw new RaiseException(getContext().getCoreLibrary().argumentError("invalid value for Float", this));
}
}

@Specialization(guards = {"!isRubyString(arguments[1])", "!isRubyNilObject(arguments[1])"})
public RubyArray coerce(VirtualFrame frame, int a, Object b) {
if (toFRespond.doesRespondTo(frame, "to_f", b)) {
final Object bFloat = toF.call(frame, b, "to_f", null);

if (bFloat instanceof Double) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), new double[]{(double) bFloat, a}, 2);
} else {
throw new RaiseException(getContext().getCoreLibrary().typeError("?", this));
}
} else {
throw new RaiseException(getContext().getCoreLibrary().typeError("?", this));
}
}

}

}
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@ public static RubiniusPrimitiveManager create() {
nodeFactories.addAll(TypePrimitiveNodesFactory.getFactories());
nodeFactories.addAll(StringPrimitiveNodesFactory.getFactories());
nodeFactories.addAll(VMPrimitiveNodesFactory.getFactories());
nodeFactories.addAll(FixnumPrimitiveNodesFactory.getFactories());

final Map<String, RubiniusPrimitiveConstructor> primitives = new HashMap<>();

Original file line number Diff line number Diff line change
@@ -485,6 +485,11 @@ public RubyException argumentError(String message, Node currentNode) {
return new RubyException(argumentErrorClass, context.makeString(message), RubyCallStack.getBacktrace(currentNode));
}

public RubyException argumentErrorInvalidRadix(int radix, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return argumentError(String.format("invalid radix %d", radix), currentNode);
}

public RubyException argumentErrorMissingKeyword(String name, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return argumentError(String.format("missing keyword: %s", name), currentNode);
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@

import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import org.jcodings.Encoding;
import org.jcodings.specific.ASCIIEncoding;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.runtime.Helpers;
import org.jruby.truffle.nodes.RubyNode;
@@ -33,7 +34,7 @@ public RubyString(RubyClass stringClass, ByteList bytes) {
}

public static RubyString fromJavaString(RubyClass stringClass, String string) {
return new RubyString(stringClass, new ByteList(org.jruby.RubyEncoding.encodeUTF8(string), UTF8Encoding.INSTANCE, false));
return new RubyString(stringClass, new ByteList(org.jruby.RubyEncoding.encodeUTF8(string), ASCIIEncoding.INSTANCE, false));
}

public static RubyString fromByteList(RubyClass stringClass, ByteList bytes) {
1 change: 1 addition & 0 deletions core/src/main/ruby/jruby/truffle/core.rb
Original file line number Diff line number Diff line change
@@ -54,5 +54,6 @@
require_relative 'core/rubinius/kernel/common/true'
require_relative 'core/rubinius/kernel/common/false'
require_relative 'core/rubinius/kernel/common/complex'
require_relative 'core/rubinius/kernel/common/fixnum'

require_relative 'core/shims'
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright (c) 2007-2014, 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' fixnum.rb

class Fixnum

def coerce(other)
Rubinius.primitive :fixnum_coerce
super other
end

end
Original file line number Diff line number Diff line change
@@ -50,4 +50,18 @@ def [](index)
index < 0 ? 0 : (self >> index) & 1
end

def even?
self & 1 == 0
end

def odd?
self & 1 == 1
end

def next
self + 1
end

alias_method :succ, :next

end
Original file line number Diff line number Diff line change
@@ -41,6 +41,10 @@ def div(other)
self.__slash__(other).floor
end

def fdiv(other)
self.to_f / other
end

def real?
true
end
12 changes: 12 additions & 0 deletions core/src/main/ruby/jruby/truffle/core/shims.rb
Original file line number Diff line number Diff line change
@@ -17,6 +17,18 @@ def eql?(other)

end

class Fixnum

alias_method :magnitude, :abs

end

class Bignum

alias_method :magnitude, :abs

end

class Channel
end

1 change: 1 addition & 0 deletions spec/truffle/tags/core/array/inspect_tags.txt
Original file line number Diff line number Diff line change
@@ -8,3 +8,4 @@ fails:Array#inspect untrusts the result if an element is untrusted
fails:Array#inspect with encoding returns a US-ASCII string for an empty Array
fails:Array#inspect with encoding use US-ASCII encoding if the default external encoding is not ascii compatible
fails:Array#inspect with encoding raises if inspected result is not default external encoding
fails:Array#inspect with encoding use the default external encoding if it is ascii compatible
1 change: 1 addition & 0 deletions spec/truffle/tags/core/array/join_tags.txt
Original file line number Diff line number Diff line change
@@ -24,3 +24,4 @@ fails:Array#join with an untrusted separator does not untrust the result if the
fails:Array#join with an untrusted separator untrusts the result if the array has two or more elements
fails:Array#join with $, separates elements with default separator when the passed separator is nil
fails:Array#join raises an ArgumentError when the Array is recursive
fails:Array#join uses the widest common encoding when other strings are incompatible
1 change: 1 addition & 0 deletions spec/truffle/tags/core/array/to_s_tags.txt
Original file line number Diff line number Diff line change
@@ -8,3 +8,4 @@ fails:Array#to_s untrusts the result if an element is untrusted
fails:Array#to_s with encoding returns a US-ASCII string for an empty Array
fails:Array#to_s with encoding use US-ASCII encoding if the default external encoding is not ascii compatible
fails:Array#to_s with encoding raises if inspected result is not default external encoding
fails:Array#to_s with encoding use the default external encoding if it is ascii compatible
1 change: 0 additions & 1 deletion spec/truffle/tags/core/fixnum/case_compare_tags.txt

This file was deleted.

6 changes: 0 additions & 6 deletions spec/truffle/tags/core/fixnum/coerce_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/fixnum/comparison_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/fixnum/div_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/fixnum/divide_tags.txt

This file was deleted.

7 changes: 0 additions & 7 deletions spec/truffle/tags/core/fixnum/element_reference_tags.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
fails:Fixnum#[] calls #to_int to convert the argument to an Integer and returns 1 if the nth bit is set
fails:Fixnum#[] calls #to_int to convert the argument to an Integer and returns 0 if the nth bit is set
fails:Fixnum#[] accepts a Float argument and returns 0 if the bit at the truncated value is not set
fails:Fixnum#[] accepts a Float argument and returns 1 if the bit at the truncated value is set
fails:Fixnum#[] raises a TypeError when passed a String
fails:Fixnum#[] raises a TypeError when #to_int does not return an Integer
fails:Fixnum#[] calls #to_int to coerce a String to a Bignum and returns 0
fails:Fixnum#[] returns 0 when passed a Float in the range of a Bignum
1 change: 0 additions & 1 deletion spec/truffle/tags/core/fixnum/equal_value_tags.txt

This file was deleted.

5 changes: 0 additions & 5 deletions spec/truffle/tags/core/fixnum/even_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/fixnum/exponent_tags.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
fails:Fixnum#** returns self raised to the given power
fails:Fixnum#** can raise 1 to a Bignum safely
fails:Fixnum#** can raise -1 to a Bignum safely
fails:Fixnum#** switches to a Float when the number is too big
fails:Fixnum#** returns a complex number when negative and raised to a fractional power
10 changes: 0 additions & 10 deletions spec/truffle/tags/core/fixnum/fdiv_tags.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
fails:Fixnum#fdiv performs floating-point division between self and a Fixnum
fails:Fixnum#fdiv performs floating-point division between self and a Bignum
fails:Fixnum#fdiv performs floating-point division between self and a Float
fails:Fixnum#fdiv returns NaN when the argument is NaN
fails:Fixnum#fdiv returns Infinity when the argument is 0
fails:Fixnum#fdiv returns -Infinity when the argument is 0 and self is negative
fails:Fixnum#fdiv returns Infinity when the argument is 0.0
fails:Fixnum#fdiv returns -Infinity when the argument is 0.0 and self is negative
fails:Fixnum#fdiv raises a TypeError when argument isn't numeric
fails:Fixnum#fdiv raises an ArgumentError when passed multiple arguments
fails:Fixnum#fdiv follows the coercion protocol
1 change: 0 additions & 1 deletion spec/truffle/tags/core/fixnum/magnitude_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/fixnum/modulo_tags.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
fails:Fixnum#% returns the modulus obtained from dividing self by the given argument
fails:Fixnum#% raises a TypeError when given a non-Integer
fails:Fixnum#modulo returns the modulus obtained from dividing self by the given argument
fails:Fixnum#modulo raises a ZeroDivisionError when the given argument is 0
fails:Fixnum#modulo raises a ZeroDivisionError when the given argument is 0 and a Float
fails:Fixnum#modulo raises a TypeError when given a non-Integer
fails:Fixnum#% raises a ZeroDivisionError when the given argument is 0 and a Float
5 changes: 0 additions & 5 deletions spec/truffle/tags/core/fixnum/odd_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/fixnum/plus_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/fixnum/right_shift_tags.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
fails:Fixnum#>> with n >> m returns 0 when m is outside the available bits and n >= 0
fails:Fixnum#>> with n >> m returns -1 when m is outside the available bits and n < 0
fails:Fixnum#>> with n >> m returns 0 when m is a Bignum
fails:Fixnum#>> with n >> m returns a Bignum == fixnum_max() * 2 when fixnum_max() >> -1 and n > 0
fails:Fixnum#>> with n >> m returns a Bignum == fixnum_min() * 2 when fixnum_min() >> -1 and n < 0
fails:Fixnum#>> with n >> m calls #to_int to convert the argument to an Integer
3 changes: 0 additions & 3 deletions spec/truffle/tags/core/fixnum/succ_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/fixnum/to_s_tags.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
fails:Fixnum#to_s when given a base returns self converted to a String in the given base
fails:Fixnum#to_s returns a String in US-ASCII encoding when Encoding.default_internal is nil
fails:Fixnum#to_s returns a String in US-ASCII encoding when Encoding.default_internal is not nil
1 change: 1 addition & 0 deletions spec/truffle/tags/language/predefined_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fails:The predefined global constant ARGV contains Strings encoded in locale Encoding