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

Commits on Jun 18, 2015

  1. Copy the full SHA
    b3f3803 View commit details
  2. Copy the full SHA
    fdec80e View commit details
  3. [Truffle] Upgraded Rubinius core files from 2.4.1 to 2.5.6.

    Part of this upgrade was to limit the number of modifications made directly to Rubinius files.  Method overrides are now done in the api/shims files where possible.  Where code cannot be overridden or must otherwise be removed, the Truffle.omit utility was introduce to clearly denote these sections.  The intent is to make it clearer where we can't use Rubinius directly and to make future upgrades go easier.
    nirvdrum committed Jun 18, 2015
    Copy the full SHA
    acec36b View commit details
Showing with 6,354 additions and 1,615 deletions.
  1. +1 −0 lib/ruby/truffle/rubysl/rubysl-timeout/lib/rubysl/timeout/timeout.rb
  2. +6 −0 spec/truffle/tags/core/kernel/public_send_tags.txt
  3. +2 −0 spec/truffle/tags/core/kernel/remove_instance_variable_tags.txt
  4. +1 −0 spec/truffle/tags/core/module/class_variable_set_tags.txt
  5. +6 −0 spec/truffle/truffle.mspec
  6. +0 −2 truffle/src/main/java/org/jruby/truffle/nodes/core/FloatNodes.java
  7. +8 −1 truffle/src/main/java/org/jruby/truffle/nodes/core/RangeNodes.java
  8. +13 −2 truffle/src/main/java/org/jruby/truffle/translator/BodyTranslator.java
  9. +23 −1 truffle/src/main/java/org/jruby/truffle/translator/ModuleTranslator.java
  10. +15 −3 truffle/src/main/ruby/core.rb
  11. +11 −1 truffle/src/main/ruby/core/rubinius/alpha.rb
  12. +184 −1 truffle/src/main/ruby/core/rubinius/api/shims/array.rb
  13. +79 −0 truffle/src/main/ruby/core/rubinius/api/shims/exception.rb
  14. +36 −1 truffle/src/main/ruby/core/rubinius/api/shims/fixnum.rb
  15. +62 −0 truffle/src/main/ruby/core/rubinius/api/shims/hash.rb
  16. +75 −0 truffle/src/main/ruby/core/rubinius/api/shims/range.rb
  17. +22 −0 truffle/src/main/ruby/core/rubinius/api/shims/rubinius.rb
  18. +53 −0 truffle/src/main/ruby/core/rubinius/api/shims/tuple.rb
  19. +3 −3 truffle/src/main/ruby/core/rubinius/common/argf.rb
  20. +1,215 −299 truffle/src/main/ruby/core/rubinius/common/array.rb
  21. +16 −4 truffle/src/main/ruby/core/rubinius/common/bignum.rb
  22. +1 −1 truffle/src/main/ruby/core/rubinius/common/channel.rb
  23. +11 −20 truffle/src/main/ruby/core/rubinius/common/comparable.rb
  24. +22 −24 truffle/src/main/ruby/core/rubinius/common/complex.rb
  25. +2 −2 truffle/src/main/ruby/core/rubinius/common/complexifier.rb
  26. +2 −2 truffle/src/main/ruby/core/rubinius/common/ctype.rb
  27. +34 −22 truffle/src/main/ruby/core/rubinius/common/dir.rb
  28. +1 −1 truffle/src/main/ruby/core/rubinius/common/dir_glob.rb
  29. +37 −37 truffle/src/main/ruby/core/rubinius/common/encoding.rb
  30. +70 −41 truffle/src/main/ruby/core/rubinius/common/enumerable.rb
  31. +39 −0 truffle/src/main/ruby/core/rubinius/common/enumerable_helper.rb
  32. +13 −11 truffle/src/main/ruby/core/rubinius/common/enumerator.rb
  33. +1 −1 truffle/src/main/ruby/core/rubinius/common/errno.rb
  34. +396 −61 truffle/src/main/ruby/core/rubinius/common/exception.rb
  35. +2 −4 truffle/src/main/ruby/core/rubinius/common/false.rb
  36. +1 −1 truffle/src/main/ruby/core/rubinius/common/file.rb
  37. +2 −2 truffle/src/main/ruby/core/rubinius/common/file_test.rb
  38. +46 −12 truffle/src/main/ruby/core/rubinius/common/fixnum.rb
  39. +217 −31 truffle/src/main/ruby/core/rubinius/common/float.rb
  40. +1 −1 truffle/src/main/ruby/core/rubinius/common/gc.rb
  41. +10 −46 truffle/src/main/ruby/core/rubinius/common/hash.rb
  42. +1 −1 truffle/src/main/ruby/core/rubinius/common/identity_map.rb
  43. +1 −1 truffle/src/main/ruby/core/rubinius/common/immediate.rb
  44. +139 −63 truffle/src/main/ruby/core/rubinius/common/integer.rb
  45. +5 −5 truffle/src/main/ruby/core/rubinius/common/io.rb
  46. +757 −91 truffle/src/main/ruby/core/rubinius/common/kernel.rb
  47. +1 −1 truffle/src/main/ruby/core/rubinius/common/lru_cache.rb
  48. +18 −1 truffle/src/main/ruby/core/rubinius/common/main.rb
  49. +10 −6 truffle/src/main/ruby/core/rubinius/common/marshal.rb
  50. +835 −3 truffle/src/main/ruby/core/rubinius/common/module.rb
  51. +57 −6 truffle/src/main/ruby/core/rubinius/common/mutex.rb
  52. +1 −1 truffle/src/main/ruby/core/rubinius/common/nil.rb
  53. +157 −128 truffle/src/main/ruby/core/rubinius/common/numeric.rb
  54. +26 −0 truffle/src/main/ruby/core/rubinius/common/numeric_mirror.rb
  55. +77 −4 truffle/src/main/ruby/core/rubinius/common/object_space.rb
  56. +220 −4 truffle/src/main/ruby/core/rubinius/common/proc.rb
  57. +240 −46 truffle/src/main/ruby/core/rubinius/common/process.rb
  58. +257 −3 truffle/src/main/ruby/core/rubinius/common/process_mirror.rb
  59. +7 −3 truffle/src/main/ruby/core/rubinius/common/random.rb
  60. +88 −130 truffle/src/main/ruby/core/rubinius/common/range.rb
  61. +26 −0 truffle/src/main/ruby/core/rubinius/common/range_mirror.rb
  62. +9 −3 truffle/src/main/ruby/core/rubinius/common/rational.rb
  63. +4 −4 truffle/src/main/ruby/core/rubinius/common/rationalizer.rb
  64. +69 −67 truffle/src/main/ruby/core/rubinius/common/regexp.rb
  65. +9 −3 truffle/src/main/ruby/core/rubinius/common/signal.rb
  66. +2 −2 truffle/src/main/ruby/core/rubinius/common/splitter.rb
  67. +1 −1 truffle/src/main/ruby/core/rubinius/common/stat.rb
  68. +320 −301 truffle/src/main/ruby/core/rubinius/common/string.rb
  69. +2 −2 truffle/src/main/ruby/core/rubinius/common/string_mirror.rb
  70. +5 −5 truffle/src/main/ruby/core/rubinius/common/struct.rb
  71. +78 −59 truffle/src/main/ruby/core/rubinius/common/symbol.rb
  72. +153 −3 truffle/src/main/ruby/core/rubinius/common/thread.rb
  73. +1 −1 truffle/src/main/ruby/core/rubinius/common/throw_catch.rb
  74. +21 −8 truffle/src/main/ruby/core/rubinius/common/time.rb
  75. +1 −5 truffle/src/main/ruby/core/rubinius/common/true.rb
  76. +4 −3 truffle/src/main/ruby/core/rubinius/common/type.rb
  77. +1 −1 truffle/src/main/ruby/core/rubinius/common/undefined.rb
  78. +1 −1 truffle/src/main/ruby/core/rubinius/delta/class.rb
  79. +1 −1 truffle/src/main/ruby/core/rubinius/delta/file.rb
  80. +2 −2 truffle/src/main/ruby/core/rubinius/delta/file_test.rb
  81. +1 −1 truffle/src/main/ruby/core/rubinius/delta/kernel.rb
  82. +1 −1 truffle/src/main/ruby/core/rubinius/delta/module.rb
  83. +1 −1 truffle/src/main/ruby/core/rubinius/delta/struct.rb
  84. +1 −1 truffle/src/main/ruby/core/rubinius/platform/ffi.rb
  85. +1 −1 truffle/src/main/ruby/core/rubinius/platform/file.rb
  86. +1 −1 truffle/src/main/ruby/core/rubinius/platform/pointer.rb
  87. +1 −1 truffle/src/main/ruby/core/rubinius/platform/pointer_accessors.rb
  88. +1 −1 truffle/src/main/ruby/core/rubinius/platform/struct.rb
Original file line number Diff line number Diff line change
@@ -122,6 +122,7 @@ def self.watch_channel

# Spin up the thread up front to avoid a thread collision problem spinning
# it up lazily.
puts caller
@controller = Thread.new { watch_channel }

def self.add_timeout(time, exc)
6 changes: 6 additions & 0 deletions spec/truffle/tags/core/kernel/public_send_tags.txt
Original file line number Diff line number Diff line change
@@ -8,3 +8,9 @@ fails:Kernel#public_send succeeds if passed an arbitrary number of arguments as
fails:Kernel#public_send succeeds when passing 1 or more arguments as a required and a splat parameter
fails:Kernel#public_send succeeds when passing 0 arguments to a method with one parameter with a default
fails:Kernel#public_send has an arity of -1
fails:Kernel#public_send raises a NoMethodError if the method is protected
fails:Kernel#public_send raises a NoMethodError if the named method is private
fails:Kernel#public_send raises a NoMethodError if the named method is an alias of a private method
fails:Kernel#public_send raises a NoMethodError if the named method is an alias of a protected method
fails:Kernel#public_send raises a NameError if the corresponding method can't be found
fails:Kernel#public_send raises a NameError if the corresponding singleton method can't be found
Original file line number Diff line number Diff line change
@@ -5,3 +5,5 @@ fails:Kernel#remove_instance_variable when passed a String removes the instance
fails:Kernel#remove_instance_variable when passed a Symbol returns the instance variable's value
fails:Kernel#remove_instance_variable when passed a Symbol removes the instance variable
fails:Kernel#remove_instance_variable when passed an Object calls #to_str to convert the argument
fails:Kernel#remove_instance_variable raises a NameError if the instance variable is not defined
fails:Kernel#remove_instance_variable raises a NameError if the argument is not a valid instance variable name
1 change: 1 addition & 0 deletions spec/truffle/tags/core/module/class_variable_set_tags.txt
Original file line number Diff line number Diff line change
@@ -4,3 +4,4 @@ fails:Module#class_variable_set sets the value of a class variable with the give
fails:Module#class_variable_set raises a RuntimeError when self is frozen
fails:Module#class_variable_set converts a non string/symbol/fixnum name to string using to_str
fails:Module#class_variable_set raises a TypeError when the given names can't be converted to strings using to_str
fails:Module#class_variable_set raises a NameError when the given name is not allowed
6 changes: 6 additions & 0 deletions spec/truffle/truffle.mspec
Original file line number Diff line number Diff line change
@@ -99,6 +99,12 @@ class MSpecScript

# LoadError for `load "prime.rb"`
"^spec/ruby/library/prime/each_spec.rb",

# Loads 'timeout', which doesn't work yet and results in a message printed to console about Rubinius::Channel#receive
# not being implemented.
"^spec/ruby/library/net",
"^spec/ruby/library/resolv",
"^spec/ruby/library/timeout"
]

set :truffle, [
Original file line number Diff line number Diff line change
@@ -340,8 +340,6 @@ public Object lessEqualCoerced(VirtualFrame frame, double a, Object b) {
@CoreMethod(names = "eql?", required = 1)
public abstract static class EqlNode extends CoreMethodArrayArgumentsNode {

@Child private CallDispatchHeadNode fallbackCallNode;

public EqlNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}
Original file line number Diff line number Diff line change
@@ -10,13 +10,15 @@
package org.jruby.truffle.nodes.core;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.CreateCast;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.NodeChildren;
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.BranchProfile;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.cast.BooleanCastNodeGen;
import org.jruby.truffle.nodes.core.array.ArrayBuilderNode;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.runtime.NotProvided;
@@ -473,20 +475,25 @@ public Object setEnd(RubyRange.ObjectRange range, Object end) {
@RubiniusOnly
@NodeChildren({
@NodeChild(type = RubyNode.class, value = "self"),
@NodeChild(type = RubyNode.class, value = "end")
@NodeChild(type = RubyNode.class, value = "excludeEnd")
})
public abstract static class InternalSetExcludeEndNode extends RubyNode {

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

@CreateCast("excludeEnd") public RubyNode castToBoolean(RubyNode excludeEnd) {
return BooleanCastNodeGen.create(getContext(), getSourceSection(), excludeEnd);
}

@Specialization
public boolean setExcludeEnd(RubyRange.ObjectRange range, boolean excludeEnd) {
range.setExcludeEnd(excludeEnd);

return excludeEnd;
}

}

}
Original file line number Diff line number Diff line change
@@ -413,6 +413,13 @@ public RubyNode visitCallNode(CallNode node) {
&& ((org.jruby.ast.Colon2ConstNode) node.getReceiverNode()).getName().equals("Primitive")
&& node.getName().equals("assert_not_compiled")) {
return AssertNotCompiledNodeGen.create(context, sourceSection);
} else if (node.getReceiverNode() instanceof org.jruby.ast.ConstNode
&& ((ConstNode) node.getReceiverNode()).getName().equals("Truffle")) {
if (node.getName().equals("omit")) {
// We're never going to run the omitted code and it's never used as the RHS for anything, so just
// replace the call with nil.
return new LiteralNode(context, sourceSection, context.getCoreLibrary().getNilObject());
}
}

return visitCallNodeExtraArgument(node, null, false, false);
@@ -1633,7 +1640,9 @@ public RubyNode visitInstVarNode(org.jruby.ast.InstVarNode node) {
* self, and @start to be 0.
*/

if (sourceSection.getSource().getPath().equals("core:/core/rubinius/common/array.rb")) {
if (sourceSection.getSource().getPath().equals("core:/core/rubinius/common/array.rb") ||
sourceSection.getSource().getPath().equals("core:/core/rubinius/api/shims/array.rb")) {

if (name.equals("@total")) {
return new RubyCallNode(context, sourceSection, "size", self, null, false);
} else if (name.equals("@tuple")) {
@@ -1687,7 +1696,9 @@ public RubyNode visitInstVarNode(org.jruby.ast.InstVarNode node) {
}
}

if (sourceSection.getSource().getPath().equals("core:/core/rubinius/common/range.rb")) {
if (sourceSection.getSource().getPath().equals("core:/core/rubinius/common/range.rb") ||
sourceSection.getSource().getPath().equals("core:/core/rubinius/api/shims/range.rb")) {

if (name.equals("@begin")) {
return RangeNodesFactory.BeginNodeFactory.create(context, sourceSection, new RubyNode[] { self });
} else if (name.equals("@end")) {
Original file line number Diff line number Diff line change
@@ -82,7 +82,29 @@ public MethodDefinitionNode compileClassNode(SourceSection sourceSection, String
public RubyNode visitDefnNode(org.jruby.ast.DefnNode node) {
final SourceSection sourceSection = translate(node.getPosition(), node.getName());
final SelfNode classNode = new SelfNode(context, sourceSection);
return translateMethodDefinition(sourceSection, classNode, node.getName(), node, node.getArgsNode(), node.getBodyNode());

// If we have a method we've defined in a node, but would like to delegate some corner cases out to the
// Rubinius implementation for simplicity, we need a way to resolve the naming conflict. The naive solution
// here is to append "_internal" to the method name, which can then be called like any other method. This is
// a bit different than aliasing because normally if a Rubinius method name conflicts with an already defined
// method, we simply ignore the method definition. Here we explicitly rename the method so it's always defined.

String methodName = node.getName();
boolean rubiniusMethodRename = false;

if (sourceSection.getSource().getPath().equals("core:/core/rubinius/common/array.rb")) {
rubiniusMethodRename = methodName.equals("zip");
} else if (sourceSection.getSource().getPath().equals("core:/core/rubinius/common/float.rb")) {
rubiniusMethodRename = methodName.equals("round");
} else if (sourceSection.getSource().getPath().equals("core:/core/rubinius/common/range.rb")) {
rubiniusMethodRename = methodName.equals("each") || methodName.equals("step") || methodName.equals("to_a");
}

if (rubiniusMethodRename) {
methodName = methodName + "_internal";
}

return translateMethodDefinition(sourceSection, classNode, methodName, node, node.getArgsNode(), node.getBodyNode());
}

@Override
18 changes: 15 additions & 3 deletions truffle/src/main/ruby/core.rb
Original file line number Diff line number Diff line change
@@ -6,6 +6,14 @@
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

module Truffle
# Utility method for commenting out part of Rubinius's implementation and detailing why. It helps clearly
# demarcate things we want to omit from things Rubinius has left commented out and as such, should help compare
# diffs when upgrading Rubinius core files.
def self.omit(reason)
end
end

require_relative 'core/pre'

# Load Rubinius API
@@ -18,13 +26,11 @@

require_relative 'core/rubinius/api/shims/mirror'
require_relative 'core/rubinius/api/shims/lookuptable'
require_relative 'core/rubinius/api/shims/array'
require_relative 'core/rubinius/api/shims/rubinius'
require_relative 'core/rubinius/api/shims/thread'
require_relative 'core/rubinius/api/shims/tuple'
require_relative 'core/rubinius/api/shims/metrics'
require_relative 'core/rubinius/api/shims/module'
require_relative 'core/rubinius/api/shims/fixnum'
require_relative 'core/rubinius/api/shims/hash'

# Load alpha.rb

@@ -108,19 +114,23 @@
#require_relative 'core/rubinius/common/class'
#require_relative 'core/rubinius/common/autoload'
require_relative 'core/rubinius/common/module'
require_relative 'core/rubinius/api/shims/module'
#require_relative 'core/rubinius/common/binding'
require_relative 'core/rubinius/common/proc'
require_relative 'core/rubinius/common/enumerable_helper'
require_relative 'core/rubinius/common/enumerable'
require_relative 'core/rubinius/common/enumerator'
require_relative 'core/rubinius/common/argf'
#require_relative 'core/rubinius/common/tuple'
require_relative 'core/rubinius/common/exception'
require_relative 'core/rubinius/api/shims/exception'
require_relative 'core/rubinius/common/undefined'
require_relative 'core/rubinius/common/type'
require_relative 'core/rubinius/common/hash'
require_relative 'core/hash' # Our changes
#require_relative 'core/rubinius/common/hash_hamt'
require_relative 'core/rubinius/common/array'
require_relative 'core/rubinius/api/shims/array'
require_relative 'core/rubinius/common/kernel'
require_relative 'core/rubinius/common/identity_map'
#require_relative 'core/rubinius/common/loaded_features'
@@ -143,6 +153,7 @@
#require_relative 'core/rubinius/common/continuation'
#require_relative 'core/rubinius/common/delegated_method'
require_relative 'core/rubinius/common/fixnum'
require_relative 'core/rubinius/api/shims/fixnum'
require_relative 'core/rubinius/common/lru_cache'
require_relative 'core/rubinius/api/shims/encoding'
require_relative 'core/rubinius/common/encoding'
@@ -175,6 +186,7 @@
require_relative 'core/rubinius/common/range_mirror'
require_relative 'core/rubinius/api/shims/range_mirror'
require_relative 'core/rubinius/common/range'
require_relative 'core/rubinius/api/shims/range'
require_relative 'core/rubinius/common/struct'
require_relative 'core/rubinius/common/process'
require_relative 'core/rubinius/common/process_mirror'
12 changes: 11 additions & 1 deletion truffle/src/main/ruby/core/rubinius/alpha.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -43,3 +43,13 @@ def include(mod)
end

end

module Kernel

# Rubinius defines this method differently, using the :object_class primitive. The two primitives are very similar,
# so rather than introduce the new one, we'll just delegate to the existing one.
def __class__
Rubinius.invoke_primitive :vm_object_class, self
end

end
185 changes: 184 additions & 1 deletion truffle/src/main/ruby/core/rubinius/api/shims/array.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
# 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.

# Modifications are subject to:
# 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
@@ -36,9 +63,165 @@ def start

class Array

def new_range(start, count)
ret = Array.new(count)

self[start..-1].each_with_index { |x, index| ret[index] = x }

ret
end

def new_reserved(count)
# TODO CS 6-Feb-15 do we want to reserve space or allow the runtime to optimise for us?
self.class.new(0 , nil)
end

# We must override the definition of `reverse!` because our Array isn't backed by a Tuple. Rubinius expects
# modifications to the Tuple to update the backing store and to do that, we treat the Array itself as its own Tuple.
# However, Rubinius::Tuple#reverse! has a different, conflicting signature from Array#reverse!. This override avoids
# all of those complications.
def reverse!
Rubinius.check_frozen
return self unless @total > 1

i = 0
while i < self.length / 2
temp = self[i]
self[i] = self[self.length - i - 1]
self[self.length - i - 1] = temp
i += 1
end

return self
end

# Rubinius expects to be able to resize the array and adjust pointers by modifying `@total` and `@start`, respectively.
# We might be able to handle such changes by special handling in the body translator, however simply resizing could
# delete elements from either side and we're not able to tell which without additional context.
def slice!(start, length=undefined)
Rubinius.check_frozen

if undefined.equal? length
if start.kind_of? Range
range = start
out = self[range]

range_start = Rubinius::Type.coerce_to_collection_index range.begin
if range_start < 0
range_start = range_start + @total
end

range_end = Rubinius::Type.coerce_to_collection_index range.end
if range_end < 0
range_end = range_end + @total
elsif range_end >= @total
range_end = @total - 1
range_end += 1 if range.exclude_end?
end

range_length = range_end - range_start
range_length += 1 unless range.exclude_end?
range_end -= 1 if range.exclude_end?

if range_start < @total && range_start >= 0 && range_end < @total && range_end >= 0 && range_length > 0
delete_range(range_start, range_length)
end
else
# make sure that negative values are not passed through to the
# []= assignment
start = Rubinius::Type.coerce_to_collection_index start
start = start + @total if start < 0

# This is to match the MRI behaviour of not extending the array
# with nil when specifying an index greater than the length
# of the array.
return out unless start >= 0 and start < @total

out = @tuple.at start + @start

# Check for shift style.
if start == 0
@tuple.put @start, nil
self.shift
@start += 1
else
delete_range(start, 1)
end
end
else
start = Rubinius::Type.coerce_to_collection_index start
length = Rubinius::Type.coerce_to_collection_length length
return nil if length < 0

out = self[start, length]

if start < 0
start = @total + start
end
if start + length > @total
length = @total - start
end

if start < @total && start >= 0
delete_range(start, length)
end
end

out
end

# Rubinius expects to modify the backing store via updates to `@tuple` and we don't support that. As such, we must
# provide our own modifying implementation here.
def delete_range(index, del_length)
# optimize for fast removal..
reg_start = index + del_length
reg_length = @total - reg_start
if reg_start <= @total
# If we're removing from the front, also reset @start to better
# use the Tuple
if index == 0
# Use a shift start optimization if we're only removing one
# element and the shift started isn't already huge.
if del_length == 1
@start += 1
else
@tuple.copy_from @tuple, reg_start + @start, reg_length, 0
@start = 0
end
else
@tuple.copy_from @tuple, reg_start + @start, reg_length,
@start + index
end

# TODO we leave the old references in the Tuple, we should
# probably clear them out though.
del_length.times do
self.pop
end

end
end

# Rubinius expects to modify the backing store via updates to `@tuple` and we don't support that. As such, we must
# provide our own modifying implementation here.
def uniq!(&block)
Rubinius.check_frozen

if block_given?
im = Rubinius::IdentityMap.from(self, &block)
else
im = Rubinius::IdentityMap.from(self)
end
return if im.size == size

m = Rubinius::Mirror::Array.reflect im.to_array
@tuple = m.tuple
@start = m.start
@total = m.total

copy_from(m.tuple, 0, m.total, 0)
delete_range(m.total, self.size - m.total)
self
end

end
79 changes: 79 additions & 0 deletions truffle/src/main/ruby/core/rubinius/api/shims/exception.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# 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.

class Exception

# Indicates if the Exception has a backtrace set
def backtrace?
backtrace ? true : false # Truffle: simplified
end

def set_backtrace(bt)
if false # bt.kind_of? Rubinius::Backtrace # Truffle: not supported
@backtrace = bt
else
# See if we stashed a Backtrace object away, and use it.
if false # hidden_bt = Rubinius::Backtrace.detect_backtrace(bt) # Truffle: not yet supported
@backtrace = hidden_bt
else
type_error = TypeError.new "backtrace must be Array of String"
case bt
when Array
if bt.all? { |s| s.kind_of? String }
@custom_backtrace = bt
else
raise type_error
end
when String
@custom_backtrace = [bt]
when nil
@custom_backtrace = nil
else
raise type_error
end
end
end
end

def exception(message=nil)
if message
unless message.equal? self
# As strange as this might seem, this IS actually the protocol
# that MRI implements for this. The explicit call to
# Exception#initialize (via __initialize__) is exactly what MRI
# does.
e = clone
Rubinius.privately do # Truffle: added the privately block as Exception#initialize (and its alias) should be private
e.__initialize__(message)
end
return e
end
end

self
end

end
37 changes: 36 additions & 1 deletion truffle/src/main/ruby/core/rubinius/api/shims/fixnum.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
# 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.

# Modifications are subject to:
# Copyright (c) 2014, 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:
@@ -11,4 +38,12 @@ class Fixnum
MIN = -9223372036854775808
MAX = 9223372036854775807

end
def fdiv(n)
if n.kind_of?(Integer) # Truffle: Fixnum => Integer, to handle Bignum as MRI
to_f / n
else
redo_coerced :fdiv, n
end
end

end
62 changes: 62 additions & 0 deletions truffle/src/main/ruby/core/rubinius/api/shims/hash.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# 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.


class Hash

# Renamed version of the Rubinius Hash#[] method
#def self.[](*args)
def self._constructor_fallback(*args)
if args.size == 1
obj = args.first
if hash = Rubinius::Type.check_convert_type(obj, Hash, :to_hash)
new_hash = allocate.replace(hash)
new_hash.default = nil
return new_hash
elsif associate_array = Rubinius::Type.check_convert_type(obj, Array, :to_ary)
return new_from_associate_array(associate_array)
end
end

return new if args.empty?

if args.size & 1 == 1
raise ArgumentError, "Expected an even number, got #{args.length}"
end

hash = new
i = 0
total = args.size

while i < total
hash[args[i]] = args[i+1]
i += 2
end

hash
end

end
75 changes: 75 additions & 0 deletions truffle/src/main/ruby/core/rubinius/api/shims/range.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# 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.

class Range

def include?(value)
if @begin.respond_to?(:to_int) ||
@end.respond_to?(:to_int) ||
@begin.kind_of?(Numeric) ||
@end.kind_of?(Numeric)
cover? value
else
# super # MODIFIED inlined this because of local jump error
each_internal { |val| return true if val == value }
false
end
end

alias_method :member?, :include?

def to_a_internal # MODIFIED called from java to_a
return to_a_from_enumerable unless @begin.kind_of? Fixnum and @end.kind_of? Fixnum

fin = @end
fin += 1 unless @excl

size = fin - @begin
return [] if size <= 0

ary = Array.new(size)

i = 0
while i < size
ary[i] = @begin + i
i += 1
end

ary
end

def to_a_from_enumerable(*arg)
ary = []
each(*arg) do
o = Rubinius.single_block_arg
ary << o
nil
end
Rubinius::Type.infect ary, self
ary
end

end
22 changes: 22 additions & 0 deletions truffle/src/main/ruby/core/rubinius/api/shims/rubinius.rb
Original file line number Diff line number Diff line change
@@ -27,6 +27,10 @@ def self.mathn_loaded?
false
end

#def self.asm
# No-op.
#end

class Fiber < ::Fiber

ENABLED = true
@@ -45,6 +49,24 @@ class DynamicLibrary
# jnr-posix hard codes this value
PATH_MAX = 1024

# Rubinius has a method for modifying attributes on global variables. We handle that internally in JRuby+Truffle.
# The shim API here is just to allow Rubinius code to run unmodified.
class Globals
def self.read_only(var)
# No-op.
end

def self.set_hook(var)
# No-op.
end
end

class Backtrace
def self.detect_backtrace(bt)
false
end
end

end

class PrimitiveFailure < Exception
53 changes: 53 additions & 0 deletions truffle/src/main/ruby/core/rubinius/api/shims/tuple.rb
Original file line number Diff line number Diff line change
@@ -6,6 +6,34 @@
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

# Some of the code in this class is transliterated from C++ code in Rubinius.
#
# 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.

module Rubinius

class Tuple < Array
@@ -24,6 +52,31 @@ def self.create(*args)
ret
end

# Taken from Rubinius.
def reverse!(start, total)
if total <= 0 || start < 0 || start >= size
return self
end

_end = start + total - 1
if _end > size
_end = size - 1
end

head_ptr = start
tail_ptr = _end

while head_ptr < tail_ptr
tmp = self[head_ptr]
self[head_ptr] = self[tail_ptr]
self[tail_ptr] = tmp

head_ptr += 1
tail_ptr -= 1
end

self
end

end

6 changes: 3 additions & 3 deletions truffle/src/main/ruby/core/rubinius/common/argf.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -456,7 +456,7 @@ def seek(*args)
def set_encoding(*args)
@encoding_args = args
if @stream and !@stream.closed?
@stream.set_encoding(*args)
@stream.set_encoding *args
end
end

@@ -477,7 +477,7 @@ def stream(file)
stream = file == "-" ? STDIN : File.open(file, "r", :external_encoding => encoding)

if @encoding_args
stream.set_encoding(*@encoding_args)
stream.set_encoding *@encoding_args
elsif encoding
stream.set_encoding encoding
end
1,514 changes: 1,215 additions & 299 deletions truffle/src/main/ruby/core/rubinius/common/array.rb

Large diffs are not rendered by default.

20 changes: 16 additions & 4 deletions truffle/src/main/ruby/core/rubinius/common/bignum.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -24,10 +24,23 @@
# 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' bignnum.rb

class Bignum < Integer

Truffle.omit(":divide is a Rubinius internal detail. We define :/ directly in Java") do
# see README-DEVELOPERS regarding safe math compiler plugin
alias_method :/, :divide
end

def eql?(value)
value.is_a?(Bignum) && self == value
end

alias_method :modulo, :%

def fdiv(n)
to_f / n
end

def **(o)
Rubinius.primitive :bignum_pow

@@ -39,5 +52,4 @@ def **(o)

redo_coerced :**, o
end

end
2 changes: 1 addition & 1 deletion truffle/src/main/ruby/core/rubinius/common/channel.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
31 changes: 11 additions & 20 deletions truffle/src/main/ruby/core/rubinius/common/comparable.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# For the version at https://github.com/rubinius/rubinius/blob/v1.4.1/kernel/common/comparable.rb:
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -25,29 +24,18 @@
# 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.

# Modifications are subject to:
# 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

module Comparable
def ==(other)
return true if equal?(other)

return false if Thread.detect_recursion(self, other) do
begin
unless comp = (self <=> other)
return false
end

return Comparable.compare_int(comp) == 0
rescue StandardError
begin
unless comp = (self <=> other)
return false
end

return Comparable.compare_int(comp) == 0
rescue StandardError, SystemStackError
return false
end
end

@@ -93,8 +81,11 @@ def between?(min, max)

# A version of MRI's rb_cmpint (sort of)
def self.compare_int(int)
return 1 if int > 0
return int if int.kind_of? Fixnum

return 1 if int > 0
return -1 if int < 0
return 0
end
end

46 changes: 22 additions & 24 deletions truffle/src/main/ruby/core/rubinius/common/complex.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -26,33 +26,31 @@

#
# complex.rb -
# $Release Version: 0.5 $
# $Revision: 1.3 $
# $Date: 1998/07/08 10:05:28 $
# by Keiju ISHITSUKA(SHL Japan Inc.)
# $Release Version: 0.5 $
# $Revision: 1.3 $
# $Date: 1998/07/08 10:05:28 $
# by Keiju ISHITSUKA(SHL Japan Inc.)
#

class Complex < Numeric

# TODO(CS 7 Jan 15) we don't define all these methods yet

#undef_method :%
#undef_method :<
#undef_method :<=
#undef_method :<=>
#undef_method :>
#undef_method :>=
#undef_method :between?
#undef_method :div
#undef_method :divmod
#undef_method :floor
#undef_method :ceil
#undef_method :modulo
#undef_method :remainder
#undef_method :round
#undef_method :step
#undef_method :truncate
#undef_method :i
undef_method :%
undef_method :<
undef_method :<=
undef_method :<=>
undef_method :>
undef_method :>=
undef_method :between?
undef_method :div
undef_method :divmod
undef_method :floor
undef_method :ceil
undef_method :modulo
undef_method :remainder
undef_method :round
undef_method :step
undef_method :truncate
undef_method :i

def self.convert(real, imag = undefined)
if real.equal?(nil) || imag.equal?(nil)
4 changes: 2 additions & 2 deletions truffle/src/main/ruby/core/rubinius/common/complexifier.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -89,4 +89,4 @@ def convert
end
end
end
end
end
4 changes: 2 additions & 2 deletions truffle/src/main/ruby/core/rubinius/common/ctype.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -74,4 +74,4 @@ def self.tolower!(num)
def self.tolower(num)
isupper(num) ? tolower!(num) : num
end
end
end
56 changes: 34 additions & 22 deletions truffle/src/main/ruby/core/rubinius/common/dir.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -24,9 +24,8 @@
# 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' dir.rb

class Dir
include Enumerable

# This seems silly, I know. But we do this to make Dir more resistent to people
# screwing with ::File later (ie, fakefs)
@@ -61,6 +60,18 @@ def self.entries(path, options=undefined)
ret
end

def self.exist?(path)
PrivateFile.directory?(path)
end

class << self
alias_method :exists?, :exist?
end

def self.home(user=nil)
PrivateFile.expand_path("~#{user}")
end

def self.[](*patterns)
if patterns.size == 1
pattern = Rubinius::Type.coerce_to_path(patterns[0])
@@ -115,12 +126,6 @@ def self.glob_split(pattern)
result << pattern.byteslice(start, pattern.bytesize)
end

def self.mkdir(path, mode = 0777)
error = FFI::Platform::POSIX.mkdir(Rubinius::Type.coerce_to_path(path), mode)
Errno.handle path if error != 0
error
end

def self.foreach(path)
return to_enum(:foreach, path) unless block_given?

@@ -160,6 +165,12 @@ def self.chdir(path = ENV['HOME'])
end
end

def self.mkdir(path, mode = 0777)
error = FFI::Platform::POSIX.mkdir(Rubinius::Type.coerce_to_path(path), mode)
Errno.handle path if error != 0
error
end

def self.rmdir(path)
error = FFI::Platform::POSIX.rmdir(Rubinius::Type.coerce_to_path(path))
Errno.handle path if error != 0
@@ -173,6 +184,12 @@ def self.getwd
Rubinius::Type.external_string wd
end

def self.chroot(path)
ret = FFI::Platform::POSIX.chroot Rubinius::Type.coerce_to_path(path)
Errno.handle path if ret != 0
ret
end

def each
return to_enum unless block_given?

@@ -183,6 +200,10 @@ def each
self
end

attr_reader :path

alias_method :to_path, :path

SeekKind = 0
RewindKind = 1
TellKind = 2
@@ -211,22 +232,13 @@ def rewind
self
end

def inspect
"#<#{self.class}:#{object_id.to_s(16)} @path=#{@path}>"
end

class << self
alias_method :pwd, :getwd
alias_method :delete, :rmdir
alias_method :unlink, :rmdir
end

def self.exist?(path)
PrivateFile.directory?(path)
end

class << self
alias_method :exists?, :exist?
end

def self.home(user=nil)
PrivateFile.expand_path("~#{user}")
end

end
2 changes: 1 addition & 1 deletion truffle/src/main/ruby/core/rubinius/common/dir_glob.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
74 changes: 37 additions & 37 deletions truffle/src/main/ruby/core/rubinius/common/encoding.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -194,8 +194,8 @@ def convert(str)
status = primitive_convert str.dup, dest, nil, nil, @options | PARTIAL_INPUT

if status == :invalid_byte_sequence or
status == :undefined_conversion or
status == :incomplete_input
status == :undefined_conversion or
status == :incomplete_input
raise last_error
end

@@ -265,8 +265,8 @@ def finish
status = primitive_convert nil, dest

if status == :invalid_byte_sequence or
status == :undefined_conversion or
status == :incomplete_input
status == :undefined_conversion or
status == :incomplete_input
raise last_error
end

@@ -288,35 +288,35 @@ def last_error
destination_encoding_name = error[:destination_encoding_name]

case result
when :invalid_byte_sequence
read_again_string = error[:read_again_string]
if read_again_string
msg = "#{error_bytes_msg} followed by #{read_again_string.dump} on #{source_encoding_name}"
else
msg = "#{error_bytes_msg} on #{source_encoding_name}"
end
when :invalid_byte_sequence
read_again_string = error[:read_again_string]
if read_again_string
msg = "#{error_bytes_msg} followed by #{read_again_string.dump} on #{source_encoding_name}"
else
msg = "#{error_bytes_msg} on #{source_encoding_name}"
end

exc = InvalidByteSequenceError.new msg
when :incomplete_input
msg = "incomplete #{error_bytes_msg} on #{source_encoding_name}"
exc = InvalidByteSequenceError.new msg
when :incomplete_input
msg = "incomplete #{error_bytes_msg} on #{source_encoding_name}"

exc = InvalidByteSequenceError.new msg
when :undefined_conversion
error_char = error_bytes
if codepoint = error[:codepoint]
error_bytes_msg = "U+%04X" % codepoint
end
exc = InvalidByteSequenceError.new msg
when :undefined_conversion
error_char = error_bytes
if codepoint = error[:codepoint]
error_bytes_msg = "U+%04X" % codepoint
end

if source_encoding_name.to_sym == @source_encoding.name and
destination_encoding_name.to_sym == @destination_encoding.name
msg = "#{error_bytes_msg} from #{source_encoding_name} to #{destination_encoding_name}"
else
msg = "#{error_bytes_msg} to #{destination_encoding_name} in conversion from #{source_encoding_name}"
transcoder = @converters.first
msg << " to #{transcoder.target}"
end
if source_encoding_name.to_sym == @source_encoding.name and
destination_encoding_name.to_sym == @destination_encoding.name
msg = "#{error_bytes_msg} from #{source_encoding_name} to #{destination_encoding_name}"
else
msg = "#{error_bytes_msg} to #{destination_encoding_name} in conversion from #{source_encoding_name}"
transcoder = @converters.first
msg << " to #{transcoder.target}"
end

exc = UndefinedConversionError.new msg
exc = UndefinedConversionError.new msg
end

Rubinius.privately do
@@ -524,13 +524,13 @@ def self.set_alias_index(name, obj)
key = name.upcase.to_sym

case obj
when Encoding
source_name = obj.name
when nil
EncodingMap[key][1] = nil
return
else
source_name = StringValue(obj)
when Encoding
source_name = obj.name
when nil
EncodingMap[key][1] = nil
return
else
source_name = StringValue(obj)
end

entry = EncodingMap[source_name.upcase.to_sym]
111 changes: 70 additions & 41 deletions truffle/src/main/ruby/core/rubinius/common/enumerable.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -36,23 +36,23 @@ def chunk(initial_state = nil, &original_block)
previous = nil
accumulate = []
block = if initial_state.nil?
original_block
else
duplicated_initial_state = initial_state.dup
Proc.new{ |val| original_block.yield(val, duplicated_initial_state)}
end
original_block
else
duplicated_initial_state = initial_state.dup
Proc.new{ |val| original_block.yield(val, duplicated_initial_state)}
end
each do |val|
key = block.yield(val)
if key.nil? || (key.is_a?(Symbol) && key.to_s[0, 1] == "_")
yielder.yield [previous, accumulate] unless accumulate.empty?
accumulate = []
previous = nil
case key
when nil, :_separator
when :_alone
yielder.yield [key, [val]]
else
raise RuntimeError, "symbols beginning with an underscore are reserved"
when nil, :_separator
when :_alone
yielder.yield [key, [val]]
else
raise RuntimeError, "symbols beginning with an underscore are reserved"
end
else
if previous.nil? || previous == key
@@ -76,7 +76,7 @@ def collect
end
ary
else
to_enum :collect
to_enum(:collect) { enumerator_size }
end
end

@@ -95,15 +95,15 @@ def count(item = undefined)
end

def each_entry(*pass)
return to_enum :each_entry, *pass unless block_given?
return to_enum(:each_entry, *pass) { enumerator_size } unless block_given?
each(*pass) do |*args|
yield args.size == 1 ? args[0] : args
end
self
end

def each_with_object(memo)
return to_enum :each_with_object, memo unless block_given?
return to_enum(:each_with_object, memo) { enumerator_size } unless block_given?
each do
obj = Rubinius.single_block_arg
yield obj, memo
@@ -114,13 +114,22 @@ def each_with_object(memo)
alias_method :with_object, :each_with_object

def flat_map
return to_enum(:flat_map) unless block_given?
return to_enum(:flat_map) { enumerator_size } unless block_given?

inject([]) do |a, e|
result = yield e
array = []
each do |*args|
result = yield(*args)

value = Rubinius::Type.try_convert(result, Array, :to_ary) || result

Rubinius::Type.object_respond_to_ary?(result) ? a.concat(result) : a.push(result)
if value.kind_of? Array
array.concat value
else
array.push value
end
end

array
end

alias_method :collect_concat, :flat_map
@@ -137,7 +146,7 @@ def enumerator_size
private :enumerator_size

def group_by
return to_enum(:group_by) unless block_given?
return to_enum(:group_by) { enumerator_size } unless block_given?

h = {}
each do
@@ -221,14 +230,14 @@ def zip(*args)
o = Rubinius.single_block_arg
entry = args.inject([o]) do |ary, a|
ary << case a
when Array
a[i]
else
begin
a.next
rescue StopIteration
nil
end
when Array
a[i]
else
begin
a.next
rescue StopIteration
nil
end
end
end

@@ -243,7 +252,7 @@ def zip(*args)
end

def each_with_index(*args)
return to_enum(:each_with_index, *args) unless block_given?
return to_enum(:each_with_index, *args) { enumerator_size } unless block_given?

idx = 0
each(*args) do
@@ -298,7 +307,7 @@ def <=>(other)
end

def sort_by
return to_enum :sort_by unless block_given?
return to_enum(:sort_by) { enumerator_size } unless block_given?

# Transform each value to a tuple with the value and it's sort by value
sort_values = map do
@@ -368,7 +377,11 @@ def any?
end

def cycle(many=nil)
return to_enum(:cycle, many) unless block_given?
unless block_given?
return to_enum(:cycle, many) do
Rubinius::EnumerableHelper.cycle_size(enumerator_size, many)
end
end

if many
many = Rubinius::Type.coerce_to_collection_index many
@@ -425,11 +438,22 @@ def drop_while
end

def each_cons(num)
return to_enum(:each_cons, num) unless block_given?

n = Rubinius::Type.coerce_to_collection_index num
raise ArgumentError, "invalid size: #{n}" if n <= 0

unless block_given?
return to_enum(:each_cons, num) do
enum_size = enumerator_size
if enum_size.nil?
nil
elsif enum_size == 0 || enum_size < n
0
else
enum_size - n + 1
end
end
end

array = []
each do
element = Rubinius.single_block_arg
@@ -441,11 +465,16 @@ def each_cons(num)
end

def each_slice(slice_size)
return to_enum(:each_slice, slice_size) unless block_given?

n = Rubinius::Type.coerce_to_collection_index slice_size
raise ArgumentError, "invalid slice size: #{n}" if n <= 0

unless block_given?
return to_enum(:each_slice, slice_size) do
enum_size = enumerator_size
enum_size.nil? ? nil : (enum_size.to_f / n).ceil
end
end

a = []
each do
element = Rubinius.single_block_arg
@@ -474,7 +503,7 @@ def find(ifnone=nil)
alias_method :detect, :find

def find_all
return to_enum(:find_all) unless block_given?
return to_enum(:find_all) { enumerator_size } unless block_given?

ary = []
each do
@@ -555,7 +584,7 @@ def max
end

def max_by
return to_enum(:max_by) unless block_given?
return to_enum(:max_by) { enumerator_size } unless block_given?

max_object = nil
max_result = undefined
@@ -575,7 +604,7 @@ def max_by
end

def min_by
return to_enum(:min_by) unless block_given?
return to_enum(:min_by) { enumerator_size } unless block_given?

min_object = nil
min_result = undefined
@@ -630,7 +659,7 @@ def minmax(&block)
end

def minmax_by(&block)
return to_enum(:minmax_by) unless block_given?
return to_enum(:minmax_by) { enumerator_size } unless block_given?

min_object = nil
min_result = undefined
@@ -691,7 +720,7 @@ def one?
end

def partition
return to_enum(:partition) unless block_given?
return to_enum(:partition) { enumerator_size } unless block_given?

left = []
right = []
@@ -704,7 +733,7 @@ def partition
end

def reject
return to_enum(:reject) unless block_given?
return to_enum(:reject) { enumerator_size } unless block_given?

ary = []
each do
@@ -716,7 +745,7 @@ def reject
end

def reverse_each(&block)
return to_enum(:reverse_each) unless block_given?
return to_enum(:reverse_each) { enumerator_size } unless block_given?

# There is no other way then to convert to an array first... see 1.9's source.
to_a.reverse_each(&block)
39 changes: 39 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/enumerable_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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.

module Rubinius
module EnumerableHelper
def self.cycle_size(enum_size, many)
if many
many = Rubinius::Type.coerce_to_collection_index many
many = 0 if many < 0
(_size = enum_size).nil? ? nil : _size * many
else
enum_size.nil? ? nil : Float::INFINITY
end
end
end
end
24 changes: 13 additions & 11 deletions truffle/src/main/ruby/core/rubinius/common/enumerator.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -24,8 +24,6 @@
# 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.

# Note TODO on line 279 (CS 30-Jan-15)

module Enumerable
class Enumerator
include Enumerable
@@ -111,7 +109,7 @@ def each_with_block
private :each_with_block

def each_with_index
return to_enum(:each_with_index) unless block_given?
return to_enum(:each_with_index) { size } unless block_given?

idx = 0

@@ -172,11 +170,12 @@ def rewind
@object.rewind if @object.respond_to? :rewind
@generator.rewind if @generator
@lookahead = []
@feedvalue = nil
self
end

def size
@size.kind_of?(Proc) ? @size.call : @size
@size.respond_to?(:call) ? @size.call : @size
end

def with_index(offset=0)
@@ -186,7 +185,7 @@ def with_index(offset=0)
offset = 0
end

return to_enum(:with_index, offset) unless block_given?
return to_enum(:with_index, offset) { size } unless block_given?

each do
o = Rubinius.single_block_arg
@@ -213,7 +212,7 @@ def initialize(&block)
private :initialize

def yield(*args)
@proc.call(*args)
@proc.call *args
end

def <<(*args)
@@ -235,7 +234,7 @@ def initialize(&block)
private :initialize

def each(*args)
enclosed_yield = Proc.new { |*enclosed_args| yield(*enclosed_args) }
enclosed_yield = Proc.new { |*enclosed_args| yield *enclosed_args }

@proc.call Yielder.new(&enclosed_yield), *args
end
@@ -278,24 +277,27 @@ def lazy
self
end

# TODO alias_method :force, :to_a
alias_method :force, :to_a

def take(n)
n = Rubinius::Type.coerce_to n, Integer, :to_int
raise ArgumentError, "attempt to take negative size" if n < 0

current_size = enumerator_size
set_size = if current_size.kind_of?(Integer)
set_size = if current_size.kind_of?(Numeric)
n < current_size ? n : current_size
else
current_size
end

return to_enum(:cycle, 0).lazy if n.zero?

taken = 0
Lazy.new(self, set_size) do |yielder, *args|
if taken < n
yielder.yield(*args)
taken += 1
raise StopLazyError unless taken < n
else
raise StopLazyError
end
@@ -494,7 +496,7 @@ def reset
@fiber = Rubinius::Fiber.new(0) do
obj = @object
@result = obj.each do |*val|
Rubinius::Fiber.yield(*val)
Rubinius::Fiber.yield *val
end
@done = true
end
2 changes: 1 addition & 1 deletion truffle/src/main/ruby/core/rubinius/common/errno.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
457 changes: 396 additions & 61 deletions truffle/src/main/ruby/core/rubinius/common/exception.rb

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions truffle/src/main/ruby/core/rubinius/common/false.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -24,16 +24,14 @@
# 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' false.rb

class FalseClass
alias_method :|, :^

def inspect
# Call #to_s rather than alias it so that people can change #to_s if they
# wish. Yes, sounds dumb.
to_s
end

end

FALSE = false
2 changes: 1 addition & 1 deletion truffle/src/main/ruby/core/rubinius/common/file.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
4 changes: 2 additions & 2 deletions truffle/src/main/ruby/core/rubinius/common/file_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -117,4 +117,4 @@ def writable_real?(path)
def zero?(path)
File.zero? path
end
end
end
58 changes: 46 additions & 12 deletions truffle/src/main/ruby/core/rubinius/common/fixnum.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -24,29 +24,64 @@
# 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
##
#--
# NOTE do not define to_sym or id2name. It's been deprecated for 5 years and
# we've decided to remove it.
#++

# Our Bignum#coerce(Fixnum).first returns a Fixnum and not a Bignum.
# Therefore all Fixnum operations should handle Bignum (or Integer)
# explicitly instead of using coercion.
class Fixnum < Integer

class Fixnum
def self.induced_from(obj)
case obj
when Fixnum
return obj
when Float, Bignum
value = obj.to_i
if value.is_a? Bignum
raise RangeError, "Object is out of range for a Fixnum"
else
return value
end
else
value = Rubinius::Type.coerce_to(obj, Integer, :to_int)
return self.induced_from(value)
end
end

alias_method :modulo, :%
#--
# see README-DEVELOPERS regarding safe math compiler plugin
#++

def coerce(other)
Rubinius.primitive :fixnum_coerce
super other
Truffle.omit(":divide is a Rubinius internal detail. We define :/ directly in Java") do
alias_method :/, :divide
end

alias_method :modulo, :%

def fdiv(n)
if n.kind_of?(Integer) # Truffle: Fixnum => Integer, to handle Bignum as MRI
if n.kind_of?(Fixnum)
to_f / n
else
redo_coerced :fdiv, n
end
end

def imaginary
0
end

Truffle.omit(":divide is a Rubinius internal detail. We define :/ directly in Java") do
# Must be it's own method, so that super calls the correct method
# on Numeric
def div(o)
if o.is_a?(Float) && o == 0.0
raise ZeroDivisionError, "division by zero"
end
divide(o).floor
end
end

def **(o)
Rubinius.primitive :fixnum_pow

@@ -58,5 +93,4 @@ def **(o)

redo_coerced :**, o
end

end
248 changes: 217 additions & 31 deletions truffle/src/main/ruby/core/rubinius/common/float.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -24,38 +24,32 @@
# 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' float.rb

class Float < Numeric

def coerce(other)
return [other, self] if other.kind_of? Float
[Float(other), self]
end

def to_r
f, e = Math.frexp self
f = Math.ldexp(f, MANT_DIG).to_i
e -= MANT_DIG
FFI = Rubinius::FFI

(f * (RADIX ** e)).to_r
def self.induced_from(obj)
case obj
when Float, Bignum, Fixnum
obj.to_f
else
raise TypeError, "failed to convert #{obj.class} into Float"
end
end

def arg
if nan?
self
elsif negative?
Math::PI
else
0
def **(other)
Rubinius.primitive :float_pow

if other.is_a?(Float) && self < 0 && other != other.round
return Complex.new(self, 0) ** other
end

b, a = math_coerce other
a ** b
end
alias_method :angle, :arg
alias_method :phase, :arg

def negative?
Rubinius.primitive :float_negative
raise PrimitiveFailure, "Float#negative primitive failed"
def imaginary
0
end

def numerator
@@ -78,13 +72,26 @@ def denominator
end
end

alias_method :quo, :/
alias_method :modulo, :%
def to_r
f, e = Math.frexp self
f = Math.ldexp(f, MANT_DIG).to_i
e -= MANT_DIG

def finite?
not(nan? or infinite?)
(f * (RADIX ** e)).to_r
end

def arg
if nan?
self
elsif negative?
Math::PI
else
0
end
end
alias_method :angle, :arg
alias_method :phase, :arg

def rationalize(eps=undefined)
if undefined.equal?(eps)
f, n = Math.frexp self
@@ -97,8 +104,7 @@ def rationalize(eps=undefined)
end
end

# MODIFIED name to call from java
def round_internal(ndigits=0)
def round(ndigits=0)
ndigits = Rubinius::Type.coerce_to(ndigits, Integer, :to_int)

if ndigits == 0
@@ -122,10 +128,190 @@ def round_internal(ndigits=0)
f = 10**ndigits
Rubinius.invoke_primitive(:float_round, self * f) / f.to_f
end
def coerce(other)
return [other, self] if other.kind_of? Float
[Float(other), self]
end

def -@
Rubinius.primitive :float_neg
raise PrimitiveFailure, "Float#-@ primitive failed"
end

def abs
FFI::Platform::Math.fabs(self)
end

alias_method :magnitude, :abs

def negative?
Rubinius.primitive :float_negative
raise PrimitiveFailure, "Float#negative primitive failed"
end

def +(other)
Rubinius.primitive :float_add
b, a = math_coerce other
a + b
end

def -(other)
Rubinius.primitive :float_sub
b, a = math_coerce other
a - b
end

def *(other)
Rubinius.primitive :float_mul
b, a = math_coerce other
a * b
end

#--
# see README-DEVELOPERS regarding safe math compiler plugin
#++

def divide(other)
Rubinius.primitive :float_div
redo_coerced :/, other
end

Truffle.omit(":divide is a Rubinius internal detail. We define :/ directly in Java") do
alias_method :/, :divide
end

alias_method :quo, :/
alias_method :fdiv, :/

INFINITY = 1.0 / 0.0
NAN = 0.0 / 0.0

def divmod(other)
Rubinius.primitive :float_divmod
b, a = math_coerce other
a.divmod b
end

def %(other)
return 0 / 0.to_f if other == 0
Rubinius.primitive :float_mod
b, a = math_coerce other
a % b
end

alias_method :modulo, :%

def <(other)
Rubinius.primitive :float_lt
b, a = math_coerce other, :compare_error
a < b
end

def <=(other)
Rubinius.primitive :float_le
b, a = math_coerce other, :compare_error
a <= b
end

def >(other)
Rubinius.primitive :float_gt
b, a = math_coerce other, :compare_error
a > b
end

def >=(other)
Rubinius.primitive :float_ge
b, a = math_coerce other, :compare_error
a >= b
end

def <=>(other)
Rubinius.primitive :float_compare
b, a = math_coerce other, :compare_error
a <=> b
rescue ArgumentError
nil
end

def ==(other)
Rubinius.primitive :float_equal
begin
b, a = math_coerce(other)
return a == b
rescue TypeError
return other == self
end
end

def eql?(other)
Rubinius.primitive :float_eql
false
end

def nan?
Rubinius.primitive :float_isnan
raise PrimitiveFailure, "Float#nan? primitive failed"
end

def infinite?
Rubinius.primitive :float_isinf
raise PrimitiveFailure, "Float#infinite? primitive failed"
end

def finite?
not (nan? or infinite?)
end

def to_f
self
end

def to_i
Rubinius.primitive :float_to_i
raise PrimitiveFailure, "Float#to_i primitive failed"
end

alias_method :to_int, :to_i
alias_method :truncate, :to_i

def to_s
to_s_minimal
end

alias_method :inspect, :to_s

def to_s_minimal
Rubinius.primitive :float_to_s_minimal
raise PrimitiveFailure, "Float#to_s_minimal primitive failed: output exceeds buffer size"
end

def to_s_formatted(fmt)
Rubinius.primitive :float_to_s_formatted
raise PrimitiveFailure, "Float#to_s_formatted primitive failed: output exceeds buffer size"
end
private :to_s_formatted

def dtoa
Rubinius.primitive :float_dtoa
raise PrimitiveFailure, "Fload#dtoa primitive failed"
end

def to_packed(size)
Rubinius.primitive :float_to_packed
raise PrimitiveFailure, "Float#to_packed primitive failed"
end

def ceil
int = to_i()

return int if self == int or self < 0
return int + 1
end

def floor
int = to_i()

return int if self > 0 or self == int
return int - 1
end
end
2 changes: 1 addition & 1 deletion truffle/src/main/ruby/core/rubinius/common/gc.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
56 changes: 10 additions & 46 deletions truffle/src/main/ruby/core/rubinius/common/hash.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -359,7 +359,7 @@ def each_item
end

def each
return to_enum(:each) unless block_given?
return to_enum(:each) { size } unless block_given?

return unless @state

@@ -403,7 +403,7 @@ def flatten(level=1)
end

def keep_if
return to_enum(:keep_if) unless block_given?
return to_enum(:keep_if) { size } unless block_given?

Rubinius.check_frozen

@@ -535,7 +535,7 @@ def replace(other)
private :initialize_copy

def select
return to_enum(:select) unless block_given?
return to_enum(:select) { size } unless block_given?

selected = Hash.allocate

@@ -549,7 +549,7 @@ def select
end

def select!
return to_enum(:select!) unless block_given?
return to_enum(:select!) { size } unless block_given?

Rubinius.check_frozen

@@ -661,7 +661,7 @@ def default=(value)
end

def delete_if(&block)
return to_enum(:delete_if) unless block_given?
return to_enum(:delete_if) { size } unless block_given?

Rubinius.check_frozen

@@ -670,14 +670,14 @@ def delete_if(&block)
end

def each_key
return to_enum(:each_key) unless block_given?
return to_enum(:each_key) { size } unless block_given?

each_item { |item| yield item.key }
self
end

def each_value
return to_enum(:each_value) unless block_given?
return to_enum(:each_value) { size } unless block_given?

each_item { |item| yield item.value }
self
@@ -777,15 +777,15 @@ def rehash
end

def reject(&block)
return to_enum(:reject) unless block_given?
return to_enum(:reject) { size } unless block_given?

hsh = dup.delete_if(&block)
hsh.taint if tainted?
hsh
end

def reject!(&block)
return to_enum(:reject!) unless block_given?
return to_enum(:reject!) { size } unless block_given?

Rubinius.check_frozen

@@ -850,39 +850,3 @@ def values_at(*args)
alias_method :indexes, :values_at
end
end

class Hash

# Renamed version of the Rubinius Hash#[] method
#def self.[](*args)
def self._constructor_fallback(*args)
if args.size == 1
obj = args.first
if hash = Rubinius::Type.check_convert_type(obj, Hash, :to_hash)
new_hash = allocate.replace(hash)
new_hash.default = nil
return new_hash
elsif associate_array = Rubinius::Type.check_convert_type(obj, Array, :to_ary)
return new_from_associate_array(associate_array)
end
end

return new if args.empty?

if args.size & 1 == 1
raise ArgumentError, "Expected an even number, got #{args.length}"
end

hash = new
i = 0
total = args.size

while i < total
hash[args[i]] = args[i+1]
i += 2
end

hash
end

end
2 changes: 1 addition & 1 deletion truffle/src/main/ruby/core/rubinius/common/identity_map.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
2 changes: 1 addition & 1 deletion truffle/src/main/ruby/core/rubinius/common/immediate.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
202 changes: 139 additions & 63 deletions truffle/src/main/ruby/core/rubinius/common/integer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -24,52 +24,38 @@
# 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' kernel.rb

class Integer < Numeric

def gcd(other)
raise TypeError, "Expected Integer but got #{other.class}" unless other.kind_of?(Integer)
min = self.abs
max = other.abs
while min > 0
tmp = min
min = max % min
max = tmp
def self.induced_from(obj)
case obj
when Fixnum, Bignum
obj
when Float
obj.to_i
else
raise TypeError, "failed to convert #{obj.class} into Integer"
end
max
end

def to_r
Rational(self, 1)
end

def [](index)
index = Rubinius::Type.coerce_to(index, Integer, :to_int)
return 0 if index.is_a?(Bignum)
index < 0 ? 0 : (self >> index) & 1
end

def even?
self & 1 == 0
def &(other)
self & Rubinius::Type.coerce_to_bitwise_operand(other)
end

def odd?
self & 1 == 1
def |(other)
self | Rubinius::Type.coerce_to_bitwise_operand(other)
end

def pred
self - 1
def ^(other)
self ^ Rubinius::Type.coerce_to_bitwise_operand(other)
end

def next
self + 1
def to_i
self
end

alias_method :succ, :next
alias_method :to_int, :to_i
alias_method :truncate, :to_i
alias_method :ceil, :to_i
alias_method :floor, :to_i
alias_method :truncate, :to_i

def chr(enc=undefined)
if self < 0 || (self & 0xffff_ffff) != self
@@ -94,36 +80,6 @@ def chr(enc=undefined)
String.from_codepoint self, enc
end

def lcm(other)
raise TypeError, "Expected Integer but got #{other.class}" unless other.kind_of?(Integer)
if self.zero? or other.zero?
0
else
(self.div(self.gcd(other)) * other).abs
end
end

def gcdlcm(other)
gcd = self.gcd(other)
if self.zero? or other.zero?
[gcd, 0]
else
[gcd, (self.div(gcd) * other).abs]
end
end

def integer?
true
end

def ord
self
end

def rationalize(eps = nil)
Rational(self, 1)
end

def round(ndigits=undefined)
return self if undefined.equal? ndigits

@@ -170,4 +126,124 @@ def round(ndigits=undefined)
end
end

alias_method :magnitude, :abs

def gcd(other)
raise TypeError, "Expected Integer but got #{other.class}" unless other.kind_of?(Integer)
min = self.abs
max = other.abs
while min > 0
tmp = min
min = max % min
max = tmp
end
max
end

def rationalize(eps = nil)
Rational(self, 1)
end

def numerator
self
end

def denominator
1
end

def to_r
Rational(self, 1)
end

def lcm(other)
raise TypeError, "Expected Integer but got #{other.class}" unless other.kind_of?(Integer)
if self.zero? or other.zero?
0
else
(self.div(self.gcd(other)) * other).abs
end
end

def gcdlcm(other)
gcd = self.gcd(other)
if self.zero? or other.zero?
[gcd, 0]
else
[gcd, (self.div(gcd) * other).abs]
end
end

def [](index)
index = Rubinius::Type.coerce_to(index, Integer, :to_int)
return 0 if index.is_a?(Bignum)
index < 0 ? 0 : (self >> index) & 1
end

# FIXME: implement a fast way to calculate bignum exponents
def **(exp)
if exp.is_a?(Bignum)
raise TypeError, "Bignum exponent #{exp} too large"
end
super(exp)
end

def next
self + 1
end

alias_method :succ, :next

def integer?
true
end

def even?
self & 1 == 0
end

def odd?
self & 1 == 1
end

def ord
self
end

def pred
self - 1
end

def times
return to_enum(:times) { self } unless block_given?

i = 0
while i < self
yield i
i += 1
end
self
end

def upto(val)
return to_enum(:upto, val) { self <= val ? val - self + 1 : 0 } unless block_given?

i = self
while i <= val
yield i
i += 1
end
self
end

def downto(val)
return to_enum(:downto, val) { self >= val ? self - val + 1 : 0 } unless block_given?

i = self
while i >= val
yield i
i -= 1
end
self
end
end
10 changes: 5 additions & 5 deletions truffle/src/main/ruby/core/rubinius/common/io.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -998,19 +998,19 @@ def self.setup(io, fd, mode=nil, sync=false)
io.mode = mode || cur_mode
io.sync = !!sync

# Truffle: STDOUT isn't defined by the time this call is made during bootstrap, so we need to guard it.
# if STDOUT.respond_to?(:fileno) and not STDOUT.closed?
if defined? STDOUT and STDOUT.respond_to?(:fileno) and not STDOUT.closed?
io.sync ||= STDOUT.fileno == fd
end

# Truffle: STDERR isn't defined by the time this call is made during bootstrap, so we need to guard it.
# if STDERR.respond_to?(:fileno) and not STDERR.closed?
if defined? STDERR and STDERR.respond_to?(:fileno) and not STDERR.closed?
io.sync ||= STDERR.fileno == fd
end
end

def self.max_open_fd
@max_open_fd.get
end

#
# Create a new IO associated with the given fd.
#
848 changes: 757 additions & 91 deletions truffle/src/main/ruby/core/rubinius/common/kernel.rb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion truffle/src/main/ruby/core/rubinius/common/lru_cache.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
19 changes: 18 additions & 1 deletion truffle/src/main/ruby/core/rubinius/common/main.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -24,6 +24,7 @@
# 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.

# Truffle doesn't have a class MAIN, but it's implied by `self`, so just use that here.
class << self
def include(*mods)
Rubinius.privately do
@@ -34,6 +35,22 @@ def include(*mods)
# Truffle: Do not define #public, #private in Ruby since they need
# to set the top-level frame visibility when called with no argument.

#def public(*methods)
# Rubinius.privately do
# Object.public(*methods)
# end
#
# Object
#end

#def private(*methods)
# Rubinius.privately do
# Object.private(*methods)
# end
#
# Object
#end

def define_method(*args, &block)
Rubinius.privately do
Object.define_method(*args, &block)
16 changes: 10 additions & 6 deletions truffle/src/main/ruby/core/rubinius/common/marshal.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -491,7 +491,7 @@ def add_non_immediate_object(obj)
end

def add_object(obj)
sz = @links.size
sz = @objects.size
@objects[sz] = obj
@links[obj.__id__] = sz
end
@@ -551,11 +551,14 @@ def construct(ivar_index = nil, call_proc = true)
construct_data
when 64 # ?@
num = construct_integer
obj = @objects[num]

raise ArgumentError, "dump format error (unlinked)" unless obj
begin
obj = @objects.fetch(num)
return obj
rescue IndexError
raise ArgumentError, "dump format error (unlinked)"
end

return obj
when 59 # ?;
num = construct_integer
sym = @symbols[num]
@@ -650,7 +653,8 @@ def construct_bignum

obj = result * sign

store_unique_object obj
add_object obj
obj
end

def construct_data
838 changes: 835 additions & 3 deletions truffle/src/main/ruby/core/rubinius/common/module.rb

Large diffs are not rendered by default.

63 changes: 57 additions & 6 deletions truffle/src/main/ruby/core/rubinius/common/mutex.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -24,9 +24,63 @@
# 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.

# Rubinius' mutex.rb without implementation-specific methods.

class Mutex
def initialize
@owner = nil
end

# Check and only allow it to be marshal'd if there are no waiters.
def marshal_dump
raise "Unable to dump locked mutex" unless @waiters.empty?
1
end

# Implemented because we must since we use marshal_load PLUS we need
# to create AND prime @lock. If we didn't do this, then Marshal
# wouldn't prime the lock anyway.
def marshal_load(bunk)
initialize
end

def locked?
Rubinius.locked?(self)
end

def try_lock
# Locking implies a memory barrier, so we don't need to use
# one explicitly.
if Rubinius.try_lock(self)
return false if @owner == Thread.current
@owner = Thread.current
true
else
false
end
end

def lock
Rubinius.memory_barrier
if @owner == Thread.current
raise ThreadError, "Recursively locking not allowed"
end

Rubinius.lock self
@owner = Thread.current
Rubinius.memory_barrier
return self
end

def unlock
Rubinius.memory_barrier

if @owner != Thread.current
raise ThreadError, "Not owner, #{@owner.inspect} is"
end

@owner = nil
Rubinius.unlock self
self
end

def synchronize
lock
@@ -40,8 +94,6 @@ def synchronize
def sleep(duration=undefined)
if duration.kind_of?(Numeric) && duration < 0
raise ArgumentError, "time interval must be positive"
elsif duration == nil
duration = undefined
end

unlock
@@ -51,5 +103,4 @@ def sleep(duration=undefined)
lock
end
end

end
2 changes: 1 addition & 1 deletion truffle/src/main/ruby/core/rubinius/common/nil.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
285 changes: 157 additions & 128 deletions truffle/src/main/ruby/core/rubinius/common/numeric.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -24,9 +24,13 @@
# 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' numeric.rb

class Numeric
include Comparable

# Always raises TypeError, as dup'ing Numerics is not allowed.
def initialize_copy(other)
raise TypeError, "copy of #{self.class} is not allowed"
end

def +@
self
@@ -36,13 +40,127 @@ def -@
0 - self
end

def divmod(other)
[div(other), self % other]
end

def eql?(other)
return false unless other.instance_of? self.class
self == other
end

def divmod(other)
[div(other), self % other]
def <=>(other)
# It's important this method NOT contain the coercion protocols!
# MRI doesn't and doing so breaks stuff!

return 0 if self.equal? other
return nil
end

def step(limit, step=1)
unless block_given?
return to_enum(:step, limit, step) do
Rubinius::Mirror::Numeric.reflect(self).step_size(limit, step)
end
end

raise ArgumentError, "step cannot be 0" if step == 0

m = Rubinius::Mirror::Numeric.reflect(self)
values = m.step_fetch_args(limit, step)
value = values[0]
limit = values[1]
step = values[2]
asc = values[3]
is_float = values[4]

if is_float
n = m.step_float_size(value, limit, step, asc)

if n > 0
if step.infinite?
yield value
else
i = 0
if asc
while i < n
d = i * step + value
d = limit if limit < d
yield d
i += 1
end
else
while i < n
d = i * step + value
d = limit if limit > d
yield d
i += 1
end
end
end
end
else
if asc
until value > limit
yield value
value += step
end
else
until value < limit
yield value
value += step
end
end
end

return self
end

def truncate
Float(self).truncate
end

# Delegate #to_int to #to_i in subclasses
def to_int
to_i
end

def integer?
false
end

def zero?
self == 0
end

def nonzero?
zero? ? nil : self
end

def round
to_f.round
end

def abs
self < 0 ? -self : self
end

def floor
FloatValue(self).floor
end

def ceil
FloatValue(self).ceil
end

def remainder(other)
mod = self % other

if mod != 0 and ((self < 0 and other > 0) or (self > 0 and other < 0))
mod - other
else
mod
end
end

#--
@@ -55,10 +173,6 @@ def divmod(other)
# b.coerce a => [Bignum, Bignum]
#++

def abs
self < 0 ? -self : self
end

def coerce(other)
if other.instance_of? self.class
return [other, self]
@@ -101,12 +215,9 @@ def redo_coerced(meth, right)
end
private :redo_coerced

def zero?
self == 0
end

def nonzero?
zero? ? nil : self
def redo_compare(meth, right)
b, a = math_coerce(right, :compare_error)
a.__send__ meth, b
end

def div(other)
@@ -118,47 +229,16 @@ def fdiv(other)
self.to_f / other
end

alias_method :magnitude, :abs

def real?
true
end

def numerator
to_r.numerator
end

def denominator
to_r.denominator
end

def abs2
self * self
end

def arg
if self < 0
Math::PI
else
0
def quo(other)
Rubinius.privately do
Rational.convert(self, 1, false) / other
end
end

alias_method :angle, :arg
alias_method :phase, :arg

def ceil
FloatValue(self).ceil
end

def conjugate
self
end
alias_method :conj, :conjugate

def floor
FloatValue(self).floor
def modulo(other)
self - other * self.div(other)
end
alias_method :%, :modulo

def i
Complex(0, self)
@@ -177,96 +257,45 @@ def imag
end
alias_method :imaginary, :imag

def rect
[self, 0]
end
alias_method :rectangular, :rect

def truncate
Float(self).truncate
end

def round
to_f.round
def arg
if self < 0
Math::PI
else
0
end
end
alias_method :angle, :arg
alias_method :phase, :arg

def polar
return abs, arg
end

# Delegate #to_int to #to_i in subclasses
def to_int
to_i
end

def integer?
false
def conjugate
self
end
alias_method :conj, :conjugate

def modulo(other)
self - other * self.div(other)
def rect
[self, 0]
end
alias_method :%, :modulo
alias_method :rectangular, :rect

def quo(other)
Rubinius.privately do
Rational.convert(self, 1, false) / other
end
def abs2
self * self
end

def step(limit, step=1)
return to_enum(:step, limit, step) unless block_given?

raise ArgumentError, "step cannot be 0" if step == 0

value = self
if value.kind_of? Float or limit.kind_of? Float or step.kind_of? Float
# Ported from MRI

value = FloatValue(value)
limit = FloatValue(limit)
step = FloatValue(step)
alias_method :magnitude, :abs

if step.infinite?
yield value if step > 0 ? value <= limit : value >= limit
else
err = (value.abs + limit.abs + (limit - value).abs) / step.abs * Float::EPSILON
if err.finite?
err = 0.5 if err > 0.5
n = ((limit - value) / step + err).floor
i = 0
if step > 0
while i <= n
d = i * step + value
d = limit if limit < d
yield d
i += 1
end
else
while i <= n
d = i * step + value
d = limit if limit > d
yield d
i += 1
end
end
end
end
else
if step > 0
until value > limit
yield value
value += step
end
else
until value < limit
yield value
value += step
end
end
end
def numerator
to_r.numerator
end

return self
def denominator
to_r.denominator
end

def real?
true
end
end
26 changes: 26 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/numeric_mirror.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
# 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.

module Rubinius
class Mirror
class Numeric < Mirror
81 changes: 77 additions & 4 deletions truffle/src/main/ruby/core/rubinius/common/object_space.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -24,12 +24,85 @@
# 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' object_space.rb

module ObjectSpace
def self.find_object(query, callable)
Rubinius.primitive :vm_find_object
raise PrimitiveFailure, "ObjectSpace#find_object primitive failed"
end

def self._id2ref(id)
ary = []
if find_object([:object_id, Integer(id)], ary) > 0
return ary.first
end

return nil
end

def self.find_references(obj)
ary = []
find_object([:references, obj], ary)
return ary
end

# @todo rewrite each_object

# Tries to handle as much as it can.
def self.each_object(what=nil, &block)
return to_enum :each_object, what unless block_given?

what ||= Object

unless what.kind_of? Object
raise TypeError, "class or module required"
end

case what
when Fixnum, Symbol
return 0
when TrueClass
yield true
return 1
when FalseClass
yield false
return 1
when NilClass
yield nil
return 1
else
return find_object([:kind_of, what], block)
end
end

def self.define_finalizer(obj, prc=nil, &block)
prc ||= block

if obj.equal? prc
# This is allowed. This is the Rubinius specific API that calls
# __finalize__ when the object is finalized.
elsif !prc and obj.respond_to?(:__finalize__)
# Allowed. Same thing as above
prc = obj
elsif !prc or !prc.respond_to?(:call)
raise ArgumentError, "action must respond to call"
end

unless Rubinius.invoke_primitive(:vm_set_finalizer, obj, prc)
raise RuntimeError, "cannot define a finalizer for a #{obj.class}"
end

[0, prc]
end

def self.undefine_finalizer(obj)
Rubinius.invoke_primitive :vm_set_finalizer, obj, nil
return obj
end

def self.run_finalizers
end

def self.garbage_collect
GC.start
end

end
Loading