Skip to content

Commit

Permalink
Showing 29 changed files with 146 additions and 166 deletions.
Original file line number Diff line number Diff line change
@@ -70,15 +70,15 @@ public DynamicObject dToA(double value) {

}

@RubiniusPrimitive(name = "float_negative")
public static abstract class FloatNegativePrimitiveNode extends RubiniusPrimitiveNode {
@RubiniusPrimitive(name = "float_signbit_p")
public static abstract class FloatSignBitNode extends RubiniusPrimitiveNode {

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

@Specialization
public boolean floatNegative(double value) {
public boolean floatSignBit(double value) {
// Edge-cases: 0, NaN and infinity can all be negative
return (Double.doubleToLongBits(value) >>> 63) == 1;
}
2 changes: 1 addition & 1 deletion truffle/src/main/ruby/core.rb
Original file line number Diff line number Diff line change
@@ -147,7 +147,6 @@ def self.omit(reason)
#require_relative 'core/rubinius/common/global'
#require_relative 'core/rubinius/common/backtrace'
require_relative 'core/rubinius/common/comparable'
require_relative 'core/rubinius/api/shims/comparable'
require_relative 'core/rubinius/common/numeric_mirror'
require_relative 'core/rubinius/common/numeric'
require_relative 'core/rubinius/common/ctype'
@@ -215,6 +214,7 @@ def self.omit(reason)
#require_relative 'core/rubinius/common/thread_group'
require_relative 'core/rubinius/common/throw_catch'
require_relative 'core/rubinius/common/time'
require_relative 'core/rubinius/api/shims/time'
require_relative 'core/rubinius/common/true'
#require_relative 'core/rubinius/common/variable_scope'
#require_relative 'core/rubinius/common/capi'
2 changes: 1 addition & 1 deletion truffle/src/main/ruby/core/rubinius/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
`bootstrap`, `common`, `delta` and `platform` contains the Ruby component of the
Rubinius kernel (core library) implementation, in some cases modified. We have
taken files from version 2.5.6 of Rubinius. This code was written by Evan
taken files from version 2.7 of Rubinius. This code was written by Evan
Phoenix, Brian Shirai, et al.

https://github.com/rubinius/rubinius
11 changes: 9 additions & 2 deletions truffle/src/main/ruby/core/rubinius/api/shims/array.rb
Original file line number Diff line number Diff line change
@@ -37,8 +37,15 @@ module Rubinius
class Mirror
class Array

def self.reflect(array)
Array.new(array)
def self.reflect(object)
if Rubinius::Type.object_kind_of? object, ::Array
Array.new(object)
elsif ary = Rubinius::Type.try_convert(object, ::Array, :to_ary)
Array.new(ary)
else
message = "expected Array, given #{Rubinius::Type.object_class(object)}"
raise TypeError, message
end
end

def initialize(array)
44 changes: 0 additions & 44 deletions truffle/src/main/ruby/core/rubinius/api/shims/comparable.rb

This file was deleted.

27 changes: 11 additions & 16 deletions truffle/src/main/ruby/core/rubinius/api/shims/metrics.rb
Original file line number Diff line number Diff line change
@@ -13,23 +13,18 @@ module Metrics
def self.data
{
:'gc.young.count' => 0,
:'gc.young.last.ms' => 0,
:'gc.young.total.ms' => 0,
:'gc.immix.concurrent.last.ms' => 0,
:'gc.immix.concurrent.total.ms' => 0,
:'gc.young.ms' => 0,
:'gc.immix.concurrent.ms' => 0,
:'gc.immix.count' => Truffle::Primitive.gc_count,
:'gc.immix.stop.last.ms' => 0,
:'gc.immix.stop.total.ms' => Truffle::Primitive.gc_time,
:'gc.large.sweep.total.ms' => 0,
:'memory.young.bytes.current' => 0,
:'memory.young.bytes.total' => 0,
:'memory.young.objects.total' => 0,
:'memory.immix.bytes.current' => 0,
:'memory.immix.bytes.total' => 0,
:'memory.immix.objects.total' => 0,
:'memory.large.bytes.current' => 0,
:'memory.promoted.bytes.total' => 0,
:'memory.promoted.objects.total' => 0,
:'gc.immix.stop.ms' => Truffle::Primitive.gc_time,
:'gc.large.sweep.us' => 0,
:'memory.young.bytes' => 0,
:'memory.young.objects' => 0,
:'memory.immix.bytes' => 0,
:'memory.immix.objects' => 0,
:'memory.large.bytes' => 0,
:'memory.promoted.bytes' => 0,
:'memory.promoted.objects' => 0,
:'memory.symbols.bytes' => 0,
:'memory.code.bytes' => 0
}
15 changes: 0 additions & 15 deletions truffle/src/main/ruby/core/rubinius/api/shims/range_mirror.rb
Original file line number Diff line number Diff line change
@@ -16,21 +16,6 @@ def excl
@object.exclude_end?
end

# Local fix until Rubinius is fixed upstream.
def step_float_iterations_size(first, last, step_size)
err = (first.abs + last.abs + (last - first).abs) / step_size.abs * Float::EPSILON
err = 0.5 if err > 0.5

if excl
iterations = ((last - first) / step_size - err).floor
iterations += 1 if iterations * step_size + first < last
else
iterations = ((last - first) / step_size + err).floor + 1
end

iterations
end

end
end
end
15 changes: 15 additions & 0 deletions truffle/src/main/ruby/core/rubinius/api/shims/time.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 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:
#
# Eclipse Public License version 1.0
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

class Time

def to_f
seconds + nsec * 0.000000001 # Truffle: optimized
end

end
2 changes: 1 addition & 1 deletion truffle/src/main/ruby/core/rubinius/bootstrap/kernel.rb
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@
# Only part of Rubinius' kernel.rb

module Kernel

alias_method :eql?, :equal?

# Truffle: no extra indirection for Kernel#send.
2 changes: 1 addition & 1 deletion truffle/src/main/ruby/core/rubinius/bootstrap/string.rb
Original file line number Diff line number Diff line change
@@ -99,7 +99,7 @@ def find_character(offset)
def num_bytes
@num_bytes
end

def byte_append(str)
Rubinius.primitive :string_byte_append
raise TypeError, "String#byte_append primitive only accepts Strings"
2 changes: 1 addition & 1 deletion truffle/src/main/ruby/core/rubinius/common/argf.rb
Original file line number Diff line number Diff line change
@@ -534,7 +534,7 @@ def advance!
@advance = false

file = ARGV.shift
@stream = stream(file)
@stream = stream(file)
@filename = file

if $-i && @stream != STDIN
15 changes: 13 additions & 2 deletions truffle/src/main/ruby/core/rubinius/common/array.rb
Original file line number Diff line number Diff line change
@@ -1982,9 +1982,20 @@ def recursively_flatten(array, out, max_levels = -1)
while i < total
o = tuple.at i

if ary = Rubinius::Type.check_convert_type(o, Array, :to_ary)
if Rubinius::Type.object_kind_of? o, Array
modified = true
recursively_flatten(ary, out, max_levels)
recursively_flatten o, out, max_levels
elsif Rubinius::Type.object_respond_to? o, :to_ary
ary = o.__send__ :to_ary
if nil.equal? ary
out << o
else
modified = true
recursively_flatten ary, out, max_levels
end
elsif ary = Rubinius::Type.execute_check_convert_type(o, Array, :to_ary)
modified = true
recursively_flatten ary, out, max_levels
else
out << o
end
14 changes: 8 additions & 6 deletions truffle/src/main/ruby/core/rubinius/common/comparable.rb
Original file line number Diff line number Diff line change
@@ -28,14 +28,16 @@ module Comparable
def ==(other)
return true if equal?(other)

begin
unless comp = (self <=> 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
return false
end

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

2 changes: 1 addition & 1 deletion truffle/src/main/ruby/core/rubinius/common/complex.rb
Original file line number Diff line number Diff line change
@@ -303,7 +303,7 @@ def rationalize(eps = nil)
def to_s
result = real.to_s

if imag.kind_of?(Float) ? !imag.nan? && imag.negative? : imag < 0
if imag.kind_of?(Float) ? !imag.nan? && imag.signbit? : imag < 0
result << "-"
else
result << "+"
6 changes: 4 additions & 2 deletions truffle/src/main/ruby/core/rubinius/common/exception.rb
Original file line number Diff line number Diff line change
@@ -279,8 +279,10 @@ def initialize(*arguments)
class RuntimeError < StandardError
end

#class SecurityError < StandardError
#end
Truffle.omit("Wrong superclass") do
class SecurityError < StandardError
end
end

class ThreadError < StandardError
end
8 changes: 4 additions & 4 deletions truffle/src/main/ruby/core/rubinius/common/float.rb
Original file line number Diff line number Diff line change
@@ -83,7 +83,7 @@ def to_r
def arg
if nan?
self
elsif negative?
elsif signbit?
Math::PI
else
0
@@ -144,9 +144,9 @@ def abs

alias_method :magnitude, :abs

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

def +(other)
24 changes: 12 additions & 12 deletions truffle/src/main/ruby/core/rubinius/common/gc.rb
Original file line number Diff line number Diff line change
@@ -32,9 +32,9 @@ def self.count

def self.time
data = stat
data[:"gc.young.total.ms"] +
data[:"gc.immix.stop.total.ms"] +
data[:"gc.large.sweep.total.ms"]
data[:"gc.young.ms"] +
data[:"gc.immix.stop.ms"] +
data[:"gc.large.sweep.us"] * 1_000
end

def self.stat
@@ -80,22 +80,22 @@ def self.result
===================================
Collections
Count Total time / concurrent (ms) Last time / concurrent (ms)
Young #{sprintf("% 22d", stats[:'gc.young.count'])} #{sprintf("% 16d ", stats[:'gc.young.total.ms'])} #{sprintf("% 16d ", stats[:'gc.young.last.ms'])}
Full #{sprintf("% 22d", stats[:'gc.immix.count'])} #{sprintf("% 16d / % 10d", stats[:'gc.immix.stop.total.ms'], stats[:'gc.immix.concurrent.total.ms'])} #{sprintf("% 16d / % 10d", stats[:'gc.immix.stop.last.ms'], stats[:'gc.immix.concurrent.last.ms'])}
Count Total time / concurrent (ms)
Young #{sprintf("% 22d", stats[:'gc.young.count'])} #{sprintf("% 16d ", stats[:'gc.young.ms'])}
Full #{sprintf("% 22d", stats[:'gc.immix.count'])} #{sprintf("% 16d / % 10d", stats[:'gc.immix.stop.ms'], stats[:'gc.immix.concurrent.ms'])}
Allocation
Objects allocated Bytes allocated
Young #{sprintf("% 22d", stats[:'memory.young.objects.total'])} #{sprintf("% 22d", stats[:'memory.young.bytes.total'])}
Promoted#{sprintf("% 22d", stats[:'memory.promoted.objects.total'])} #{sprintf("% 22d", stats[:'memory.promoted.bytes.total'])}
Mature #{sprintf("% 22d", stats[:'memory.immix.objects.total'])} #{sprintf("% 22d", stats[:'memory.immix.bytes.total'])}
Young #{sprintf("% 22d", stats[:'memory.young.objects'])} #{sprintf("% 22d", stats[:'memory.young.bytes'])}
Promoted#{sprintf("% 22d", stats[:'memory.promoted.objects'])} #{sprintf("% 22d", stats[:'memory.promoted.bytes'])}
Mature #{sprintf("% 22d", stats[:'memory.immix.objects'])} #{sprintf("% 22d", stats[:'memory.immix.bytes'])}
Usage
Bytes used
Young #{sprintf("% 22d", stats[:'memory.young.bytes.current'])}
Mature #{sprintf("% 22d", stats[:'memory.immix.bytes.current'])}
Large #{sprintf("% 22d", stats[:'memory.large.bytes.current'])}
Young #{sprintf("% 22d", stats[:'memory.young.bytes'])}
Mature #{sprintf("% 22d", stats[:'memory.immix.bytes'])}
Large #{sprintf("% 22d", stats[:'memory.large.bytes'])}
Code #{sprintf("% 22d", stats[:'memory.code.bytes'])}
Symbols #{sprintf("% 22d", stats[:'memory.symbols.bytes'])}
OUT
4 changes: 2 additions & 2 deletions truffle/src/main/ruby/core/rubinius/common/kernel.rb
Original file line number Diff line number Diff line change
@@ -809,8 +809,8 @@ def sprintf(str, *args)
end
module_function :sprintf

alias_method :formatBacktrace, :sprintf
module_function :formatBacktrace
alias_method :format, :sprintf
module_function :format

def sleep(duration=undefined)
Rubinius.primitive :vm_sleep
3 changes: 3 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/marshal.rb
Original file line number Diff line number Diff line change
@@ -701,8 +701,11 @@ def construct_hash
store_unique_object obj

construct_integer.times do
original_modules = @modules
@modules = nil
key = construct
val = construct
@modules = original_modules

# Use __store__ (an alias for []=) to get around subclass overrides
obj.__store__ key, val
2 changes: 2 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/module.rb
Original file line number Diff line number Diff line change
@@ -156,6 +156,7 @@ def constants(all=undefined)
end

def private_constant(*names)
names = names.map(&:to_sym)
unknown_constants = names - @constant_table.keys
if unknown_constants.size > 0
raise NameError, "#{unknown_constants.size > 1 ? 'Constants' : 'Constant'} #{unknown_constants.map{|e| "#{name}::#{e}"}.join(', ')} undefined"
@@ -167,6 +168,7 @@ def private_constant(*names)
end

def public_constant(*names)
names = names.map(&:to_sym)
unknown_constants = names - @constant_table.keys
if unknown_constants.size > 0
raise NameError, "#{unknown_constants.size > 1 ? 'Constants' : 'Constant'} #{unknown_constants.map{|e| "#{name}::#{e}"}.join(', ')} undefined"
1 change: 1 addition & 0 deletions truffle/src/main/ruby/core/rubinius/common/object_space.rb
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@ def self._id2ref(id)
if find_object([:object_id, Integer(id)], ary) > 0
return ary.first
end

return nil
end

14 changes: 1 addition & 13 deletions truffle/src/main/ruby/core/rubinius/common/proc.rb
Original file line number Diff line number Diff line change
@@ -127,19 +127,7 @@ def curry(curried_arity = nil)

def source_location
if @ruby_method
code = @ruby_method.executable
if code.respond_to? :file
file = code.file
if code.lines
line = code.first_line
else
line = -1
end
else
file = "(unknown)"
line = -1
end
[file.to_s, line]
@ruby_method.source_location
elsif @bound_method
if @bound_method.respond_to?(:source_location)
@bound_method.source_location
44 changes: 22 additions & 22 deletions truffle/src/main/ruby/core/rubinius/common/range.rb
Original file line number Diff line number Diff line change
@@ -77,47 +77,47 @@ def bsearch

last_true = nil

if max < 0 and min < 0
value = min + (max - min) / 2
elsif min < -max
value = -((-1 - min - max) / 2 + 1)
else
value = (min + max) / 2
end

while min < max
x = yield value
seeker = Proc.new do |current|
x = yield current

return value if x == 0
return current if x == 0

case x
when Numeric
if x > 0
min = value + 1
min = current + 1
else
max = value
max = current
end
when true
last_true = value
max = value
last_true = current
max = current
when false, nil
min = value + 1
min = current + 1
else
raise TypeError, "Range#bsearch block must return Numeric or boolean"
end
end

while min < max
if max < 0 and min < 0
value = min + (max - min) / 2
mid = min + (max - min) / 2
elsif min < -max
value = -((-1 - min - max) / 2 + 1)
mid = -((-1 - min - max) / 2 + 1)
else
value = (min + max) / 2
end
mid = (min + max) / 2
end

seeker.call mid
end

if min == max
seeker.call min
end

if min < max
return @begin if value == start
return @begin.kind_of?(Float) ? value.to_f : value
return @begin if mid == start
return @begin.kind_of?(Float) ? mid.to_f : mid
end

if last_true
2 changes: 2 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/range_mirror.rb
Original file line number Diff line number Diff line change
@@ -43,6 +43,8 @@ def step_float_iterations_size(first, last, step_size)
else
iterations = ((last - first) / step_size + err).floor + 1
end

iterations
end

def step_iterations_size(first, last, step_size)
4 changes: 3 additions & 1 deletion truffle/src/main/ruby/core/rubinius/common/splitter.rb
Original file line number Diff line number Diff line change
@@ -58,7 +58,9 @@ def self.split(string, pattern, limit)
return [string.dup] if limit == 1
limited = true
else
tail_empty = true
if limit < 0
tail_empty = true
end
limited = false
end
end
3 changes: 3 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/symbol.rb
Original file line number Diff line number Diff line change
@@ -33,6 +33,9 @@ def <=>(other)
to_s <=> other.to_s
end

# Use equal? for == (and not Comparable version)
alias_method :==, :equal?

def capitalize
to_s.capitalize.to_sym
end
3 changes: 1 addition & 2 deletions truffle/src/main/ruby/core/rubinius/common/time.rb
Original file line number Diff line number Diff line change
@@ -173,8 +173,7 @@ def to_r
end

def to_f
seconds + nsec * 0.000000001 # Truffle: optimized
#to_r.to_f
to_r.to_f
end

def +(other)
26 changes: 13 additions & 13 deletions truffle/src/main/ruby/core/rubinius/delta/ffi.rb
Original file line number Diff line number Diff line change
@@ -25,22 +25,22 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

module Rubinius
module FFI
module FFI

module Library
# Once the kernel is loaded, we want to raise an error if attempting to
# attach to a non-existent function.
def ffi_function_missing(name, *args)
raise FFI::NotFoundError, "Unable to find foreign function '#{name}'"
end
module Library
# Once the kernel is loaded, we want to raise an error if attempting to
# attach to a non-existent function.
def ffi_function_missing(name, *args)
raise FFI::NotFoundError, "Unable to find foreign function '#{name}'"
end
end

# We can only add Enumerable here since it needs everything else setup
class Struct
class InlineArray
include Enumerable
end
# We can only add Enumerable here since it needs everything else setup
class Struct
class InlineArray
include Enumerable
end

end

end
end
7 changes: 7 additions & 0 deletions truffle/src/main/ruby/core/rubinius/platform/pointer.rb
Original file line number Diff line number Diff line change
@@ -405,6 +405,13 @@ def autorelease=(val)
raise PrimitiveFailure, "FFI::MemoryPointer#autorelease= primitive failed"
end

##
# Returns true if autorelease is enabled, otherwise false.
def autorelease?
Rubinius.primitive :pointer_autorelease_p
raise PrimitiveFailure, "FFI::MemoryPointer#pointer_autorelease_p primitive failed"
end

end

class DynamicLibrary::Symbol < Pointer

0 comments on commit 8eb466e

Please sign in to comment.