Skip to content
Browse files

Moved implementation classes under Rubinius namespace.

The following classes have been namespaced under Rubinius:

ARGFClass                   InstructionSet
AccessVariable              Location
BlockEnvironment            LookupTable
ByteArray                   MachineMethod
Channel                     MethodTable
CompactLookupTable          NativeMethod
CompiledFile                Scheduler
CompiledMethod              Selector
DelegatedMethod             SendSite
EnvironmentVariables        Sprintf
Executable                  StaticScope
GlobalVariables             ThrownValue
Globals                     Tuple
IncludedModule              VariableScope
InstructionSequence

Evan specifically requested to not namespace MetaClass. Backtrace
is also not namespaced. Compiler was not namespaced because it will
be restructured in the near future.

The following method was used:

module Rubinius
  class Tuple
  end
end

rather than

class Rubinius::Tuple
end

Primarily, this was chosen because it allows implementation classes
to refer to other implementation classes without qualifying the name.
This results in less noise in the implementation classes and is less
likely to cause exceptions if someone forgets to qualify a name. In
the regular classes like Kernel, references to implemetation classes
do need to be qualified (e.g. Rubinius::VariableScope in Kernel#eval).
A consequence of this method is that git blame history info is masked
for a number of classes. (If this info is needed, check out a branch
and git reset --hard to this commit - 1.)
  • Loading branch information...
1 parent 51ad981 commit 1822f6924c94276c8955bc87b30dac37fed279c1 Brian Ford committed Apr 23, 2009
Showing with 3,423 additions and 3,377 deletions.
  1. +68 −64 kernel/alpha.rb
  2. +1 −1 kernel/bootstrap/array.rb
  3. +14 −12 kernel/bootstrap/block_environment.rb
  4. +58 −56 kernel/bootstrap/bytearray.rb
  5. +63 −61 kernel/bootstrap/channel.rb
  6. +26 −24 kernel/bootstrap/compactlookuptable.rb
  7. +44 −42 kernel/bootstrap/compiled_method.rb
  8. +8 −6 kernel/bootstrap/executable.rb
  9. +2 −2 kernel/bootstrap/hash.rb
  10. +96 −94 kernel/bootstrap/lookuptable.rb
  11. +129 −128 kernel/bootstrap/scheduler.rb
  12. +9 −7 kernel/bootstrap/selector.rb
  13. +40 −38 kernel/bootstrap/sendsite.rb
  14. +6 −4 kernel/bootstrap/static_scope.rb
  15. +51 −49 kernel/bootstrap/tuple.rb
  16. +0 −10 kernel/bootstrap/undef.rb
  17. +63 −63 kernel/bootstrap/variable_scope.rb
  18. +1 −1 kernel/bootstrap/weakref.rb
  19. +133 −131 kernel/common/argf.rb
  20. +11 −11 kernel/common/array.rb
  21. +1 −1 kernel/common/backtrace.rb
  22. +69 −67 kernel/common/block_environment.rb
  23. +19 −17 kernel/common/bytearray.rb
  24. +5 −3 kernel/common/channel.rb
  25. +2 −2 kernel/common/class.rb
  26. +368 −367 kernel/common/compiled_method.rb
  27. +17 −15 kernel/common/delegated_method.rb
  28. +142 −140 kernel/common/env.rb
  29. +23 −23 kernel/common/eval.rb
  30. +14 −13 kernel/common/executable.rb
  31. +80 −78 kernel/common/global.rb
  32. +3 −3 kernel/common/io.rb
  33. +5 −5 kernel/common/kernel.rb
  34. +62 −60 kernel/common/location.rb
  35. +1 −1 kernel/common/lookuptable.rb
  36. +1 −1 kernel/common/marshal.rb
  37. +22 −20 kernel/common/method_table.rb
  38. +27 −27 kernel/common/module.rb
  39. +45 −43 kernel/common/native_method.rb
  40. +2 −2 kernel/common/objectspace.rb
  41. +2 −2 kernel/common/proc.rb
  42. +1 −1 kernel/common/process.rb
  43. +9 −9 kernel/common/regexp.rb
  44. +10 −8 kernel/common/selector.rb
  45. +321 −319 kernel/common/sprintf.rb
  46. +95 −93 kernel/common/static_scope.rb
  47. +23 −52 kernel/common/string.rb
  48. +3 −3 kernel/common/thread.rb
  49. +33 −33 kernel/common/throw_catch.rb
  50. +87 −86 kernel/common/tuple.rb
  51. +28 −26 kernel/common/variable_scope.rb
  52. +1 −1 kernel/compiler/blocks.rb
  53. +12 −6 kernel/compiler/bytecode.rb
  54. +3 −3 kernel/compiler/compile.rb
  55. +2 −2 kernel/compiler/execute.rb
  56. +12 −12 kernel/compiler/generator.rb
  57. +499 −494 kernel/compiler/iseq.rb
  58. +1 −1 kernel/compiler/local.rb
  59. +1 −1 kernel/compiler/stack.rb
  60. +2 −2 kernel/delta/breakpoint.rb
  61. +1 −1 kernel/delta/class.rb
  62. +10 −10 kernel/delta/kernel.rb
  63. +11 −10 kernel/delta/module.rb
  64. +266 −264 kernel/delta/profiler.rb
  65. +1 −1 kernel/delta/string.rb
  66. +6 −6 kernel/loader.rb
  67. +9 −7 kernel/platform/env.rb
  68. +2 −2 kernel/platform/ffi.rb
  69. +2 −2 kernel/platform/struct.rb
  70. +8 −8 lib/actor.rb
  71. +2 −2 lib/bin/describe.rb
  72. +3 −3 lib/compiler/mri_compile.rb
  73. +17 −16 lib/compiler/mri_shim.rb
  74. +3 −3 lib/debugger/standard_commands.rb
  75. +5 −5 lib/debugger/vm_commands.rb
  76. +2 −2 lib/decompiler.rb
  77. +1 −1 lib/irb/rubinius.rb
  78. +2 −2 lib/join.rb
  79. +1 −1 lib/mailbox.rb
  80. +1 −1 lib/semaphore.rb
  81. +6 −6 lib/thread.rb
  82. +10 −10 lib/vmactor.rb
  83. +2 −1 spec/compiler/defined_spec.rb
  84. +1 −1 spec/compiler/dstr_spec.rb
  85. +1 −1 spec/compiler/gasgn_spec.rb
  86. +4 −4 spec/compiler/gvar_spec.rb
  87. +1 −1 spec/compiler/masgn_spec.rb
  88. +1 −1 spec/compiler/match_spec.rb
  89. +4 −4 spec/compiler/plugins/fastnew_spec.rb
  90. +1 −1 spec/compiler/valias_spec.rb
  91. +2 −2 spec/core/bytearray/new_spec.rb
  92. +6 −6 spec/core/compiledmethod/decode_spec.rb
  93. +1 −1 spec/core/context/fixtures/classes.rb
  94. +1 −1 spec/core/hash/allocate_spec.rb
  95. +4 −4 spec/core/lookuptable/allocate_spec.rb
  96. +1 −1 spec/core/lookuptable/clone_spec.rb
  97. +2 −2 spec/core/lookuptable/delete_spec.rb
  98. +1 −1 spec/core/lookuptable/dup_spec.rb
  99. +2 −2 spec/core/lookuptable/element_reference_spec.rb
  100. +2 −2 spec/core/lookuptable/element_set_spec.rb
  101. +2 −2 spec/core/lookuptable/entries_spec.rb
  102. +1 −1 spec/core/lookuptable/fixtures/classes.rb
  103. +1 −1 spec/core/lookuptable/has_key_spec.rb
  104. +1 −1 spec/core/lookuptable/include_spec.rb
  105. +2 −2 spec/core/lookuptable/initialize_spec.rb
  106. +1 −1 spec/core/lookuptable/key_spec.rb
  107. +2 −2 spec/core/lookuptable/keys_spec.rb
  108. +1 −1 spec/core/lookuptable/member_spec.rb
  109. +4 −4 spec/core/lookuptable/new_spec.rb
  110. +2 −2 spec/core/lookuptable/shared/clone.rb
  111. +1 −1 spec/core/lookuptable/shared/has_key.rb
  112. +2 −2 spec/core/lookuptable/size_spec.rb
  113. +2 −2 spec/core/lookuptable/values_spec.rb
  114. +2 −2 spec/core/profiler/instrumenter/info_spec.rb
  115. +1 −1 spec/core/profiler/instrumenter/profile_spec.rb
  116. +1 −1 spec/core/profiler/instrumenter/profiler_spec.rb
  117. +1 −1 spec/core/profiler/instrumenter/start_spec.rb
  118. +1 −1 spec/core/profiler/instrumenter/stop_spec.rb
  119. +1 −1 spec/core/tuple/at_spec.rb
  120. +2 −2 spec/core/tuple/constructor_spec.rb
  121. +2 −2 spec/core/tuple/dup_spec.rb
  122. +4 −4 spec/core/tuple/each_spec.rb
  123. +1 −1 spec/core/tuple/element_reference_spec.rb
  124. +1 −1 spec/core/tuple/element_set_spec.rb
  125. +2 −2 spec/core/tuple/first_spec.rb
  126. +2 −2 spec/core/tuple/inspect_spec.rb
  127. +4 −4 spec/core/tuple/join_spec.rb
  128. +6 −6 spec/core/tuple/join_upto_spec.rb
  129. +2 −2 spec/core/tuple/last_spec.rb
  130. +7 −7 spec/core/tuple/new_spec.rb
  131. +2 −2 spec/core/tuple/pattern_spec.rb
  132. +3 −3 spec/core/tuple/plus_spec.rb
  133. +1 −1 spec/core/tuple/put_spec.rb
  134. +3 −3 spec/core/tuple/shared/at.rb
  135. +3 −3 spec/core/tuple/shared/put.rb
  136. +4 −4 spec/core/tuple/shift_spec.rb
  137. +2 −2 spec/core/tuple/swap_spec.rb
  138. +5 −5 spec/core/tuple/to_a_spec.rb
  139. +1 −1 spec/custom/helpers/generator.rb
  140. +1 −1 spec/library/fixtures/pingpong.rb
  141. +2 −2 spec/library/vmactor/container/spawn_actor_spec.rb
  142. +1 −1 vm/builtin/access_variable.cpp
  143. +1 −1 vm/builtin/block_environment.cpp
  144. +1 −1 vm/builtin/bytearray.cpp
  145. +1 −1 vm/builtin/channel.cpp
  146. +1 −1 vm/builtin/compactlookuptable.cpp
  147. +1 −1 vm/builtin/compiledmethod.cpp
  148. +1 −1 vm/builtin/executable.cpp
  149. +1 −1 vm/builtin/iseq.cpp
  150. +1 −1 vm/builtin/location.cpp
  151. +1 −1 vm/builtin/nativemethod.cpp
  152. +1 −1 vm/builtin/selector.cpp
  153. +1 −1 vm/builtin/sendsite.cpp
  154. +1 −1 vm/builtin/staticscope.cpp
  155. +1 −1 vm/builtin/variable_scope.cpp
  156. +1 −0 vm/capi/capi.cpp
  157. +2 −2 vm/capi/globals.cpp
  158. +2 −0 vm/capi/ruby.h
  159. +15 −13 vm/codegen/instructions_gen.rb
  160. +11 −8 vm/ontology.cpp
  161. +7 −6 vm/test/test_ontology.hpp
View
132 kernel/alpha.rb
@@ -131,47 +131,49 @@ def clone
end
end
-class CompiledMethod < Executable
- class Visibility
- # Create a MethodVisibility for +method+ with +visibility+
- def initialize(method, visibility)
- @method = method
- @visibility = visibility
+module Rubinius
+ class CompiledMethod < Executable
+ class Visibility
+ # Create a MethodVisibility for +method+ with +visibility+
+ def initialize(method, visibility)
+ @method = method
+ @visibility = visibility
+ end
end
end
-end
-class AccessVariable
- def self.allocate
- Ruby.primitive :accessvariable_allocate
- raise PrimitiveFailure, "AccessVariable.allocate primitive failed"
- end
+ class AccessVariable
+ def self.allocate
+ Ruby.primitive :accessvariable_allocate
+ raise PrimitiveFailure, "AccessVariable.allocate primitive failed"
+ end
- def initialize(variable, write)
- @primitive = nil
- @serial = 0
- @name = "@#{variable}".to_sym
- @write = write
- end
+ def initialize(variable, write)
+ @primitive = nil
+ @serial = 0
+ @name = "@#{variable}".to_sym
+ @write = write
+ end
- def self.get_ivar(name)
- new(name, false)
- end
+ def self.get_ivar(name)
+ new(name, false)
+ end
- def self.set_ivar(name)
- new(name, true)
+ def self.set_ivar(name)
+ new(name, true)
+ end
end
-end
-class LookupTable
- def [](key)
- Ruby.primitive :lookuptable_aref
- raise PrimitiveFailure, "LookupTable#[] primitive failed"
- end
+ class LookupTable
+ def [](key)
+ Ruby.primitive :lookuptable_aref
+ raise PrimitiveFailure, "LookupTable#[] primitive failed"
+ end
- def []=(key, val)
- Ruby.primitive :lookuptable_store
- raise PrimitiveFailure, "LookupTable#[]= primitive failed"
+ def []=(key, val)
+ Ruby.primitive :lookuptable_store
+ raise PrimitiveFailure, "LookupTable#[]= primitive failed"
+ end
end
end
@@ -257,7 +259,7 @@ def direct_superclass
end
def append_features(mod)
- im = IncludedModule.new(self)
+ im = Rubinius::IncludedModule.new(self)
im.attach_to mod
end
@@ -270,13 +272,13 @@ def include(mod)
end
def attr_reader(name)
- meth = AccessVariable.get_ivar name
+ meth = Rubinius::AccessVariable.get_ivar name
@method_table[name] = meth
return nil
end
def attr_writer(name)
- meth = AccessVariable.set_ivar name
+ meth = Rubinius::AccessVariable.set_ivar name
@method_table["#{name}=".to_sym] = meth
return nil
end
@@ -289,21 +291,21 @@ def attr_accessor(name)
def private(name)
if entry = @method_table[name]
- unless entry.kind_of? Executable
+ unless entry.kind_of? Rubinius::Executable
entry.visibility = :private
else
- cmv = CompiledMethod::Visibility.new entry, :private
+ cmv = Rubinius::CompiledMethod::Visibility.new entry, :private
@method_table[name] = cmv
end
end
end
def protected(name)
if entry = @method_table[name]
- unless entry.kind_of? Executable
+ unless entry.kind_of? Rubinius::Executable
entry.visibility = :protected
else
- cmv = CompiledMethod::Visibility.new entry, :protected
+ cmv = Rubinius::CompiledMethod::Visibility.new entry, :protected
@method_table[name] = cmv
end
end
@@ -327,7 +329,7 @@ def alias_method(new_name, current_name)
def module_function(name)
if cm = @method_table[name]
- if cm.kind_of? Tuple
+ if cm.kind_of? Rubinius::Tuple
cm = cm[1]
end
meta = class << self; self; end
@@ -337,35 +339,37 @@ def module_function(name)
end
end
-class IncludedModule < Module
- attr_reader :superclass
- attr_reader :module
+module Rubinius
+ class IncludedModule < Module
+ attr_reader :superclass
+ attr_reader :module
- def self.allocate
- Ruby.primitive :included_module_allocate
- raise PrimitiveFailure, "IncludedModule.allocate primitive failed"
- end
+ def self.allocate
+ Ruby.primitive :included_module_allocate
+ raise PrimitiveFailure, "IncludedModule.allocate primitive failed"
+ end
- def initialize(mod)
- @method_table = mod.method_table
- @method_cache = nil
- @name = nil
- @constants = mod.constant_table
- @encloser = mod.encloser
- @module = mod
- end
+ def initialize(mod)
+ @method_table = mod.method_table
+ @method_cache = nil
+ @name = nil
+ @constants = mod.constant_table
+ @encloser = mod.encloser
+ @module = mod
+ end
- def attach_to(cls)
- @superclass = cls.direct_superclass
- cls.superclass = self
- end
+ def attach_to(cls)
+ @superclass = cls.direct_superclass
+ cls.superclass = self
+ end
- def name
- @module.name
- end
+ def name
+ @module.name
+ end
- def to_s
- @module.to_s
+ def to_s
+ @module.to_s
+ end
end
end
View
2 kernel/bootstrap/array.rb
@@ -19,7 +19,7 @@ def [](idx)
def []=(idx, ent)
if idx >= @tuple.fields
- nt = Tuple.new(idx + 10)
+ nt = Rubinius::Tuple.new(idx + 10)
nt.copy_from @tuple, @start, @total, 0
@tuple = nt
end
View
26 kernel/bootstrap/block_environment.rb
@@ -1,16 +1,18 @@
-class BlockEnvironment
- def self.allocate
- Ruby.primitive :blockenvironment_allocate
- raise PrimitiveFailure, "BlockEnvironment.allocate primitive failed"
- end
+module Rubinius
+ class BlockEnvironment
+ def self.allocate
+ Ruby.primitive :blockenvironment_allocate
+ raise PrimitiveFailure, "BlockEnvironment.allocate primitive failed"
+ end
- def call(*args)
- Ruby.primitive :block_call
- raise PrimitiveFailure, "BlockEnvironment#call primitive failed"
- end
+ def call(*args)
+ Ruby.primitive :block_call
+ raise PrimitiveFailure, "BlockEnvironment#call primitive failed"
+ end
- def call_under(recv, static_scope, *args)
- Ruby.primitive :block_call_under
- raise PrimitiveFailure, "BlockEnvironment#call_under primitive failed"
+ def call_under(recv, static_scope, *args)
+ Ruby.primitive :block_call_under
+ raise PrimitiveFailure, "BlockEnvironment#call_under primitive failed"
+ end
end
end
View
114 kernel/bootstrap/bytearray.rb
@@ -1,69 +1,71 @@
-class ByteArray
- def self.allocate
- raise TypeError, "ByteArray cannot be created via allocate()"
- end
-
- def self.allocate_sized(cnt)
- Ruby.primitive :bytearray_allocate
- raise PrimitiveFailure, "ByteArray#allocate primitive failed"
- end
+module Rubinius
+ class ByteArray
+ def self.allocate
+ raise TypeError, "ByteArray cannot be created via allocate()"
+ end
- def self.new(cnt)
- obj = allocate_sized cnt
- Rubinius.asm(obj) do |obj|
- push_block
- run obj
- send_with_block :initialize, 0, true
+ def self.allocate_sized(cnt)
+ Ruby.primitive :bytearray_allocate
+ raise PrimitiveFailure, "ByteArray#allocate primitive failed"
end
- return obj
- end
+ def self.new(cnt)
+ obj = allocate_sized cnt
+ Rubinius.asm(obj) do |obj|
+ push_block
+ run obj
+ send_with_block :initialize, 0, true
+ end
- def fetch_bytes(start, count)
- Ruby.primitive :bytearray_fetch_bytes
- raise PrimitiveFailure, "ByteArray#fetch_bytes primitive failed"
- end
+ return obj
+ end
- def move_bytes(start, count, dest)
- Ruby.primitive :bytearray_move_bytes
- raise ArgumentError, "ByteArray#move_bytes primitive failed"
- end
+ def fetch_bytes(start, count)
+ Ruby.primitive :bytearray_fetch_bytes
+ raise PrimitiveFailure, "ByteArray#fetch_bytes primitive failed"
+ end
- def get_byte(index)
- Ruby.primitive :bytearray_get_byte
- raise PrimitiveFailure, "ByteArray#get_byte primitive failed"
- end
+ def move_bytes(start, count, dest)
+ Ruby.primitive :bytearray_move_bytes
+ raise ArgumentError, "ByteArray#move_bytes primitive failed"
+ end
- def set_byte(index, value)
- Ruby.primitive :bytearray_set_byte
- raise PrimitiveFailure, "ByteArray#set_byte primitive failed"
- end
+ def get_byte(index)
+ Ruby.primitive :bytearray_get_byte
+ raise PrimitiveFailure, "ByteArray#get_byte primitive failed"
+ end
- def compare_bytes(other, a, b)
- Ruby.primitive :bytearray_compare_bytes
- raise PrimitiveFailure, "ByteArray#compare_bytes primitive failed"
- end
+ def set_byte(index, value)
+ Ruby.primitive :bytearray_set_byte
+ raise PrimitiveFailure, "ByteArray#set_byte primitive failed"
+ end
- def size
- Ruby.primitive :bytearray_size
- raise PrimitiveFailure, "ByteArray#size primitive failed"
- end
+ def compare_bytes(other, a, b)
+ Ruby.primitive :bytearray_compare_bytes
+ raise PrimitiveFailure, "ByteArray#compare_bytes primitive failed"
+ end
- def dup(cls=nil)
- cls ||= self.class
- obj = cls.new(self.size)
- obj.copy_object self
- obj.send :initialize_copy, self
- return obj
- end
+ def size
+ Ruby.primitive :bytearray_size
+ raise PrimitiveFailure, "ByteArray#size primitive failed"
+ end
- ##
- # Searches for +pattern+ in the ByteArray. Returns the number
- # of characters from the front of the ByteArray to the end
- # of the pattern if a match is found. Returns Qnil if a match
- # is not found. Starts searching at index +start+.
- def locate(pattern, start)
- Ruby.primitive :bytearray_locate
- raise PrimitiveFailure, "ByteArray#locate primitive failed"
+ def dup(cls=nil)
+ cls ||= self.class
+ obj = cls.new(self.size)
+ obj.copy_object self
+ obj.send :initialize_copy, self
+ return obj
+ end
+
+ ##
+ # Searches for +pattern+ in the ByteArray. Returns the number
+ # of characters from the front of the ByteArray to the end
+ # of the pattern if a match is found. Returns Qnil if a match
+ # is not found. Starts searching at index +start+.
+ def locate(pattern, start)
+ Ruby.primitive :bytearray_locate
+ raise PrimitiveFailure, "ByteArray#locate primitive failed"
+ end
end
end
View
124 kernel/bootstrap/channel.rb
@@ -12,86 +12,88 @@
# Channel is used heavily by Scheduler, to allow ruby code to interact with
# the outside world in a thread aware manner.
-class Channel
+module Rubinius
+ class Channel
- ##
- # Returns nil if nothing is waiting, or a List object which contains all
- # Thread objects waiting on this Channel.
+ ##
+ # Returns nil if nothing is waiting, or a List object which contains all
+ # Thread objects waiting on this Channel.
- attr_reader :waiting
+ attr_reader :waiting
- ##
- # Returns nil if there are no values, otherwise a List object containing all
- # values the Channel contains.
+ ##
+ # Returns nil if there are no values, otherwise a List object containing all
+ # values the Channel contains.
- attr_reader :value
+ attr_reader :value
- ##
- # Creates a new Channel and registers it with the VM.
+ ##
+ # Creates a new Channel and registers it with the VM.
- def self.new
- Ruby.primitive :channel_new
- raise PrimitiveFailure, "Channel.new primitive failed"
- end
+ def self.new
+ Ruby.primitive :channel_new
+ raise PrimitiveFailure, "Channel.new primitive failed"
+ end
- ##
- # Puts +obj+ in the Channel. If there are waiting threads the first thread
- # will be woken up and handed +obj+.
+ ##
+ # Puts +obj+ in the Channel. If there are waiting threads the first thread
+ # will be woken up and handed +obj+.
- def send(obj)
- Ruby.primitive :channel_send
- raise PrimitiveFailure, "Channel#send primitive failed"
- end
+ def send(obj)
+ Ruby.primitive :channel_send
+ raise PrimitiveFailure, "Channel#send primitive failed"
+ end
- alias_method :<<, :send
+ alias_method :<<, :send
- ##
- # Removes and returns the first value from the Channel. If the channel
- # is empty, Thread.current is put to sleep until #send is called.
+ ##
+ # Removes and returns the first value from the Channel. If the channel
+ # is empty, Thread.current is put to sleep until #send is called.
- def receive
- Ruby.primitive :channel_receive
- raise PrimitiveFailure, "Channel#receive primitive failed"
- end
-
- def receive_timeout(duration)
- Ruby.primitive :channel_receive_timeout
- raise PrimitiveFailure, "Channel#receive_timeout primitive failed"
- end
+ def receive
+ Ruby.primitive :channel_receive
+ raise PrimitiveFailure, "Channel#receive primitive failed"
+ end
- def try_receive
- Ruby.primitive :channel_try_receive
- raise PrimitiveFailure, "Channel#try_receive primitive failed"
- end
+ def receive_timeout(duration)
+ Ruby.primitive :channel_receive_timeout
+ raise PrimitiveFailure, "Channel#receive_timeout primitive failed"
+ end
- ##
- # Converts +obj+ into a Channel using #to_channel.
+ def try_receive
+ Ruby.primitive :channel_try_receive
+ raise PrimitiveFailure, "Channel#try_receive primitive failed"
+ end
- def self.convert_to_channel(obj)
- return obj if Channel === obj
- begin
- o2 = obj.to_channel
- unless Channel === o2
- raise ArgumentError, "to_channel on #{obj.inspect} did not return a Channel"
+ ##
+ # Converts +obj+ into a Channel using #to_channel.
+
+ def self.convert_to_channel(obj)
+ return obj if Channel === obj
+ begin
+ o2 = obj.to_channel
+ unless Channel === o2
+ raise ArgumentError, "to_channel on #{obj.inspect} did not return a Channel"
+ end
+ return o2
+ rescue NoMethodError
+ raise ArgumentError, "Unable to convert #{obj.inspect} into a channel"
end
- return o2
- rescue NoMethodError
- raise ArgumentError, "Unable to convert #{obj.inspect} into a channel"
end
- end
- ##
- # Legacy API. To be removed.
+ ##
+ # Legacy API. To be removed.
- def self.receive(obj) # :nodoc:
- return convert_to_channel(obj).receive
- end
+ def self.receive(obj) # :nodoc:
+ return convert_to_channel(obj).receive
+ end
- ##
- # API compliance, returns self.
+ ##
+ # API compliance, returns self.
- def to_channel
- self
- end
+ def to_channel
+ self
+ end
+ end
end
View
50 kernel/bootstrap/compactlookuptable.rb
@@ -1,31 +1,33 @@
-class CompactLookupTable
- def self.allocate
- Ruby.primitive :compactlookuptable_allocate
- raise PrimitiveFailure, "CompactLookupTable.allocate primitive failed"
- end
+module Rubinius
+ class CompactLookupTable
+ def self.allocate
+ Ruby.primitive :compactlookuptable_allocate
+ raise PrimitiveFailure, "CompactLookupTable.allocate primitive failed"
+ end
- def [](key)
- Ruby.primitive :compactlookuptable_fetch
- raise PrimitiveFailure, "CompactLookupTable#[] primitive failed"
- end
+ def [](key)
+ Ruby.primitive :compactlookuptable_fetch
+ raise PrimitiveFailure, "CompactLookupTable#[] primitive failed"
+ end
- def []=(key, val)
- Ruby.primitive :compactlookuptable_store
- raise PrimitiveFailure, "CompactLookupTable#[]= primitive failed"
- end
+ def []=(key, val)
+ Ruby.primitive :compactlookuptable_store
+ raise PrimitiveFailure, "CompactLookupTable#[]= primitive failed"
+ end
- def key?(key)
- Ruby.primitive :compactlookuptable_has_key
- raise PrimitiveFailure, "CompactLookupTable#key? primitive failed"
- end
+ def key?(key)
+ Ruby.primitive :compactlookuptable_has_key
+ raise PrimitiveFailure, "CompactLookupTable#key? primitive failed"
+ end
- def keys
- Ruby.primitive :compactlookuptable_keys
- raise PrimitiveFailure, "CompactLookupTable#keys primitive failed"
- end
+ def keys
+ Ruby.primitive :compactlookuptable_keys
+ raise PrimitiveFailure, "CompactLookupTable#keys primitive failed"
+ end
- def values
- Ruby.primitive :compactlookuptable_values
- raise PrimitiveFailure, "CompactLookupTable#keys primitive failed"
+ def values
+ Ruby.primitive :compactlookuptable_values
+ raise PrimitiveFailure, "CompactLookupTable#keys primitive failed"
+ end
end
end
View
86 kernel/bootstrap/compiled_method.rb
@@ -1,54 +1,56 @@
-class CompiledMethod < Executable
+module Rubinius
+ class CompiledMethod < Executable
- def self.allocate
- Ruby.primitive :compiledmethod_allocate
- raise PrimitiveFailure, "CompiledMethod.allocate primitive failed"
- end
-
- def compile
- Ruby.primitive :compiledmethod_compile
- raise PrimitiveFailure, "CompiledMethod#compile primitive failed"
- end
-
- def make_machine_method
- Ruby.primitive :compiledmethod_make_machine_method
- raise PrimitiveFailure, "CompiledMethod#make_machine_method primitive failed"
- end
-
- def activate(recv, mod, args)
- Ruby.primitive :compiledmethod_activate
- raise PrimitiveFailure, "CompiledMethod#activate failed"
- end
-
- def self.of_sender
- Ruby.primitive :compiledmethod_of_sender
- raise PrimitiveFailure, "CompiledMethod.of_sender failed"
- end
+ def self.allocate
+ Ruby.primitive :compiledmethod_allocate
+ raise PrimitiveFailure, "CompiledMethod.allocate primitive failed"
+ end
- ##
- # An instance of Visibility is stored in a class's or module's
- # method table and records a method's visibility. The Visibility
- # instance contains a reference to the actual compiled method.
+ def compile
+ Ruby.primitive :compiledmethod_compile
+ raise PrimitiveFailure, "CompiledMethod#compile primitive failed"
+ end
- class Visibility
- attr_accessor :method
- attr_accessor :visibility
+ def make_machine_method
+ Ruby.primitive :compiledmethod_make_machine_method
+ raise PrimitiveFailure, "CompiledMethod#make_machine_method primitive failed"
+ end
- # Is this method private?
- def private?
- @visibility == :private
+ def activate(recv, mod, args)
+ Ruby.primitive :compiledmethod_activate
+ raise PrimitiveFailure, "CompiledMethod#activate failed"
end
- ##
- # Is this method protected?
- def protected?
- @visibility == :protected
+ def self.of_sender
+ Ruby.primitive :compiledmethod_of_sender
+ raise PrimitiveFailure, "CompiledMethod.of_sender failed"
end
##
- # Is this method public?
- def public?
- @visibility == :public
+ # An instance of Visibility is stored in a class's or module's
+ # method table and records a method's visibility. The Visibility
+ # instance contains a reference to the actual compiled method.
+
+ class Visibility
+ attr_accessor :method
+ attr_accessor :visibility
+
+ # Is this method private?
+ def private?
+ @visibility == :private
+ end
+
+ ##
+ # Is this method protected?
+ def protected?
+ @visibility == :protected
+ end
+
+ ##
+ # Is this method public?
+ def public?
+ @visibility == :public
+ end
end
end
end
View
14 kernel/bootstrap/executable.rb
@@ -1,9 +1,11 @@
-class Executable
- attr_accessor :serial
- attr_accessor :primitive
+module Rubinius
+ class Executable
+ attr_accessor :serial
+ attr_accessor :primitive
- def self.allocate
- Ruby.primitive :executable_allocate
- raise PrimitiveFailure, "Executable.allocate primitive failed"
+ def self.allocate
+ Ruby.primitive :executable_allocate
+ raise PrimitiveFailure, "Executable.allocate primitive failed"
+ end
end
end
View
4 kernel/bootstrap/hash.rb
@@ -126,7 +126,7 @@ def self.allocate
def __initialize__
# We don't need the nanny checking our symbols
@records = MIN_SIZE
- @bins = Tuple.new(MIN_SIZE)
+ @bins = Rubinius::Tuple.new(MIN_SIZE)
@count = 0
end
@@ -197,7 +197,7 @@ def redistribute(rehash = true)
i = to_iter
@records = new_size
- @bins = Tuple.new @records
+ @bins = Rubinius::Tuple.new @records
while entry = i.next
while entry
View
190 kernel/bootstrap/lookuptable.rb
@@ -28,124 +28,126 @@
# String keys are converted to Symbols. LookupTable is NOT intended to be
# used generally like Hash.
-class LookupTable
- class Bucket
- attr_reader :key
- attr_reader :value
- attr_reader :next
- end
+module Rubinius
+ class LookupTable
+ class Bucket
+ attr_reader :key
+ attr_reader :value
+ attr_reader :next
+ end
- class Association
- attr_reader :key
- attr_writer :active
+ class Association
+ attr_reader :key
+ attr_writer :active
- attr_accessor :value
+ attr_accessor :value
- def active?
- @active
- end
+ def active?
+ @active
+ end
- def self.new(name, value)
- Ruby.primitive :lookuptableassociation_allocate
- raise PrimitiveFailure, "LookupTable::Association.allocate failed"
- end
+ def self.new(name, value)
+ Ruby.primitive :lookuptableassociation_allocate
+ raise PrimitiveFailure, "LookupTable::Association.allocate failed"
+ end
- def inspect
- "#<LookupTable::Association:0x#{object_id.to_s(16)} @key=#{@key.inspect} @value=#{@value.inspect} @valid=#{@active.inspect}>"
+ def inspect
+ "#<LookupTable::Association:0x#{object_id.to_s(16)} @key=#{@key.inspect} @value=#{@value.inspect} @valid=#{@active.inspect}>"
+ end
end
- end
- attr_reader :values
- attr_reader :bins
+ attr_reader :values
+ attr_reader :bins
- def size
- @entries
- end
+ def size
+ @entries
+ end
- alias_method :length, :size
+ alias_method :length, :size
- def self.allocate
- Ruby.primitive :lookuptable_allocate
- raise PrimitiveFailure, "LookupTable.allocate primitive failed"
- end
-
- def initialize(hash=nil)
- return unless hash
- hash.each do |k,v|
- self[k] = v
+ def self.allocate
+ Ruby.primitive :lookuptable_allocate
+ raise PrimitiveFailure, "LookupTable.allocate primitive failed"
end
- end
-
- def duplicate
- Ruby.primitive :lookuptable_duplicate
- raise PrimitiveFailure, "LookupTable#duplicate primitive failed"
- end
- def dup
- copy = duplicate
- copy.send :initialize_copy, self
- copy
- end
+ def initialize(hash=nil)
+ return unless hash
+ hash.each do |k,v|
+ self[k] = v
+ end
+ end
- def fetch(key, return_on_failure)
- Ruby.primitive :lookuptable_fetch
- raise PrimitiveFailure, "fetch failed"
- end
+ def duplicate
+ Ruby.primitive :lookuptable_duplicate
+ raise PrimitiveFailure, "LookupTable#duplicate primitive failed"
+ end
- def key?(key)
- Ruby.primitive :lookuptable_has_key
- raise PrimitiveFailure, "LookupTable#key? primitive failed"
- end
+ def dup
+ copy = duplicate
+ copy.send :initialize_copy, self
+ copy
+ end
- alias_method :has_key?, :key?
- alias_method :include?, :key?
- alias_method :member?, :key?
+ def fetch(key, return_on_failure)
+ Ruby.primitive :lookuptable_fetch
+ raise PrimitiveFailure, "fetch failed"
+ end
- def delete(key)
- Ruby.primitive :lookuptable_delete
- raise PrimitiveFailure, "LookupTable#delete primitive failed"
- end
+ def key?(key)
+ Ruby.primitive :lookuptable_has_key
+ raise PrimitiveFailure, "LookupTable#key? primitive failed"
+ end
- def keys
- Ruby.primitive :lookuptable_keys
- raise PrimitiveFailure, "LookupTable#keys primitive failed"
- end
+ alias_method :has_key?, :key?
+ alias_method :include?, :key?
+ alias_method :member?, :key?
- def values
- Ruby.primitive :lookuptable_values
- raise PrimitiveFailure, "LookupTable#keys primitive failed"
- end
+ def delete(key)
+ Ruby.primitive :lookuptable_delete
+ raise PrimitiveFailure, "LookupTable#delete primitive failed"
+ end
- def entries
- Ruby.primitive :lookuptable_entries
- raise PrimitiveFailure, "LookupTable#entries primitive failed"
- end
+ def keys
+ Ruby.primitive :lookuptable_keys
+ raise PrimitiveFailure, "LookupTable#keys primitive failed"
+ end
- def each
- raise LocalJumpError, "no block given" unless block_given? or @entries == 0
+ def values
+ Ruby.primitive :lookuptable_values
+ raise PrimitiveFailure, "LookupTable#keys primitive failed"
+ end
- ents = entries
- i = ents.start
- total = ents.start + ents.total
- while i < total
- entry = ents[i]
- yield [entry.key, entry.value]
- i += 1
+ def entries
+ Ruby.primitive :lookuptable_entries
+ raise PrimitiveFailure, "LookupTable#entries primitive failed"
end
- self
- end
- def each_entry
- raise LocalJumpError, "no block given" unless block_given? or @entries == 0
+ def each
+ raise LocalJumpError, "no block given" unless block_given? or @entries == 0
+
+ ents = entries
+ i = ents.start
+ total = ents.start + ents.total
+ while i < total
+ entry = ents[i]
+ yield [entry.key, entry.value]
+ i += 1
+ end
+ self
+ end
- ents = entries
- i = ents.start
- total = ents.start + ents.total
- while i < total
- entry = ents[i]
- yield entry.key, entry.value
- i += 1
+ def each_entry
+ raise LocalJumpError, "no block given" unless block_given? or @entries == 0
+
+ ents = entries
+ i = ents.start
+ total = ents.start + ents.total
+ while i < total
+ entry = ents[i]
+ yield entry.key, entry.value
+ i += 1
+ end
+ self
end
- self
end
end
View
257 kernel/bootstrap/scheduler.rb
@@ -17,134 +17,135 @@
# ready to be read. Instead of directly calling read(2), send_on_readable is
# called and waits in the VM until the file descriptor is ready to be read.
-class Scheduler
-
- ##
- # In +microseconds+ send the +tag+ to +channel+. Returns an event id for
- # use with #cancel. This is used to implement sleep. For example:
- #
- # chan = Channel.new
- # Scheduler.send_in_microseconds chan, 1000, :hello
- # p chan.receive
- # # 1 second later :hello is printed
- #
- # The chan.receive appears to block the current thread, waking up when there
- # is a value on the channel. To the caller of this code it appears that
- # they have slept for 1 seconds.
-
- def self.send_in_microseconds(channel, microseconds, tag)
- Ruby.primitive :scheduler_send_in_microseconds
- raise PrimitiveFailure, "Scheduler.send_in_microseconds primitive failed"
- end
-
- ##
- # Same as send_in_microseconds, but the 2nd argument is seconds, not
- # microseconds.
-
- def self.send_in_seconds(chan, seconds, tag)
- Ruby.primitive :scheduler_send_in_seconds
- raise PrimitiveFailure, "Scheduler.send_in_seconds primitive failed"
- end
-
- ##
- # Instructs the VM to send a value to +channel+ when the IO object +io+ is
- # readable. +buffer+ and +nbytes+ are optional, and should be set to nil if
- # you don't wish to use them. Returns an event id, for use with #cancel
- #
- # There are 2 modes of operation, depending on if +buffer+ is nil or not.
- #
- # If +buffer+ is nil the +channel+ is sent the file descriptor for +io+.
- # This can be used to wait on multiple IO objects with one channel and
- # figure out which IO object was ready given the return value of #receive3
- #
- # The second mode is when +buffer+ is an IO::Buffer object. In this mode
- # when +io+ becomes readable +nbytes+ bytes are read from IO and stored into
- # +buffer+. Note that this is done using the read(2) C function and thus
- # +nbytes+ is the maximum number of bytes that will be read, not the actual
- # number read. The value sent to the channel is the actual number of bytes
- # read as a Fixnum object.
- #
- # If an error occurs while reading in the 2nd mode, the value sent to the
- # channel is a SystemCallError representing the failure in read(2).
- #
- # See IO#sysread in kernel/common/io.rb for a simple example.
-
- def self.send_on_readable(chan, io, buffer, nbytes)
- Ruby.primitive :scheduler_send_on_readable
- raise PrimitiveFailure, "Scheduler.send_on_readable primitive failed"
- end
-
- ##
- # Instructs the VM to send the file descriptor for +io+ to +channel+
- # when +io+ is writable. Returns an event id, for use with #cancel
-
- def self.send_on_writable(chan, io)
- Ruby.primitive :scheduler_send_on_writable
- raise PrimitiveFailure, "Scheduler.send_on_writable primitive failed"
- end
+module Rubinius
+ class Scheduler
+
+ ##
+ # In +microseconds+ send the +tag+ to +channel+. Returns an event id for
+ # use with #cancel. This is used to implement sleep. For example:
+ #
+ # chan = Channel.new
+ # Scheduler.send_in_microseconds chan, 1000, :hello
+ # p chan.receive
+ # # 1 second later :hello is printed
+ #
+ # The chan.receive appears to block the current thread, waking up when there
+ # is a value on the channel. To the caller of this code it appears that
+ # they have slept for 1 seconds.
+
+ def self.send_in_microseconds(channel, microseconds, tag)
+ Ruby.primitive :scheduler_send_in_microseconds
+ raise PrimitiveFailure, "Scheduler.send_in_microseconds primitive failed"
+ end
+
+ ##
+ # Same as send_in_microseconds, but the 2nd argument is seconds, not
+ # microseconds.
+
+ def self.send_in_seconds(chan, seconds, tag)
+ Ruby.primitive :scheduler_send_in_seconds
+ raise PrimitiveFailure, "Scheduler.send_in_seconds primitive failed"
+ end
+
+ ##
+ # Instructs the VM to send a value to +channel+ when the IO object +io+ is
+ # readable. +buffer+ and +nbytes+ are optional, and should be set to nil if
+ # you don't wish to use them. Returns an event id, for use with #cancel
+ #
+ # There are 2 modes of operation, depending on if +buffer+ is nil or not.
+ #
+ # If +buffer+ is nil the +channel+ is sent the file descriptor for +io+.
+ # This can be used to wait on multiple IO objects with one channel and
+ # figure out which IO object was ready given the return value of #receive3
+ #
+ # The second mode is when +buffer+ is an IO::Buffer object. In this mode
+ # when +io+ becomes readable +nbytes+ bytes are read from IO and stored into
+ # +buffer+. Note that this is done using the read(2) C function and thus
+ # +nbytes+ is the maximum number of bytes that will be read, not the actual
+ # number read. The value sent to the channel is the actual number of bytes
+ # read as a Fixnum object.
+ #
+ # If an error occurs while reading in the 2nd mode, the value sent to the
+ # channel is a SystemCallError representing the failure in read(2).
+ #
+ # See IO#sysread in kernel/common/io.rb for a simple example.
+
+ def self.send_on_readable(chan, io, buffer, nbytes)
+ Ruby.primitive :scheduler_send_on_readable
+ raise PrimitiveFailure, "Scheduler.send_on_readable primitive failed"
+ end
+
+ ##
+ # Instructs the VM to send the file descriptor for +io+ to +channel+
+ # when +io+ is writable. Returns an event id, for use with #cancel
+
+ def self.send_on_writable(chan, io)
+ Ruby.primitive :scheduler_send_on_writable
+ raise PrimitiveFailure, "Scheduler.send_on_writable primitive failed"
+ end
+
+ ##
+ # Instructs the VM to send a Thread object to +chan+ when UNIX signal
+ # +signum+, a Fixnum, is received by the process. Returns an event id, for
+ # use with #cancel
+ #
+ # The Thread object that will be sent is the Thread object that was running
+ # when the signal was received by the process.
+ #
+ # Example:
+ #
+ # chan = Channel.new
+ # Scheduler.send_on_signal chan, 2 # 2 is SIGINT
+ # thr = Thread.new { some_long_operation }
+ # val = chan.receive # blocks Thread.current until SIGINT is received
+ # # => #<Thread:0x....>
+ # p val == thr # => true
+ #
+ # Unlike all other +send_on+ methods, this one is persistant. Calling
+ # +send_on_signal+ once for SIGINT will cause all future SIGINTs to send a
+ # value to +chan+.
+
+ def self.send_on_signal(channel, signum)
+ Ruby.primitive :scheduler_send_on_signal
+ raise PrimitiveFailure, "Scheduler.send_on_signal primitive failed"
+ end
+
+ ##
+ # Wrapper for the primitive, use +send_on_stopped+
+ #
+ def self.send_on_stopped_prim(channel, pid, flags)
+ Ruby.primitive :scheduler_send_on_stopped
+ raise PrimitiveFailure, "Scheduler.send_on_stopped_prim primitive failed"
+ end
+
+ ##
+ # Instructs the VM to send a value to +channel+ when process +pid+ is no
+ # longer running. This is used to implement Process.wait. Returns an event
+ # id for use with #cancel.
+ #
+ # Flags is a Fixnum and currently accepts only Process::WNOHANG to indicate
+ # send_on_stopped should send nil if the process is still running instead of
+ # blocking.
+ #
+ # The value sent to the channel is either:
+ # * A tuple containing +pid+ and +exit_status+
+ # * +false+ if there is no process +pid+
+ # * nil if flags indicated NOHANG
+
+ def self.send_on_stopped(channel, pid=-1, flags=0)
+ send_on_stopped_prim(channel, pid, flags)
+ end
+
+ ##
+ # All +send_on+ methods return an event id for the registered event. That
+ # id can be passed to #cancel to inform the VM that we're not longer
+ # interested in the event. No value is sent to the channel that was
+ # registered.
+
+ def self.cancel(id)
+ Ruby.primitive :scheduler_cancel
+ raise PrimitiveFailure, "Scheduler.cancel primitive failed"
+ end
- ##
- # Instructs the VM to send a Thread object to +chan+ when UNIX signal
- # +signum+, a Fixnum, is received by the process. Returns an event id, for
- # use with #cancel
- #
- # The Thread object that will be sent is the Thread object that was running
- # when the signal was received by the process.
- #
- # Example:
- #
- # chan = Channel.new
- # Scheduler.send_on_signal chan, 2 # 2 is SIGINT
- # thr = Thread.new { some_long_operation }
- # val = chan.receive # blocks Thread.current until SIGINT is received
- # # => #<Thread:0x....>
- # p val == thr # => true
- #
- # Unlike all other +send_on+ methods, this one is persistant. Calling
- # +send_on_signal+ once for SIGINT will cause all future SIGINTs to send a
- # value to +chan+.
-
- def self.send_on_signal(channel, signum)
- Ruby.primitive :scheduler_send_on_signal
- raise PrimitiveFailure, "Scheduler.send_on_signal primitive failed"
end
-
- ##
- # Wrapper for the primitive, use +send_on_stopped+
- #
- def self.send_on_stopped_prim(channel, pid, flags)
- Ruby.primitive :scheduler_send_on_stopped
- raise PrimitiveFailure, "Scheduler.send_on_stopped_prim primitive failed"
- end
-
- ##
- # Instructs the VM to send a value to +channel+ when process +pid+ is no
- # longer running. This is used to implement Process.wait. Returns an event
- # id for use with #cancel.
- #
- # Flags is a Fixnum and currently accepts only Process::WNOHANG to indicate
- # send_on_stopped should send nil if the process is still running instead of
- # blocking.
- #
- # The value sent to the channel is either:
- # * A tuple containing +pid+ and +exit_status+
- # * +false+ if there is no process +pid+
- # * nil if flags indicated NOHANG
-
- def self.send_on_stopped(channel, pid=-1, flags=0)
- send_on_stopped_prim(channel, pid, flags)
- end
-
- ##
- # All +send_on+ methods return an event id for the registered event. That
- # id can be passed to #cancel to inform the VM that we're not longer
- # interested in the event. No value is sent to the channel that was
- # registered.
-
- def self.cancel(id)
- Ruby.primitive :scheduler_cancel
- raise PrimitiveFailure, "Scheduler.cancel primitive failed"
- end
-
end
-
View
16 kernel/bootstrap/selector.rb
@@ -3,14 +3,16 @@
# When a method is redefined the Selector is used to clear all the SendSites
# referencing the method's name.
-class Selector
+module Rubinius
+ class Selector
- ##
- # Clears this Selector's SendSites allowing each SendSite to discover a new
- # Executable.
+ ##
+ # Clears this Selector's SendSites allowing each SendSite to discover a new
+ # Executable.
- def clear
- Ruby.primitive :selector_clear
- raise PrimitiveFailure, "Selector#clear primitive failed"
+ def clear
+ Ruby.primitive :selector_clear
+ raise PrimitiveFailure, "Selector#clear primitive failed"
+ end
end
end
View
78 kernel/bootstrap/sendsite.rb
@@ -5,43 +5,45 @@
# is used. Otherwise the MethodTable is consulted (see MethodTable) and the
# SendSite is filled in with that Executable.
-class SendSite
-
- attr_accessor :name
- attr_accessor :sender
- attr_accessor :selector
- attr_accessor :method
- attr_accessor :module
- attr_accessor :recv_class
-
- def self.new(name)
- SendSite.create name
- end
-
- def self.create(name)
- Ruby.primitive :sendsite_create
- raise PrimitiveFailure, "SendSite.create primitive failed"
- end
-
- def hits
- Ruby.primitive :sendsite_hits
- raise PrimitiveFailure, "Sendsite#hits primitive failed"
- end
-
- def misses
- Ruby.primitive :sendsite_misses
- raise PrimitiveFailure, "Sendsite#misses primitive failed"
- end
-
- ##
- # Sets the sender field on the SendSite.
- # +cm+ must be a CompiledMethod object
- def sender=(cm)
- Ruby.primitive :sendsite_set_sender
- raise PrimitiveFailure, "primitive failed"
- end
-
- def inspect
- "#<SendSite:0x#{object_id.to_s(16)} name=#{name} hits=#{hits} misses=#{misses}>"
+module Rubinius
+ class SendSite
+
+ attr_accessor :name
+ attr_accessor :sender
+ attr_accessor :selector
+ attr_accessor :method
+ attr_accessor :module
+ attr_accessor :recv_class
+
+ def self.new(name)
+ SendSite.create name
+ end
+
+ def self.create(name)
+ Ruby.primitive :sendsite_create
+ raise PrimitiveFailure, "SendSite.create primitive failed"
+ end
+
+ def hits
+ Ruby.primitive :sendsite_hits
+ raise PrimitiveFailure, "Sendsite#hits primitive failed"
+ end
+
+ def misses
+ Ruby.primitive :sendsite_misses
+ raise PrimitiveFailure, "Sendsite#misses primitive failed"
+ end
+
+ ##
+ # Sets the sender field on the SendSite.
+ # +cm+ must be a CompiledMethod object
+ def sender=(cm)
+ Ruby.primitive :sendsite_set_sender
+ raise PrimitiveFailure, "primitive failed"
+ end
+
+ def inspect
+ "#<SendSite:0x#{object_id.to_s(16)} name=#{name} hits=#{hits} misses=#{misses}>"
+ end
end
end
View
10 kernel/bootstrap/static_scope.rb
@@ -1,6 +1,8 @@
-class StaticScope
- def self.of_sender
- Ruby.primitive :static_scope_of_sender
- raise PrimitiveFailure, "primitive failed"
+module Rubinius
+ class StaticScope
+ def self.of_sender
+ Ruby.primitive :static_scope_of_sender
+ raise PrimitiveFailure, "primitive failed"
+ end
end
end
View
100 kernel/bootstrap/tuple.rb
@@ -1,63 +1,65 @@
-class Tuple
+module Rubinius
+ class Tuple
- def self.allocate
- raise TypeError, "Tuple cannot be created via allocate()"
- end
+ def self.allocate
+ raise TypeError, "Tuple cannot be created via allocate()"
+ end
- def self.new(cnt)
- Ruby.primitive :tuple_allocate
- raise PrimitiveFailure, "Tuple.new primitive failed"
- end
+ def self.new(cnt)
+ Ruby.primitive :tuple_allocate
+ raise PrimitiveFailure, "Tuple.new primitive failed"
+ end
- def self.pattern(size, obj)
- Ruby.primitive :tuple_pattern
- raise PrimitiveFailure, "Tuple.pattern primitive failed"
- end
+ def self.pattern(size, obj)
+ Ruby.primitive :tuple_pattern
+ raise PrimitiveFailure, "Tuple.pattern primitive failed"
+ end
- def [](idx)
- Ruby.primitive :tuple_at
- raise PrimitiveFailure, "Tuple#[] primitive failed"
- end
+ def [](idx)
+ Ruby.primitive :tuple_at
+ raise PrimitiveFailure, "Tuple#[] primitive failed"
+ end
- def []=(idx, val)
- Ruby.primitive :tuple_put
- raise PrimitiveFailure, "Tuple#[]= primitive failed"
- end
+ def []=(idx, val)
+ Ruby.primitive :tuple_put
+ raise PrimitiveFailure, "Tuple#[]= primitive failed"
+ end
- def at(idx)
- Ruby.primitive :tuple_at
- raise PrimitiveFailure, "Tuple#[] primitive failed"
- end
+ def at(idx)
+ Ruby.primitive :tuple_at
+ raise PrimitiveFailure, "Tuple#[] primitive failed"
+ end
- def put(idx, val)
- Ruby.primitive :tuple_put
- raise PrimitiveFailure, "Tuple#[]= primitive failed"
- end
+ def put(idx, val)
+ Ruby.primitive :tuple_put
+ raise PrimitiveFailure, "Tuple#[]= primitive failed"
+ end
- def fields
- Ruby.primitive :tuple_fields
- raise PrimitiveFailure, "Tuple#fields primitive failed"
- end
+ def fields
+ Ruby.primitive :tuple_fields
+ raise PrimitiveFailure, "Tuple#fields primitive failed"
+ end
- def copy_from(other, start, length, dest)
- Ruby.primitive :tuple_copy_from
- raise PrimitiveFailure, "Tuple#copy_from primitive failed"
- end
+ def copy_from(other, start, length, dest)
+ Ruby.primitive :tuple_copy_from
+ raise PrimitiveFailure, "Tuple#copy_from primitive failed"
+ end
- def dup
- obj = self.class.new(self.size)
- obj.copy_object self
- obj.send :initialize_copy, self
- obj
- end
+ def dup
+ obj = self.class.new(self.size)
+ obj.copy_object self
+ obj.send :initialize_copy, self
+ obj
+ end
- def delete(start,length,object)
- Ruby.primitive :tuple_delete_inplace
- raise PrimitiveFailure, "Tuple#delete primitive failed"
- end
+ def delete(start,length,object)
+ Ruby.primitive :tuple_delete_inplace
+ raise PrimitiveFailure, "Tuple#delete primitive failed"
+ end
- def self.create_weakref(object)
- Ruby.primitive :tuple_create_weakref
- raise PrimitiveFailure, "Tuple.create_weakref failed, unable to create a weak reference"
+ def self.create_weakref(object)
+ Ruby.primitive :tuple_create_weakref
+ raise PrimitiveFailure, "Tuple.create_weakref failed, unable to create a weak reference"
+ end
end
end
View
10 kernel/bootstrap/undef.rb
@@ -1,10 +0,0 @@
-# TODO: should this be removed?
-class UndefClass
- def undef?
- true
- end
-
- def to_s
- "undef"
- end
-end
View
126 kernel/bootstrap/variable_scope.rb
@@ -1,82 +1,82 @@
-class VariableScope
- def self.of_sender
- Ruby.primitive :variable_scope_of_sender
-
- raise PrimitiveFailure, "Unable to get VariableScope of sender"
- end
-
- def self.current
- Ruby.primitive :variable_scope_current
+module Rubinius
+ class VariableScope
+ def self.of_sender
+ Ruby.primitive :variable_scope_of_sender
+ raise PrimitiveFailure, "Unable to get VariableScope of sender"
+ end
- raise PrimitiveFailure, "Unable to get current VariableScope"
- end
+ def self.current
+ Ruby.primitive :variable_scope_current
+ raise PrimitiveFailure, "Unable to get current VariableScope"
+ end
- def locals
- Ruby.primitive :variable_scope_locals
- raise PrimitiveFailure, "Unable to get VariableScope locals"
- end
+ def locals
+ Ruby.primitive :variable_scope_locals
+ raise PrimitiveFailure, "Unable to get VariableScope locals"
+ end
- # To handle Module#private, protected
- attr_accessor :method_visibility
+ # To handle Module#private, protected
+ attr_accessor :method_visibility
- # To handle $~, $1, etc
+ # To handle $~, $1, etc
- def last_match=(match)
- if parent
- scope = self
- while scope.parent
- scope = scope.parent
+ def last_match=(match)
+ if parent
+ scope = self
+ while scope.parent
+ scope = scope.parent
+ end
+ scope.last_match = match
+ else
+ @last_match = match
end
- scope.last_match = match
- else
- @last_match = match
+
+ match
end
- match
- end
+ def last_match
+ if parent
+ scope = self
+ while scope.parent
+ scope = scope.parent
+ end
- def last_match
- if parent
- scope = self
- while scope.parent
- scope = scope.parent
+ scope.last_match
+ else
+ @last_match
end
-
- scope.last_match
- else
- @last_match
- end
- end
- ##
- # The Nth group of the last regexp match.
-
- def nth_ref(n)
- if lm = last_match()
- return lm[n]
end
+ ##
+ # The Nth group of the last regexp match.
- return nil
- end
+ def nth_ref(n)
+ if lm = last_match()
+ return lm[n]
+ end
- ##
- # One of the special globals $&, $`, $' or $+.
+ return nil
+ end
- def back_ref(kind)
- if lm = last_match()
- res = case kind
- when :&
- lm[0]
- when :"`"
- lm.pre_match
- when :"'"
- lm.post_match
- when :+
- lm.captures.last
+ ##
+ # One of the special globals $&, $`, $' or $+.
+
+ def back_ref(kind)
+ if lm = last_match()
+ res = case kind
+ when :&
+ lm[0]
+ when :"`"
+ lm.pre_match
+ when :"'"
+ lm.post_match
+ when :+
+ lm.captures.last
+ end
+
+ return res
end
- return res
+ return nil
end
-
- return nil
end
end
View
2 kernel/bootstrap/weakref.rb
@@ -3,7 +3,7 @@ class WeakRef
class RefError < RuntimeError; end
def initialize(object)
- @wr = Tuple.create_weakref(object)
+ @wr = Rubinius::Tuple.create_weakref(object)
end
def inspect
View
264 kernel/common/argf.rb
@@ -4,176 +4,178 @@
# The virtual concatenation file of the files given on command line (or from
# $stdin if no files were given).
-class ARGFClass
- include Enumerable
+module Rubinius
+ class ARGFClass
+ include Enumerable
- def getc
- stream = next_stream
- stream.getc if stream
- end
+ def getc
+ stream = next_stream
+ stream.getc if stream
+ end
- def gets
- stream = next_stream
- if stream
- stream.lineno = $.
- value = stream.gets
- @lineno = stream.lineno
- value
+ def gets
+ stream = next_stream
+ if stream
+ stream.lineno = $.
+ value = stream.gets
+ @lineno = stream.lineno
+ value
+ end
end
- end
- def each_line(&block)
- while stream = next_stream
- stream.each_line(&block)
+ def each_line(&block)
+ while stream = next_stream
+ stream.each_line(&block)
+ end
end
- end
- def each(&block)
- each_line &block
- end
+ def each(&block)
+ each_line &block
+ end
- def each_byte(&block)
- while stream = next_stream
- stream.each_byte(&block)
+ def each_byte(&block)
+ while stream = next_stream
+ stream.each_byte(&block)
+ end
end
- end
- def read(bytes=nil, output=nil)
- result = ""
- have_enough = false
- while not have_enough and stream = next_stream
- to_read = bytes ? (bytes-result.size) : nil
- result << stream.read(to_read)
- have_enough = bytes ? (result.size == bytes) : false
+ def read(bytes=nil, output=nil)
+ result = ""
+ have_enough = false
+ while not have_enough and stream = next_stream
+ to_read = bytes ? (bytes-result.size) : nil
+ result << stream.read(to_read)
+ have_enough = bytes ? (result.size == bytes) : false
+ end
+ output ? output << result : result
end
- output ? output << result : result
- end
- def readlines
- lines = []
- while stream = next_stream
- lines << stream.gets
+ def readlines
+ lines = []
+ while stream = next_stream
+ lines << stream.gets
+ end
+ lines.any? ? lines : nil
end
- lines.any? ? lines : nil
- end
- def readline
- stream = next_stream
- raise EOFError unless stream
- stream.readline
- end
+ def readline
+ stream = next_stream
+ raise EOFError unless stream
+ stream.readline
+ end
- alias_method :to_a, :readlines
+ alias_method :to_a, :readlines
- def readchar
- stream = next_stream
- raise EOFError unless stream
- stream.readchar
- end
-
- def pos
- raise ArgumentError if closed?
- current_stream.pos
- end
+ def readchar
+ stream = next_stream
+ raise EOFError unless stream
+ stream.readchar
+ end
- alias_method :tell, :pos
+ def pos
+ raise ArgumentError if closed?
+ current_stream.pos
+ end
- def pos=(position)
- current_stream.pos = position unless current_stream.closed?
- end
+ alias_method :tell, :pos
- def seek(offset, whence=IO::SEEK_SET)
- current_stream.seek(offset, whence) unless closed? or current_stream.closed?
- end
+ def pos=(position)
+ current_stream.pos = position unless current_stream.closed?
+ end
- def rewind
- raise ArgumentError if closed?
- $. = @last_stream_lineno
- current_stream.rewind
- end
+ def seek(offset, whence=IO::SEEK_SET)
+ current_stream.seek(offset, whence) unless closed? or current_stream.closed?
+ end
- def fileno
- raise ArgumentError if closed?
- @fileno
- end
+ def rewind
+ raise ArgumentError if closed?
+ $. = @last_stream_lineno
+ current_stream.rewind
+ end
- def lineno
- @lineno || 0
- end
+ def fileno
+ raise ArgumentError if closed?
+ @fileno
+ end
- def lineno=(value)
- stream = current_stream
- stream.lineno = value if stream
- $. = @lineno = value
- @last_stream_lineno = 0
- end
+ def lineno
+ @lineno || 0
+ end
- alias_method :to_i, :fileno
+ def lineno=(value)
+ stream = current_stream
+ stream.lineno = value if stream
+ $. = @lineno = value
+ @last_stream_lineno = 0
+ end
- def filename
- current_stream
- @last_filename
- end
+ alias_method :to_i, :fileno
- alias_method :path, :filename
+ def filename
+ current_stream
+ @last_filename
+ end
- def file
- current_stream
- @last_file
- end
+ alias_method :path, :filename
- def to_io
- current_stream.to_io
- end
+ def file
+ current_stream
+ @last_file
+ end
- def skip
- current_stream.close unless closed? or current_stream.closed?
- end
+ def to_io
+ current_stream.to_io
+ end
- def eof?
- raise IOError if closed?
- current_stream.eof
- end
+ def skip
+ current_stream.close unless closed? or current_stream.closed?
+ end
- alias_method :eof, :eof?
+ def eof?
+ raise IOError if closed?
+ current_stream.eof
+ end
- def close
- close_stream if current_stream
- end
+ alias_method :eof, :eof?
- def closed?
- ARGV.empty? and @stream == nil
- end
+ def close
+ close_stream if current_stream
+ end
- def current_stream
- @stream or next_stream
- end
- private :current_stream
+ def closed?
+ ARGV.empty? and @stream == nil
+ end
- def next_stream
- return @stream unless @stream == nil or @stream.closed? or @stream.eof?
+ def current_stream
+ @stream or next_stream
+ end
+ private :current_stream
- close_stream if @stream
- return nil if ARGV.empty? # nothing left
- $. = @last_stream_lineno = 0 unless @stream # reset values on first file
+ def next_stream
+ return @stream unless @stream == nil or @stream.closed? or @stream.eof?
- $FILENAME = @last_filename = ARGV.shift
- @stream = @last_filename == '-' ? STDIN : File.open(@last_filename, 'r')
- @last_file = @stream
- @fileno = (@fileno || 0) + 1
+ close_stream if @stream
+ return nil if ARGV.empty? # nothing left
+ $. = @last_stream_lineno = 0 unless @stream # reset values on first file
- @stream
- end
- private :next_stream
+ $FILENAME = @last_filename = ARGV.shift
+ @stream = @last_filename == '-' ? STDIN : File.open(@last_filename, 'r')
+ @last_file = @stream
+ @fileno = (@fileno || 0) + 1
- def close_stream
- unless @stream.closed? or @stream.fileno == 0 # STDIN
- @last_stream_lineno = @stream.lineno
- @stream.close
+ @stream
+ end
+ private :next_stream
+
+ def close_stream
+ unless @stream.closed? or @stream.fileno == 0 # STDIN
+ @last_stream_lineno = @stream.lineno
+ @stream.close
+ end
+ @stream = nil if ARGV.empty? # close ARGF
end
- @stream = nil if ARGV.empty? # close ARGF
+ private :close_stream
end
- private :close_stream
end
-ARGF = ARGFClass.new
+ARGF = Rubinius::ARGFClass.new
View
22 kernel/common/array.rb
@@ -39,7 +39,7 @@ def initialize(size_or_array=Undefined, obj=Undefined)
if size_or_array.equal? Undefined
unless @total == 0
@total = @start = 0
- @tuple = Tuple.new 8
+ @tuple = Rubinius::Tuple.new 8
end
return self
@@ -64,15 +64,15 @@ def initialize(size_or_array=Undefined, obj=Undefined)
raise ArgumentError, "size must be <= #{Fixnum::MAX}" if size > Fixnum::MAX
if block_given?
- @tuple = Tuple.new size
+ @tuple = Rubinius::Tuple.new size
@total = i