Skip to content
Browse files

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...
2 parents c9a4c35 + aba14a9 commit a83cc7686f16aa28e9ca3cbde65d9db37e5e04f6 Evan Phoenix committed May 2, 2011
Showing with 2,332 additions and 2,510 deletions.
  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
View
1 Rakefile
@@ -86,6 +86,7 @@ ENV['CC'] = BUILD_CONFIG[:cc] unless ENV['CC']
ENV['CXX'] = BUILD_CONFIG[:cxx] unless ENV['CXX']
$dlext = RbConfig::CONFIG["DLEXT"]
+$CC = ENV['CC']
def run_specs(flags=nil)
unless File.directory? BUILD_CONFIG[:runtime]
View
14 benchmark/core/array/bench_map.rb
@@ -0,0 +1,14 @@
+require 'benchmark'
+require 'benchmark/ips'
+
+Benchmark.ips do |x|
+ ary = (0..100).to_a
+
+ x.report "map" do
+ ary.map { |x| 1 }
+ end
+
+ x.report "map!" do
+ ary.dup.map! { |x| 1 }
+ end
+end
View
25 benchmark/core/array/bench_uniq.rb
@@ -0,0 +1,25 @@
+require 'benchmark'
+require 'benchmark/ips'
+require File.expand_path('../shared_array.rb', __FILE__)
+
+Benchmark.ips do |x|
+ large_array = $large_array.dup
+
+ x.report "uniq" do |times|
+ i = 0
+ while i < times
+ large_array.uniq
+ i += 1
+ end
+ end
+
+ x.report "uniq!" do |times|
+ i = 0
+ while i < times
+ large_array = $large_array.dup
+ large_array.uniq!
+ i += 1
+ end
+ end
+
+end
View
61 benchmark/core/marshal/bench_dump.rb
@@ -0,0 +1,61 @@
+require 'benchmark'
+require 'benchmark/ips'
+
+class Foo
+ def initialize(s, i, f)
+ @s = s
+ @i = i
+ @f = f
+ end
+end
+
+Benchmark.ips do |x|
+
+ x.report '#dump with a short string' do |times|
+ i = 0
+ while i < times
+ Marshal.dump('hello, world')
+ i += 1
+ end
+ end
+
+ x.report '#dump with a long string' do |times|
+ i = 0
+ while i < times
+ Marshal.dump('hello, world' * 10_000)
+ i += 1
+ end
+ end
+
+ x.report '#dump with a small integer' do |times|
+ i = 0
+ while i < times
+ Marshal.dump(137)
+ i += 1
+ end
+ end
+
+ x.report '#dump with a large integer' do |times|
+ i = 0
+ while i < times
+ Marshal.dump(602_300_000_000_000_000_000_000)
+ i += 1
+ end
+ end
+
+ x.report '#dump with a float' do |times|
+ i = 0
+ while i < times
+ Marshal.dump(3.141592653)
+ i += 1
+ end
+ end
+
+ x.report '#dump with an object' do |times|
+ i = 0
+ while i < times
+ Marshal.dump(Foo.new('hello, world', 137, 3.141592653))
+ i += 1
+ end
+ end
+end
View
23 benchmark/core/module/bench_instance_methods.rb
@@ -0,0 +1,23 @@
+require 'benchmark'
+require 'benchmark/ips'
+
+Benchmark.ips do |x|
+ m = Module.new do
+ 0.upto(100) do |i|
+ eval "def method#{i}; end"
+ end
+ end
+
+ c = Class.new do
+ include m
+ end
+
+ x.report "on module" do
+ m.instance_methods
+ end
+
+ x.report "on class" do
+ c.instance_methods
+ end
+
+end
View
23 benchmark/core/module/bench_private_instance_methods.rb
@@ -0,0 +1,23 @@
+require 'benchmark'
+require 'benchmark/ips'
+
+Benchmark.ips do |x|
+ m = Module.new do
+ 0.upto(100) do |i|
+ eval "private; def method#{i}; end"
+ end
+ end
+
+ c = Class.new do
+ include m
+ end
+
+ x.report "on module" do
+ m.private_instance_methods
+ end
+
+ x.report "on class" do
+ c.private_instance_methods
+ end
+
+end
View
23 benchmark/core/module/bench_protected_instance_methods.rb
@@ -0,0 +1,23 @@
+require 'benchmark'
+require 'benchmark/ips'
+
+Benchmark.ips do |x|
+ m = Module.new do
+ 0.upto(100) do |i|
+ eval "protected; def method#{i}; end"
+ end
+ end
+
+ c = Class.new do
+ include m
+ end
+
+ x.report "on module" do
+ m.protected_instance_methods
+ end
+
+ x.report "on class" do
+ c.protected_instance_methods
+ end
+
+end
View
23 benchmark/core/module/bench_public_instance_methods.rb
@@ -0,0 +1,23 @@
+require 'benchmark'
+require 'benchmark/ips'
+
+Benchmark.ips do |x|
+ m = Module.new do
+ 0.upto(100) do |i|
+ eval "def method#{i}; end"
+ end
+ end
+
+ c = Class.new do
+ include m
+ end
+
+ x.report "on module" do
+ m.public_instance_methods
+ end
+
+ x.report "on class" do
+ c.public_instance_methods
+ end
+
+end
View
56 kernel/alpha.rb
@@ -107,32 +107,6 @@ def new(*args)
module Kernel
- # Send message to object with given arguments.
- #
- # Ignores visibility of method, and may therefore be used to
- # invoke protected or private methods.
- #
- # As denoted by the double-underscore, this method must not
- # be removed or redefined by user code.
- #
- def __send__(message, *args)
- Ruby.primitive :object_send
-
- # MRI checks for Fixnum explicitly and raises ArgumentError
- # instead of TypeError. Seems silly, so we don't bother.
- #
- case message
- when String
- message = Rubinius::Type.coerce_to message, Symbol, :to_sym
- when Symbol
- # nothing!
- else
- raise TypeError, "#{message.inspect} is not a symbol"
- end
-
- __send__ message, *args
- end
-
# Return the Class object this object is an instance of.
#
# Note that this method must always be called with an
@@ -143,6 +117,14 @@ def class
raise PrimitiveFailure, "Kernel#class primitive failed."
end
+ # Return the class object of self.
+ #
+ # This is the same as #class, but named to always be available.
+ def __class__
+ Ruby.primitive :object_class
+ raise PrimitiveFailure, "Kernel#class primitive failed."
+ end
+
# String representation of an object.
#
# By default, the representation is the name of the object's
@@ -443,8 +425,7 @@ def self.exit!(code=1)
class Module
def method_table ; @method_table ; end
- def constant_table ; @constants ; end
- def encloser ; @encloser ; end
+ def constants_table; @constants ; end
def name ; @module_name.to_s ; end
# Specialised allocator.
@@ -512,7 +493,9 @@ def included(mod); end
#
def include(mod)
mod.append_features(self)
- mod.__send__ :included, self
+ Rubinius.privately do
+ mod.included self
+ end
self
end
@@ -640,6 +623,10 @@ def module_function(name)
module Rubinius
+ class AccessVariable
+ attr_reader :name
+ end
+
# Visibility handling for MethodTables.
#
# See kernel/bootstrap/methodtable.rb and
@@ -670,6 +657,8 @@ def protected?
# ancestor hierarchy for method- and constant lookup in a
# roughly transparent fashion.
#
+ # This class is known to the VM.
+ #
class IncludedModule < Module
attr_reader :superclass
attr_reader :module
@@ -689,10 +678,7 @@ def self.allocate
#
def initialize(mod)
@method_table = mod.method_table
- @method_cache = nil
- @name = nil
- @constants = mod.constant_table
- @encloser = mod.encloser
+ @constants = mod.constants_table
@module = mod
end
@@ -743,10 +729,6 @@ def ==(other)
end
end
-module Kernel
- alias_method :__class__, :class
-end
-
class Object
include Kernel
end
View
43 kernel/bootstrap/array.rb
@@ -80,10 +80,26 @@ def each
self
end
- # Runtime method to support case when *foo syntax
- def __matches_when__(receiver)
- each { |x| return true if x === receiver }
- false
+ # Creates a new Array from the return values of passing
+ # each element in self to the supplied block.
+ def map
+ return dup unless block_given?
+ out = Array.new size
+
+ i = @start
+ total = i + @total
+ tuple = @tuple
+
+ out_tuple = out.tuple
+
+ j = 0
+ while i < total
+ out_tuple[j] = yield tuple.at(i)
+ i += 1
+ j += 1
+ end
+
+ out
end
# Replaces each element in self with the return value
@@ -93,8 +109,14 @@ def map!
return to_enum(:map!) unless block_given?
- i = -1
- each { |x| self[i+=1] = yield(x) }
+ i = @start
+ total = i + @total
+ tuple = @tuple
+
+ while i < total
+ tuple[i] = yield tuple.at(i)
+ i += 1
+ end
self
end
@@ -104,4 +126,13 @@ def to_tuple
tuple.copy_from @tuple, @start, @total, 0
tuple
end
+
+ # Runtime method to support case when *foo syntax
+ # TODO move to compiler runtimesupport (it might not
+ # exist yet, but it should)
+ def __matches_when__(receiver)
+ each { |x| return true if x === receiver }
+ false
+ end
+
end
View
10 kernel/bootstrap/block_environment.rb
@@ -27,23 +27,23 @@ def self.new(block_env)
end
def arity
- @block_env.method.arity
+ @block_env.code.arity
end
def local_names
- @block_env.method.local_names
+ @block_env.code.local_names
end
def required_args
- @block_env.method.required_args
+ @block_env.code.required_args
end
def total_args
- @block_env.method.total_args
+ @block_env.code.total_args
end
def splat
- @block_env.method.splat
+ @block_env.code.splat
end
def file
View
9 kernel/bootstrap/class.rb
@@ -1,8 +1,4 @@
class Class
- attr_accessor :instance_type
-
- attr_reader :instance_flags
-
def self.allocate
Ruby.primitive :class_s_allocate
raise PrimitiveFailure, "Unable to create a new Class"
@@ -14,9 +10,4 @@ def set_superclass(sup)
end
private :set_superclass
-
- def packed!(ary)
- Ruby.primitive :class_set_packed
- raise PrimitiveFailure, "Class#pack! failed"
- end
end
View
11 kernel/bootstrap/compactlookuptable.rb
@@ -29,16 +29,5 @@ def values
Ruby.primitive :compactlookuptable_values
raise PrimitiveFailure, "CompactLookupTable#keys primitive failed"
end
-
- def delete(val)
- i = 0
- while i < size
- if at(i) == val
- put i, nil
- put i+1, nil
- end
- i += 2
- end
- end
end
end
View
10 kernel/bootstrap/compiled_method.rb
@@ -13,16 +13,6 @@ def dup
raise PrimitiveFailure, "CompiledMethod#dup primitive failed"
end
- def jit_now
- Ruby.primitive :compiledmethod_jit_now
- raise PrimitiveFailure, "CompiledMethod#jit_now primitive failed"
- end
-
- def jit_soon
- Ruby.primitive :compiledmethod_jit_soon
- raise PrimitiveFailure, "CompiledMethod#jit_soon primitive failed"
- end
-
# Return the CompiledMethod for caller of the method that called
# .of_sender.
#
View
2 kernel/bootstrap/configuration.rb
@@ -3,6 +3,8 @@ class Configuration
def initialize
end
+ private :initialize
+
def get_variable(name)
Ruby.primitive :vm_get_config_item
raise PrimitiveFailure, "Unable to get config variable"
View
49 kernel/bootstrap/kernel.rb
@@ -1,4 +1,46 @@
module Kernel
+ # Send message to object with given arguments.
+ #
+ # Ignores visibility of method, and may therefore be used to
+ # invoke protected or private methods.
+ #
+ # As denoted by the double-underscore, this method must not
+ # be removed or redefined by user code.
+ #
+ def __send__(message, *args)
+ Ruby.primitive :object_send
+
+ # MRI checks for Fixnum explicitly and raises ArgumentError
+ # instead of TypeError. Seems silly, so we don't bother.
+ #
+ case message
+ when String
+ message = Rubinius::Type.coerce_to message, Symbol, :to_sym
+ when Symbol
+ # nothing!
+ else
+ raise TypeError, "#{message.inspect} is not a symbol"
+ end
+
+ __send__ message, *args
+ end
+
+ def equal?(other)
+ Ruby.primitive :object_equal
+ raise PrimitiveFailure, "Kernel#equal? primitive failed"
+ end
+
+ def eql?(other) # HACK dup of equal?
+ Ruby.primitive :object_equal
+ raise PrimitiveFailure, "Kernel#eql? primitive failed"
+ end
+
+ alias_method :==, :equal?
+ alias_method :===, :equal?
+
+ def singleton_class
+ Rubinius::Type.object_singleton_class self
+ end
def extend(*mods)
Rubinius::Type.object_singleton_class(self).include(*mods)
@@ -41,13 +83,6 @@ def respond_to_all?(meth, include)
private :respond_to_all?
- # Rather than attr = !!value or attr = value && true or attr = (value
- # and true) littering code, we provide attr = value.to_bool for when
- # an attribute must be true or false.
- def to_bool
- !!self
- end
-
def taint
Ruby.primitive :object_taint
raise PrimitiveFailure, "Kernel#taint primitive failed"
View
2 kernel/bootstrap/load_order18.txt
@@ -21,7 +21,7 @@ iseq.rbc
kernel18.rbc
kernel.rbc
lookuptable.rbc
-methodtable.rbc
+method_table.rbc
nil.rbc
object.rbc
proc.rbc
View
2 kernel/bootstrap/load_order19.txt
@@ -22,7 +22,7 @@ iseq.rbc
kernel19.rbc
kernel.rbc
lookuptable.rbc
-methodtable.rbc
+method_table.rbc
nil.rbc
object.rbc
proc.rbc
View
2 kernel/bootstrap/load_order20.txt
@@ -22,7 +22,7 @@ iseq.rbc
kernel19.rbc
kernel.rbc
lookuptable.rbc
-methodtable.rbc
+method_table.rbc
nil.rbc
object.rbc
proc.rbc
View
78 kernel/bootstrap/lookuptable.rb
@@ -20,13 +20,12 @@
# l.show # => #<Tuple: nil, ..., nil, #<Bucket: @key=>:a, @value=>1,
# @next=>nil>, nil, nil, nil>
#
-# where ... is ten "nil, " entries. This only works for Objects that
-# are tagged data (see e.g. shotgun/lib/oop.h). This will NOT work with
-# a String, for instance.
+# where ... is ten "nil, " entries.
#
-# LookupTable is intended to be used with Symbol or Fixnum keys. Internally,
-# String keys are converted to Symbols. LookupTable is NOT intended to be
-# used generally like Hash.
+# LookupTable is intended to be used with Symbol or Fixnum keys because
+# it is a strict identity map. Usage of Strings as keys will likely result
+# in strange behavior.
+# LookupTable is NOT intended to be used generally like Hash.
module Rubinius
class LookupTable
@@ -36,33 +35,10 @@ class Bucket
attr_reader :next
end
- class Association
- attr_reader :key
- attr_writer :active
-
- attr_accessor :value
-
- def active?
- @active
- 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}>"
- end
- end
-
attr_reader :values
attr_reader :bins
- def size
- @entries
- end
-
+ attr_reader_specific :entries, :size
alias_method :length, :size
def self.allocate
@@ -86,7 +62,9 @@ def duplicate
def dup
copy = duplicate
- copy.send :initialize_copy, self
+ Rubinius.privately do
+ copy.initialize_copy self
+ end
copy
end
@@ -121,37 +99,27 @@ def values
raise PrimitiveFailure, "LookupTable#keys primitive failed"
end
- def entries
- Ruby.primitive :lookuptable_entries
- raise PrimitiveFailure, "LookupTable#entries primitive failed"
- end
-
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]
+ max = @bins
+ i = 0
+ vals = @values
+
+ while i < max
+ entry = vals.at(i)
+
+ while entry
+ yield entry.key, entry.value
+ entry = entry.next
+ end
i += 1
end
self
end
- def each_entry
- raise LocalJumpError, "no block given" unless block_given? or @entries == 0
+ alias_method :each_entry, :each
- 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
+ def empty?
+ @entries == 0
end
end
end
View
46 kernel/bootstrap/methodtable.rb → kernel/bootstrap/method_table.rb
@@ -41,7 +41,9 @@ def duplicate
def dup
copy = duplicate
- copy.send :initialize_copy, self
+ Rubinius.privately do
+ copy.initialize_copy self
+ end
copy
end
@@ -59,21 +61,6 @@ def delete(name)
raise PrimitiveFailure, "MethodTable#delete primitive failed"
end
- def names
- Ruby.primitive :methodtable_names
- raise PrimitiveFailure, "MethodTable#names primitive failed"
- end
-
- def values
- Ruby.primitive :methodtable_values
- raise PrimitiveFailure, "MethodTable#names primitive failed"
- end
-
- def entries
- Ruby.primitive :methodtable_entries
- raise PrimitiveFailure, "MethodTable#entries primitive failed"
- end
-
def each_entry
raise LocalJumpError, "no block given" unless block_given?
@@ -95,8 +82,11 @@ def each
raise LocalJumpError, "no block given" unless block_given?
i = 0
- while i < @bins
- if entry = @values.at(i)
+ max = @bins
+ vals = @values
+
+ while i < max
+ if entry = vals.at(i)
while entry
yield entry.name, entry.method, entry.visibility
entry = entry.next
@@ -107,25 +97,5 @@ def each
self
end
- def filter_entries
- raise LocalJumpError, "no block given" unless block_given?
-
- out = []
- i = 0
- while i < @bins
- if entry = @values.at(i)
- while entry
- if val = yield(entry)
- out << val
- end
-
- entry = entry.next
- end
- end
- i += 1
- end
-
- out
- end
end
end
View
2 kernel/bootstrap/nil.rb
@@ -4,7 +4,7 @@ def &(other)
end
def ^(other)
- (other.nil? or other.equal?(false)) ? false : true
+ !!other
end
def to_s
View
4 kernel/bootstrap/object.rb
@@ -1,7 +1,7 @@
class Object
- def singleton_class
- Rubinius::Type.object_singleton_class self
+ def initialize
end
+ private :initialize
def __fixnum__
Ruby.primitive :object_is_fixnum
View
5 kernel/bootstrap/rubinius.rb
@@ -1,4 +1,9 @@
module Rubinius
+ # Ruby 1.8 returns strings for method and constant names
+ def self.convert_to_names(list)
+ list.map! { |x| x.to_s }
+ end
+
def self.watch_signal(sig)
Ruby.primitive :vm_watch_signal
watch_signal(sig.to_signal)
View
5 kernel/bootstrap/string.rb
@@ -79,10 +79,7 @@ def secure_compare(other)
end
# Returns the length of <i>self</i>.
- def length
- @num_bytes
- end
-
+ attr_reader_specific :num_bytes, :length
alias_method :size, :length
def find_character(offset)
View
4 kernel/bootstrap/true.rb
@@ -1,10 +1,10 @@
class TrueClass
def &(other)
- (other.nil? or other.equal?(false)) ? false : true
+ !!other
end
def ^(other)
- (other.nil? or other.equal?(false)) ? true : false
+ !other
end
def |(other)
View
17 kernel/bootstrap/tuple.rb
@@ -25,6 +25,8 @@ def [](idx)
raise PrimitiveFailure, "Tuple#[] primitive failed"
end
+ alias_method :at, :[]
+
def []=(idx, val)
Ruby.primitive :tuple_put
@@ -34,15 +36,7 @@ def []=(idx, val)
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
+ alias_method :put, :[]=
def fields
Ruby.primitive :tuple_fields
@@ -157,10 +151,5 @@ def reverse!(start, total)
Rubinius::Type.coerce_to(total, Fixnum, :to_i))
end
- 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
20 kernel/bootstrap/vm.rb
@@ -77,24 +77,4 @@ def self.perform_hook(obj, meth, arg, ret)
obj.__send__(meth, arg)
return ret
end
-
- def self.spawn_prim(args)
- Ruby.primitive :machine_new
- raise PrimitiveFailure, "Rubinius::VM.spawn_prim primitive failed"
- end
-
- def self.join(id)
- Ruby.primitive :machine_join
- raise PrimitiveFailure, "Rubinius::VM.join primitive failed"
- end
-
- def self.poll_message
- Ruby.primitive :machine_get_message
- raise PrimitiveFailure, "Rubinius::VM.poll_message primitive failed"
- end
-
- def self.send_message(id, obj)
- Ruby.primitive :machine_send_message
- raise PrimitiveFailure, "Rubinius::VM.send_message primitive failed"
- end
end
View
26 kernel/common/argf.rb
@@ -67,9 +67,6 @@ def chars(&b)
#
# Close stream.
#
- # @todo Should this #advance!? That may cause an error
- # to be raised, for example. --rue
- #
def close
advance!
@stream.close
@@ -83,9 +80,6 @@ def close
#
# True if the stream is closed.
#
- # @todo Should this #advance!? That may cause an error
- # to be raised, for example. --rue
- #
def closed?
advance!
@stream.closed?
@@ -214,7 +208,7 @@ def file
# reading from a file, the stream is closed.
#
def getc
- while true # Performance
+ while true
return nil unless advance!
if val = @stream.getc
return val
@@ -236,10 +230,10 @@ def getc
# The mechanism does track the line numbers,
# and updates $. accordingly.
#
- def gets
- while true # Performance
+ def gets(sep=$/)
+ while true
return nil unless advance!
- line = @stream.gets
+ line = @stream.gets(sep)
unless line
return nil if @use_stdin_only
@@ -340,7 +334,7 @@ def readbyte
# is provided, as by default, a String with the data is
# returned instead.
#
- def read(bytes = nil, output = nil)
+ def read(bytes=nil, output=nil)
# The user might try to pass in nil, so we have to check here
output ||= ""
@@ -383,11 +377,11 @@ def read(bytes = nil, output = nil)
#
# @see #gets
#
- def readlines
+ def readlines(sep=$/)
return nil unless advance!
lines = []
- while line = gets()
+ while line = gets(sep)
lines << line
end
@@ -403,10 +397,10 @@ def readlines
#
# @see #gets
#
- def readline
+ def readline(sep=$/)
raise EOFError, "ARGF at end" unless advance!
- if line = gets()
+ if line = gets(sep)
return line
end
@@ -442,8 +436,6 @@ def seek(*args)
# STDIN is not closed if being used, otherwise the
# stream gets closed. Returns self.
#
- # @todo Need more detail on the genesis/purpose
- # of this method. --rue
def skip
return self if @use_stdin_only
@stream.close unless @stream.closed?
View
199 kernel/common/array.rb
@@ -481,8 +481,11 @@ def ==(other)
return false unless size == other.size
Thread.detect_recursion self, other do
- i = -1
- each { |x| return false unless x == other[i+=1] }
+ i = 0
+ each do |x|
+ return false unless x == other[i]
+ i += 1
+ end
end
true
@@ -493,7 +496,11 @@ def ==(other)
# contained Array using elem == obj. Returns the first contained
# Array that matches (the first 'associated' Array) or nil.
def assoc(obj)
- each { |x| return x if x.kind_of? Array and x.first == obj }
+ each do |x|
+ if x.kind_of? Array and x.first == obj
+ return x
+ end
+ end
nil
end
@@ -547,7 +554,7 @@ def combination(num)
while true
yield values_at(*picks)
- move = lookup.each{ |pick, max| picks[pick] < max }.first
+ move = lookup.each { |pick, max| picks[pick] < max }.first
new_index = picks[move] + 1
picks[move...num] = (new_index...(new_index+num-move)).to_a
end
@@ -587,7 +594,7 @@ def concat(other)
# Calls block for each element repeatedly n times or forever if none
# or nil is given. If a non-positive number is given or the array is empty,
# does nothing. Returns nil if the loop has finished without getting interrupted.
- def cycle(n = nil, &block)
+ def cycle(n=nil, &block)
return to_enum(:cycle, n) unless block_given?
# Don't use nil? because, historically, lame code has overridden that method
@@ -716,34 +723,39 @@ def eql?(other)
return false if @total != other.size
Thread.detect_recursion self, other do
- i = -1
- each { |x| return false unless x.eql? other[i+=1] }
+ i = 0
+ each do |x|
+ return false unless x.eql? other[i]
+ i += 1
+ end
end
true
end
# True if Array has no elements.
- def empty?()
+ def empty?
@total == 0
end
# Attempts to return the element at the given index. By default
# an IndexError is raised if the element is out of bounds. The
# user may supply either a default value or a block that takes
# the index object instead.
- def fetch(idx, *rest)
- raise ArgumentError, "Expected 1-2, got #{1 + rest.length}" if rest.length > 1
- warn 'Block supercedes default object' if !rest.empty? && block_given?
+ def fetch(idx, default=undefined)
+ orig = idx
+ idx = Rubinius::Type.coerce_to(idx, Fixnum, :to_int)
- idx, orig = Rubinius::Type.coerce_to(idx, Fixnum, :to_int), idx
idx += @total if idx < 0
- if idx < 0 || idx >= @total
- return yield(orig) if block_given?
- return rest.at(0) unless rest.empty?
+ if idx < 0 or idx >= @total
+ if block_given?
+ return yield(orig)
+ end
+
+ return default unless default.equal? undefined
- raise IndexError, "Index #{idx} out of array" if rest.empty?
+ raise IndexError, "index #{idx} out of bounds"
end
at(idx)
@@ -769,19 +781,20 @@ def fetch(idx, *rest)
def fill(a=undefined, b=undefined, c=undefined)
Ruby.check_frozen
- if (block_given? and c != undefined) ||
- (!block_given? and a == undefined)
- raise ArgumentError, "wrong number of arguments"
- end
-
if block_given?
+ if undefined != c
+ raise ArgumentError, "wrong number of arguments"
+ end
one, two = a, b
else
+ if a.equal? undefined
+ raise ArgumentError, "wrong number of arguments"
+ end
obj, one, two = a, b, c
end
if one.kind_of? Range
- raise TypeError, "length invalid with range" unless two == undefined
+ raise TypeError, "length invalid with range" unless two.equal? undefined
left = Rubinius::Type.coerce_to one.begin, Fixnum, :to_int
left += size if left < 0
@@ -791,6 +804,7 @@ def fill(a=undefined, b=undefined, c=undefined)
right += size if right < 0
right += 1 unless one.exclude_end?
return self if right <= left # Nothing to modify
+
elsif one and one != undefined
left = Rubinius::Type.coerce_to one, Fixnum, :to_int
left += size if left < 0
@@ -800,7 +814,7 @@ def fill(a=undefined, b=undefined, c=undefined)
begin
right = Rubinius::Type.coerce_to two, Fixnum, :to_int
rescue TypeError
- raise ArgumentError, "argument #{two.inspect} must be a Fixnum"
+ raise ArgumentError, "second argument must be a Fixnum"
end
return self if right == 0
@@ -813,16 +827,19 @@ def fill(a=undefined, b=undefined, c=undefined)
right = size
end
- i = @start + left
total = @start + right
- if right > size
+ if right > @total
reallocate total
@total = right
end
+ # Must be after the potential call to reallocate, since
+ # reallocate might change @tuple
tuple = @tuple
+ i = @start + left
+
if block_given?
while i < total
tuple.put i, yield(i-@start)
@@ -848,7 +865,7 @@ def first(n = undefined)
n = Rubinius::Type.coerce_to n, Fixnum, :to_int
raise ArgumentError, "Size must be positive" if n < 0
- self[0...n].to_a
+ self[0,n]
end
# Recursively flatten any contained Arrays into an one-dimensional result.
@@ -967,9 +984,15 @@ def include?(obj)
def index(obj=undefined)
i = 0
if obj.equal? undefined
- each { |x| return i if yield(x); i += 1 }
+ each do |x|
+ return i if yield(x)
+ i += 1
+ end
else
- each { |x| return i if x == obj; i += 1 }
+ each do |x|
+ return i if x == obj
+ i += 1
+ end
end
nil
end
@@ -985,7 +1008,8 @@ def indexes(*args)
if a.kind_of? Range
out << self[a]
else
- out << at(Rubinius::Type.coerce_to(a, Fixnum, :to_int))
+ idx = Rubinius::Type.coerce_to(a, Fixnum, :to_int)
+ out << at(idx)
end
end
@@ -1018,6 +1042,7 @@ def insert(idx, *items)
# are indicated as [...].
def inspect
return "[]" if @total == 0
+
comma = ", "
result = "["
@@ -1036,6 +1061,7 @@ def inspect
# Arrays.
def join(sep=nil)
return "" if @total == 0
+
out = ""
return "[...]" if Thread.detect_recursion self do
sep = sep ? StringValue(sep) : $,
@@ -1086,21 +1112,19 @@ def join(sep=nil)
# otherwise an empty Array. Always returns an Array.
def last(n=undefined)
if size < 1
- return if n.equal? undefined
+ return nil if n.equal? undefined
return []
end
- return at(-1) if n.equal? undefined
- unless n.respond_to?(:to_int)
- raise TypeError, "Can't convert #{n.class} into Integer"
- end
+ return at(-1) if n.equal? undefined
n = Rubinius::Type.coerce_to n, Fixnum, :to_int
- return [] if n.zero?
- raise ArgumentError, "Number must be positive" if n < 0
+ return [] if n == 0
+
+ raise ArgumentError, "count must be positive" if n < 0
n = size if n > size
- self[-n..-1].to_a
+ self[-n..-1]
end
alias_method :collect, :map
@@ -1110,7 +1134,7 @@ def last(n=undefined)
# Returns number of non-nil elements in self, may be zero
def nitems
sum = 0
- each { |elem| sum += 1 unless elem.nil? }
+ each { |elem| sum += 1 unless elem.equal? nil }
sum
end
@@ -1215,6 +1239,7 @@ def pack(directives)
#
def permutation(num=undefined, &block)
return to_enum(:permutation, num) unless block_given?
+
if num.equal? undefined
num = @total
else
@@ -1231,15 +1256,16 @@ def permutation(num=undefined, &block)
each { |val| yield [val] }
else
# this is the general case
- p = Array.new(num)
+ perm = Array.new(num)
used = Array.new(@total, false)
- __permute__(num, p, 0, used, &block)
+
+ __permute__(num, perm, 0, used, &block)
end
self
end
- def __permute__(num, p, index, used, &block)
+ def __permute__(num, perm, index, used, &block)
# Recursively compute permutations of r elements of the set [0..n-1].
# When we have a complete permutation of array indexes, copy the values
# at those indexes into a new array and yield that array.
@@ -1252,13 +1278,13 @@ def __permute__(num, p, index, used, &block)
# Note: not as efficient as could be for big num.
@total.times do |i|
unless used[i]
- p[index] = i
+ perm[index] = i
if index < num-1
used[i] = true
- __permute__(num, p, index+1, used, &block)
+ __permute__(num, perm, index+1, used, &block)
used[i] = false
else
- yield values_at(*p)
+ yield values_at(*perm)
end
end
end
@@ -1276,18 +1302,25 @@ def pop(many=undefined)
index = @start + @total
elem = @tuple.at(index)
- @tuple.put(index,nil)
-
- # reallocate_shrink()
+ @tuple.put index, nil
elem
else
many = Rubinius::Type.coerce_to(many, Fixnum, :to_int)
raise ArgumentError, "negative array size" if many < 0
- first = size - many
+ first = @total - many
first = 0 if first < 0
- slice!(first..size).to_a
+
+ out = self[first, many]
+
+ if many > @total
+ @total = 0
+ else
+ @total -= many
+ end
+
+ return out
end
end
@@ -1301,23 +1334,27 @@ def pop(many=undefined)
# with one responsible to append the values.
# ++
def product(*args)
- args.map!{|x| Rubinius::Type.coerce_to(x, Array, :to_ary)}
+ args.map! { |x| Rubinius::Type.coerce_to(x, Array, :to_ary) }
# Check the result size will fit in an Array.
- unless args.inject(size) { |n, x| n * x.size }.kind_of?(Fixnum)
+ sum = args.inject(size) { |n, x| n * x.size }
+
+ if sum > Fixnum::MAX
raise RangeError, "product result is too large"
end
+ # TODO rewrite this to not use a tree of Proc objects.
+
# to get the results in the same order as in MRI, vary the last argument first
args.reverse!
result = []
args.push self
- outer_lambda = args.inject(result.method(:push)) do |proc, values|
+ outer_lambda = args.inject(result.method(:push)) do |trigger, values|
lambda do |partial|
values.each do |val|
- proc.call(partial.dup << val)
+ trigger.call(partial.dup << val)
end
end
end
@@ -1364,10 +1401,11 @@ def reject!(&block)
return to_enum(:reject!) unless block_given?
- was = length
+ was = size()
delete_if(&block)
- self if was != length # Too clever?
+ return nil if was == size()
+ self
end
# Replaces contents of self with contents of other,
@@ -1383,6 +1421,9 @@ def replace(other)
self
end
+ alias_method :initialize_copy, :replace
+ private :initialize_copy
+
# Returns a new Array or subclass populated from self
# but in reverse order.
def reverse
@@ -1429,7 +1470,10 @@ def rindex(obj=undefined)
i = @total - 1
while i >= 0
return i if yield @tuple.at(@start + i)
+
+ # Compensate for the array being modified by the block
i = @total if i > @total
+
i -= 1
end
else
@@ -1445,25 +1489,9 @@ def rindex(obj=undefined)
nil
end
- # Choose a random element, or the random n elements, from the array.
- # If the array is empty, the first form returns nil, and the second
- # form returns an empty array.
- def choice(n=undefined)
- return at(Kernel.rand(size)) if n.equal? undefined
-
- n = Rubinius::Type.coerce_to(n, Fixnum, :to_int)
- raise ArgumentError, "negative array size" if n < 0
-
- n = size if n > size
- result = Array.new(self)
-
- n.times do |i|
- r = i + Kernel.rand(size - i)
- result.tuple.swap(i,r)
- end
-
- result[n..size] = []
- result
+ # Choose a random element from an array.
+ def choice
+ at Kernel.rand(size)
end
# Some code depends on Array having it's own #select method,
@@ -1483,14 +1511,12 @@ def shift(n=undefined)
@start += 1
@total -= 1
- # reallocate_shrink()
-
obj
else
n = Rubinius::Type.coerce_to(n, Fixnum, :to_int)
raise ArgumentError, "negative array size" if n < 0
- slice!(0, n).to_a
+ slice!(0, n)
end
end
@@ -1637,7 +1663,7 @@ def sort_inplace(&block)
# Returns self except on subclasses which are converted
# or 'upcast' to Arrays.
def to_a
- if self.class == Array
+ if self.instance_of? Array
self
else
Array.new(self)
@@ -1652,7 +1678,7 @@ def to_ary
# Produces a string by joining all elements without a
# separator. See #join
def to_s
- self.join
+ join
end
# Treats all elements as being Arrays of equal lengths and
@@ -1662,7 +1688,8 @@ def to_s
def transpose
return [] if empty?
- out, max = [], nil
+ out = []
+ max = nil
each do |ary|
ary = Rubinius::Type.coerce_to ary, Array, :to_ary
@@ -1671,7 +1698,10 @@ def transpose
# Catches too-large as well as too-small (for which #fetch would suffice)
raise IndexError, "All arrays must be same length" if ary.size != max
- ary.size.times { |i| (out[i] ||= []) << ary.at(i) }
+ ary.size.times do |i|
+ entry = (out[i] ||= [])
+ entry << ary.at(i)
+ end
end
out
@@ -1778,20 +1808,17 @@ def unshift(*values)
@start -= values.size
@tuple.copy_from(values.tuple,0,values.size,@start)
else
- # FIXME: provision for more unshift prepends?
new_tuple = Rubinius::Tuple.new @total + values.size
new_tuple.copy_from values.tuple, 0, values.size, 0
new_tuple.copy_from @tuple, @start, @total, values.size
@start = 0
@tuple = new_tuple
end
+
@total += values.size
self
end
- alias_method :initialize_copy, :replace
- private :initialize_copy
-
# Reallocates the internal Tuple to accommodate at least given size
def reallocate(at_least)
return if at_least < @tuple.size
@@ -1877,7 +1904,6 @@ def qsort!
if right > left
pivotindex = left + ((right - left) / 2)
- # pi_new = qsort_partition(left, right, pi)
# inline pivot routine
pivot = @tuple.at(pivotindex)
@@ -2000,6 +2026,7 @@ def isort_block!(left, right, block)
end
private :isort_block!
+ # Move to compiler runtime
def __rescue_match__(exception)
each { |x| return true if x === exception }
false
View
14 kernel/common/backtrace.rb
@@ -1,7 +1,7 @@
##
# Contains all logic for gathering and displaying backtraces.
-class Backtrace
+class Rubinius::Backtrace
include Enumerable
MAX_WIDTH = 36
@@ -59,7 +59,8 @@ def show(sep="\n", show_color=true)
times = 0
@locations.each do |loc|
- if loc.name == last_name and loc.method == last_method and loc.line == last_line
+ if loc.name == last_name and loc.method == last_method \
+ and loc.line == last_line
times += 1
else
lines.last[-1] = times if lines.size > 0
@@ -81,14 +82,10 @@ def show(sep="\n", show_color=true)
pos = location.position(Dir.getwd)
color = show_color ? color_from_loc(pos, first) : ""
first = false # special handling for first line
+
spaces = max - recv.size
spaces = 0 if spaces < 0
- # trim the path unless we're debugging.
- #unless $DEBUG
- # pos = "...#{pos[pos.size-max-3..-1]}" if pos.size > max
- #end
-
if show_color and location.inlined?
start = " #{' ' * spaces}#{recv} #{@inline_effect}at#{clear}#{color} "
else
@@ -157,6 +154,7 @@ def join(sep)
def color_from_loc(loc, first)
return @first_color if first
+
if loc =~ /^kernel/
@kernel_color
elsif loc =~ /\(eval\)/
@@ -179,8 +177,6 @@ def self.detect_backtrace(obj)
return nil
end
- # HACK: This should be MRI compliant-ish. --rue
- #
def to_mri
return @mri_backtrace if @mri_backtrace
View
51 kernel/common/block_environment.rb
@@ -4,13 +4,14 @@
module Rubinius
class BlockEnvironment
- attr_accessor :scope
- attr_accessor :top_scope
- attr_accessor :local_count
- attr_accessor :method # The CompiledMethod object that we were called from
+ attr_reader :scope
+ attr_reader :top_scope
+
+ # The CompiledMethod that implements the code for the block
+ attr_reader :code
attr_accessor :proc_environment
- attr_accessor :metadata_container
+ attr_reader :metadata_container
def from_proc?
@proc_environment
@@ -19,15 +20,34 @@ def from_proc?
def under_context(scope, cmethod)
@top_scope = scope
@scope = scope
- @method = cmethod
- @local_count = cmethod.local_count
+ @code = cmethod
@module = cmethod.scope.module
return self
end
- def receiver=(obj)
- @top_scope.self = obj
+ def change_name(name)
+ @code = @code.change_name name
+ end
+
+ def repoint_scope(where)
+ @code.scope.using_current_as where
+ end
+
+ def disable_scope!
+ @code.scope.using_disabled_scope
+ end
+
+ def static_scope
+ @code.scope
+ end
+
+ def to_binding
+ Binding.setup @scope, @code, @code.scope
+ end
+
+ def set_eval_binding(bind)
+ @code.scope.script.eval_binding = bind
end
##
@@ -49,24 +69,23 @@ def make_independent
end
def call_on_instance(obj, *args)
- call_under obj, method.scope, *args
+ call_under obj, @code.scope, *args
end
def arity
- if method.splat and (method.splat >= 0 or method.splat == -2)
- -(method.required_args + 1)
+ if @code.splat and (@code.splat >= 0 or @code.splat == -2)
+ -(@code.required_args + 1)
else
- method.required_args
+ @code.required_args
end
end
- # TODO: are file,line actually used?
def file
- method.file
+ @code.file
end
def line
- method.line_from_ip(0)
+ @code.line_from_ip(0)
end
end
end
View
33 kernel/common/bytearray.rb
@@ -2,26 +2,25 @@
# 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
+class Rubinius::ByteArray
+ alias_method :[], :get_byte
+ alias_method :[]=, :set_byte
- def each
- i = 0
- s = size
- while i < s
- yield get_byte(i)
- i += 1
- end
- end
+ def each
+ i = 0
+ max = size()
- def inspect
- "#<#{self.class}:0x#{object_id.to_s(16)} #{size} bytes>"
+ while i < max
+ yield get_byte(i)
+ i += 1
end
+ end
- def <=>(other)
- compare_bytes(other, size, other.size)
- end
+ def inspect
+ "#<#{self.class}:0x#{object_id.to_s(16)} #{size} bytes>"
+ end
+
+ def <=>(other)
+ compare_bytes other, size, other.size
end
end
View
15 kernel/common/class.rb
@@ -50,8 +50,6 @@
class Class