crystalizer 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. data/Changelog +27 -0
  2. data/README +79 -0
  3. data/Rakefile +24 -0
  4. data/TODO +14 -0
  5. data/VERSION +1 -0
  6. data/benchmarks/bench.rb +129 -0
  7. data/benchmarks/concretize_test.rb +26 -0
  8. data/benchmarks/extconf.rb +10 -0
  9. data/benchmarks/tak_rb.rb +7 -0
  10. data/benchmarks/tak_so.rb +7 -0
  11. data/benchmarks/tak_source.rb +16 -0
  12. data/bin/rb2cx +162 -0
  13. data/doc/eval2c.txt +246 -0
  14. data/doc/gen_html.rb +26 -0
  15. data/doc/html_template +10 -0
  16. data/doc/index.txt +169 -0
  17. data/doc/limitations.txt +529 -0
  18. data/doc/optimizations.txt +185 -0
  19. data/doc/rb2cx.txt +130 -0
  20. data/doc/style.css +27 -0
  21. data/lib/concretizer.rb +3 -0
  22. data/lib/ruby2cext/c_function.rb +617 -0
  23. data/lib/ruby2cext/common_node_comp.rb +1412 -0
  24. data/lib/ruby2cext/compiler.rb +311 -0
  25. data/lib/ruby2cext/concretize.rb +269 -0
  26. data/lib/ruby2cext/error.rb +15 -0
  27. data/lib/ruby2cext/eval2c.rb +126 -0
  28. data/lib/ruby2cext/parser.rb +36 -0
  29. data/lib/ruby2cext/plugin.rb +24 -0
  30. data/lib/ruby2cext/plugins/builtin_methods.rb +817 -0
  31. data/lib/ruby2cext/plugins/cache_call.rb +293 -0
  32. data/lib/ruby2cext/plugins/case_optimize.rb +102 -0
  33. data/lib/ruby2cext/plugins/const_cache.rb +36 -0
  34. data/lib/ruby2cext/plugins/direct_self_call.rb +70 -0
  35. data/lib/ruby2cext/plugins/inline_builtin.rb +797 -0
  36. data/lib/ruby2cext/plugins/inline_methods.rb +68 -0
  37. data/lib/ruby2cext/plugins/ivar_cache.rb +147 -0
  38. data/lib/ruby2cext/plugins/require_include.rb +69 -0
  39. data/lib/ruby2cext/plugins/util.rb +154 -0
  40. data/lib/ruby2cext/plugins/warnings.rb +121 -0
  41. data/lib/ruby2cext/scopes.rb +225 -0
  42. data/lib/ruby2cext/str_to_c_strlit.rb +12 -0
  43. data/lib/ruby2cext/tools.rb +80 -0
  44. data/lib/ruby2cext/version.rb +22 -0
  45. data/results +68 -0
  46. data/setup.rb +1585 -0
  47. data/stuff/builtin_methods.rb +69 -0
  48. data/stuff/builtin_methods_test.rb +37 -0
  49. data/test/bootstrap.rb +10 -0
  50. data/test/causes_crash_all_opts.rb +1165 -0
  51. data/test/eval2c/test_eval2c.rb +37 -0
  52. data/test/temp_17.rb +16 -0
  53. data/test/temp_18.rb +8 -0
  54. data/test/temp_19.rb +8 -0
  55. data/test/temp_2.rb +7 -0
  56. data/test/temp_20.rb +5 -0
  57. data/test/temp_21.rb +161 -0
  58. data/test/temp_22.rb +7 -0
  59. data/test/temp_23.rb +7 -0
  60. data/test/temp_24.rb +219 -0
  61. data/test/temp_25.rb +7 -0
  62. data/test/temp_26.rb +11 -0
  63. data/test/temp_27.rb +11 -0
  64. data/test/temp_28.rb +9 -0
  65. data/test/temp_29.rb +9 -0
  66. data/test/temp_3.rb +0 -0
  67. data/test/temp_30.rb +0 -0
  68. data/test/temp_31.rb +10 -0
  69. data/test/temp_32.rb +10 -0
  70. data/test/temp_33.rb +15 -0
  71. data/test/temp_34.rb +15 -0
  72. data/test/temp_35.rb +7 -0
  73. data/test/temp_36.rb +7 -0
  74. data/test/temp_37.rb +10 -0
  75. data/test/temp_38.rb +10 -0
  76. data/test/temp_39.rb +0 -0
  77. data/test/temp_4.rb +7 -0
  78. data/test/temp_40.rb +50 -0
  79. data/test/temp_41.rb +50 -0
  80. data/test/temp_42.rb +8 -0
  81. data/test/temp_43.rb +8 -0
  82. data/test/temp_44.rb +0 -0
  83. data/test/temp_48.rb +7 -0
  84. data/test/temp_49.rb +7 -0
  85. data/test/temp_5.rb +7 -0
  86. data/test/temp_59.rb +7 -0
  87. data/test/temp_6.rb +7 -0
  88. data/test/temp_60.rb +7 -0
  89. data/test/temp_68.rb +239 -0
  90. data/test/temp_7.rb +7 -0
  91. data/test/temp_70.rb +7 -0
  92. data/test/temp_71.rb +7 -0
  93. data/test/temp_72.rb +13 -0
  94. data/test/temp_73.rb +7 -0
  95. data/test/temp_74.rb +7 -0
  96. data/test/temp_76.rb +7 -0
  97. data/test/temp_77.rb +13 -0
  98. data/test/temp_79.rb +7 -0
  99. data/test/temp_8.rb +14 -0
  100. data/test/temp_81.rb +14 -0
  101. data/test/temp_83.rb +0 -0
  102. data/test/temp_84.rb +7 -0
  103. data/test/temp_85.rb +7 -0
  104. data/test/temp_86.rb +14 -0
  105. data/test/temp_87.rb +7 -0
  106. data/test/temp_88.rb +7 -0
  107. data/test/temp_89.rb +7 -0
  108. data/test/temp_9.rb +14 -0
  109. data/test/temp_90.rb +0 -0
  110. data/test/temp_91.rb +7 -0
  111. data/test/temp_92.rb +7 -0
  112. data/test/temp_93.rb +7 -0
  113. data/test/temp_94.rb +7 -0
  114. data/test/temp_95.rb +7 -0
  115. data/test/temp_96.rb +0 -0
  116. data/test/temp_97.rb +0 -0
  117. data/test/temp_98.rb +7 -0
  118. data/test/temp_99.rb +7 -0
  119. data/test/test_concretize.rb +132 -0
  120. data/test/test_concretize_all.rb +15 -0
  121. data/test/test_crystalize_block.rb +73 -0
  122. data/test/test_files/test.rb +615 -0
  123. data/test/test_files/vmode_test.rb +73 -0
  124. data/test/test_files/warn_test.rb +35 -0
  125. data/test/test_syntax.rb +25 -0
  126. metadata +268 -0
@@ -0,0 +1,37 @@
1
+
2
+ require "ruby2cext/eval2c"
3
+
4
+ $e2c = Ruby2CExtension::Eval2C.new
5
+
6
+ $e2c.toplevel_eval("p __FILE__")
7
+
8
+ 3.times { $e2c.toplevel_eval("p 'hello'") }
9
+
10
+ class A
11
+ $e2c.module_eval(self, %{
12
+ def initialize(x)
13
+ @x = x
14
+ end
15
+ def foo(y)
16
+ @x + y
17
+ end
18
+ })
19
+ end
20
+
21
+ p A.new(5).foo(6)
22
+
23
+ p $e2c.instance_eval("4321", "reverse")
24
+
25
+ p $e2c.compile_to_proc("|a,b| a+b").call(2, 3)
26
+
27
+ class B
28
+ def m1; m2; end
29
+ protected
30
+ def m2; m3; end
31
+ private
32
+ def m3; :m3; end
33
+
34
+ $e2c.compile_methods(self, :m1, :m2, :m3)
35
+ end
36
+
37
+ p B.new.m1
@@ -0,0 +1,16 @@
1
+ # concretize temp file: autogenerated: Tue Nov 10 14:04:09 -0700 2009
2
+ class Object
3
+ public
4
+ def taguri
5
+ if respond_to?(:to_yaml_type) then
6
+ YAML.tagurize(to_yaml_type[(1..-1)])
7
+ else
8
+ return @taguri if (defined? @taguri and @taguri)
9
+ tag = "tag:ruby.yaml.org,2002:object"
10
+ if (self.class.yaml_tag_subclasses? and (not (self.class == YAML.tagged_classes[tag]))) then
11
+ tag = "#{tag}:#{self.class.yaml_tag_class_name}"
12
+ end
13
+ tag
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,8 @@
1
+ # concretize temp file: autogenerated: Tue Nov 10 14:04:10 -0700 2009
2
+ class Object
3
+ public
4
+ def sprint(*args)
5
+ print(*args)
6
+ puts
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # concretize temp file: autogenerated: Tue Nov 10 14:04:10 -0700 2009
2
+ class Object
3
+ public
4
+ def sprint(*args)
5
+ print(*args)
6
+ puts
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
2
+ class F < Object
3
+ public
4
+ def go
5
+ # do nothing
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ # concretize temp file: autogenerated: Tue Nov 10 14:04:10 -0700 2009
2
+ class Object
3
+ public
4
+ attr_writer :taguri
5
+ end
@@ -0,0 +1,161 @@
1
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
2
+ class F < Object
3
+ public
4
+ def go
5
+ # do nothing
6
+ end
7
+ end
8
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
9
+ class Object
10
+ public
11
+ def in?(collection)
12
+ collection.include?(self)
13
+ end
14
+ end
15
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
16
+ class Object
17
+ public
18
+ def to_yaml_style
19
+ # do nothing
20
+ end
21
+ end
22
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
23
+ class Object
24
+ public
25
+ def _dbg
26
+ require("rubygems")
27
+ require("pp")
28
+ begin
29
+ (require("ruby-debug")
30
+ debugger)
31
+ rescue LoadError => e
32
+ throw("unable to load ruby-debug gem for _dbg... #{e}")
33
+ end
34
+ end
35
+ end
36
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
37
+ class Object
38
+ public
39
+ def to_yaml_properties
40
+ instance_variables.sort
41
+ end
42
+ end
43
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
44
+ class Object
45
+ public
46
+ def deep_clone
47
+ Marshal.load(Marshal.dump(self))
48
+ end
49
+ end
50
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
51
+ class Object
52
+ public
53
+ def aliash(hash)
54
+ hash.each_pair { |new, old| alias_method(new, old) }
55
+ end
56
+ end
57
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
58
+ class Object
59
+ public
60
+ def taguri
61
+ if respond_to?(:to_yaml_type) then
62
+ YAML.tagurize(to_yaml_type[(1..-1)])
63
+ else
64
+ return @taguri if (defined? @taguri and @taguri)
65
+ tag = "tag:ruby.yaml.org,2002:object"
66
+ if (self.class.yaml_tag_subclasses? and (not (self.class == YAML.tagged_classes[tag]))) then
67
+ tag = "#{tag}:#{self.class.yaml_tag_class_name}"
68
+ end
69
+ tag
70
+ end
71
+ end
72
+ end
73
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
74
+ class Object
75
+ public
76
+ def sprint(*args)
77
+ print(*args)
78
+ puts
79
+ end
80
+ end
81
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
82
+ class Object
83
+ public
84
+ attr_writer :taguri
85
+ end
86
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
87
+ class Object
88
+ public
89
+ def concretize_ruby!
90
+ Ruby2CExtension::Concretize.concretize_all!
91
+ end
92
+ end
93
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
94
+ class Object
95
+ public
96
+ def assert(should_be_true, string = nil)
97
+ raise("assertion failed #{string}") unless should_be_true
98
+ end
99
+ end
100
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
101
+ class Object
102
+ public
103
+ def to_yaml(opts = { })
104
+ YAML.quick_emit(self, opts) do |out|
105
+ out.map(taguri, to_yaml_style) do |map|
106
+ to_yaml_properties.each { |m| map.add(m[(1..-1)], instance_variable_get(m)) }
107
+ end
108
+ end
109
+ end
110
+ end
111
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
112
+ class Object
113
+ public
114
+ def singleton_class
115
+ class << self
116
+ self
117
+ end
118
+ end
119
+ end
120
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:30 -0700 2009
121
+ module PP::ObjectMixin
122
+ public
123
+ def pretty_print_cycle(q)
124
+ q.object_address_group(self) do
125
+ q.breakable
126
+ q.text("...")
127
+ end
128
+ end
129
+ end
130
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:30 -0700 2009
131
+ module PP::ObjectMixin
132
+ public
133
+ def pretty_print(q)
134
+ if /\(Kernel\)#/ =~ method(:inspect).inspect then
135
+ if ((not /\(Kernel\)#/ =~ method(:to_s).inspect) and instance_variables.empty?) then
136
+ q.text(self.to_s)
137
+ else
138
+ q.pp_object(self)
139
+ end
140
+ else
141
+ q.text(self.inspect)
142
+ end
143
+ end
144
+ end
145
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:30 -0700 2009
146
+ module PP::ObjectMixin
147
+ public
148
+ def pretty_print_instance_variables
149
+ instance_variables.sort
150
+ end
151
+ end
152
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:30 -0700 2009
153
+ module PP::ObjectMixin
154
+ public
155
+ def pretty_print_inspect
156
+ if /\(PP::ObjectMixin\)#/ =~ method(:pretty_print).inspect then
157
+ raise("pretty_print is not overridden for #{self.class}")
158
+ end
159
+ PP.singleline_pp(self, "")
160
+ end
161
+ end
@@ -0,0 +1,7 @@
1
+ # concretize temp file: autogenerated: Tue Nov 10 14:04:11 -0700 2009
2
+ class Object
3
+ public
4
+ def concretize_ruby!
5
+ Ruby2CExtension::Concretize.concretize_all!
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # concretize temp file: autogenerated: Tue Nov 10 14:04:11 -0700 2009
2
+ class Object
3
+ public
4
+ def concretize_ruby!
5
+ Ruby2CExtension::Concretize.concretize_all!
6
+ end
7
+ end
@@ -0,0 +1,219 @@
1
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
2
+ class F < Object
3
+ public
4
+ def go
5
+ # do nothing
6
+ end
7
+ end
8
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
9
+ class Object
10
+ public
11
+ def in?(collection)
12
+ collection.include?(self)
13
+ end
14
+ end
15
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
16
+ class Object
17
+ public
18
+ def to_yaml_style
19
+ # do nothing
20
+ end
21
+ end
22
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
23
+ class Object
24
+ public
25
+ def _dbg
26
+ require("rubygems")
27
+ require("pp")
28
+ begin
29
+ (require("ruby-debug")
30
+ debugger)
31
+ rescue LoadError => e
32
+ throw("unable to load ruby-debug gem for _dbg... #{e}")
33
+ end
34
+ end
35
+ end
36
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
37
+ class Object
38
+ public
39
+ def to_yaml_properties
40
+ instance_variables.sort
41
+ end
42
+ end
43
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
44
+ class Object
45
+ public
46
+ def deep_clone
47
+ Marshal.load(Marshal.dump(self))
48
+ end
49
+ end
50
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
51
+ class Object
52
+ public
53
+ def aliash(hash)
54
+ hash.each_pair { |new, old| alias_method(new, old) }
55
+ end
56
+ end
57
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
58
+ class Object
59
+ public
60
+ def taguri
61
+ if respond_to?(:to_yaml_type) then
62
+ YAML.tagurize(to_yaml_type[(1..-1)])
63
+ else
64
+ return @taguri if (defined? @taguri and @taguri)
65
+ tag = "tag:ruby.yaml.org,2002:object"
66
+ if (self.class.yaml_tag_subclasses? and (not (self.class == YAML.tagged_classes[tag]))) then
67
+ tag = "#{tag}:#{self.class.yaml_tag_class_name}"
68
+ end
69
+ tag
70
+ end
71
+ end
72
+ end
73
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
74
+ class Object
75
+ public
76
+ def sprint(*args)
77
+ print(*args)
78
+ puts
79
+ end
80
+ end
81
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
82
+ class Object
83
+ public
84
+ attr_writer :taguri
85
+ end
86
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
87
+ class Object
88
+ public
89
+ def concretize_ruby!
90
+ Ruby2CExtension::Concretize.concretize_all!
91
+ end
92
+ end
93
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
94
+ class Object
95
+ public
96
+ def assert(should_be_true, string = nil)
97
+ raise("assertion failed #{string}") unless should_be_true
98
+ end
99
+ end
100
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
101
+ class Object
102
+ public
103
+ def to_yaml(opts = { })
104
+ YAML.quick_emit(self, opts) do |out|
105
+ out.map(taguri, to_yaml_style) do |map|
106
+ to_yaml_properties.each { |m| map.add(m[(1..-1)], instance_variable_get(m)) }
107
+ end
108
+ end
109
+ end
110
+ end
111
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:29 -0700 2009
112
+ class Object
113
+ public
114
+ def singleton_class
115
+ class << self
116
+ self
117
+ end
118
+ end
119
+ end
120
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:30 -0700 2009
121
+ module PP::ObjectMixin
122
+ public
123
+ def pretty_print_cycle(q)
124
+ q.object_address_group(self) do
125
+ q.breakable
126
+ q.text("...")
127
+ end
128
+ end
129
+ end
130
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:30 -0700 2009
131
+ module PP::ObjectMixin
132
+ public
133
+ def pretty_print(q)
134
+ if /\(Kernel\)#/ =~ method(:inspect).inspect then
135
+ if ((not /\(Kernel\)#/ =~ method(:to_s).inspect) and instance_variables.empty?) then
136
+ q.text(self.to_s)
137
+ else
138
+ q.pp_object(self)
139
+ end
140
+ else
141
+ q.text(self.inspect)
142
+ end
143
+ end
144
+ end
145
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:30 -0700 2009
146
+ module PP::ObjectMixin
147
+ public
148
+ def pretty_print_instance_variables
149
+ instance_variables.sort
150
+ end
151
+ end
152
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:30 -0700 2009
153
+ module PP::ObjectMixin
154
+ public
155
+ def pretty_print_inspect
156
+ if /\(PP::ObjectMixin\)#/ =~ method(:pretty_print).inspect then
157
+ raise("pretty_print is not overridden for #{self.class}")
158
+ end
159
+ PP.singleline_pp(self, "")
160
+ end
161
+ end
162
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:32 -0700 2009
163
+ module RequireAll
164
+ public
165
+ def require_all(*args)
166
+ args = args.flatten
167
+ if (args.size > 1) then
168
+ files = args
169
+ else
170
+ arg = args.first
171
+ begin
172
+ (stat = File.stat(arg)
173
+ if stat.file? then
174
+ files = [arg]
175
+ else
176
+ if stat.directory? then
177
+ files = Dir.glob(File.join(arg, "**", "*.rb"))
178
+ else
179
+ raise(ArgumentError, "#{arg} isn't a file or directory")
180
+ end
181
+ end)
182
+ rescue Errno::ENOENT
183
+ files = Dir.glob(arg)
184
+ if File.file?((arg + ".rb")) then
185
+ require((arg + ".rb"))
186
+ return true
187
+ end
188
+ raise(LoadError, "no such file to load -- #{arg}") if files.empty?
189
+ end
190
+ end
191
+ files.map! { |file| File.expand_path(file) }
192
+ begin
193
+ (failed = []
194
+ first_name_error = nil
195
+ files.each do |file|
196
+ begin
197
+ require(file)
198
+ rescue NameError => ex
199
+ (failed << file)
200
+ first_name_error ||= ex
201
+ rescue ArgumentError => ex
202
+ raise unless ex.message["is not missing constant"]
203
+ STDERR.puts("Warning: require_all swallowed ActiveSupport 'is not missing constant' error")
204
+ STDERR.puts(ex.backtrace[(0..9)])
205
+ end
206
+ end
207
+ (failed.size == files.size) ? (raise(first_name_error)) : (files = failed))
208
+ end until failed.empty?
209
+ true
210
+ end
211
+ end
212
+ # concretize temp file: autogenerated: Tue Nov 10 14:15:32 -0700 2009
213
+ module RequireAll
214
+ public
215
+ def require_rel(path)
216
+ source_directory = File.dirname(caller.first.sub(/:\d+$/, ""))
217
+ require_all(File.join(source_directory, path))
218
+ end
219
+ end