Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:evanphx/rubinius
Browse files Browse the repository at this point in the history
  • Loading branch information
rkh committed Jan 5, 2009
2 parents b9af12a + e15f927 commit b5c32eb
Show file tree
Hide file tree
Showing 56 changed files with 791 additions and 490 deletions.
5 changes: 5 additions & 0 deletions kernel/bootstrap/array.rb
Expand Up @@ -5,6 +5,11 @@ def total ; @total ; end
def tuple ; @tuple ; end def tuple ; @tuple ; end
def start ; @start ; end def start ; @start ; end


def self.allocate
Ruby.primitive :array_allocate
raise PrimitiveFailure, "Array.allocate primitive failed"
end

def size def size
@total @total
end end
Expand Down
16 changes: 0 additions & 16 deletions kernel/bootstrap/task.rb
Expand Up @@ -78,22 +78,6 @@ def raise(exc)
Kernel.raise PrimitiveFailure, "primitive failed" Kernel.raise PrimitiveFailure, "primitive failed"
end 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 def probe
@probe @probe
end end
Expand Down
115 changes: 35 additions & 80 deletions kernel/common/array.rb
Expand Up @@ -28,14 +28,6 @@ def self.[](*args)
new args new args
end 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 # Creates a new Array. Without arguments, an empty
# Array is returned. If the only argument is an object # Array is returned. If the only argument is an object
# that responds to +to_ary+, a copy of that Array is # that responds to +to_ary+, a copy of that Array is
Expand All @@ -47,38 +39,44 @@ def self.allocate
# will be run size times to fill the Array with its # will be run size times to fill the Array with its
# result. The block supercedes any object given. If # result. The block supercedes any object given. If
# neither is provided, the Array is filled with nil. # neither is provided, the Array is filled with nil.
def initialize(*args) def initialize(size_or_array=Undefined, obj=Undefined)
raise ArgumentError, "Wrong number of arguments, #{args.size} for 2" if args.size > 2 if size_or_array.equal? Undefined
unless @total == 0
@total = @start = 0
@tuple = Tuple.new 8
end


if args.empty? return self
@tuple = Tuple.new 8 end
@start = 0
@total = 0 if obj.equal? Undefined
else obj = nil
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 if size_or_array.respond_to? :to_ary
ary = Type.coerce_to size_or_array, Array, :to_ary


@tuple = ary.tuple.dup @tuple = ary.tuple.dup
@start = ary.start @start = ary.start
@total = ary.size @total = ary.size
else
count = Type.check_and_coerce_to args.first, Integer, :to_int return self
raise ArgumentError, "size must be positive" if count < 0 end
raise ArgumentError, "size must be a Fixnum" unless count.is_a? Fixnum end
obj = args[1]

size = Type.coerce_to size_or_array, Integer, :to_int
@total = count raise ArgumentError, "size must be positive" if size < 0
if block_given? raise ArgumentError, "size must be <= #{MAX_SIZE}" if size > MAX_SIZE
@tuple = Tuple.new(count)
i = 0 if block_given?
while i < count @tuple = Tuple.new size
@tuple.put i, yield(i) @total = i = 0
i += 1 while i < size
end @tuple.put i, yield(i)
else @total = i += 1
@tuple = Tuple.pattern(count, obj)
end
end end
else
@total = size
@tuple = Tuple.pattern size, obj
end end


self self
Expand Down Expand Up @@ -1165,9 +1163,9 @@ def pack schema
size.times do |i| size.times do |i|
item = Type.coerce_to(self[arr_idx], Integer, :to_int) item = Type.coerce_to(self[arr_idx], Integer, :to_int)


# MRI seems only only raise RangeError at 2**32 and above, even shorts if item.abs >= 2**Rubinius::WORDSIZE
raise RangeError, "bignum too big to convert into 'unsigned long'" if raise RangeError, "bignum too big to convert into 'unsigned long'"
item.abs >= 2**32 # FIX: const end


ret << if little_endian then ret << if little_endian then
item += 2 ** (8 * bytes) if item < 0 item += 2 ** (8 * bytes) if item < 0
Expand Down Expand Up @@ -1261,49 +1259,6 @@ def pop()
elem elem
end 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 # Appends the given object(s) to the Array and returns
# the modified self. # the modified self.
def push(*args) def push(*args)
Expand Down
16 changes: 16 additions & 0 deletions kernel/common/method_context.rb
Expand Up @@ -384,6 +384,22 @@ def get_eval_local(name)
return @dynamic_locals[name] return @dynamic_locals[name]
end 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 end


# #
Expand Down
4 changes: 3 additions & 1 deletion lib/debugger/standard_commands.rb
@@ -1,3 +1,5 @@
require 'pp'

# Defines standard debugger commands that are always available # Defines standard debugger commands that are always available
class Debugger class Debugger


Expand Down Expand Up @@ -358,7 +360,7 @@ def execute(dbg, interface, md)
end end


output = Output.info("S-expression for source lines [#{first+1}-#{last+1}] in #{file}:") 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 << sexp
output output
end end
Expand Down
29 changes: 25 additions & 4 deletions mspec/lib/mspec/utils/script.rb
Expand Up @@ -25,6 +25,18 @@ def self.set(key, value)
config[key] = value config[key] = value
end 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 def initialize
config[:formatter] = nil config[:formatter] = nil
config[:includes] = [] config[:includes] = []
Expand Down Expand Up @@ -148,13 +160,22 @@ def entries(partial)
Dir[partial] Dir[partial]
end end


# Resolves each entry in +list+ to a set of files. If the entry # Resolves each entry in +list+ to a set of files.
# 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 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) def files(list)
list.inject([]) do |files, item| list.inject([]) do |files, item|
if item[0] == ?^ case item[0]
when ?^
files -= entries(item[1..-1]) files -= entries(item[1..-1])
when ?:
key = item[1..-1].to_sym
files += files(Array(config[key]))
else else
files += entries(item) files += entries(item)
end end
Expand Down
28 changes: 28 additions & 0 deletions mspec/spec/utils/script_spec.rb
Expand Up @@ -19,6 +19,13 @@
end end
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 describe MSpecScript, "#config" do
it "returns the MSpecScript config hash" do it "returns the MSpecScript config hash" do
MSpecScript.set :b, 5 MSpecScript.set :b, 5
Expand Down Expand Up @@ -380,3 +387,24 @@ class MSSClass < MSpecScript; end
@script.files(["^a", "a", "b"]).should == ["file1", "file2"] @script.files(["^a", "a", "b"]).should == ["file1", "file2"]
end end
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
12 changes: 12 additions & 0 deletions spec/core/context/fixtures/classes.rb
Expand Up @@ -66,6 +66,18 @@ def called_from_ret_7?
end end
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 # Simple listener class to receive call-backs when yield_debugger is hit
class Listener class Listener
def initialize def initialize
Expand Down
21 changes: 21 additions & 0 deletions spec/core/context/stack_at_spec.rb
@@ -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
8 changes: 8 additions & 0 deletions spec/core/context/stack_depth_spec.rb
@@ -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
10 changes: 0 additions & 10 deletions spec/core/task/get_stack_value_spec.rb

This file was deleted.

6 changes: 3 additions & 3 deletions spec/frozen/core/array/delete_if_spec.rb
Expand Up @@ -3,11 +3,11 @@


describe "Array#delete_if" do describe "Array#delete_if" do
before do before do
@a = [ "a", "b", "c" ] @a = [ "a", "b", "c" ]
end end


it "removes each element for which block returns true" do 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.delete_if { |x| x >= "b" }
@a.should == ["a"] @a.should == ["a"]
end end
Expand All @@ -18,7 +18,7 @@


ruby_version_is "" ... "1.8.7" do ruby_version_is "" ... "1.8.7" do
it "raises a LocalJumpError if no block given" 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
end end
ruby_version_is "1.8.7" ... "1.9" do ruby_version_is "1.8.7" ... "1.9" do
Expand Down

0 comments on commit b5c32eb

Please sign in to comment.