Skip to content

Commit

Permalink
Merge branch 'master' of github.com:topazproject/topaz into fix_defined
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerd Mömken committed Jun 3, 2013
2 parents 80c39bc + 054f9b1 commit 0fcaddb
Show file tree
Hide file tree
Showing 47 changed files with 251 additions and 123 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env:
- TEST_TYPE=translate
# - TEST_TYPE=rubyspec_untranslated
install:
- pip install --use-mirrors requests invoke
- pip install requests invoke
- invoke travis.install_requirements
script: invoke travis.run_tests
after_success: invoke travis.upload_build
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ If you run ``homebrew`` on OS X, it's even easier::
$ brew update && brew install ruby-build
$ ruby-build topaz-dev /path/to/install/topaz

You can also build ``topaz`` using ``ruby-build`` as a plugin to ``rbenv``::
You can also install the latest nightly build of ``topaz`` using ``ruby-build`` as a plugin to ``rbenv``::

$ brew update && brew install rbenv ruby-build
$ rbenv install topaz-dev
Expand Down
18 changes: 18 additions & 0 deletions lib-topaz/array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -433,4 +433,22 @@ def repeated_permutation(r, &block)
Topaz::Array.repeated_permutation(self, r, &block)
self
end

def transpose
return [] if self.empty?

max = nil
lists = self.map do |ary|
ary = Topaz.convert_type(ary, Array, :to_ary)
max ||= ary.size
raise IndexError.new("element size differs (#{ary.size} should be #{max})") if ary.size != max
ary
end

out = []
max.times do |i|
out << lists.map { |l| l[i] }
end
out
end
end
1 change: 1 addition & 0 deletions lib-topaz/bootstrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
load_bootstrap.call("comparable.rb")
load_bootstrap.call("enumerable.rb")
load_bootstrap.call("enumerator.rb")
load_bootstrap.call("errno.rb")
load_bootstrap.call("file.rb")
load_bootstrap.call("fixnum.rb")
load_bootstrap.call("hash.rb")
Expand Down
64 changes: 64 additions & 0 deletions lib-topaz/enumerable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -437,4 +437,68 @@ def grep(pattern, &block)
end
ret
end

def chunk(initial_state = nil, &original_block)
raise ArgumentError.new("no block given") unless original_block
::Enumerator.new do |yielder|
previous = nil
accumulate = []
block = initial_state.nil? ? original_block : Proc.new{ |val| original_block.yield(val, initial_state.clone)}
each do |val|
key = block.yield(val)
if key.nil? || (key.is_a?(Symbol) && key.to_s[0, 1] == "_")
yielder.yield [previous, accumulate] unless accumulate.empty?
accumulate = []
previous = nil
case key
when nil, :_separator
when :_alone
yielder.yield [key, [val]]
else
raise RuntimeError.new("symbols beginning with an underscore are reserved")
end
else
if previous.nil? || previous == key
accumulate << val
else
yielder.yield [previous, accumulate] unless accumulate.empty?
accumulate = [val]
end
previous = key
end
end
yielder.yield [previous, accumulate] unless accumulate.empty?
end
end

def slice_before(*args, &block)
arg = nil
if block
raise ArgumentError.new("wrong number of arguments (#{args.size} for 0..1)") if args.size > 1
if args.size == 1
has_init = true
arg = args[0]
end
else
raise ArgumentError.new("wrong number of arguments (#{args.size} for 1)") if args.size > 1
raise ArgumentError.new("wrong number of arguments (0 for 1)") if args.empty?
arg = args[0]
block = Proc.new{ |elem| arg === elem }
end
::Enumerator.new do |yielder|
init = arg.dup if has_init
accumulator = nil
each do |elem|
start_new = has_init ? block.yield(elem, init) : block.yield(elem)
if start_new
yielder.yield accumulator if accumulator
accumulator = [elem]
else
accumulator ||= []
accumulator << elem
end
end
yielder.yield accumulator if accumulator
end
end
end
25 changes: 25 additions & 0 deletions lib-topaz/enumerator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,31 @@ def each(&block)
end
end

def each_with_index(&block)
return self.enum_for(:each_with_index) unless block

i = 0
self.each do |*e|
v = (e.size == 1) ? e[0] : e
val = yield(v, i)
i += 1
val
end
end

def with_index(offset = nil, &block)
return self.enum_for(:with_index, offset) unless block
offset = offset ? Topaz.convert_type(offset, Fixnum, :to_int) : 0

i = offset
self.each do |*e|
v = (e.size == 1) ? e[0] : e
val = yield(v, i)
i += 1
val
end
end

def rewind
@object.rewind if @object.respond_to?(:rewind)
@nextvals = nil
Expand Down
19 changes: 19 additions & 0 deletions lib-topaz/errno.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Errno
class ENOENT < SystemCallError
end

class ECHILD < SystemCallError
end

class EACCES < SystemCallError
end

class ENOTDIR < SystemCallError
end

class EISDIR < SystemCallError
end

class ENOTEMPTY < SystemCallError
end
end
8 changes: 4 additions & 4 deletions lib-topaz/kernel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def <=>(other)
end

def Array(arg)
if arg.respond_to? :to_ary
arg.to_ary
elsif arg.respond_to? :to_a
arg.to_a
if ary = Topaz.try_convert_type(arg, Array, :to_ary)
ary
elsif arg.respond_to?(:to_a) && ary = Topaz.try_convert_type(arg, Array, :to_a)
ary
else
[arg]
end
Expand Down
9 changes: 8 additions & 1 deletion lib-topaz/process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ def self.waitpid2(pid = -1)
return [pid, $?]
end

def self.wait2(pid = -1)
waitpid2(pid)
end

def self.waitall
raise NotImplementedError.new("Process.waitall")
result = []
result << wait2 while true
rescue Errno::ECHILD
result
end

class Status
Expand Down
4 changes: 4 additions & 0 deletions lib-topaz/range.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,8 @@ def ==(other)
end

alias eql? ==

def to_s
"#{self.begin}#{self.exclude_end? ? '...' : '..'}#{self.end}"
end
end
1 change: 0 additions & 1 deletion spec/tags/core/array/allocate_tags.txt

This file was deleted.

7 changes: 0 additions & 7 deletions spec/tags/core/array/transpose_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/tags/core/dir/chdir_tags.txt

This file was deleted.

4 changes: 0 additions & 4 deletions spec/tags/core/dir/delete_tags.txt

This file was deleted.

4 changes: 0 additions & 4 deletions spec/tags/core/dir/rmdir_tags.txt

This file was deleted.

4 changes: 0 additions & 4 deletions spec/tags/core/dir/unlink_tags.txt

This file was deleted.

18 changes: 0 additions & 18 deletions spec/tags/core/enumerable/chunk_tags.txt

This file was deleted.

6 changes: 0 additions & 6 deletions spec/tags/core/enumerable/slice_before_tags.txt

This file was deleted.

5 changes: 0 additions & 5 deletions spec/tags/core/enumerator/each_with_index_tags.txt

This file was deleted.

11 changes: 0 additions & 11 deletions spec/tags/core/enumerator/with_index_tags.txt

This file was deleted.

10 changes: 0 additions & 10 deletions spec/tags/core/kernel/Array_tags.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
fails:Kernel has private instance method Array()
fails:Kernel.Array does not call #to_ary on an Array
fails:Kernel.Array calls #to_a if #to_ary returns nil
fails:Kernel.Array returns an Array containing the argument if #to_a returns nil
fails:Kernel.Array raises a TypeError if #to_ary does not return an Array
fails:Kernel.Array raises a TypeError if #to_a does not return an Array
fails:Kernel#Array does not call #to_ary on an Array
fails:Kernel#Array calls #to_a if #to_ary returns nil
fails:Kernel#Array returns an Array containing the argument if #to_a returns nil
fails:Kernel#Array raises a TypeError if #to_ary does not return an Array
fails:Kernel#Array raises a TypeError if #to_a does not return an Array
2 changes: 0 additions & 2 deletions spec/tags/core/process/wait2_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/tags/core/process/wait_tags.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
fails:Process.wait raises a Errno::ECHILD if there are no child processes
fails:Process.wait waits for any child process if no pid is given
fails:Process.wait waits for a specific child if a pid is given
fails:Process.wait coerces the pid to an Integer
Expand Down
2 changes: 0 additions & 2 deletions spec/tags/core/process/waitall_tags.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
fails:Process.waitall returns an empty array when there are no children
fails:Process.waitall waits for all children
fails:Process.waitall returns an array of pid/status pairs
1 change: 0 additions & 1 deletion spec/tags/core/range/to_s_tags.txt

This file was deleted.

2 changes: 1 addition & 1 deletion tasks/travis.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, func, deps=[], needs_rpython=True, needs_rubyspec=False,
self.create_build = create_build

def install_deps(self):
run("pip install --use-mirrors {}".format(" ".join(self.deps)))
run("pip install {}".format(" ".join(self.deps)))

def download_rpython(self):
run("wget https://bitbucket.org/pypy/pypy/get/default.tar.bz2 -O `pwd`/../pypy.tar.bz2 || wget https://bitbucket.org/pypy/pypy/get/default.tar.bz2 -O `pwd`/../pypy.tar.bz2")
Expand Down
6 changes: 3 additions & 3 deletions tests/objects/test_dirobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def test_new(self, space, tmpdir):
f = d.join("content")
f.write("hello")
space.execute("Dir.new('%s')" % d)
with self.raises(space, "SystemCallError"):
with self.raises(space, "Errno::ENOENT"):
space.execute("Dir.new('this does not exist')")
with self.raises(space, "SystemCallError"):
with self.raises(space, "Errno::ENOTDIR"):
space.execute("Dir.new('%s')" % f)

def test_delete(self, space, tmpdir):
Expand All @@ -30,7 +30,7 @@ def test_delete(self, space, tmpdir):
d = tmpdir.mkdir("sub")
f = d.join("content")
f.write("hello")
with self.raises(space, "SystemCallError"):
with self.raises(space, "Errno::ENOTEMPTY"):
space.execute("Dir.delete('%s')" % d)

def test_mkdir(self, space, tmpdir):
Expand Down
2 changes: 1 addition & 1 deletion tests/objects/test_fileobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_new_simple(self, space, tmpdir):
space.execute("File.new('%s', 'rw+')" % f)
with self.raises(space, "ArgumentError", "invalid access mode ra"):
space.execute("File.new('%s', 'ra')" % f)
with self.raises(space, "SystemCallError"):
with self.raises(space, "Errno::ENOENT"):
space.execute("File.new('%s', 1)" % tmpdir.join("non-existant"))

w_res = space.execute("return File.new('%s%snonexist', 'w')" % (tmpdir.dirname, os.sep))
Expand Down
27 changes: 27 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,15 @@ def test_def(self, space):
ast.Statement(ast.Function(None, "f", [], None, None, ast.Nil()))
]))

r = space.parse("""
def
f
end
""")
assert r == ast.Main(ast.Block([
ast.Statement(ast.Function(None, "f", [], None, None, ast.Nil()))
]))

assert space.parse("def []; end") == ast.Main(ast.Block([
ast.Statement(ast.Function(None, "[]", [], None, None, ast.Nil()))
]))
Expand Down Expand Up @@ -1242,6 +1251,14 @@ class X
ast.Statement(ast.Class(ast.Scope(2), "X", None, ast.Nil()))
]))

r = space.parse("""
class
X
end""")
assert r == ast.Main(ast.Block([
ast.Statement(ast.Class(ast.Scope(3), "X", None, ast.Nil()))
]))

r = space.parse("""
class X
def f()
Expand Down Expand Up @@ -2388,6 +2405,16 @@ def test_ternary_operator(self, space):
ast.ConstantInt(0),
))
]))
r = space.parse("""
0 ?
(0) : 0
""")
assert r == ast.Main(ast.Block([
ast.Statement(ast.If(ast.ConstantInt(0),
ast.Block([ast.Statement(ast.ConstantInt(0))]),
ast.ConstantInt(0),
))
]))

def test_case(self, space):
r = space.parse("""
Expand Down
Loading

0 comments on commit 0fcaddb

Please sign in to comment.