Permalink
Browse files

Merge branch 'master' of git@github.com:evanphx/rubinius

  • Loading branch information...
2 parents b9af12a + e15f927 commit b5c32eb42357ab9e2729b07f3c7fa847ccb94f5c @rkh rkh committed Jan 5, 2009
Showing with 791 additions and 490 deletions.
  1. +5 −0 kernel/bootstrap/array.rb
  2. +0 −16 kernel/bootstrap/task.rb
  3. +35 −80 kernel/common/array.rb
  4. +16 −0 kernel/common/method_context.rb
  5. +3 −1 lib/debugger/standard_commands.rb
  6. +25 −4 mspec/lib/mspec/utils/script.rb
  7. +28 −0 mspec/spec/utils/script_spec.rb
  8. +12 −0 spec/core/context/fixtures/classes.rb
  9. +21 −0 spec/core/context/stack_at_spec.rb
  10. +8 −0 spec/core/context/stack_depth_spec.rb
  11. +0 −10 spec/core/task/get_stack_value_spec.rb
  12. +3 −3 spec/frozen/core/array/delete_if_spec.rb
  13. +3 −3 spec/frozen/core/array/each_index_spec.rb
  14. +6 −6 spec/frozen/core/array/each_spec.rb
  15. +11 −11 spec/frozen/core/array/fill_spec.rb
  16. +27 −7 spec/frozen/core/array/fixtures/classes.rb
  17. +108 −96 spec/frozen/core/array/initialize_spec.rb
  18. +105 −91 spec/frozen/core/array/new_spec.rb
  19. +8 −8 spec/frozen/core/array/pack_spec.rb
  20. +3 −3 spec/frozen/core/array/pop_spec.rb
  21. +1 −1 spec/frozen/core/array/shared/collect.rb
  22. +5 −5 spec/frozen/core/array/shared/join.rb
  23. +3 −3 spec/frozen/core/bignum/div_spec.rb
  24. +5 −5 spec/frozen/core/bignum/divmod_spec.rb
  25. +5 −5 spec/frozen/core/class/new_spec.rb
  26. +11 −5 spec/frozen/core/dir/shared/open.rb
  27. +3 −3 spec/frozen/core/enumerable/all_spec.rb
  28. +3 −3 spec/frozen/core/enumerable/any_spec.rb
  29. +1 −1 spec/frozen/core/file/open_spec.rb
  30. +1 −1 spec/frozen/core/io/close_spec.rb
  31. +1 −1 spec/frozen/core/io/open_spec.rb
  32. +4 −4 spec/frozen/core/io/readpartial_spec.rb
  33. +5 −3 spec/frozen/core/io/shared/tty_shared.rb
  34. +5 −0 spec/frozen/core/kernel/raise_spec.rb
  35. +1 −1 spec/frozen/core/kernel/throw_spec.rb
  36. +24 −0 spec/frozen/core/thread/fixtures/classes.rb
  37. +121 −1 spec/frozen/core/thread/raise_spec.rb
  38. +11 −29 spec/frozen/core/thread/wakeup_spec.rb
  39. +6 −5 spec/frozen/language/encoding_spec.rb
  40. +4 −0 spec/frozen/language/fixtures/private.rb
  41. +4 −14 spec/frozen/language/private_spec.rb
  42. +0 −41 spec/frozen/language/raise_spec.rb
  43. +11 −4 spec/frozen/ruby.1.8.mspec
  44. +11 −4 spec/frozen/ruby.1.9.mspec
  45. +43 −0 spec/frozen/shared/kernel/raise.rb
  46. +0 −1 spec/tags/core/task/get_stack_value_tags.txt
  47. +0 −1 spec/tags/frozen/core/array/initialize_tags.txt
  48. +0 −1 spec/tags/frozen/core/array/new_tags.txt
  49. +12 −0 spec/tags/frozen/core/array/pack_tags.txt
  50. +7 −0 spec/tags/frozen/core/thread/raise_tags.txt
  51. +10 −0 vm/builtin/array.cpp
  52. +3 −0 vm/builtin/array.hpp
  53. +13 −0 vm/builtin/contexts.hpp
  54. +13 −9 vm/ontology.cpp
  55. +16 −0 vm/test/test_array.hpp
  56. +1 −0 vm/vm.hpp
@@ -5,6 +5,11 @@ def total ; @total ; end
def tuple ; @tuple ; end
def start ; @start ; end
+ def self.allocate
+ Ruby.primitive :array_allocate
+ raise PrimitiveFailure, "Array.allocate primitive failed"
+ end
+
def size
@total
end
View
@@ -78,22 +78,6 @@ def raise(exc)
Kernel.raise PrimitiveFailure, "primitive failed"
end
- # Returns the current size of the stack for this task.
- def stack_size
- Ruby.primitive :task_stack_size
- Kernel.raise PrimitiveFailure, "primitive failed"
- end
-
- # Returns the value at the specified depth on the task stack, where depth is
- # a positive integer counting down from the top of the stack.
- def get_stack_value(depth)
- Ruby.primitive :task_get_stack_value
-
- # If we get here, the primitive failed
- # Kernel raise is used, since we don't want to use the raise primitive above
- Kernel.raise ArgumentError, "#{self.class} stack index out of range"
- end
-
def probe
@probe
end
View
@@ -28,14 +28,6 @@ def self.[](*args)
new args
end
- def self.allocate
- ary = super()
- ary.start = 0
- ary.total = 0
- ary.tuple = Tuple.new 8
- ary
- end
-
# Creates a new Array. Without arguments, an empty
# Array is returned. If the only argument is an object
# that responds to +to_ary+, a copy of that Array is
@@ -47,38 +39,44 @@ def self.allocate
# will be run size times to fill the Array with its
# result. The block supercedes any object given. If
# neither is provided, the Array is filled with nil.
- def initialize(*args)
- raise ArgumentError, "Wrong number of arguments, #{args.size} for 2" if args.size > 2
+ def initialize(size_or_array=Undefined, obj=Undefined)
+ if size_or_array.equal? Undefined
+ unless @total == 0
+ @total = @start = 0
+ @tuple = Tuple.new 8
+ end
- if args.empty?
- @tuple = Tuple.new 8
- @start = 0
- @total = 0
- else
- if args.size == 1 and (args.first.__kind_of__ Array or args.first.respond_to? :to_ary)
- ary = Type.coerce_to args.first, Array, :to_ary
+ return self
+ end
+
+ if obj.equal? Undefined
+ obj = nil
+
+ if size_or_array.respond_to? :to_ary
+ ary = Type.coerce_to size_or_array, Array, :to_ary
@tuple = ary.tuple.dup
@start = ary.start
@total = ary.size
- else
- count = Type.check_and_coerce_to args.first, Integer, :to_int
- raise ArgumentError, "size must be positive" if count < 0
- raise ArgumentError, "size must be a Fixnum" unless count.is_a? Fixnum
- obj = args[1]
-
- @total = count
- if block_given?
- @tuple = Tuple.new(count)
- i = 0
- while i < count
- @tuple.put i, yield(i)
- i += 1
- end
- else
- @tuple = Tuple.pattern(count, obj)
- end
+
+ return self
+ end
+ end
+
+ size = Type.coerce_to size_or_array, Integer, :to_int
+ raise ArgumentError, "size must be positive" if size < 0
+ raise ArgumentError, "size must be <= #{MAX_SIZE}" if size > MAX_SIZE
+
+ if block_given?
+ @tuple = Tuple.new size
+ @total = i = 0
+ while i < size
+ @tuple.put i, yield(i)
+ @total = i += 1
end
+ else
+ @total = size
+ @tuple = Tuple.pattern size, obj
end
self
@@ -1165,9 +1163,9 @@ def pack schema
size.times do |i|
item = Type.coerce_to(self[arr_idx], Integer, :to_int)
- # MRI seems only only raise RangeError at 2**32 and above, even shorts
- raise RangeError, "bignum too big to convert into 'unsigned long'" if
- item.abs >= 2**32 # FIX: const
+ if item.abs >= 2**Rubinius::WORDSIZE
+ raise RangeError, "bignum too big to convert into 'unsigned long'"
+ end
ret << if little_endian then
item += 2 ** (8 * bytes) if item < 0
@@ -1261,49 +1259,6 @@ def pop()
elem
end
- # Rubinius-only, better inspect representation of the Array
- def indented_inspect(indent = 0)
- # Here there be dragons. In fact, there is one jusAAAAAAAARGH
- str = "["
-
- sub = false
- i = 0
- lst = size - 1
- while i < size
- element = self[i]
- if Array === element
- estr = element.indented_inspect(indent + 2)
- if str.size > 30 or estr.size > 30
- if estr[0] != ?\s
- estr = "#{' ' * (indent + 2)}#{estr}"
- end
-
- str << "\n#{estr}"
- sub = true
- else
- str << estr
- end
- else
- str << element.inspect
- end
-
- str << ", " unless i == lst
- i += 1
- end
-
- if sub
- str << "\n#{' ' * indent}]"
- else
- str << "]"
- end
-
- if sub
- return "#{' ' * indent}#{str}"
- end
-
- return str
- end
-
# Appends the given object(s) to the Array and returns
# the modified self.
def push(*args)
@@ -384,6 +384,22 @@ def get_eval_local(name)
return @dynamic_locals[name]
end
+ # Returns the current depth of the stack for this context.
+ def stack_depth
+ Ruby.primitive :context_stack_depth
+ Kernel.raise PrimitiveFailure, "primitive failed"
+ end
+
+ # Returns the value at the specified depth on the task stack, where depth is
+ # a positive integer counting down from the top of the stack.
+ def stack_at(depth)
+ Ruby.primitive :context_stack_at
+
+ # If we get here, the primitive failed
+ # Kernel raise is used, since we don't want to use the raise primitive above
+ Kernel.raise ArgumentError, "#{self.class} stack index out of range"
+ end
+
end
#
@@ -1,3 +1,5 @@
+require 'pp'
+
# Defines standard debugger commands that are always available
class Debugger
@@ -358,7 +360,7 @@ def execute(dbg, interface, md)
end
output = Output.info("S-expression for source lines [#{first+1}-#{last+1}] in #{file}:")
- sexp = lines[first..last].join().to_sexp.indented_inspect
+ sexp = lines[first..last].join().to_sexp.pretty_inspect
output << sexp
output
end
@@ -25,6 +25,18 @@ def self.set(key, value)
config[key] = value
end
+ # Gets the value of +key+ from the config object. Simplifies
+ # getting values in a config file:
+ #
+ # class MSpecScript
+ # set :a, 1
+ # set :b, 2
+ # set :c, get(:a) + get(:b)
+ # end
+ def self.get(key)
+ config[key]
+ end
+
def initialize
config[:formatter] = nil
config[:includes] = []
@@ -148,13 +160,22 @@ def entries(partial)
Dir[partial]
end
- # Resolves each entry in +list+ to a set of files. If the entry
- # has a leading '^' character, the list of files is subtracted
- # from the list of files accumulated to that point.
+ # Resolves each entry in +list+ to a set of files.
+ #
+ # If the entry has a leading '^' character, the list of files
+ # is subtracted from the list of files accumulated to that point.
+ #
+ # If the entry has a leading ':' character, the corresponding
+ # key is looked up in the config object and the entries in the
+ # value retrieved are processed through #entries.
def files(list)
list.inject([]) do |files, item|
- if item[0] == ?^
+ case item[0]
+ when ?^
files -= entries(item[1..-1])
+ when ?:
+ key = item[1..-1].to_sym
+ files += files(Array(config[key]))
else
files += entries(item)
end
@@ -19,6 +19,13 @@
end
end
+describe MSpecScript, ".get" do
+ it "gets the config hash value for a key" do
+ MSpecScript.set :a, 10
+ MSpecScript.get(:a).should == 10
+ end
+end
+
describe MSpecScript, "#config" do
it "returns the MSpecScript config hash" do
MSpecScript.set :b, 5
@@ -380,3 +387,24 @@ class MSSClass < MSpecScript; end
@script.files(["^a", "a", "b"]).should == ["file1", "file2"]
end
end
+
+describe MSpecScript, "#files" do
+ before :each do
+ MSpecScript.set :files, ["file1", "file2"]
+
+ @script = MSpecScript.new
+ end
+
+ after :each do
+ MSpecScript.config.delete :files
+ end
+
+ it "looks up items with leading ':' in the config object" do
+ @script.should_receive(:entries).and_return(["file1"], ["file2"])
+ @script.files(":files").should == ["file1", "file2"]
+ end
+
+ it "returns an empty list if the config key is not set" do
+ @script.files(":all_files").should == []
+ end
+end
@@ -66,6 +66,18 @@ def called_from_ret_7?
end
end
+ class B
+ def inspect_stack(depth)
+ ctx = Rubinius::Task.current.current_context
+ #puts ctx.method.decode
+ inspector 'First', :second, 3, [4, 5, 6], ctx.stack_at(depth)
+ end
+
+ def inspector(*args)
+ args.last
+ end
+ end
+
# Simple listener class to receive call-backs when yield_debugger is hit
class Listener
def initialize
@@ -0,0 +1,21 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/fixtures/classes.rb'
+
+describe "MethodContext#stack_at" do
+ before :each do
+ @b = ContextSpecs::B.new
+ end
+
+ it "returns the value on the context operand stack at the specified depth" do
+ @b.inspect_stack(3).should == 'First'
+ @b.inspect_stack(4).should == :second
+ @b.inspect_stack(5).should == 3
+ @b.inspect_stack(6).should == [4,5,6]
+ end
+
+ it "throws an ArgumentError if depth is out of range" do
+ lambda { @b.inspect_stack(0) }.should_not raise_error(ArgumentError)
+ lambda { @b.inspect_stack(-1) }.should raise_error(ArgumentError)
+ lambda { @b.inspect_stack(10) }.should raise_error(ArgumentError)
+ end
+end
@@ -0,0 +1,8 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe "MethodContext#stack_depth" do
+ it "returns the depth of the bytecode operand stack" do
+ ctx = Rubinius::Task.current.current_context
+ ctx.stack_depth.should == 1
+ end
+end
@@ -1,10 +0,0 @@
-require File.dirname(__FILE__) + '/../../spec_helper'
-
-describe "Task#get_stack_value" do
- it "throws an ArgumentError if depth is out of range" do
- lambda { Task.current.get_stack_value(0) }.should_not raise_error(ArgumentError)
- lambda { Task.current.get_stack_value(-1) }.should raise_error(ArgumentError)
- lambda { Task.current.get_stack_value(Task.current.stack_size) }.should raise_error(ArgumentError)
- lambda { Task.current.get_stack_value(Task.current.stack_size-1) }.should_not raise_error(ArgumentError)
- end
-end
@@ -3,11 +3,11 @@
describe "Array#delete_if" do
before do
- @a = [ "a", "b", "c" ]
+ @a = [ "a", "b", "c" ]
end
it "removes each element for which block returns true" do
- @a = [ "a", "b", "c" ]
+ @a = [ "a", "b", "c" ]
@a.delete_if { |x| x >= "b" }
@a.should == ["a"]
end
@@ -18,7 +18,7 @@
ruby_version_is "" ... "1.8.7" do
it "raises a LocalJumpError if no block given" do
- lambda { @a.delete_if }.should raise_error(LocalJumpError, /no block given/)
+ lambda { @a.delete_if }.should raise_error(LocalJumpError)
end
end
ruby_version_is "1.8.7" ... "1.9" do
Oops, something went wrong.

0 comments on commit b5c32eb

Please sign in to comment.