Skip to content

Commit

Permalink
Start merging kernel/ into a single directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Jan 25, 2016
1 parent fa397f8 commit f787371
Show file tree
Hide file tree
Showing 133 changed files with 2,230 additions and 2,113 deletions.
File renamed without changes.
File renamed without changes.
129 changes: 129 additions & 0 deletions kernel/common/array.rb → kernel/array.rb
@@ -1,3 +1,132 @@
class Array
def self.allocate
Rubinius.primitive :array_allocate
raise PrimitiveFailure, "Array.allocate primitive failed"
end

def size
@total
end

alias_method :length, :size

def new_range(start, count)
Rubinius.primitive :array_new_range
raise PrimitiveFailure, "Array.new_range primitive failed"
end

def new_reserved(count)
Rubinius.primitive :array_new_reserved
raise PrimitiveFailure, "Array.new_reserved primitive failed"
end

# THIS MUST NOT BE REMOVED. the kernel requires a simple
# Array#[] to work while parts of the kernel boot.
def [](idx)
at(idx)
end

def []=(idx, ent)
Rubinius.check_frozen

if idx >= @tuple.fields
new_tuple = Rubinius::Tuple.new(idx + 10)
new_tuple.copy_from @tuple, @start, @total, 0
@tuple = new_tuple
end

@tuple.put @start + idx, ent
if idx >= @total - 1
@total = idx + 1
end
return ent
end

# Returns the element at the given index. If the
# index is negative, counts from the end of the
# Array. If the index is out of range, nil is
# returned. Slightly faster than +Array#[]+
def at(idx)
Rubinius.primitive :array_aref
idx = Rubinius::Type.coerce_to_collection_index idx

total = @start + @total

if idx < 0
idx += total
else
idx += @start
end

if idx >= @start and idx < total
return @tuple.at idx
end
end

# Passes each element in the Array to the given block
# and returns self.
def each
return to_enum(:each) { size } unless block_given?

i = @start
total = i + @total
tuple = @tuple

while i < total
yield tuple.at(i)
i += 1
end

self
end

# Creates a new Array from the return values of passing
# each element in self to the supplied block.
def map
return to_enum(:map) { size } unless block_given?
out = Array.new size

i = @start
total = i + @total
src = @tuple

dest = Rubinius::Mirror.reflect(out).tuple

j = 0
while i < total
dest[j] = yield src[i]
i += 1
j += 1
end

out
end

# Replaces each element in self with the return value
# of passing that element to the supplied block.
def map!
return to_enum(:map!) { size } unless block_given?

Rubinius.check_frozen

i = @start
total = i + @total
tuple = @tuple

while i < total
tuple[i] = yield tuple.at(i)
i += 1
end

self
end

def to_tuple
tuple = Rubinius::Tuple.new @total
tuple.copy_from @tuple, @start, @total, 0
tuple
end
end
class Array
include Enumerable

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
31 changes: 31 additions & 0 deletions kernel/bootstrap/basic_object.rb → kernel/basic_object.rb
Expand Up @@ -38,3 +38,34 @@ def __id__
raise ::PrimitiveFailure, "BasicObject#__id__ primitive failed"
end
end
class BasicObject
def method_missing(meth, *args)
::Kernel.raise ::NoMethodError, "Unable to send '#{meth}' on instance of BasicObject"
end
private :method_missing

def singleton_method_added(name) end
private :singleton_method_added

def singleton_method_removed(name) end
private :singleton_method_removed

def singleton_method_undefined(name) end
private :singleton_method_undefined

def __all_instance_variables__
Rubinius.primitive :object_ivar_names

raise PrimitiveFailure, "BasicObject#__instance_variables__ failed"
end
private :__all_instance_variables__

def __instance_variables__
ary = []
__all_instance_variables__.each do |sym|
ary << sym if sym.is_ivar?
end

ary
end
end
27 changes: 27 additions & 0 deletions kernel/bootstrap/bignum.rb → kernel/bignum.rb
Expand Up @@ -168,3 +168,30 @@ def size
raise PrimitiveFailure, "Bignum#size primitive failed"
end
end
class Bignum < Integer

# see README-DEVELOPERS regarding safe math compiler plugin
alias_method :/, :divide

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

if o.is_a?(Float) && self < 0 && o != o.round
return Complex.new(self, 0) ** o
elsif o.is_a?(Integer) && o < 0
return Rational.new(self, 1) ** o
end

redo_coerced :**, o
end
end
File renamed without changes.
66 changes: 66 additions & 0 deletions kernel/common/block_environment.rb → kernel/block_environment.rb
@@ -1,3 +1,69 @@
module Rubinius
class BlockEnvironment
def self.allocate
Rubinius.primitive :blockenvironment_allocate
raise PrimitiveFailure, "BlockEnvironment.allocate primitive failed"
end

def call(*args)
Rubinius.primitive :block_call
raise PrimitiveFailure, "BlockEnvironment#call primitive failed"
end

def call_under(recv, constant_scope, visibility_scope, *args)
Rubinius.primitive :block_call_under
raise PrimitiveFailure, "BlockEnvironment#call_under primitive failed"
end

def self.of_sender
Rubinius.primitive :block_env_of_sender
raise PrimitiveFailure, "BlockEnvironment#of_sender primitive failed"
end

class AsMethod < Executable
def self.new(block_env)
Rubinius.primitive :block_as_method_create
raise PrimitiveFailure, "BlockEnvironment::AsMethod.new primitive failed"
end

def arity
@block_env.compiled_code.arity
end

def local_names
@block_env.compiled_code.local_names
end

def required_args
@block_env.compiled_code.required_args
end

def total_args
@block_env.compiled_code.total_args
end

def post_args
@block_env.compiled_code.post_args
end

def splat
@block_env.compiled_code.splat
end

def block_index
@block_env.compiled_code.block_index
end

def file
@block_env.file
end

def defined_line
@block_env.line
end
end
end
end
##
# Describes the environment a block was created in. BlockEnvironment is used
# to create a BlockContext.
Expand Down
129 changes: 0 additions & 129 deletions kernel/bootstrap/array.rb

This file was deleted.

0 comments on commit f787371

Please sign in to comment.