pure 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/CHANGES.rdoc +7 -0
  2. data/MANIFEST +44 -20
  3. data/README.rdoc +553 -16
  4. data/Rakefile +25 -2
  5. data/devel/jumpstart.rb +606 -253
  6. data/install.rb +1 -2
  7. data/lib/pure.rb +38 -16
  8. data/lib/pure/bundled_parsers.rb +4 -0
  9. data/lib/pure/bundled_plugin.rb +49 -0
  10. data/lib/pure/compiler/ruby_parser.rb +63 -0
  11. data/lib/pure/delegate.rb +16 -0
  12. data/lib/pure/driver.rb +33 -0
  13. data/lib/pure/dsl.rb +2 -0
  14. data/lib/pure/dsl_definition.rb +11 -0
  15. data/lib/pure/error.rb +89 -0
  16. data/lib/pure/extracted_functions.rb +11 -0
  17. data/lib/pure/extractor.rb +59 -0
  18. data/lib/pure/names.rb +9 -0
  19. data/lib/pure/native_worker.rb +27 -0
  20. data/lib/pure/parser/impl/base_parser.rb +21 -0
  21. data/lib/pure/parser/impl/internal.rb +31 -0
  22. data/lib/pure/parser/impl/ripper.rb +96 -0
  23. data/lib/pure/parser/impl/ruby_parser.rb +77 -0
  24. data/lib/pure/parser/internal.rb +4 -0
  25. data/lib/pure/parser/ripper.rb +2 -0
  26. data/lib/pure/parser/ruby_parser.rb +2 -0
  27. data/lib/pure/pure.rb +32 -0
  28. data/lib/pure/pure_module.rb +141 -0
  29. data/lib/pure/util.rb +15 -0
  30. data/lib/pure/version.rb +4 -0
  31. data/spec/compiler_ruby_parser_spec.rb +79 -0
  32. data/spec/compute_overrides_spec.rb +99 -0
  33. data/spec/compute_spec.rb +86 -0
  34. data/spec/compute_thread_spec.rb +29 -0
  35. data/spec/compute_timed_spec.rb +40 -0
  36. data/spec/delegate_spec.rb +141 -0
  37. data/spec/fstat_example.rb +26 -0
  38. data/spec/parser_sexp_spec.rb +100 -0
  39. data/spec/parser_spec.rb +18 -31
  40. data/spec/pure_combine_spec.rb +77 -0
  41. data/spec/pure_def_spec.rb +186 -0
  42. data/spec/pure_define_method_spec.rb +24 -0
  43. data/spec/pure_eval_spec.rb +18 -0
  44. data/spec/pure_fun_spec.rb +243 -0
  45. data/spec/pure_nested_spec.rb +35 -0
  46. data/spec/pure_parser_spec.rb +50 -0
  47. data/spec/pure_spec.rb +81 -0
  48. data/spec/pure_spec_base.rb +106 -0
  49. data/spec/pure_splat_spec.rb +18 -0
  50. data/spec/pure_two_defs_spec.rb +20 -0
  51. data/spec/pure_worker_spec.rb +33 -0
  52. data/spec/readme_spec.rb +36 -32
  53. data/spec/splat_spec.rb +12 -11
  54. data/spec/worker_spec.rb +89 -0
  55. metadata +157 -41
  56. data/devel/jumpstart/lazy_attribute.rb +0 -38
  57. data/devel/jumpstart/ruby.rb +0 -44
  58. data/devel/jumpstart/simple_installer.rb +0 -85
  59. data/lib/pure/pure_private/creator.rb +0 -27
  60. data/lib/pure/pure_private/driver.rb +0 -48
  61. data/lib/pure/pure_private/error.rb +0 -32
  62. data/lib/pure/pure_private/extractor.rb +0 -79
  63. data/lib/pure/pure_private/extractor_ripper.rb +0 -95
  64. data/lib/pure/pure_private/extractor_ruby_parser.rb +0 -47
  65. data/lib/pure/pure_private/function_database.rb +0 -10
  66. data/lib/pure/pure_private/singleton_features.rb +0 -67
  67. data/lib/pure/pure_private/util.rb +0 -23
  68. data/spec/basic_spec.rb +0 -38
  69. data/spec/combine_spec.rb +0 -62
  70. data/spec/common.rb +0 -44
  71. data/spec/error_spec.rb +0 -146
  72. data/spec/fun_spec.rb +0 -122
  73. data/spec/lazy_spec.rb +0 -22
  74. data/spec/subseqent_spec.rb +0 -42
  75. data/spec/timed_spec.rb +0 -30
@@ -0,0 +1,89 @@
1
+ require File.dirname(__FILE__) + '/pure_spec_base'
2
+
3
+ require 'thread'
4
+
5
+ def create_worker
6
+ memo = Array.new
7
+ mutex = Mutex.new
8
+
9
+ worker = Class.new do
10
+ define_method :define_function_begin do |pure_mod, num_parallel|
11
+ memo.push [:begin, pure_mod, num_parallel]
12
+ end
13
+
14
+ define_method :define_function do |*args|
15
+ lambda { |*a|
16
+ mutex.synchronize {
17
+ memo.push args
18
+ }
19
+ }
20
+ end
21
+
22
+ define_method :define_function_end do
23
+ memo.push :end
24
+ end
25
+
26
+ def num_parallel
27
+ 3
28
+ end
29
+ end
30
+
31
+ mod = pure do
32
+ def f(x)
33
+ 33
34
+ end
35
+ def x
36
+ 9
37
+ end
38
+ end
39
+
40
+ [worker, mod, memo]
41
+ end
42
+
43
+ def check_function_specs(mod, memo, num_parallel)
44
+ memo[0].should eql([:begin, mod, num_parallel])
45
+ memo[1].should eql(:end)
46
+
47
+ memo[2].should be_a(Array)
48
+ memo[2].size.should eql(1)
49
+ memo[2][0].should be_a(Hash)
50
+
51
+ memo[3].should be_a(Array)
52
+ memo[3].size.should eql(1)
53
+ memo[3][0].should be_a(Hash)
54
+
55
+ names = [memo[2][0][:name], memo[3][0][:name]]
56
+ names.map { |t| t.to_s }.sort.should eql(["f", "x"])
57
+ f_index = 2 + names.index(:f)
58
+ x_index = 2 + names.index(:x)
59
+
60
+ memo[x_index][0][:origin].should eql(:def)
61
+ memo[x_index][0][:name].should eql(:x)
62
+ memo[x_index][0][:args].should eql([])
63
+
64
+ memo[f_index][0][:origin].should eql(:def)
65
+ memo[f_index][0][:name].should eql(:f)
66
+ memo[f_index][0][:args].should eql([:x])
67
+ end
68
+
69
+ describe "worker" do
70
+ it "should be given function specs" do
71
+ worker, mod, memo = create_worker
72
+ Pure.worker.object_id.should_not eql(worker.object_id)
73
+ mod.compute(worker).f
74
+ Pure.worker.object_id.should_not eql(worker.object_id)
75
+ check_function_specs(mod, memo, nil)
76
+ end
77
+
78
+ it "should be given num_parallel hint" do
79
+ worker, mod, memo = create_worker
80
+ previous = Pure.worker
81
+ Pure.worker = worker
82
+ begin
83
+ mod.compute(11).f
84
+ check_function_specs(mod, memo, 11)
85
+ ensure
86
+ Pure.worker = previous
87
+ end
88
+ end
89
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pure
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James M. Lawrence
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-21 00:00:00 -04:00
12
+ date: 2009-10-22 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,9 +20,39 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 0.7.6
23
+ version: 1.0.0
24
24
  version:
25
- description: +Pure+ is an importation of the pure functional paradigm into Ruby.
25
+ - !ruby/object:Gem::Dependency
26
+ name: ruby_parser
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.4
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: ruby2ruby
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.2.2
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: rspec
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 1.2.6
54
+ version:
55
+ description: Pure imports aspects of the pure functional paradigm into Ruby.
26
56
  email:
27
57
  - quixoticsycophant@gmail.com
28
58
  executables: []
@@ -33,37 +63,63 @@ extra_rdoc_files:
33
63
  - README.rdoc
34
64
  files:
35
65
  - CHANGES.rdoc
36
- - MANIFEST
37
66
  - README.rdoc
38
67
  - Rakefile
39
68
  - devel/jumpstart.rb
40
- - devel/jumpstart/lazy_attribute.rb
41
- - devel/jumpstart/ruby.rb
42
- - devel/jumpstart/simple_installer.rb
43
69
  - install.rb
44
70
  - lib/pure.rb
45
- - lib/pure/pure_private/creator.rb
46
- - lib/pure/pure_private/driver.rb
47
- - lib/pure/pure_private/error.rb
48
- - lib/pure/pure_private/extractor.rb
49
- - lib/pure/pure_private/extractor_ripper.rb
50
- - lib/pure/pure_private/extractor_ruby_parser.rb
51
- - lib/pure/pure_private/function_database.rb
52
- - lib/pure/pure_private/singleton_features.rb
53
- - lib/pure/pure_private/util.rb
54
- - spec/basic_spec.rb
55
- - spec/combine_spec.rb
56
- - spec/common.rb
57
- - spec/error_spec.rb
58
- - spec/fun_spec.rb
59
- - spec/lazy_spec.rb
71
+ - lib/pure/bundled_parsers.rb
72
+ - lib/pure/bundled_plugin.rb
73
+ - lib/pure/compiler/ruby_parser.rb
74
+ - lib/pure/delegate.rb
75
+ - lib/pure/driver.rb
76
+ - lib/pure/dsl.rb
77
+ - lib/pure/dsl_definition.rb
78
+ - lib/pure/error.rb
79
+ - lib/pure/extracted_functions.rb
80
+ - lib/pure/extractor.rb
81
+ - lib/pure/names.rb
82
+ - lib/pure/native_worker.rb
83
+ - lib/pure/parser/impl/base_parser.rb
84
+ - lib/pure/parser/impl/internal.rb
85
+ - lib/pure/parser/impl/ripper.rb
86
+ - lib/pure/parser/impl/ruby_parser.rb
87
+ - lib/pure/parser/internal.rb
88
+ - lib/pure/parser/ripper.rb
89
+ - lib/pure/parser/ruby_parser.rb
90
+ - lib/pure/pure.rb
91
+ - lib/pure/pure_module.rb
92
+ - lib/pure/util.rb
93
+ - lib/pure/version.rb
94
+ - spec/compiler_ruby_parser_spec.rb
95
+ - spec/compute_overrides_spec.rb
96
+ - spec/compute_spec.rb
97
+ - spec/compute_thread_spec.rb
98
+ - spec/compute_timed_spec.rb
99
+ - spec/delegate_spec.rb
100
+ - spec/fstat_example.rb
101
+ - spec/parser_sexp_spec.rb
60
102
  - spec/parser_spec.rb
103
+ - spec/pure_combine_spec.rb
104
+ - spec/pure_def_spec.rb
105
+ - spec/pure_define_method_spec.rb
106
+ - spec/pure_eval_spec.rb
107
+ - spec/pure_fun_spec.rb
108
+ - spec/pure_nested_spec.rb
109
+ - spec/pure_parser_spec.rb
110
+ - spec/pure_spec.rb
111
+ - spec/pure_spec_base.rb
112
+ - spec/pure_splat_spec.rb
113
+ - spec/pure_two_defs_spec.rb
114
+ - spec/pure_worker_spec.rb
61
115
  - spec/readme_spec.rb
62
116
  - spec/splat_spec.rb
63
- - spec/subseqent_spec.rb
64
- - spec/timed_spec.rb
117
+ - spec/worker_spec.rb
118
+ - MANIFEST
65
119
  has_rdoc: true
66
120
  homepage: http://purefunctional.rubyforge.org
121
+ licenses: []
122
+
67
123
  post_install_message:
68
124
  rdoc_options:
69
125
  - --main
@@ -73,43 +129,103 @@ rdoc_options:
73
129
  - --exclude
74
130
  - CHANGES.rdoc
75
131
  - --exclude
76
- - MANIFEST
77
- - --exclude
78
132
  - README.rdoc
79
133
  - --exclude
80
134
  - Rakefile
81
135
  - --exclude
82
136
  - devel/jumpstart.rb
83
137
  - --exclude
84
- - devel/jumpstart/lazy_attribute.rb
138
+ - install.rb
85
139
  - --exclude
86
- - devel/jumpstart/ruby.rb
140
+ - lib/pure.rb
87
141
  - --exclude
88
- - devel/jumpstart/simple_installer.rb
142
+ - lib/pure/bundled_parsers.rb
89
143
  - --exclude
90
- - install.rb
144
+ - lib/pure/bundled_plugin.rb
145
+ - --exclude
146
+ - lib/pure/compiler/ruby_parser.rb
91
147
  - --exclude
92
- - spec/basic_spec.rb
148
+ - lib/pure/delegate.rb
93
149
  - --exclude
94
- - spec/combine_spec.rb
150
+ - lib/pure/driver.rb
95
151
  - --exclude
96
- - spec/common.rb
152
+ - lib/pure/error.rb
97
153
  - --exclude
98
- - spec/error_spec.rb
154
+ - lib/pure/extracted_functions.rb
99
155
  - --exclude
100
- - spec/fun_spec.rb
156
+ - lib/pure/extractor.rb
101
157
  - --exclude
102
- - spec/lazy_spec.rb
158
+ - lib/pure/names.rb
159
+ - --exclude
160
+ - lib/pure/native_worker.rb
161
+ - --exclude
162
+ - lib/pure/parser/impl/base_parser.rb
163
+ - --exclude
164
+ - lib/pure/parser/impl/internal.rb
165
+ - --exclude
166
+ - lib/pure/parser/impl/ripper.rb
167
+ - --exclude
168
+ - lib/pure/parser/impl/ruby_parser.rb
169
+ - --exclude
170
+ - lib/pure/parser/internal.rb
171
+ - --exclude
172
+ - lib/pure/parser/ripper.rb
173
+ - --exclude
174
+ - lib/pure/parser/ruby_parser.rb
175
+ - --exclude
176
+ - lib/pure/util.rb
177
+ - --exclude
178
+ - lib/pure/version.rb
179
+ - --exclude
180
+ - spec/compiler_ruby_parser_spec.rb
181
+ - --exclude
182
+ - spec/compute_overrides_spec.rb
183
+ - --exclude
184
+ - spec/compute_spec.rb
185
+ - --exclude
186
+ - spec/compute_thread_spec.rb
187
+ - --exclude
188
+ - spec/compute_timed_spec.rb
189
+ - --exclude
190
+ - spec/delegate_spec.rb
191
+ - --exclude
192
+ - spec/fstat_example.rb
193
+ - --exclude
194
+ - spec/parser_sexp_spec.rb
103
195
  - --exclude
104
196
  - spec/parser_spec.rb
105
197
  - --exclude
198
+ - spec/pure_combine_spec.rb
199
+ - --exclude
200
+ - spec/pure_def_spec.rb
201
+ - --exclude
202
+ - spec/pure_define_method_spec.rb
203
+ - --exclude
204
+ - spec/pure_eval_spec.rb
205
+ - --exclude
206
+ - spec/pure_fun_spec.rb
207
+ - --exclude
208
+ - spec/pure_nested_spec.rb
209
+ - --exclude
210
+ - spec/pure_parser_spec.rb
211
+ - --exclude
212
+ - spec/pure_spec.rb
213
+ - --exclude
214
+ - spec/pure_spec_base.rb
215
+ - --exclude
216
+ - spec/pure_splat_spec.rb
217
+ - --exclude
218
+ - spec/pure_two_defs_spec.rb
219
+ - --exclude
220
+ - spec/pure_worker_spec.rb
221
+ - --exclude
106
222
  - spec/readme_spec.rb
107
223
  - --exclude
108
224
  - spec/splat_spec.rb
109
225
  - --exclude
110
- - spec/subseqent_spec.rb
226
+ - spec/worker_spec.rb
111
227
  - --exclude
112
- - spec/timed_spec.rb
228
+ - MANIFEST
113
229
  require_paths:
114
230
  - lib
115
231
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -127,9 +243,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
243
  requirements: []
128
244
 
129
245
  rubyforge_project: purefunctional
130
- rubygems_version: 1.3.1
246
+ rubygems_version: 1.3.5
131
247
  signing_key:
132
- specification_version: 2
248
+ specification_version: 3
133
249
  summary: Language-level support for automatic parallelism and lazy evaluation.
134
250
  test_files: []
135
251
 
@@ -1,38 +0,0 @@
1
-
2
- class Jumpstart
3
- #
4
- # Mixin for lazily-evaluated attributes.
5
- #
6
- module LazyAttribute
7
- #
8
- # &block is evaluated when this attribute is requested. The same
9
- # result is returned for subsequent calls until the attribute is
10
- # assigned a different value.
11
- #
12
- def attribute(reader, &block)
13
- writer = "#{reader}="
14
-
15
- singleton = (class << self ; self ; end)
16
-
17
- define_evaluated_reader = lambda { |value|
18
- singleton.class_eval {
19
- remove_method(reader)
20
- define_method(reader) { value }
21
- }
22
- }
23
-
24
- singleton.class_eval {
25
- define_method(reader) {
26
- value = block.call
27
- define_evaluated_reader.call(value)
28
- value
29
- }
30
-
31
- define_method(writer) { |value|
32
- define_evaluated_reader.call(value)
33
- value
34
- }
35
- }
36
- end
37
- end
38
- end
@@ -1,44 +0,0 @@
1
-
2
- require 'rbconfig'
3
-
4
- class Jumpstart
5
- module Ruby
6
- EXECUTABLE = lambda {
7
- name = File.join(
8
- Config::CONFIG["bindir"],
9
- Config::CONFIG["RUBY_INSTALL_NAME"]
10
- )
11
-
12
- if Config::CONFIG["host"] =~ %r!(mswin|cygwin|mingw)! and
13
- File.basename(name) !~ %r!\.(exe|com|bat|cmd)\Z!i
14
- name + Config::CONFIG["EXEEXT"]
15
- else
16
- name
17
- end
18
- }.call
19
-
20
- class << self
21
- def run(*args)
22
- cmd = [EXECUTABLE, *args]
23
- unless system(*cmd)
24
- cmd_str = cmd.map { |t| "'#{t}'" }.join(", ")
25
- raise "system(#{cmd_str}) failed with status #{$?.exitstatus}"
26
- end
27
- end
28
-
29
- def with_warnings(value = true)
30
- previous = $VERBOSE
31
- $VERBOSE = value
32
- begin
33
- yield
34
- ensure
35
- $VERBOSE = previous
36
- end
37
- end
38
-
39
- def no_warnings(&block)
40
- with_warnings(false, &block)
41
- end
42
- end
43
- end
44
- end
@@ -1,85 +0,0 @@
1
-
2
- require 'rbconfig'
3
- require 'fileutils'
4
- require 'find'
5
-
6
- class Jumpstart
7
- class SimpleInstaller
8
- def initialize
9
- dest_root = Config::CONFIG["sitelibdir"]
10
- sources = []
11
- Find.find("./lib") { |source|
12
- if install_file?(source)
13
- sources << source
14
- end
15
- }
16
- @spec = sources.inject(Array.new) { |acc, source|
17
- if source == "./lib"
18
- acc
19
- else
20
- dest = File.join(dest_root, source.sub(%r!\A\./lib!, ""))
21
-
22
- install = lambda {
23
- if File.directory?(source)
24
- unless File.directory?(dest)
25
- puts "mkdir #{dest}"
26
- FileUtils.mkdir(dest)
27
- end
28
- else
29
- puts "install #{source} --> #{dest}"
30
- FileUtils.install(source, dest)
31
- end
32
- }
33
-
34
- uninstall = lambda {
35
- if File.directory?(source)
36
- if File.directory?(dest)
37
- puts "rmdir #{dest}"
38
- FileUtils.rmdir(dest)
39
- end
40
- else
41
- if File.file?(dest)
42
- puts "rm #{dest}"
43
- FileUtils.rm(dest)
44
- end
45
- end
46
- }
47
-
48
- acc << {
49
- :source => source,
50
- :dest => dest,
51
- :install => install,
52
- :uninstall => uninstall,
53
- }
54
- end
55
- }
56
- end
57
-
58
- def install_file?(source)
59
- File.directory?(source) or
60
- (File.file?(source) and File.extname(source) == ".rb")
61
- end
62
-
63
- def install
64
- @spec.each { |entry|
65
- entry[:install].call
66
- }
67
- end
68
-
69
- def uninstall
70
- @spec.reverse.each { |entry|
71
- entry[:uninstall].call
72
- }
73
- end
74
-
75
- def run(args = ARGV)
76
- if args.empty?
77
- install
78
- elsif args.size == 1 and args.first == "--uninstall"
79
- uninstall
80
- else
81
- raise "unrecognized arguments: #{args.inspect}"
82
- end
83
- end
84
- end
85
- end