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: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: d01c24fff1a5
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3a683eba51d9
Choose a head ref
  • 11 commits
  • 198 files changed
  • 1 contributor

Commits on Jan 25, 2016

  1. Copy the full SHA
    f787371 View commit details

Commits on Jan 26, 2016

  1. Finished merging kernel/ into a single directory.

    Kernel does not yet boot. Some dependencies still need to be resolved.
    brixen committed Jan 26, 2016
    Copy the full SHA
    5bf7a88 View commit details
  2. Copy the full SHA
    719f02c View commit details

Commits on Jan 29, 2016

  1. Fix building kernel.

    brixen committed Jan 29, 2016
    Copy the full SHA
    3f183cc View commit details
  2. Copy the full SHA
    7115986 View commit details
  3. More kernel build cleanup.

    brixen committed Jan 29, 2016
    Copy the full SHA
    a1e9ca3 View commit details
  4. Copy the full SHA
    7ae9bc7 View commit details

Commits on Jan 30, 2016

  1. Copy the full SHA
    0037254 View commit details
  2. Copy the full SHA
    97a9f59 View commit details
  3. Copy the full SHA
    74ef319 View commit details
  4. Copy the full SHA
    3a683eb View commit details
Showing with 4,219 additions and 4,383 deletions.
  1. +2 −4 configure
  2. 0 kernel/{bootstrap → }/alias.rb
  3. 0 kernel/{common → }/argf.rb
  4. +129 −0 kernel/{common → }/array.rb
  5. 0 kernel/{bootstrap → }/array_mirror.rb
  6. 0 kernel/{bootstrap → }/atomic.rb
  7. 0 kernel/{common → }/autoload.rb
  8. 0 kernel/{common → }/backtrace.rb
  9. +31 −0 kernel/{bootstrap → }/basic_object.rb
  10. +27 −0 kernel/{bootstrap → }/bignum.rb
  11. 0 kernel/{common → }/binding.rb
  12. +66 −0 kernel/{common → }/block_environment.rb
  13. +0 −129 kernel/bootstrap/array.rb
  14. +0 −66 kernel/bootstrap/block_environment.rb
  15. +0 −14 kernel/bootstrap/class.rb
  16. +0 −68 kernel/bootstrap/compiled_code.rb
  17. +0 −36 kernel/bootstrap/constant_scope.rb
  18. +0 −52 kernel/bootstrap/dir.rb
  19. +0 −22 kernel/bootstrap/encoding.rb
  20. +0 −5 kernel/bootstrap/exception.rb
  21. +0 −21 kernel/bootstrap/executable.rb
  22. +0 −15 kernel/bootstrap/false.rb
  23. +0 −44 kernel/bootstrap/gc.rb
  24. +0 −160 kernel/bootstrap/io.rb
  25. +0 −110 kernel/bootstrap/kernel.rb
  26. +0 −55 kernel/bootstrap/load_order.txt
  27. +0 −36 kernel/bootstrap/proc.rb
  28. +0 −16 kernel/bootstrap/process.rb
  29. +0 −69 kernel/bootstrap/regexp.rb
  30. +0 −225 kernel/bootstrap/rubinius.rb
  31. +0 −103 kernel/bootstrap/stat.rb
  32. +0 −175 kernel/bootstrap/string.rb
  33. +0 −31 kernel/bootstrap/symbol.rb
  34. +0 −40 kernel/bootstrap/time.rb
  35. +0 −20 kernel/bootstrap/true.rb
  36. +0 −129 kernel/bootstrap/type.rb
  37. +0 −56 kernel/bootstrap/variable_scope.rb
  38. +39 −0 kernel/{bootstrap → }/byte_array.rb
  39. 0 kernel/{bootstrap → }/call_custom_cache.rb
  40. 0 kernel/{bootstrap → }/call_site.rb
  41. 0 kernel/{common → }/capi.rb
  42. +11 −0 kernel/{bootstrap → }/channel.rb
  43. 0 kernel/{bootstrap → }/character.rb
  44. +23 −0 kernel/{common → }/class.rb
  45. +237 −0 kernel/{common → }/code_loader.rb
  46. +0 −31 kernel/common/basic_object.rb
  47. +0 −27 kernel/common/bignum.rb
  48. +0 −39 kernel/common/byte_array.rb
  49. +0 −11 kernel/common/channel.rb
  50. +0 −51 kernel/common/ctype.rb
  51. +0 −65 kernel/common/fixnum.rb
  52. +0 −94 kernel/common/load_order.txt
  53. +0 −15 kernel/common/lookup_table.rb
  54. +0 −57 kernel/common/method_table.rb
  55. +0 −21 kernel/common/nil.rb
  56. +0 −264 kernel/common/struct.rb
  57. +0 −166 kernel/common/thread.rb
  58. +0 −150 kernel/common/tuple.rb
  59. 0 kernel/{bootstrap → }/compact_lookup_table.rb
  60. 0 kernel/{common → }/comparable.rb
  61. +68 −0 kernel/{common → }/compiled_code.rb
  62. 0 kernel/{common → }/complex.rb
  63. 0 kernel/{common → }/complexifier.rb
  64. 0 kernel/{bootstrap → }/configuration.rb
  65. 0 kernel/{delta → }/console.rb
  66. 0 kernel/{bootstrap → }/constant_cache.rb
  67. +36 −0 kernel/{common → }/constant_scope.rb
  68. 0 kernel/{bootstrap → }/constant_table.rb
  69. 0 kernel/{common → }/continuation.rb
  70. 0 kernel/{delta → }/converter_paths.rb
  71. +51 −0 kernel/{delta → }/ctype.rb
  72. 0 kernel/{common → }/delegated_method.rb
  73. +0 −9 kernel/delta/class.rb
  74. +0 −237 kernel/delta/code_loader.rb
  75. +0 −17 kernel/delta/exception.rb
  76. +0 −20 kernel/delta/ffi.rb
  77. +0 −19 kernel/delta/file.rb
  78. +0 −26 kernel/delta/file_test.rb
  79. +0 −173 kernel/delta/kernel.rb
  80. +0 −24 kernel/delta/load_order.txt
  81. +0 −56 kernel/delta/math.rb
  82. +0 −218 kernel/delta/module.rb
  83. +0 −13 kernel/delta/signal.rb
  84. +0 −104 kernel/delta/struct.rb
  85. +0 −6 kernel/delta/thread.rb
  86. 0 kernel/{delta → }/deprecations.rb
  87. +52 −0 kernel/{common → }/dir.rb
  88. 0 kernel/{common → }/dir_glob.rb
  89. +22 −0 kernel/{common → }/encoding.rb
  90. 0 kernel/{platform → }/enum.rb
  91. 0 kernel/{common → }/enumerable.rb
  92. 0 kernel/{common → }/enumerable_helper.rb
  93. 0 kernel/{common → }/enumerator.rb
  94. +11 −0 kernel/{common → }/env.rb
  95. 0 kernel/{common → }/errno.rb
  96. 0 kernel/{common → }/eval.rb
  97. +22 −0 kernel/{common → }/exception.rb
  98. +21 −0 kernel/{common → }/executable.rb
  99. +15 −0 kernel/{common → }/false.rb
  100. +20 −0 kernel/{platform → }/ffi.rb
  101. 0 kernel/{common → }/fiber.rb
  102. +29 −0 kernel/{common → }/file.rb
  103. +26 −0 kernel/{common → }/file_test.rb
  104. +65 −0 kernel/{bootstrap → }/fixnum.rb
  105. 0 kernel/{common → }/float.rb
  106. 0 kernel/{delta → }/fsevent.rb
  107. +44 −0 kernel/{common → }/gc.rb
  108. 0 kernel/{common → }/global.rb
  109. 0 kernel/{common → }/hash.rb
  110. 0 kernel/{common → }/hash_hamt.rb
  111. 0 kernel/{common → }/hook.rb
  112. 0 kernel/{common → }/identity_map.rb
  113. 0 kernel/{common → }/immediate.rb
  114. 0 kernel/{common → }/integer.rb
  115. +160 −0 kernel/{common → }/io.rb
  116. 0 kernel/{bootstrap → }/iseq.rb
  117. 0 kernel/{bootstrap → }/jit.rb
  118. +283 −0 kernel/{common → }/kernel.rb
  119. 0 kernel/{platform → }/library.rb
  120. +136 −0 kernel/load_order.txt
  121. 0 kernel/{common → }/loaded_features.rb
  122. 0 kernel/{common → }/location.rb
  123. 0 kernel/{bootstrap → }/logger.rb
  124. +15 −0 kernel/{bootstrap → }/lookup_table.rb
  125. 0 kernel/{common → }/lru_cache.rb
  126. 0 kernel/{common → }/main.rb
  127. 0 kernel/{common → }/marshal.rb
  128. +102 −0 kernel/{common → }/math.rb
  129. 0 kernel/{common → }/method.rb
  130. 0 kernel/{common → }/method_equality.rb
  131. +57 −0 kernel/{bootstrap → }/method_table.rb
  132. 0 kernel/{delta → }/metrics.rb
  133. 0 kernel/{bootstrap → }/mirror.rb
  134. 0 kernel/{common → }/missing_method.rb
  135. +218 −0 kernel/{common → }/module.rb
  136. 0 kernel/{bootstrap → }/mono_inline_cache.rb
  137. 0 kernel/{common → }/mutex.rb
  138. 0 kernel/{common → }/native_method.rb
  139. +21 −0 kernel/{bootstrap → }/nil.rb
  140. 0 kernel/{common → }/numeric.rb
  141. 0 kernel/{common → }/numeric_mirror.rb
  142. 0 kernel/{common → }/object_space.rb
  143. 0 kernel/{delta → }/options.rb
  144. 0 kernel/{delta → }/pack.rb
  145. +0 −11 kernel/platform/env.rb
  146. +0 −10 kernel/platform/file.rb
  147. +0 −11 kernel/platform/load_order.txt
  148. +0 −46 kernel/platform/math.rb
  149. +0 −312 kernel/platform/struct.rb
  150. 0 kernel/{platform → }/pointer.rb
  151. 0 kernel/{platform → }/pointer_accessors.rb
  152. 0 kernel/{bootstrap → }/poly_inline_cache.rb
  153. 0 kernel/{platform → }/posix.rb
  154. +36 −0 kernel/{common → }/proc.rb
  155. 0 kernel/{common → }/proc_mirror.rb
  156. +16 −0 kernel/{common → }/process.rb
  157. 0 kernel/{common → }/process_mirror.rb
  158. 0 kernel/{common → }/random.rb
  159. 0 kernel/{common → }/range.rb
  160. 0 kernel/{common → }/range_mirror.rb
  161. 0 kernel/{common → }/rational.rb
  162. 0 kernel/{common → }/rationalizer.rb
  163. +254 −0 kernel/rbconfig.rb
  164. +69 −0 kernel/{common → }/regexp.rb
  165. 0 kernel/{bootstrap → }/respond_to_cache.rb
  166. +225 −0 kernel/{delta → }/rubinius.rb
  167. 0 kernel/{delta → }/ruby_constants.rb
  168. 0 kernel/{delta → }/runtime.rb
  169. +13 −0 kernel/{common → }/signal.rb
  170. 0 kernel/{common → }/splitter.rb
  171. 0 kernel/{common → }/sprinter.rb
  172. +103 −0 kernel/{common → }/stat.rb
  173. 0 kernel/{delta → }/stats.rb
  174. +175 −0 kernel/{common → }/string.rb
  175. 0 kernel/{common → }/string_mirror.rb
  176. +680 −0 kernel/struct.rb
  177. +31 −0 kernel/{common → }/symbol.rb
  178. +172 −0 kernel/{bootstrap → }/thread.rb
  179. 0 kernel/{common → }/thread_group.rb
  180. 0 kernel/{common → }/thread_group_mirror.rb
  181. 0 kernel/{bootstrap → }/thread_mirror.rb
  182. 0 kernel/{common → }/throw_catch.rb
  183. 0 kernel/{bootstrap → }/thunk.rb
  184. +40 −0 kernel/{common → }/time.rb
  185. +20 −0 kernel/{common → }/true.rb
  186. +150 −0 kernel/{bootstrap → }/tuple.rb
  187. +129 −0 kernel/{common → }/type.rb
  188. 0 kernel/{common → }/undefined.rb
  189. 0 kernel/{platform → }/union.rb
  190. +56 −0 kernel/{common → }/variable_scope.rb
  191. 0 kernel/{bootstrap → }/vm.rb
  192. 0 kernel/{bootstrap → }/weakref.rb
  193. +3 −256 library/rbconfig.rb
  194. +0 −13 library/rbconfig/datadir.rb
  195. +8 −62 rakelib/kernel.rake
  196. +0 −1 vm/builtin/thread.cpp
  197. +0 −46 vm/environment.cpp
  198. +0 −1 vm/environment.hpp
6 changes: 2 additions & 4 deletions configure
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ end

root = File.expand_path File.dirname(__FILE__)

require File.join(root, "kernel", "delta", "options")
require File.join(root, "kernel", "options")

class Configure

@@ -1622,9 +1622,7 @@ int main() { return tgetnum(""); }

write_config_rb @config, config_settings

lib_rubinius_dir = "#{@sourcedir}/library/rubinius"
FileUtils.mkdir_p lib_rubinius_dir unless File.directory? lib_rubinius_dir
FileUtils.cp @config, "#{lib_rubinius_dir}/build_config.rb"
FileUtils.cp @config, "#{@sourcedir}/kernel/build_config.rb"

# Write the config file used to build the C++ VM.
Dir.mkdir "vm/gen" unless File.directory? "vm/gen"
File renamed without changes.
File renamed without changes.
129 changes: 129 additions & 0 deletions kernel/common/array.rb → kernel/array.rb
Original file line number Diff line number Diff line change
@@ -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

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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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.
129 changes: 0 additions & 129 deletions kernel/bootstrap/array.rb

This file was deleted.

66 changes: 0 additions & 66 deletions kernel/bootstrap/block_environment.rb

This file was deleted.

14 changes: 0 additions & 14 deletions kernel/bootstrap/class.rb

This file was deleted.

68 changes: 0 additions & 68 deletions kernel/bootstrap/compiled_code.rb

This file was deleted.

36 changes: 0 additions & 36 deletions kernel/bootstrap/constant_scope.rb

This file was deleted.

52 changes: 0 additions & 52 deletions kernel/bootstrap/dir.rb

This file was deleted.

22 changes: 0 additions & 22 deletions kernel/bootstrap/encoding.rb

This file was deleted.

5 changes: 0 additions & 5 deletions kernel/bootstrap/exception.rb

This file was deleted.

21 changes: 0 additions & 21 deletions kernel/bootstrap/executable.rb

This file was deleted.

15 changes: 0 additions & 15 deletions kernel/bootstrap/false.rb

This file was deleted.

44 changes: 0 additions & 44 deletions kernel/bootstrap/gc.rb

This file was deleted.

160 changes: 0 additions & 160 deletions kernel/bootstrap/io.rb

This file was deleted.

110 changes: 0 additions & 110 deletions kernel/bootstrap/kernel.rb

This file was deleted.

55 changes: 0 additions & 55 deletions kernel/bootstrap/load_order.txt

This file was deleted.

36 changes: 0 additions & 36 deletions kernel/bootstrap/proc.rb

This file was deleted.

16 changes: 0 additions & 16 deletions kernel/bootstrap/process.rb

This file was deleted.

69 changes: 0 additions & 69 deletions kernel/bootstrap/regexp.rb

This file was deleted.

225 changes: 0 additions & 225 deletions kernel/bootstrap/rubinius.rb

This file was deleted.

103 changes: 0 additions & 103 deletions kernel/bootstrap/stat.rb

This file was deleted.

175 changes: 0 additions & 175 deletions kernel/bootstrap/string.rb

This file was deleted.

31 changes: 0 additions & 31 deletions kernel/bootstrap/symbol.rb

This file was deleted.

40 changes: 0 additions & 40 deletions kernel/bootstrap/time.rb

This file was deleted.

20 changes: 0 additions & 20 deletions kernel/bootstrap/true.rb

This file was deleted.

129 changes: 0 additions & 129 deletions kernel/bootstrap/type.rb

This file was deleted.

56 changes: 0 additions & 56 deletions kernel/bootstrap/variable_scope.rb

This file was deleted.

39 changes: 39 additions & 0 deletions kernel/bootstrap/byte_array.rb → kernel/byte_array.rb
Original file line number Diff line number Diff line change
@@ -89,3 +89,42 @@ def reverse(start, total)
end
end
end
##
# An array of bytes, used as a low-level data store for implementing various
# other classes.

module Rubinius
class ByteArray
alias_method :[], :get_byte
alias_method :[]=, :set_byte

# TODO: encoding
def character_at_index(index)
"" << self[index]
end

def each
i = 0
max = size()

while i < max
yield get_byte(i)
i += 1
end
end

def inspect
"#<#{self.class}:0x#{object_id.to_s(16)} #{size} bytes>"
end

def <=>(other)
compare_bytes other, size, other.size
end

# Sets the first character to be an ASCII capitalize letter
# if it's an ASCII lower case letter
def first_capitalize!
self[0] = self[0].toupper
end
end
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions kernel/bootstrap/channel.rb → kernel/channel.rb
Original file line number Diff line number Diff line change
@@ -73,3 +73,14 @@ def try_receive
end
end
end
##
# A communication mechanism based on pi-calculus channels used primarily to
# communicate between ruby and the VM about events.

module Rubinius
class Channel
def inspect
"#<Rubinius::Channel:0x#{object_id.to_s(16)}>"
end
end
end
File renamed without changes.
23 changes: 23 additions & 0 deletions kernel/common/class.rb → kernel/class.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
class Class
def self.allocate
Rubinius.primitive :class_s_allocate
raise PrimitiveFailure, "Class.allocate primitive failed"
end

def set_superclass(sup)
Rubinius.primitive :class_set_superclass
kind = Rubinius::Type.object_class(sup)
raise TypeError, "Class.set_superclass: argument must be a Class (#{kind} given)"
end

private :set_superclass
end
class Class

def initialize(sclass=Object, name=nil, under=nil)
@@ -51,3 +65,12 @@ def superclass
return cls
end
end
code = Class.method_table.lookup(:new).get_method
code.serial = Rubinius::CompiledCode::KernelMethodSerial

class Class
undef_method :append_features
undef_method :extend_object
undef_method :module_function
undef_method :prepend_features
end
237 changes: 237 additions & 0 deletions kernel/common/code_loader.rb → kernel/code_loader.rb
Original file line number Diff line number Diff line change
@@ -469,3 +469,240 @@ def update_paths(file, path)
end
end
end
# Implementation-specific behavior for Kernel#require and Kernel#load.
#
# In particular, this file implements #load_file for loading a Ruby source
# file and #load_library for loading a shared library extension file.
#
# Also provides #require_compiled which loads a precompiled version of a Ruby
# source file. Several CodeLoader class methods are implemented as a
# convenient way to invoke the CodeLoader.

module Rubinius
class InvalidRBC < RuntimeError; end

class CodeLoader

# Loads compiled files. Performs exactly as Kernel#require except that
#
# require "some_file"
#
# will resolve to "some_file.rbc" on the $LOAD_PATH, rather than
# "some_file.rb".
#
# However, if "some_file.rbc" does not exist, then like #require, this
# method will search for a shared library extension file to load using the
# platform's file extension for shared libraries. This simplifies loading
# a set of pre-compiled .rbc files that also may load an extension as in
# the case of loading the compiler on bootstrap.
def require_compiled(check_version=true)
saved_check = CodeLoader.check_version
saved_extension = CodeLoader.source_extension

CodeLoader.load_compiled = true
CodeLoader.check_version = check_version
CodeLoader.source_extension = ".rbc"

req = self.require

Rubinius.run_script self.compiled_code

CodeLoader.loaded_hook.trigger!(@path)

add_feature

return true
ensure
req.remove! if req

CodeLoader.check_version = saved_check
CodeLoader.source_extension = saved_extension
CodeLoader.load_compiled = false
end

# Loads a Ruby source file specified on the command line. There is no
# search required as the path on the command line must directly refernce a
# loadable file. Also, the value of __FILE__ in a script loaded on the
# command line differs from the value in a file loaded by Kernel#require
# or Kernel#load.
def load_script(debug)
@file_path = @path
@load_path = File.expand_path @path

load_error unless loadable? @load_path
script = load_file

script.make_main!

Rubinius.run_script self.compiled_code

CodeLoader.loaded_hook.trigger!(@path)
end

# Overrides the version of #add_feature provided in kernel/common. When
# loading precompiled source files via #require, adds ".rb" files to
# $LOADED_FEATURES.
def add_feature
name = @feature.suffix?(".rbc") ? @feature[0..-2] : @feature
$LOADED_FEATURES << name
add_feature_to_index(feature)
end

# Default check_version flag to true
@check_version = true

# Requires pre-installed gems directly to prevent Bundler and RubyGems
# from disabling the gems and to permit bootstrapping RubyGems.
#
# TODO: Patch Bundler to recognize pre-installed gems when resolving
# dependencies and fix RubyGems hijacking #require.
def rubygems_require
if dir = rubygems_search_require
$LOAD_PATH.unshift dir
return true
end

return false
end

def rubygems_search_require
library_found = nil

self.class.rubygems_dirs.each do |dir|
if @type and check_path(dir, @path, "", @type)
return dir
elsif check_path(dir, @path, CodeLoader.source_extension, :ruby)
return dir
elsif check_path(dir, @path, LIBSUFFIX, :library)
library_found = dir
end
end

library_found
end

class << self
attr_accessor :load_compiled
attr_accessor :check_version

def rubygems_dirs
@rubygems_dirs ||= Dir["#{Rubinius::GEMS_PATH}/gems/**/lib"]
end

# Loads rubygems using the bootstrap standard library files.
def load_rubygems
require "rubygems"
end

# Loads the pre-compiled bytecode compiler. Sets up paths needed by the
# compiler to find dependencies like the parser.
def load_compiler
begin
Dir["#{Rubinius::RUNTIME_PATH}/gems/**/lib"].each do |dir|
$LOAD_PATH.unshift dir
end

require_compiled "rubinius/code/toolset"

Rubinius::ToolSets.create :runtime do
require_compiled "rubinius/code/melbourne"
require_compiled "rubinius/code/processor"
require_compiled "rubinius/code/compiler"
require_compiled "rubinius/code/ast"
end
rescue Object => e
raise LoadError, "Unable to load the bytecode compiler", e
end
end

def require_compiled(name, check_version=true)
new(name).require_compiled(check_version)
end

def load_script(name, debug=false)
new(name).load_script(debug)
end

def execute_script(script)
eval(script, TOPLEVEL_BINDING)
end

def save_compiled?
@save_compiled ||= Config["compiler.no_rbc"] == nil
end
end

# Given a path to a Ruby source file to load (i.e. @load_path), determines
# whether a compiled version exists and is up-to-date. If it is, loads the
# compiled version. Otherwise, compiles the Ruby source file.
#
# TODO: Make the compiled version checking logic available as a Compiler
# convenience method.
def load_file(wrap=false)
signature = CodeLoader.check_version ? Signature : 0
version = Rubinius::RUBY_LIB_VERSION

if CodeLoader.load_compiled
code = load_compiled_file @load_path, signature, version
else
c = Rubinius::ToolSets::Runtime::Compiler
compiled_name = c.compiled_name @load_path

if compiled_name
begin
compiled_stat = File::Stat.stat compiled_name

if compiled_stat and @stat.mtime >= compiled_stat.mtime
code = compile_file @load_path, compiled_name
else
begin
code = load_compiled_file compiled_name, signature, version
rescue TypeError, InvalidRBC
code = compile_file @load_path, compiled_name
end
end
rescue Errno::ENOENT
code = compile_file @load_path, compiled_name
end
else
code = compile_file @load_path, compiled_name
end
end

script = code.create_script(wrap)
script.file_path = @file_path
script.data_path = @load_path

@compiled_code = code
CodeLoader.compiled_hook.trigger! script
return script
end

attr_reader :compiled_code

# Compile a Ruby source file and save the compiled file. Return the
# internal representation (CompiledCode) of the Ruby source file.
def compile_file(file, compiled)
c = Rubinius::ToolSets::Runtime::Compiler
if CodeLoader.save_compiled?
c.compile file, compiled
else
c.compile_file file
end
end

# Load a compiled version of a Ruby source file.
def load_compiled_file(path, signature, version)
Rubinius.primitive :compiledfile_load

raise InvalidRBC, path
end

# Load a shared library extension file.
def load_library
name = File.basename @load_path, LIBSUFFIX

NativeMethod.load_extension(@load_path, name)
end
end
end
31 changes: 0 additions & 31 deletions kernel/common/basic_object.rb

This file was deleted.

27 changes: 0 additions & 27 deletions kernel/common/bignum.rb

This file was deleted.

39 changes: 0 additions & 39 deletions kernel/common/byte_array.rb

This file was deleted.

11 changes: 0 additions & 11 deletions kernel/common/channel.rb

This file was deleted.

51 changes: 0 additions & 51 deletions kernel/common/ctype.rb

This file was deleted.

65 changes: 0 additions & 65 deletions kernel/common/fixnum.rb

This file was deleted.

94 changes: 0 additions & 94 deletions kernel/common/load_order.txt

This file was deleted.

15 changes: 0 additions & 15 deletions kernel/common/lookup_table.rb

This file was deleted.

57 changes: 0 additions & 57 deletions kernel/common/method_table.rb

This file was deleted.

21 changes: 0 additions & 21 deletions kernel/common/nil.rb

This file was deleted.

264 changes: 0 additions & 264 deletions kernel/common/struct.rb

This file was deleted.

166 changes: 0 additions & 166 deletions kernel/common/thread.rb

This file was deleted.

Loading