Skip to content
This repository
Browse code

Merge remote branch 'origin/master' into hydra

Conflicts:
	kernel/bootstrap/array.rb
	kernel/bootstrap/kernel.rb
	kernel/bootstrap/load_order.txt
	kernel/common/bytearray.rb
	kernel/common/env.rb
	kernel/common/eval.rb
	kernel/common/io.rb
	kernel/common/kernel.rb
	kernel/common/load_order.txt
	kernel/common/module.rb
	kernel/common/static_scope.rb
	kernel/common/thread.rb
	kernel/delta/load_order.txt
	kernel/platform/library.rb
	vm/builtin/block_environment.cpp
	vm/builtin/class.hpp
  • Loading branch information...
commit a83cc7686f16aa28e9ca3cbde65d9db37e5e04f6 2 parents c9a4c35 + aba14a9
Evan Phoenix authored

Showing 171 changed files with 2,332 additions and 2,510 deletions. Show diff stats Hide diff stats

  1. +1 0  Rakefile
  2. +14 0 benchmark/core/array/bench_map.rb
  3. +25 0 benchmark/core/array/bench_uniq.rb
  4. +61 0 benchmark/core/marshal/bench_dump.rb
  5. +23 0 benchmark/core/module/bench_instance_methods.rb
  6. +23 0 benchmark/core/module/bench_private_instance_methods.rb
  7. +23 0 benchmark/core/module/bench_protected_instance_methods.rb
  8. +23 0 benchmark/core/module/bench_public_instance_methods.rb
  9. +19 37 kernel/alpha.rb
  10. +37 6 kernel/bootstrap/array.rb
  11. +5 5 kernel/bootstrap/block_environment.rb
  12. +0 9 kernel/bootstrap/class.rb
  13. +0 11 kernel/bootstrap/compactlookuptable.rb
  14. +0 10 kernel/bootstrap/compiled_method.rb
  15. +2 0  kernel/bootstrap/configuration.rb
  16. +42 7 kernel/bootstrap/kernel.rb
  17. +1 1  kernel/bootstrap/load_order18.txt
  18. +1 1  kernel/bootstrap/load_order19.txt
  19. +1 1  kernel/bootstrap/load_order20.txt
  20. +23 55 kernel/bootstrap/lookuptable.rb
  21. +8 38 kernel/bootstrap/{methodtable.rb → method_table.rb}
  22. +1 1  kernel/bootstrap/nil.rb
  23. +2 2 kernel/bootstrap/object.rb
  24. +5 0 kernel/bootstrap/rubinius.rb
  25. +1 4 kernel/bootstrap/string.rb
  26. +2 2 kernel/bootstrap/true.rb
  27. +3 14 kernel/bootstrap/tuple.rb
  28. +0 20 kernel/bootstrap/vm.rb
  29. +9 17 kernel/common/argf.rb
  30. +113 86 kernel/common/array.rb
  31. +5 9 kernel/common/backtrace.rb
  32. +35 16 kernel/common/block_environment.rb
  33. +16 17 kernel/common/bytearray.rb
  34. +11 4 kernel/common/class.rb
  35. +0 71 kernel/common/compiled_method.rb
  36. +1 10 kernel/common/continuation.rb
  37. +23 24 kernel/common/ctype.rb
  38. +1 2  kernel/common/delegated_method.rb
  39. +3 3 kernel/common/dir.rb
  40. +0 13 kernel/common/dtrace.rb
  41. +181 89 kernel/common/enumerable.rb
  42. +9 3 kernel/common/enumerator.rb
  43. +92 33 kernel/common/env.rb
  44. +22 83 kernel/common/eval.rb
  45. +33 12 kernel/common/exception.rb
  46. +82 54 kernel/common/file.rb
  47. +4 0 kernel/common/float.rb
  48. +2 2 kernel/common/global.rb
  49. +47 22 kernel/common/hash.rb
  50. +0 9 kernel/common/immediate.rb
  51. +6 6 kernel/common/integer.rb
  52. +104 97 kernel/common/io.rb
  53. +96 136 kernel/common/kernel.rb
  54. +0 5 kernel/common/load_order18.txt
  55. +0 5 kernel/common/load_order19.txt
  56. +0 5 kernel/common/load_order20.txt
  57. +5 4 kernel/common/location.rb
  58. +1 5 kernel/common/lookuptable.rb
  59. +3 1 kernel/common/main.rb
  60. +21 20 kernel/common/math.rb
  61. +13 7 kernel/common/method.rb
  62. +19 0 kernel/common/method_table.rb
  63. +118 113 kernel/common/module.rb
  64. +0 265 kernel/common/moment.rb
  65. +26 21 kernel/common/numeric.rb
  66. +0 7 kernel/common/object.rb
  67. +1 1  kernel/common/proc.rb
  68. +90 10 kernel/common/process.rb
  69. +3 2 kernel/common/random.rb
  70. +19 9 kernel/common/range.rb
  71. +35 17 kernel/common/regexp.rb
  72. +0 18 kernel/common/rubinius.rb
  73. +3 1 kernel/common/signal.rb
  74. +2 1  kernel/common/sprinter.rb
  75. +9 16 kernel/common/static_scope.rb
  76. +169 235 kernel/common/string.rb
  77. +30 22 kernel/common/struct.rb
  78. +3 3 kernel/common/symbol.rb
  79. +9 18 kernel/common/thread.rb
  80. +2 7 kernel/common/throw_catch.rb
  81. +7 5 kernel/common/time.rb
  82. +6 4 kernel/common/tuple.rb
  83. +17 0 kernel/common/type.rb
  84. +0 70 kernel/common/vm.rb
  85. +2 2 kernel/delta/ctype.rb
  86. +4 9 kernel/delta/kernel.rb
  87. +2 2 kernel/delta/load_order18.txt
  88. +2 2 kernel/delta/load_order19.txt
  89. +2 2 kernel/delta/load_order20.txt
  90. +2 4 kernel/delta/math.rb
  91. +7 2 kernel/delta/module.rb
  92. +0 25 kernel/delta/rubinius.rb
  93. +5 1 kernel/delta/ruby_constants.rb
  94. +9 17 kernel/loader.rb
  95. +2 3 kernel/platform/ffi.rb
  96. +7 5 kernel/platform/library.rb
  97. +6 3 kernel/platform/pointer.rb
  98. +0 52 kernel/platform/posix.rb
  99. +2 2 kernel/platform/struct.rb
  100. +4 0 lib/compiler/ast/definitions.rb
  101. +32 2 lib/compiler/compiler.rb
  102. +9 0 lib/compiler/stages.rb
  103. +8 0 lib/ext/openssl/extconf.rb
  104. +13 0 lib/ext/openssl/ossl_ssl.c
  105. +0 1  lib/openssl/ssl.rb
  106. +18 6 lib/tooling/profiler/profiler.rb
  107. +5 0 mspec/lib/mspec/mocks/mock.rb
  108. +4 0 mspec/lib/mspec/mocks/object.rb
  109. +23 0 mspec/lib/mspec/mocks/proxy.rb
  110. +13 1 mspec/lib/mspec/runner/formatters/dotted.rb
  111. +1 0  mspec/lib/mspec/utils/script.rb
  112. +3 0  rakelib/blueprint.rb
  113. +1 1  rakelib/build.rb
  114. +0 36 rakelib/vm.rake
  115. +3 3 spec/core/backtrace/show_spec.rb
  116. +5 2 spec/core/ctype/isalnum_spec.rb
  117. +5 2 spec/core/ctype/isctrl_spec.rb
  118. +4 1 spec/core/ctype/isdigit_spec.rb
  119. +5 2 spec/core/ctype/islower_spec.rb
  120. +4 1 spec/core/ctype/isspace_spec.rb
  121. +4 1 spec/core/ctype/isupper_spec.rb
  122. +9 3 spec/core/ctype/tolower_spec.rb
  123. +14 7 spec/core/ctype/toprint_spec.rb
  124. +9 3 spec/core/ctype/toupper_spec.rb
  125. +2 3 spec/core/kernel/fixtures/classes.rb
  126. +0 17 spec/core/kernel/to_bool_spec.rb
  127. +40 0 spec/core/lookuptable/each_spec.rb
  128. +0 13 spec/core/lookuptable/entries_spec.rb
  129. +1 1  spec/library/actor/link_spec.rb
  130. +12 0 spec/ruby/core/class/dup_spec.rb
  131. +9 4 spec/ruby/core/enumerable/cycle_spec.rb
  132. +2 1  spec/ruby/core/io/select_spec.rb
  133. +14 0 spec/ruby/core/module/instance_methods_spec.rb
  134. +1 9 spec/ruby/core/process/detach_spec.rb
  135. +0 4 spec/ruby/core/process/fork_spec.rb
  136. +2 2 spec/ruby/core/process/getpgid_spec.rb
  137. +4 5 spec/ruby/core/process/getpriority_spec.rb
  138. +0 4 spec/ruby/core/process/groups_spec.rb
  139. +0 5 spec/ruby/core/process/initgroups_spec.rb
  140. +4 10 spec/ruby/core/process/kill_spec.rb
  141. +1 0  spec/ruby/core/process/ppid_spec.rb
  142. +1 8 spec/ruby/core/process/setpgid_spec.rb
  143. +0 5 spec/ruby/core/process/setpgrp_spec.rb
  144. +31 41 spec/ruby/core/process/setpriority_spec.rb
  145. +17 28 spec/ruby/core/process/setrlimit_spec.rb
  146. +0 6 spec/ruby/core/process/setsid_spec.rb
  147. +8 1 spec/ruby/core/process/wait_spec.rb
  148. +3 3 vm/builtin/block_as_method.cpp
  149. +10 13 vm/builtin/block_environment.cpp
  150. +2 4 vm/builtin/block_environment.hpp
  151. +0 23 vm/builtin/class.cpp
  152. +0 3  vm/builtin/class.hpp
  153. +0 44 vm/builtin/compiledmethod.cpp
  154. +0 6 vm/builtin/compiledmethod.hpp
  155. +17 56 vm/builtin/methodtable.cpp
  156. +0 17 vm/builtin/methodtable.hpp
  157. +3 1 vm/builtin/nativefunction.cpp
  158. +5 5 vm/builtin/proc.cpp
  159. +1 1  vm/builtin/system.cpp
  160. +17 0 vm/environment.cpp
  161. +9 9 vm/external_libs/udis86/libudis86/opgen.py
  162. +1 0  vm/gc/inflated_headers.hpp
  163. +1 1  vm/instruments/tooling.cpp
  164. +2 2 vm/llvm/jit_block.cpp
  165. +4 5 vm/llvm/offset.hpp
  166. +0 1  vm/llvm/types.cpp.gen
  167. +2 1  vm/primitives.cpp
  168. +1 1  web/_site/doc/en/bytecode-compiler/parser/index.html
  169. +2 2 web/_site/doc/en/how-to/fix-a-failing-spec/index.html
  170. +1 1  web/doc/en/bytecode-compiler/parser.markdown
  171. +2 2 web/doc/en/how-to/fix-a-failing-spec.markdown
1  Rakefile
@@ -86,6 +86,7 @@ ENV['CC'] = BUILD_CONFIG[:cc] unless ENV['CC']
86 86 ENV['CXX'] = BUILD_CONFIG[:cxx] unless ENV['CXX']
87 87
88 88 $dlext = RbConfig::CONFIG["DLEXT"]
  89 +$CC = ENV['CC']
89 90
90 91 def run_specs(flags=nil)
91 92 unless File.directory? BUILD_CONFIG[:runtime]
14 benchmark/core/array/bench_map.rb
... ... @@ -0,0 +1,14 @@
  1 +require 'benchmark'
  2 +require 'benchmark/ips'
  3 +
  4 +Benchmark.ips do |x|
  5 + ary = (0..100).to_a
  6 +
  7 + x.report "map" do
  8 + ary.map { |x| 1 }
  9 + end
  10 +
  11 + x.report "map!" do
  12 + ary.dup.map! { |x| 1 }
  13 + end
  14 +end
25 benchmark/core/array/bench_uniq.rb
... ... @@ -0,0 +1,25 @@
  1 +require 'benchmark'
  2 +require 'benchmark/ips'
  3 +require File.expand_path('../shared_array.rb', __FILE__)
  4 +
  5 +Benchmark.ips do |x|
  6 + large_array = $large_array.dup
  7 +
  8 + x.report "uniq" do |times|
  9 + i = 0
  10 + while i < times
  11 + large_array.uniq
  12 + i += 1
  13 + end
  14 + end
  15 +
  16 + x.report "uniq!" do |times|
  17 + i = 0
  18 + while i < times
  19 + large_array = $large_array.dup
  20 + large_array.uniq!
  21 + i += 1
  22 + end
  23 + end
  24 +
  25 +end
61 benchmark/core/marshal/bench_dump.rb
... ... @@ -0,0 +1,61 @@
  1 +require 'benchmark'
  2 +require 'benchmark/ips'
  3 +
  4 +class Foo
  5 + def initialize(s, i, f)
  6 + @s = s
  7 + @i = i
  8 + @f = f
  9 + end
  10 +end
  11 +
  12 +Benchmark.ips do |x|
  13 +
  14 + x.report '#dump with a short string' do |times|
  15 + i = 0
  16 + while i < times
  17 + Marshal.dump('hello, world')
  18 + i += 1
  19 + end
  20 + end
  21 +
  22 + x.report '#dump with a long string' do |times|
  23 + i = 0
  24 + while i < times
  25 + Marshal.dump('hello, world' * 10_000)
  26 + i += 1
  27 + end
  28 + end
  29 +
  30 + x.report '#dump with a small integer' do |times|
  31 + i = 0
  32 + while i < times
  33 + Marshal.dump(137)
  34 + i += 1
  35 + end
  36 + end
  37 +
  38 + x.report '#dump with a large integer' do |times|
  39 + i = 0
  40 + while i < times
  41 + Marshal.dump(602_300_000_000_000_000_000_000)
  42 + i += 1
  43 + end
  44 + end
  45 +
  46 + x.report '#dump with a float' do |times|
  47 + i = 0
  48 + while i < times
  49 + Marshal.dump(3.141592653)
  50 + i += 1
  51 + end
  52 + end
  53 +
  54 + x.report '#dump with an object' do |times|
  55 + i = 0
  56 + while i < times
  57 + Marshal.dump(Foo.new('hello, world', 137, 3.141592653))
  58 + i += 1
  59 + end
  60 + end
  61 +end
23 benchmark/core/module/bench_instance_methods.rb
... ... @@ -0,0 +1,23 @@
  1 +require 'benchmark'
  2 +require 'benchmark/ips'
  3 +
  4 +Benchmark.ips do |x|
  5 + m = Module.new do
  6 + 0.upto(100) do |i|
  7 + eval "def method#{i}; end"
  8 + end
  9 + end
  10 +
  11 + c = Class.new do
  12 + include m
  13 + end
  14 +
  15 + x.report "on module" do
  16 + m.instance_methods
  17 + end
  18 +
  19 + x.report "on class" do
  20 + c.instance_methods
  21 + end
  22 +
  23 +end
23 benchmark/core/module/bench_private_instance_methods.rb
... ... @@ -0,0 +1,23 @@
  1 +require 'benchmark'
  2 +require 'benchmark/ips'
  3 +
  4 +Benchmark.ips do |x|
  5 + m = Module.new do
  6 + 0.upto(100) do |i|
  7 + eval "private; def method#{i}; end"
  8 + end
  9 + end
  10 +
  11 + c = Class.new do
  12 + include m
  13 + end
  14 +
  15 + x.report "on module" do
  16 + m.private_instance_methods
  17 + end
  18 +
  19 + x.report "on class" do
  20 + c.private_instance_methods
  21 + end
  22 +
  23 +end
23 benchmark/core/module/bench_protected_instance_methods.rb
... ... @@ -0,0 +1,23 @@
  1 +require 'benchmark'
  2 +require 'benchmark/ips'
  3 +
  4 +Benchmark.ips do |x|
  5 + m = Module.new do
  6 + 0.upto(100) do |i|
  7 + eval "protected; def method#{i}; end"
  8 + end
  9 + end
  10 +
  11 + c = Class.new do
  12 + include m
  13 + end
  14 +
  15 + x.report "on module" do
  16 + m.protected_instance_methods
  17 + end
  18 +
  19 + x.report "on class" do
  20 + c.protected_instance_methods
  21 + end
  22 +
  23 +end
23 benchmark/core/module/bench_public_instance_methods.rb
... ... @@ -0,0 +1,23 @@
  1 +require 'benchmark'
  2 +require 'benchmark/ips'
  3 +
  4 +Benchmark.ips do |x|
  5 + m = Module.new do
  6 + 0.upto(100) do |i|
  7 + eval "def method#{i}; end"
  8 + end
  9 + end
  10 +
  11 + c = Class.new do
  12 + include m
  13 + end
  14 +
  15 + x.report "on module" do
  16 + m.public_instance_methods
  17 + end
  18 +
  19 + x.report "on class" do
  20 + c.public_instance_methods
  21 + end
  22 +
  23 +end
56 kernel/alpha.rb
@@ -107,32 +107,6 @@ def new(*args)
107 107
108 108 module Kernel
109 109
110   - # Send message to object with given arguments.
111   - #
112   - # Ignores visibility of method, and may therefore be used to
113   - # invoke protected or private methods.
114   - #
115   - # As denoted by the double-underscore, this method must not
116   - # be removed or redefined by user code.
117   - #
118   - def __send__(message, *args)
119   - Ruby.primitive :object_send
120   -
121   - # MRI checks for Fixnum explicitly and raises ArgumentError
122   - # instead of TypeError. Seems silly, so we don't bother.
123   - #
124   - case message
125   - when String
126   - message = Rubinius::Type.coerce_to message, Symbol, :to_sym
127   - when Symbol
128   - # nothing!
129   - else
130   - raise TypeError, "#{message.inspect} is not a symbol"
131   - end
132   -
133   - __send__ message, *args
134   - end
135   -
136 110 # Return the Class object this object is an instance of.
137 111 #
138 112 # Note that this method must always be called with an
@@ -143,6 +117,14 @@ def class
143 117 raise PrimitiveFailure, "Kernel#class primitive failed."
144 118 end
145 119
  120 + # Return the class object of self.
  121 + #
  122 + # This is the same as #class, but named to always be available.
  123 + def __class__
  124 + Ruby.primitive :object_class
  125 + raise PrimitiveFailure, "Kernel#class primitive failed."
  126 + end
  127 +
146 128 # String representation of an object.
147 129 #
148 130 # By default, the representation is the name of the object's
@@ -443,8 +425,7 @@ def self.exit!(code=1)
443 425
444 426 class Module
445 427 def method_table ; @method_table ; end
446   - def constant_table ; @constants ; end
447   - def encloser ; @encloser ; end
  428 + def constants_table; @constants ; end
448 429 def name ; @module_name.to_s ; end
449 430
450 431 # Specialised allocator.
@@ -512,7 +493,9 @@ def included(mod); end
512 493 #
513 494 def include(mod)
514 495 mod.append_features(self)
515   - mod.__send__ :included, self
  496 + Rubinius.privately do
  497 + mod.included self
  498 + end
516 499 self
517 500 end
518 501
@@ -640,6 +623,10 @@ def module_function(name)
640 623
641 624 module Rubinius
642 625
  626 + class AccessVariable
  627 + attr_reader :name
  628 + end
  629 +
643 630 # Visibility handling for MethodTables.
644 631 #
645 632 # See kernel/bootstrap/methodtable.rb and
@@ -670,6 +657,8 @@ def protected?
670 657 # ancestor hierarchy for method- and constant lookup in a
671 658 # roughly transparent fashion.
672 659 #
  660 + # This class is known to the VM.
  661 + #
673 662 class IncludedModule < Module
674 663 attr_reader :superclass
675 664 attr_reader :module
@@ -689,10 +678,7 @@ def self.allocate
689 678 #
690 679 def initialize(mod)
691 680 @method_table = mod.method_table
692   - @method_cache = nil
693   - @name = nil
694   - @constants = mod.constant_table
695   - @encloser = mod.encloser
  681 + @constants = mod.constants_table
696 682 @module = mod
697 683 end
698 684
@@ -743,10 +729,6 @@ def ==(other)
743 729 end
744 730 end
745 731
746   -module Kernel
747   - alias_method :__class__, :class
748   -end
749   -
750 732 class Object
751 733 include Kernel
752 734 end
43 kernel/bootstrap/array.rb
@@ -80,10 +80,26 @@ def each
80 80 self
81 81 end
82 82
83   - # Runtime method to support case when *foo syntax
84   - def __matches_when__(receiver)
85   - each { |x| return true if x === receiver }
86   - false
  83 + # Creates a new Array from the return values of passing
  84 + # each element in self to the supplied block.
  85 + def map
  86 + return dup unless block_given?
  87 + out = Array.new size
  88 +
  89 + i = @start
  90 + total = i + @total
  91 + tuple = @tuple
  92 +
  93 + out_tuple = out.tuple
  94 +
  95 + j = 0
  96 + while i < total
  97 + out_tuple[j] = yield tuple.at(i)
  98 + i += 1
  99 + j += 1
  100 + end
  101 +
  102 + out
87 103 end
88 104
89 105 # Replaces each element in self with the return value
@@ -93,8 +109,14 @@ def map!
93 109
94 110 return to_enum(:map!) unless block_given?
95 111
96   - i = -1
97   - each { |x| self[i+=1] = yield(x) }
  112 + i = @start
  113 + total = i + @total
  114 + tuple = @tuple
  115 +
  116 + while i < total
  117 + tuple[i] = yield tuple.at(i)
  118 + i += 1
  119 + end
98 120
99 121 self
100 122 end
@@ -104,4 +126,13 @@ def to_tuple
104 126 tuple.copy_from @tuple, @start, @total, 0
105 127 tuple
106 128 end
  129 +
  130 + # Runtime method to support case when *foo syntax
  131 + # TODO move to compiler runtimesupport (it might not
  132 + # exist yet, but it should)
  133 + def __matches_when__(receiver)
  134 + each { |x| return true if x === receiver }
  135 + false
  136 + end
  137 +
107 138 end
10 kernel/bootstrap/block_environment.rb
@@ -27,23 +27,23 @@ def self.new(block_env)
27 27 end
28 28
29 29 def arity
30   - @block_env.method.arity
  30 + @block_env.code.arity
31 31 end
32 32
33 33 def local_names
34   - @block_env.method.local_names
  34 + @block_env.code.local_names
35 35 end
36 36
37 37 def required_args
38   - @block_env.method.required_args
  38 + @block_env.code.required_args
39 39 end
40 40
41 41 def total_args
42   - @block_env.method.total_args
  42 + @block_env.code.total_args
43 43 end
44 44
45 45 def splat
46   - @block_env.method.splat
  46 + @block_env.code.splat
47 47 end
48 48
49 49 def file
9 kernel/bootstrap/class.rb
... ... @@ -1,8 +1,4 @@
1 1 class Class
2   - attr_accessor :instance_type
3   -
4   - attr_reader :instance_flags
5   -
6 2 def self.allocate
7 3 Ruby.primitive :class_s_allocate
8 4 raise PrimitiveFailure, "Unable to create a new Class"
@@ -14,9 +10,4 @@ def set_superclass(sup)
14 10 end
15 11
16 12 private :set_superclass
17   -
18   - def packed!(ary)
19   - Ruby.primitive :class_set_packed
20   - raise PrimitiveFailure, "Class#pack! failed"
21   - end
22 13 end
11 kernel/bootstrap/compactlookuptable.rb
@@ -29,16 +29,5 @@ def values
29 29 Ruby.primitive :compactlookuptable_values
30 30 raise PrimitiveFailure, "CompactLookupTable#keys primitive failed"
31 31 end
32   -
33   - def delete(val)
34   - i = 0
35   - while i < size
36   - if at(i) == val
37   - put i, nil
38   - put i+1, nil
39   - end
40   - i += 2
41   - end
42   - end
43 32 end
44 33 end
10 kernel/bootstrap/compiled_method.rb
@@ -13,16 +13,6 @@ def dup
13 13 raise PrimitiveFailure, "CompiledMethod#dup primitive failed"
14 14 end
15 15
16   - def jit_now
17   - Ruby.primitive :compiledmethod_jit_now
18   - raise PrimitiveFailure, "CompiledMethod#jit_now primitive failed"
19   - end
20   -
21   - def jit_soon
22   - Ruby.primitive :compiledmethod_jit_soon
23   - raise PrimitiveFailure, "CompiledMethod#jit_soon primitive failed"
24   - end
25   -
26 16 # Return the CompiledMethod for caller of the method that called
27 17 # .of_sender.
28 18 #
2  kernel/bootstrap/configuration.rb
@@ -3,6 +3,8 @@ class Configuration
3 3 def initialize
4 4 end
5 5
  6 + private :initialize
  7 +
6 8 def get_variable(name)
7 9 Ruby.primitive :vm_get_config_item
8 10 raise PrimitiveFailure, "Unable to get config variable"
49 kernel/bootstrap/kernel.rb
... ... @@ -1,4 +1,46 @@
1 1 module Kernel
  2 + # Send message to object with given arguments.
  3 + #
  4 + # Ignores visibility of method, and may therefore be used to
  5 + # invoke protected or private methods.
  6 + #
  7 + # As denoted by the double-underscore, this method must not
  8 + # be removed or redefined by user code.
  9 + #
  10 + def __send__(message, *args)
  11 + Ruby.primitive :object_send
  12 +
  13 + # MRI checks for Fixnum explicitly and raises ArgumentError
  14 + # instead of TypeError. Seems silly, so we don't bother.
  15 + #
  16 + case message
  17 + when String
  18 + message = Rubinius::Type.coerce_to message, Symbol, :to_sym
  19 + when Symbol
  20 + # nothing!
  21 + else
  22 + raise TypeError, "#{message.inspect} is not a symbol"
  23 + end
  24 +
  25 + __send__ message, *args
  26 + end
  27 +
  28 + def equal?(other)
  29 + Ruby.primitive :object_equal
  30 + raise PrimitiveFailure, "Kernel#equal? primitive failed"
  31 + end
  32 +
  33 + def eql?(other) # HACK dup of equal?
  34 + Ruby.primitive :object_equal
  35 + raise PrimitiveFailure, "Kernel#eql? primitive failed"
  36 + end
  37 +
  38 + alias_method :==, :equal?
  39 + alias_method :===, :equal?
  40 +
  41 + def singleton_class
  42 + Rubinius::Type.object_singleton_class self
  43 + end
2 44
3 45 def extend(*mods)
4 46 Rubinius::Type.object_singleton_class(self).include(*mods)
@@ -41,13 +83,6 @@ def respond_to_all?(meth, include)
41 83
42 84 private :respond_to_all?
43 85
44   - # Rather than attr = !!value or attr = value && true or attr = (value
45   - # and true) littering code, we provide attr = value.to_bool for when
46   - # an attribute must be true or false.
47   - def to_bool
48   - !!self
49   - end
50   -
51 86 def taint
52 87 Ruby.primitive :object_taint
53 88 raise PrimitiveFailure, "Kernel#taint primitive failed"
2  kernel/bootstrap/load_order18.txt
@@ -21,7 +21,7 @@ iseq.rbc
21 21 kernel18.rbc
22 22 kernel.rbc
23 23 lookuptable.rbc
24   -methodtable.rbc
  24 +method_table.rbc
25 25 nil.rbc
26 26 object.rbc
27 27 proc.rbc
2  kernel/bootstrap/load_order19.txt
@@ -22,7 +22,7 @@ iseq.rbc
22 22 kernel19.rbc
23 23 kernel.rbc
24 24 lookuptable.rbc
25   -methodtable.rbc
  25 +method_table.rbc
26 26 nil.rbc
27 27 object.rbc
28 28 proc.rbc
2  kernel/bootstrap/load_order20.txt
@@ -22,7 +22,7 @@ iseq.rbc
22 22 kernel19.rbc
23 23 kernel.rbc
24 24 lookuptable.rbc
25   -methodtable.rbc
  25 +method_table.rbc
26 26 nil.rbc
27 27 object.rbc
28 28 proc.rbc
78 kernel/bootstrap/lookuptable.rb
@@ -20,13 +20,12 @@
20 20 # l.show # => #<Tuple: nil, ..., nil, #<Bucket: @key=>:a, @value=>1,
21 21 # @next=>nil>, nil, nil, nil>
22 22 #
23   -# where ... is ten "nil, " entries. This only works for Objects that
24   -# are tagged data (see e.g. shotgun/lib/oop.h). This will NOT work with
25   -# a String, for instance.
  23 +# where ... is ten "nil, " entries.
26 24 #
27   -# LookupTable is intended to be used with Symbol or Fixnum keys. Internally,
28   -# String keys are converted to Symbols. LookupTable is NOT intended to be
29   -# used generally like Hash.
  25 +# LookupTable is intended to be used with Symbol or Fixnum keys because
  26 +# it is a strict identity map. Usage of Strings as keys will likely result
  27 +# in strange behavior.
  28 +# LookupTable is NOT intended to be used generally like Hash.
30 29
31 30 module Rubinius
32 31 class LookupTable
@@ -36,33 +35,10 @@ class Bucket
36 35 attr_reader :next
37 36 end
38 37
39   - class Association
40   - attr_reader :key
41   - attr_writer :active
42   -
43   - attr_accessor :value
44   -
45   - def active?
46   - @active
47   - end
48   -
49   - def self.new(name, value)
50   - Ruby.primitive :lookuptableassociation_allocate
51   - raise PrimitiveFailure, "LookupTable::Association.allocate failed"
52   - end
53   -
54   - def inspect
55   - "#<LookupTable::Association:0x#{object_id.to_s(16)} @key=#{@key.inspect} @value=#{@value.inspect} @valid=#{@active.inspect}>"
56   - end
57   - end
58   -
59 38 attr_reader :values
60 39 attr_reader :bins
61 40
62   - def size
63   - @entries
64   - end
65   -
  41 + attr_reader_specific :entries, :size
66 42 alias_method :length, :size
67 43
68 44 def self.allocate
@@ -86,7 +62,9 @@ def duplicate
86 62
87 63 def dup
88 64 copy = duplicate
89   - copy.send :initialize_copy, self
  65 + Rubinius.privately do
  66 + copy.initialize_copy self
  67 + end
90 68 copy
91 69 end
92 70
@@ -121,37 +99,27 @@ def values
121 99 raise PrimitiveFailure, "LookupTable#keys primitive failed"
122 100 end
123 101
124   - def entries
125   - Ruby.primitive :lookuptable_entries
126   - raise PrimitiveFailure, "LookupTable#entries primitive failed"
127   - end
128   -
129 102 def each
130   - raise LocalJumpError, "no block given" unless block_given? or @entries == 0
131   -
132   - ents = entries
133   - i = ents.start
134   - total = ents.start + ents.total
135   - while i < total
136   - entry = ents[i]
137   - yield [entry.key, entry.value]
  103 + max = @bins
  104 + i = 0
  105 + vals = @values
  106 +
  107 + while i < max
  108 + entry = vals.at(i)
  109 +
  110 + while entry
  111 + yield entry.key, entry.value
  112 + entry = entry.next
  113 + end
138 114 i += 1
139 115 end
140 116 self
141 117 end
142 118
143   - def each_entry
144   - raise LocalJumpError, "no block given" unless block_given? or @entries == 0
  119 + alias_method :each_entry, :each
145 120
146   - ents = entries
147   - i = ents.start
148   - total = ents.start + ents.total
149   - while i < total
150   - entry = ents[i]
151   - yield entry.key, entry.value
152   - i += 1
153   - end
154   - self
  121 + def empty?
  122 + @entries == 0
155 123 end
156 124 end
157 125 end
46 kernel/bootstrap/methodtable.rb → kernel/bootstrap/method_table.rb
@@ -41,7 +41,9 @@ def duplicate
41 41
42 42 def dup
43 43 copy = duplicate
44   - copy.send :initialize_copy, self
  44 + Rubinius.privately do
  45 + copy.initialize_copy self
  46 + end
45 47 copy
46 48 end
47 49
@@ -59,21 +61,6 @@ def delete(name)
59 61 raise PrimitiveFailure, "MethodTable#delete primitive failed"
60 62 end
61 63
62   - def names
63   - Ruby.primitive :methodtable_names
64   - raise PrimitiveFailure, "MethodTable#names primitive failed"
65   - end
66   -
67   - def values
68   - Ruby.primitive :methodtable_values
69   - raise PrimitiveFailure, "MethodTable#names primitive failed"
70   - end
71   -
72   - def entries
73   - Ruby.primitive :methodtable_entries
74   - raise PrimitiveFailure, "MethodTable#entries primitive failed"
75   - end
76   -
77 64 def each_entry
78 65 raise LocalJumpError, "no block given" unless block_given?
79 66
@@ -95,8 +82,11 @@ def each
95 82 raise LocalJumpError, "no block given" unless block_given?
96 83
97 84 i = 0
98   - while i < @bins
99   - if entry = @values.at(i)
  85 + max = @bins
  86 + vals = @values
  87 +
  88 + while i < max
  89 + if entry = vals.at(i)
100 90 while entry
101 91 yield entry.name, entry.method, entry.visibility
102 92 entry = entry.next
@@ -107,25 +97,5 @@ def each
107 97 self
108 98 end
109 99
110   - def filter_entries
111   - raise LocalJumpError, "no block given" unless block_given?
112   -
113   - out = []
114   - i = 0
115   - while i < @bins
116   - if entry = @values.at(i)
117   - while entry
118   - if val = yield(entry)
119   - out << val
120   - end
121   -
122   - entry = entry.next
123   - end
124   - end
125   - i += 1
126   - end
127   -
128   - out
129   - end
130 100 end
131 101 end
2  kernel/bootstrap/nil.rb
@@ -4,7 +4,7 @@ def &(other)
4 4 end
5 5
6 6 def ^(other)
7   - (other.nil? or other.equal?(false)) ? false : true
  7 + !!other
8 8 end
9 9
10 10 def to_s
4 kernel/bootstrap/object.rb
... ... @@ -1,7 +1,7 @@
1 1 class Object
2   - def singleton_class
3   - Rubinius::Type.object_singleton_class self
  2 + def initialize
4 3 end
  4 + private :initialize
5 5
6 6 def __fixnum__
7 7 Ruby.primitive :object_is_fixnum
5 kernel/bootstrap/rubinius.rb
... ... @@ -1,4 +1,9 @@
1 1 module Rubinius
  2 + # Ruby 1.8 returns strings for method and constant names
  3 + def self.convert_to_names(list)
  4 + list.map! { |x| x.to_s }
  5 + end
  6 +
2 7 def self.watch_signal(sig)
3 8 Ruby.primitive :vm_watch_signal
4 9 watch_signal(sig.to_signal)
5 kernel/bootstrap/string.rb
@@ -79,10 +79,7 @@ def secure_compare(other)
79 79 end
80 80
81 81 # Returns the length of <i>self</i>.
82   - def length
83   - @num_bytes
84   - end
85   -
  82 + attr_reader_specific :num_bytes, :length
86 83 alias_method :size, :length
87 84
88 85 def find_character(offset)
4 kernel/bootstrap/true.rb
... ... @@ -1,10 +1,10 @@
1 1 class TrueClass
2 2 def &(other)
3   - (other.nil? or other.equal?(false)) ? false : true
  3 + !!other
4 4 end
5 5
6 6 def ^(other)
7   - (other.nil? or other.equal?(false)) ? true : false
  7 + !other
8 8 end
9 9
10 10 def |(other)
17 kernel/bootstrap/tuple.rb
@@ -25,6 +25,8 @@ def [](idx)
25 25 raise PrimitiveFailure, "Tuple#[] primitive failed"
26 26 end
27 27
  28 + alias_method :at, :[]
  29 +
28 30 def []=(idx, val)
29 31 Ruby.primitive :tuple_put
30 32
@@ -34,15 +36,7 @@ def []=(idx, val)
34 36 raise PrimitiveFailure, "Tuple#[]= primitive failed"
35 37 end
36 38
37   - def at(idx)
38   - Ruby.primitive :tuple_at
39   - raise PrimitiveFailure, "Tuple#[] primitive failed"
40   - end
41   -
42   - def put(idx, val)
43   - Ruby.primitive :tuple_put
44   - raise PrimitiveFailure, "Tuple#[]= primitive failed"
45   - end
  39 + alias_method :put, :[]=
46 40
47 41 def fields
48 42 Ruby.primitive :tuple_fields
@@ -157,10 +151,5 @@ def reverse!(start, total)
157 151 Rubinius::Type.coerce_to(total, Fixnum, :to_i))
158 152 end
159 153
160   - def self.create_weakref(object)
161   - Ruby.primitive :tuple_create_weakref
162   - raise PrimitiveFailure, "Tuple.create_weakref failed, unable to create a weak reference"
163   - end
164   -
165 154 end
166 155 end
20 kernel/bootstrap/vm.rb
@@ -77,24 +77,4 @@ def self.perform_hook(obj, meth, arg, ret)
77 77 obj.__send__(meth, arg)
78 78 return ret
79 79 end
80   -
81   - def self.spawn_prim(args)
82   - Ruby.primitive :machine_new
83   - raise PrimitiveFailure, "Rubinius::VM.spawn_prim primitive failed"
84   - end
85   -
86   - def self.join(id)
87   - Ruby.primitive :machine_join
88   - raise PrimitiveFailure, "Rubinius::VM.join primitive failed"
89   - end
90   -
91   - def self.poll_message
92   - Ruby.primitive :machine_get_message
93   - raise PrimitiveFailure, "Rubinius::VM.poll_message primitive failed"
94   - end
95   -
96   - def self.send_message(id, obj)
97   - Ruby.primitive :machine_send_message
98   - raise PrimitiveFailure, "Rubinius::VM.send_message primitive failed"
99   - end
100 80 end
26 kernel/common/argf.rb
@@ -67,9 +67,6 @@ def chars(&b)
67 67 #
68 68 # Close stream.
69 69 #
70   - # @todo Should this #advance!? That may cause an error
71   - # to be raised, for example. --rue
72   - #
73 70 def close
74 71 advance!
75 72 @stream.close
@@ -83,9 +80,6 @@ def close
83 80 #
84 81 # True if the stream is closed.
85 82 #
86   - # @todo Should this #advance!? That may cause an error
87   - # to be raised, for example. --rue
88   - #
89 83 def closed?
90 84 advance!
91 85 @stream.closed?
@@ -214,7 +208,7 @@ def file
214 208 # reading from a file, the stream is closed.
215 209 #
216 210 def getc
217   - while true # Performance
  211 + while true
218 212 return nil unless advance!
219 213 if val = @stream.getc
220 214 return val
@@ -236,10 +230,10 @@ def getc
236 230 # The mechanism does track the line numbers,
237 231 # and updates $. accordingly.
238 232 #
239   - def gets
240   - while true # Performance
  233 + def gets(sep=$/)
  234 + while true
241 235 return nil unless advance!
242   - line = @stream.gets
  236 + line = @stream.gets(sep)
243 237
244 238 unless line
245 239 return nil if @use_stdin_only
@@ -340,7 +334,7 @@ def readbyte
340 334 # is provided, as by default, a String with the data is
341 335 # returned instead.
342 336 #
343   - def read(bytes = nil, output = nil)
  337 + def read(bytes=nil, output=nil)
344 338 # The user might try to pass in nil, so we have to check here
345 339 output ||= ""
346 340
@@ -383,11 +377,11 @@ def read(bytes = nil, output = nil)
383 377 #
384 378 # @see #gets
385 379 #
386   - def readlines
  380 + def readlines(sep=$/)
387 381 return nil unless advance!
388 382
389 383 lines = []
390   - while line = gets()
  384 + while line = gets(sep)
391 385 lines << line
392 386 end
393 387
@@ -403,10 +397,10 @@ def readlines
403 397 #
404 398 # @see #gets
405 399 #
406   - def readline
  400 + def readline(sep=$/)
407 401 raise EOFError, "ARGF at end" unless advance!
408 402
409   - if line = gets()
  403 + if line = gets(sep)
410 404 return line
411 405 end
412 406
@@ -442,8 +436,6 @@ def seek(*args)
442 436 # STDIN is not closed if being used, otherwise the
443 437 # stream gets closed. Returns self.
444 438 #
445   - # @todo Need more detail on the genesis/purpose
446   - # of this method. --rue
447 439 def skip
448 440 return self if @use_stdin_only
449 441 @stream.close unless @stream.closed?
199 kernel/common/array.rb
@@ -481,8 +481,11 @@ def ==(other)
481 481 return false unless size == other.size
482 482
483 483 Thread.detect_recursion self, other do
484   - i = -1
485   - each { |x| return false unless x == other[i+=1] }
  484 + i = 0
  485 + each do |x|
  486 + return false unless x == other[i]
  487 + i += 1
  488 + end
486 489 end
487 490
488 491 true
@@ -493,7 +496,11 @@ def ==(other)
493 496 # contained Array using elem == obj. Returns the first contained
494 497 # Array that matches (the first 'associated' Array) or nil.
495 498 def assoc(obj)
496   - each { |x| return x if x.kind_of? Array and x.first == obj }
  499 + each do |x|
  500 + if x.kind_of? Array and x.first == obj
  501 + return x
  502 + end
  503 + end
497 504
498 505 nil
499 506 end
@@ -547,7 +554,7 @@ def combination(num)
547 554
548 555 while true
549 556 yield values_at(*picks)
550   - move = lookup.each{ |pick, max| picks[pick] < max }.first
  557 + move = lookup.each { |pick, max| picks[pick] < max }.first
551 558 new_index = picks[move] + 1
552 559 picks[move...num] = (new_index...(new_index+num-move)).to_a
553 560 end
@@ -587,7 +594,7 @@ def concat(other)
587 594 # Calls block for each element repeatedly n times or forever if none
588 595 # or nil is given. If a non-positive number is given or the array is empty,
589 596 # does nothing. Returns nil if the loop has finished without getting interrupted.
590   - def cycle(n = nil, &block)
  597 + def cycle(n=nil, &block)
591 598 return to_enum(:cycle, n) unless block_given?
592 599
593 600 # Don't use nil? because, historically, lame code has overridden that method
@@ -716,15 +723,18 @@ def eql?(other)
716 723 return false if @total != other.size
717 724
718 725 Thread.detect_recursion self, other do
719   - i = -1
720   - each { |x| return false unless x.eql? other[i+=1] }
  726 + i = 0
  727 + each do |x|
  728 + return false unless x.eql? other[i]
  729 + i += 1
  730 + end