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

Commits on Jun 13, 2016

  1. Copy the full SHA
    d09139b View commit details
  2. [Truffle] putting back code used in if/case branches

    of not removed methods
    pitr-ch committed Jun 13, 2016
    Copy the full SHA
    4df834d View commit details
  3. Copy the full SHA
    4c155c9 View commit details
  4. Copy the full SHA
    dec2534 View commit details
67 changes: 67 additions & 0 deletions truffle/src/main/ruby/core/identity_map.rb
Original file line number Diff line number Diff line change
@@ -52,6 +52,14 @@ def self.from(*arrays, &block)
im
end

def initialize
capacity = MIN_CAPACITY
@table = Table.new capacity
@mask = capacity - 4
@max = capacity
@size = 0
end

# Adds +item+ to the IdentityMap if it does not already exist. May cause
# a row to be added or enlarged. Returns +self+.
def insert(item, &block)
@@ -204,6 +212,65 @@ def resize(total)
end
private :resize

def redistribute
table = @table
resize @size

i = 0
total = table.size

while i < total
if num_entries = table[i]
if num_entries == 1
if item_hash = table[i+1]
add_item table[i+2], item_hash, table[i+3]
end
else
row = table[i+1]
k = row[0]
j = 1
while j < k
if item_hash = row[j]
add_item row[j+1], item_hash, row[j+2]
end
j += 3
end
end
end

i += 4
end
end
private :redistribute

def add_item(item, item_hash, ordinal)
index = item_hash & @mask
table = @table

if num_entries = table[index]
index += 1

if num_entries == 1
table[index-1] = 2
table[index] = promote_row table, index, item, item_hash, ordinal
else
row = table[index]
i = row[0]

if i == row.size
table[index] = enlarge_row row, item, item_hash, ordinal
else
set_item row, i, item, item_hash, ordinal
row[0] = i + 3
end
end
else
table[index] = 1
set_item table, index+1, item, item_hash, ordinal
end
end
private :add_item

# Given an Array of Enumerable instances, computes a bounding set
# to contain them and then adds each item to the IdentityMap.
def load(arrays, &block)
88 changes: 88 additions & 0 deletions truffle/src/main/ruby/core/process_mirror.rb
Original file line number Diff line number Diff line change
@@ -35,6 +35,16 @@
module Rubinius
class Mirror
module Process
def self.set_status_global(status)
::Thread.current[:$?] = status
end

def self.exec(*args)
exe = Execute.new(*args)
exe.spawn_setup
exe.exec exe.command, exe.argv
end

def self.spawn(*args)
exe = Execute.new(*args)

@@ -148,6 +158,78 @@ def initialize(env_or_cmd, *args)
end
end

def redirect(options, from, to)
case to
when ::Fixnum
map = (options[:redirect_fd] ||= [])
map << from << to
when ::Array
map = (options[:assign_fd] ||= [])
map << from
map.concat to
end
end

def convert_io_fd(obj)
case obj
when ::Fixnum
obj
when :in
0
when :out
1
when :err
2
when ::IO
obj.fileno
else
raise ArgementError, "wrong exec option: #{obj.inspect}"
end
end

def convert_to_fd(obj, target)
case obj
when ::Fixnum
obj
when :in
0
when :out
1
when :err
2
when :close
nil
when ::IO
obj.fileno
when ::String
[obj, default_mode(target), 0644]
when ::Array
case obj.size
when 1
[obj[0], File::RDONLY, 0644]
when 2
if obj[0] == :child
fd = convert_to_fd obj[1], target
fd.kind_of?(::Fixnum) ? -(fd + 1) : fd
else
[obj[0], convert_file_mode(obj[1]), 0644]
end
when 3
[obj[0], convert_file_mode(obj[1]), obj[2]]
end
else
raise ArgumentError, "wrong exec redirect: #{obj.inspect}"
end
end

def default_mode(target)
if target == 1 or target == 2
OFLAGS["w"]
else
OFLAGS["r"]
end
end

# Mapping of string open modes to integer oflag versions.
OFLAGS = {
"r" => ::File::RDONLY,
@@ -171,6 +253,12 @@ def spawn(options, command, arguments)

Truffle::Process.spawn command, arguments, env_array
end

def exec(command, args)
Truffle.primitive :vm_exec
raise PrimitiveFailure,
"Rubinius::Mirror::Process::Execute#exec primitive failed"
end
end
end
end
31 changes: 31 additions & 0 deletions truffle/src/main/ruby/core/random.rb
Original file line number Diff line number Diff line change
@@ -103,6 +103,37 @@ def generate_seed
raise PrimitiveFailure, "Randomizer#gen_seed primitive failed"
end

##
# Returns a random value from a range made out of Time, Date or DateTime
# instances.
#
# @param [Range] range
# @return [Time|Date|DateTime]
#
def random_time_range(range)
min = time_to_float(range.min)
max = time_to_float(range.max)
time = Time.at(random(min..max))

if Object.const_defined?(:DateTime) && range.min.is_a?(DateTime)
time = time.to_datetime
elsif Object.const_defined?(:DateTime) && range.min.is_a?(Date)
time = time.to_date
end

return time
end

##
# Casts a Time/Date/DateTime instance to a Float.
#
# @param [Time|Date|DateTime] input
# @return [Float]
#
def time_to_float(input)
return input.respond_to?(:to_time) ? input.to_time.to_f : input.to_f
end

##
# Checks if a given value is a Time, Date or DateTime object.
#
9 changes: 9 additions & 0 deletions truffle/src/main/ruby/core/range_mirror.rb
Original file line number Diff line number Diff line change
@@ -51,6 +51,15 @@ def step_float_iterations_size(first, last, step_size)
iterations
end

def step_iterations_size(first, last, step_size)
case first
when Float
step_float_iterations_size(first, last, step_size)
else
@object.size.nil? ? nil : (@object.size.fdiv(step_size)).ceil
end
end

def validate_step_size(first, last, step_size)
if step_size.kind_of? Float or first.kind_of? Float or last.kind_of? Float
# if any are floats they all must be