comp_tree 0.5.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/CHANGES +24 -0
  2. data/README +19 -52
  3. data/Rakefile +1 -138
  4. data/comp_tree.gemspec +33 -30
  5. data/install.rb +3 -3
  6. data/lib/comp_tree/algorithm.rb +117 -156
  7. data/lib/comp_tree/driver.rb +39 -154
  8. data/lib/comp_tree/error.rb +18 -23
  9. data/lib/comp_tree/node.rb +46 -50
  10. data/lib/comp_tree.rb +56 -0
  11. data/rakelib/jumpstart/ruby.rb +51 -0
  12. data/{contrib/quix/lib/quix → rakelib/jumpstart}/simple_installer.rb +11 -13
  13. data/test/common.rb +29 -0
  14. data/test/test_basic.rb +189 -0
  15. data/test/test_circular.rb +34 -31
  16. data/test/test_drain.rb +38 -0
  17. data/test/test_exception.rb +37 -86
  18. data/test/test_flood.rb +14 -0
  19. data/test/test_grind.rb +77 -0
  20. data/test/test_sequential.rb +21 -0
  21. metadata +45 -58
  22. data/contrib/quix/Rakefile +0 -16
  23. data/contrib/quix/install.rb +0 -3
  24. data/contrib/quix/lib/quix/builtin/dir/casefold_brackets.rb +0 -7
  25. data/contrib/quix/lib/quix/builtin/kernel/tap.rb +0 -9
  26. data/contrib/quix/lib/quix/builtin/module/include.rb +0 -21
  27. data/contrib/quix/lib/quix/builtin/module/private.rb +0 -41
  28. data/contrib/quix/lib/quix/config.rb +0 -37
  29. data/contrib/quix/lib/quix/cygwin.rb +0 -60
  30. data/contrib/quix/lib/quix/diagnostic.rb +0 -44
  31. data/contrib/quix/lib/quix/enumerable.rb +0 -33
  32. data/contrib/quix/lib/quix/fileutils.rb +0 -37
  33. data/contrib/quix/lib/quix/hash_struct.rb +0 -27
  34. data/contrib/quix/lib/quix/kernel.rb +0 -61
  35. data/contrib/quix/lib/quix/lazy_struct.rb +0 -55
  36. data/contrib/quix/lib/quix/string.rb +0 -38
  37. data/contrib/quix/lib/quix/subpackager.rb +0 -52
  38. data/contrib/quix/lib/quix/thread_local.rb +0 -32
  39. data/contrib/quix/lib/quix/vars.rb +0 -138
  40. data/contrib/quix/lib/quix.rb +0 -32
  41. data/contrib/quix/test/all.rb +0 -12
  42. data/contrib/quix/test/test_deps.rb +0 -25
  43. data/contrib/quix/test/test_include.rb +0 -47
  44. data/contrib/quix/test/test_private.rb +0 -86
  45. data/contrib/quix/test/test_root.rb +0 -19
  46. data/contrib/quix/test/test_struct.rb +0 -48
  47. data/contrib/quix/test/test_vars.rb +0 -187
  48. data/lib/comp_tree/bucket_ipc.rb +0 -151
  49. data/lib/comp_tree/diagnostic.rb +0 -44
  50. data/lib/comp_tree/misc.rb +0 -61
  51. data/lib/comp_tree/retriable_fork.rb +0 -42
  52. data/lib/comp_tree/tap.rb +0 -9
  53. data/lib/comp_tree/task_node.rb +0 -22
  54. data/test/all.rb +0 -12
  55. data/test/test_bucketipc.rb +0 -72
  56. data/test/test_comp_tree.rb +0 -364
@@ -1,52 +0,0 @@
1
-
2
- require 'quix/hash_struct'
3
-
4
- module Quix
5
- module Subpackager
6
- WARNING = %q{
7
-
8
-
9
- ######################################################
10
- #
11
- # **** DO NOT EDIT ****
12
- #
13
- # **** THIS IS A GENERATED FILE *****
14
- #
15
- ######################################################
16
-
17
-
18
- }.gsub(%r!^ +!, "")
19
-
20
- def self.run(packages)
21
- HashStruct.recursive_new(packages).each_pair { |pkg, pkg_spec|
22
- pkg_spec.subpackages.each_pair { |subpkg, subpkg_spec|
23
- process_path = lambda { |path|
24
- source = "#{subpkg_spec.lib_dir}/#{path}.rb"
25
- dest = "#{pkg_spec.lib_dir}/#{pkg}/#{path}.rb"
26
-
27
- contents =
28
- WARNING +
29
- File.read(source).gsub(%r!require [\'\"]#{subpkg}!) {
30
- |match|
31
- match.sub(%r!#{subpkg}\Z!, "#{pkg}/#{subpkg}")
32
- }.gsub(subpkg_spec.name_in_ruby) {
33
- "#{pkg_spec.name_in_ruby}::#{subpkg_spec.name_in_ruby}"
34
- } +
35
- WARNING
36
-
37
- mkdir_p(File.dirname(dest))
38
- puts "#{source} --> #{dest}"
39
- File.open(dest, "w") { |t| t.print(contents) }
40
- }
41
-
42
- unless subpkg_spec.ignore_root_rb
43
- process_path.call(subpkg)
44
- end
45
- subpkg_spec.sources.each { |path|
46
- process_path.call("#{subpkg}/#{path}")
47
- }
48
- }
49
- }
50
- end
51
- end
52
- end
@@ -1,32 +0,0 @@
1
-
2
- require 'thread'
3
- require 'quix/kernel'
4
-
5
- module CompTree
6
- class ThreadLocal
7
- include Misc
8
-
9
- def initialize(prefix = nil, &default)
10
- @name = gensym(prefix)
11
- @accessed = gensym(prefix)
12
- @default = default
13
- end
14
-
15
- def value
16
- t = Thread.current
17
- unless t[@accessed]
18
- if @default
19
- t[@name] = @default.call
20
- end
21
- t[@accessed] = true
22
- end
23
- t[@name]
24
- end
25
-
26
- def value=(value)
27
- t = Thread.current
28
- t[@accessed] = true
29
- t[@name] = value
30
- end
31
- end
32
- end
@@ -1,138 +0,0 @@
1
-
2
- require 'quix/kernel'
3
- require 'quix/thread_local'
4
- require 'quix/builtin/kernel/tap'
5
- require 'ostruct'
6
-
7
- module CompTree
8
- module Vars
9
- include CompTree::Misc
10
-
11
- def eval_locals(code_with_locals, &block)
12
- code_with_locals.call.split(",").map { |name|
13
- # trim
14
- name.sub(%r!\A\s+!, "").sub(%r!\s+\Z!, "")
15
- }.each { |name|
16
- block.call(name, eval(name, code_with_locals.binding))
17
- }
18
- end
19
-
20
- def hash_to_locals(&block)
21
- if hash = block.call
22
- hash.each_pair { |name, value|
23
- Vars.argument_cache.value = value
24
- eval("#{name} = #{Vars.name}.argument_cache.value", block.binding)
25
- }
26
- end
27
- end
28
-
29
- def locals_to_hash(&block)
30
- Hash.new.tap { |hash|
31
- eval_locals(block) { |name, value|
32
- hash[name.to_sym] = value
33
- }
34
- }
35
- end
36
-
37
- def config_to_hash(code)
38
- Hash.new.tap { |hash|
39
- each_config_pair(code) { |name, value|
40
- hash[name] = value
41
- }
42
- }
43
- end
44
-
45
- def each_config_pair(code, &block)
46
- Vars.argument_cache.value = code
47
- vars, bind = private__eval_config_code
48
- vars.each { |var|
49
- yield(var.to_sym, eval(var, bind))
50
- }
51
- end
52
-
53
- def hash_to_ivs(opts = nil, &block)
54
- if hash = block.call
55
- private__hash_to_ivs(
56
- hash,
57
- eval("self", block.binding),
58
- opts && opts[:force])
59
- end
60
- end
61
-
62
- def locals_to_ivs(opts = nil, &block)
63
- hash = Hash.new
64
- eval_locals(block) { |name, value|
65
- hash[name] = value
66
- }
67
- private__hash_to_ivs(
68
- hash,
69
- eval("self", block.binding),
70
- opts && opts[:force])
71
- end
72
-
73
- def with_readers(hash, *args, &block)
74
- caller_self = eval("self", block.binding)
75
- readers =
76
- if args.empty?
77
- hash.keys
78
- else
79
- args
80
- end
81
- singleton_class.instance_eval {
82
- added = Array.new
83
- begin
84
- readers.each { |reader|
85
- if caller_self.respond_to?(reader)
86
- raise(
87
- "Reader '#{reader}' already exists in #{caller_self.inspect}")
88
- end
89
- define_method(reader) {
90
- hash[reader]
91
- }
92
- added << reader
93
- }
94
- block.call
95
- ensure
96
- added.each { |reader|
97
- remove_method(reader)
98
- }
99
- end
100
- }
101
- end
102
-
103
- private
104
-
105
- class << self
106
- attr_accessor :argument_cache
107
- end
108
- @argument_cache = ThreadLocal.new
109
-
110
- def private__eval_config_code
111
- eval %Q{
112
- #{Vars.argument_cache.value}
113
-
114
- [local_variables, binding]
115
- }
116
- end
117
-
118
- def private__hash_to_ivs(hash, target, force)
119
- target.instance_eval {
120
- hash.each_pair { |name, value|
121
- ivar = "@#{name}"
122
- unless force
123
- existing_value = no_warnings {
124
- instance_variable_get(ivar)
125
- }
126
- unless existing_value.nil?
127
- raise "instance variable already set: #{name}"
128
- end
129
- end
130
- instance_variable_set(ivar, value)
131
- }
132
- }
133
- end
134
-
135
- extend self
136
- end
137
- end
138
-
@@ -1,32 +0,0 @@
1
- #
2
- # Convience only -- include most everything
3
- #
4
-
5
- root = File.dirname(__FILE__)
6
- pkgname = File.basename(__FILE__).sub(%r!\.rb\Z!, "")
7
-
8
- Dir["#{root}/#{pkgname}/**/*.rb"].map { |file|
9
- # change to relative paths
10
- file.sub(%r!\A#{root}/!, "").sub(%r!\.rb\Z!, "")
11
- }.reject { |file|
12
- (file =~ %r!cygwin! and RUBY_PLATFORM !~ %r!cygwin!) or
13
- file =~ %r!builtin!
14
- }.each { |file|
15
- require file
16
- }
17
-
18
- require 'quix/builtin/kernel/tap'
19
-
20
- %w(Config Enumerable FileUtils String).each { |name|
21
- Kernel.const_get(name).module_eval {
22
- include Quix.const_get(name)
23
- }
24
- }
25
-
26
- Config.extend(Quix::Config)
27
-
28
- class Object
29
- include Quix::Kernel
30
- end
31
-
32
- include Quix
@@ -1,12 +0,0 @@
1
- $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
2
-
3
- require 'quix/config'
4
-
5
- #
6
- # Run in separate exec to check for missing dependencies.
7
- #
8
- Dir["#{File.dirname(__FILE__)}/test_*.rb"].each { |test|
9
- unless system(Quix::Config.ruby_executable, test)
10
- raise "test failed: #{test}"
11
- end
12
- }
@@ -1,25 +0,0 @@
1
- $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
2
-
3
- require 'test/unit'
4
- require 'quix/config'
5
-
6
- class TestDeps < Test::Unit::TestCase
7
- include Quix::Config
8
- def test_deps
9
- ruby = ruby_executable
10
- root = File.expand_path("#{File.dirname(__FILE__)}/../lib")
11
- Dir["#{root}/**/*.rb"].map { |file|
12
- file.
13
- sub(%r!\A#{root}/!, "").
14
- sub(%r!\.rb\Z!, "")
15
- }.each { |file|
16
- unless file =~ %r!cygwin! and RUBY_PLATFORM !~ %r!cygwin!
17
- Dir.chdir(root) {
18
- assert(
19
- system(ruby, "-r", file, "-e", ""),
20
- "error requiring: '#{file}'")
21
- }
22
- end
23
- }
24
- end
25
- end
@@ -1,47 +0,0 @@
1
- $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
2
-
3
- require 'test/unit'
4
- require 'open3'
5
- require 'quix/config'
6
-
7
- class TestInclude < Test::Unit::TestCase
8
- include Quix::Config
9
-
10
- def test_include
11
- Dir.chdir(File.dirname(__FILE__)) {
12
- code = %q{
13
- $LOAD_PATH.unshift "../lib"
14
- require 'quix/builtin/module/include'
15
-
16
- module A
17
- def f ; end
18
- end
19
-
20
- module B
21
- def f ; end
22
- end
23
-
24
- module C
25
- include A
26
- include B
27
- end
28
-
29
- class D
30
- include B
31
- include A
32
- end
33
- }
34
- ruby = ruby_executable
35
- begin
36
- stdin, stdout, stderr = Open3.popen3("#{ruby} -d -")
37
- stdin.puts(code)
38
- stdin.close_write
39
- assert_equal(stderr.readlines,
40
- ["Note: replacing C#f with B#f\n",
41
- "Note: replacing D#f with A#f\n"])
42
- rescue NotImplementedError
43
- puts "Skipping #{File.basename(__FILE__)}."
44
- end
45
- }
46
- end
47
- end
@@ -1,86 +0,0 @@
1
- $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
2
-
3
- require 'test/unit'
4
- require 'quix/config'
5
- require 'quix/kernel'
6
-
7
- if Quix::Config.version_ge("1.8.7")
8
- require 'test/unit'
9
- require 'quix/builtin/module/private'
10
-
11
- class TestPrivate < Test::Unit::TestCase
12
- BODY = %{
13
- def f ; end
14
-
15
- private {
16
- def g ; end
17
- def h ; end
18
- }
19
-
20
- def i ; end
21
-
22
- private {
23
- def j ; end
24
- }
25
-
26
- def k ; end
27
-
28
- private {
29
- }
30
-
31
- def l ; end
32
-
33
- def m ; end
34
- def n ; end
35
- private :m, :n
36
-
37
- def o ; end
38
- }
39
-
40
- class A
41
- eval(BODY)
42
- end
43
-
44
- module B
45
- eval(BODY)
46
- end
47
-
48
- class C
49
- include B
50
- end
51
-
52
- def test_1
53
- [A, C].map { |klass| klass.new }.each { |t|
54
- assert_nothing_raised { t.f }
55
- assert_raises(NoMethodError) { t.g }
56
- assert_raises(NoMethodError) { t.h }
57
- assert_nothing_raised { t.i }
58
- assert_raises(NoMethodError) { t.j }
59
- assert_nothing_raised { t.k }
60
- assert_nothing_raised { t.l }
61
- assert_raises(NoMethodError) { t.m }
62
- assert_raises(NoMethodError) { t.n }
63
- assert_nothing_raised { t.o }
64
- }
65
- end
66
-
67
- def test_2
68
- added = []
69
- Class.new {
70
- extend(Quix::Kernel).singleton_class.instance_eval {
71
- define_method(:method_added) { |name|
72
- added << name
73
- }
74
- }
75
-
76
- private {
77
- def f ; end
78
- }
79
-
80
- def g ; end
81
- }
82
- assert_equal([:f, :g], added)
83
- end
84
- end
85
- end
86
-
@@ -1,19 +0,0 @@
1
- $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
2
-
3
- require 'quix'
4
- require 'test/unit'
5
-
6
- class TestRoot < Test::Unit::TestCase
7
- def test_1
8
- assert_equal(class << self ; self ; end, singleton_class)
9
- assert_equal("moo", "moo".tap { |t| t*2 })
10
- assert_equal("moomoo", "moo".let { |t| t*2 })
11
- assert_equal("zzz", " zzz ".trim)
12
- assert_nothing_raised {
13
- ThreadLocal.new
14
- LazyStruct.new
15
- HashStruct.new
16
- Config.ruby_executable
17
- }
18
- end
19
- end
@@ -1,48 +0,0 @@
1
- $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
2
-
3
- require 'test/unit'
4
- require 'quix/lazy_struct'
5
- require 'quix/hash_struct'
6
-
7
- class TestLazyStruct < Test::Unit::TestCase
8
- def common(s)
9
- s.f = 33
10
- assert_equal(33, s.f)
11
-
12
- n = 0
13
- s.attribute(:f) {
14
- n += 1
15
- 44
16
- }
17
-
18
- 3.times {
19
- assert_equal(44, s.f)
20
- }
21
- assert_equal(1, n)
22
- end
23
-
24
- def test_1
25
- common(Quix::LazyStruct.new)
26
- end
27
-
28
- def test_2
29
- s = OpenStruct.new
30
- class << s
31
- include Quix::LazyStruct::Mixin
32
- end
33
- common(s)
34
- end
35
-
36
- def test_3
37
- s = Quix::HashStruct.new
38
- class << s
39
- include Quix::LazyStruct::Mixin
40
- end
41
- common(s)
42
- s[:g] = 55
43
- assert_equal(
44
- { :f => 33, :g => 55 },
45
- s.keys.inject(Hash.new) { |acc, e| acc.merge(e => s[e]) })
46
- end
47
- end
48
-
@@ -1,187 +0,0 @@
1
- $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
2
-
3
- require 'test/unit'
4
- require 'quix/vars'
5
- require 'quix/hash_struct'
6
-
7
- class TestVars < Test::Unit::TestCase
8
- include Quix::Vars
9
-
10
- def test_locals_to_hash
11
- a = 33
12
- b = Object.new
13
- c = lambda { a + 11 }
14
-
15
- hash = locals_to_hash {%{a, b, c}}
16
-
17
- assert_equal(a.object_id, hash[:a].object_id)
18
- assert_equal(b.object_id, hash[:b].object_id)
19
- assert_equal(c.object_id, hash[:c].object_id)
20
-
21
- assert_equal(hash[:c].call, 44)
22
- end
23
-
24
- def test_hash_to_locals
25
- a = nil
26
- b = nil
27
- c = nil
28
-
29
- hash = {
30
- :a => 33,
31
- :b => Object.new,
32
- :c => lambda { hash[:a] + 11 },
33
- }
34
-
35
- hash_to_locals { hash }
36
-
37
- assert_equal(a.object_id, hash[:a].object_id)
38
- assert_equal(b.object_id, hash[:b].object_id)
39
- assert_equal(c.object_id, hash[:c].object_id)
40
-
41
- assert_equal(hash[:c].call, 44)
42
- assert_nothing_raised { hash_to_locals { nil } }
43
- end
44
-
45
- def test_with_readers
46
- hash = {
47
- :a => 33,
48
- :b => Object.new,
49
- :c => lambda { hash[:a] + 11 },
50
- }
51
-
52
- assert_raise(NameError) { a }
53
- assert_raise(NameError) { b }
54
- assert_raise(NameError) { c }
55
-
56
- with_readers(hash) {
57
- assert_equal(a.object_id, hash[:a].object_id)
58
- assert_equal(b.object_id, hash[:b].object_id)
59
- assert_equal(c.object_id, hash[:c].object_id)
60
- }
61
-
62
- assert_raise(NameError) { a }
63
- assert_raise(NameError) { b }
64
- assert_raise(NameError) { c }
65
-
66
- with_readers(hash, :a, :b) {
67
- assert_equal(a.object_id, hash[:a].object_id)
68
- assert_equal(b.object_id, hash[:b].object_id)
69
- assert_raise(NameError) { c }
70
- }
71
- end
72
-
73
- def test_locals_to_ivs
74
- a = 33
75
- b = Object.new
76
- c = lambda { a + 11 }
77
-
78
- assert(!defined?(@a))
79
- assert(!defined?(@b))
80
- assert(!defined?(@c))
81
-
82
- locals_to_ivs {%{a, b, c}}
83
-
84
- assert_equal(a.object_id, @a.object_id)
85
- assert_equal(b.object_id, @b.object_id)
86
- assert_equal(c.object_id, @c.object_id)
87
-
88
- assert_equal(@c.call, 44)
89
- end
90
-
91
- def test_hash_to_ivs
92
- hash = {
93
- :d => 33,
94
- :e => Object.new,
95
- :f => lambda { hash[:d] + 11 },
96
- }
97
-
98
- assert(!defined?(@d))
99
- assert(!defined?(@e))
100
- assert(!defined?(@f))
101
-
102
- hash_to_ivs { hash }
103
-
104
- assert_equal(hash[:d].object_id, @d.object_id)
105
- assert_equal(hash[:e].object_id, @e.object_id)
106
- assert_equal(hash[:f].object_id, @f.object_id)
107
-
108
- assert_equal(hash[:f].call, 44)
109
- assert_nothing_raised { hash_to_ivs { nil } }
110
- end
111
-
112
- def test_config_to_hash
113
- config = %q{
114
- a = 33
115
- b = a + 11
116
- c = 5*(a - 22)
117
- d = (1..3).map { |n| n*n }
118
- e = "moo"
119
- f = lambda { a + 66 }
120
-
121
- a_object_id = a.object_id
122
- b_object_id = b.object_id
123
- c_object_id = c.object_id
124
- d_object_id = d.object_id
125
- e_object_id = e.object_id
126
- f_object_id = f.object_id
127
- }
128
-
129
- hash = config_to_hash(config)
130
-
131
- assert_equal(hash[:a], 33)
132
- assert_equal(hash[:b], 44)
133
- assert_equal(hash[:c], 55)
134
- assert_equal(hash[:d], [1, 4, 9])
135
- assert_equal(hash[:e], "moo")
136
- assert_equal(hash[:f].call, 99)
137
-
138
- assert_equal(hash[:a].object_id, hash[:a_object_id])
139
- assert_equal(hash[:b].object_id, hash[:b_object_id])
140
- assert_equal(hash[:c].object_id, hash[:c_object_id])
141
- assert_equal(hash[:d].object_id, hash[:d_object_id])
142
- assert_equal(hash[:e].object_id, hash[:e_object_id])
143
- assert_equal(hash[:f].object_id, hash[:f_object_id])
144
- end
145
-
146
- def test_hash_struct
147
- hash = {
148
- :a => {
149
- :b => :c,
150
- :d => :e,
151
- :f => {
152
- :g => :h,
153
- :i => :j,
154
- },
155
- },
156
- :k => :l,
157
- :m => [ :n, :o, :p ],
158
- :q => {
159
- :r => {},
160
- :s => [],
161
- },
162
- :t => [
163
- {
164
- :u => :v,
165
- :w => :x,
166
- },
167
- ],
168
- :w => {
169
- :x => {
170
- :y => :z,
171
- },
172
- },
173
- }
174
-
175
- s = Quix::HashStruct.recursive_new(hash)
176
- assert_equal(s.a.b, :c)
177
- assert_equal(s.a.d, :e)
178
- assert_equal(s.a.f.g, :h)
179
- assert_equal(s.a.f.i, :j)
180
- assert_equal(s.k, :l)
181
- assert_equal(s.m, [:n, :o, :p])
182
- assert_equal(s.q.r, OpenStruct.new)
183
- assert_equal(s.q.s, [])
184
- assert_equal(s.t, [{ :u => :v, :w => :x }])
185
- assert_equal(s.w.x.y, :z)
186
- end
187
- end