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.
- data/Changelog +27 -0
- data/README +79 -0
- data/Rakefile +24 -0
- data/TODO +14 -0
- data/VERSION +1 -0
- data/benchmarks/bench.rb +129 -0
- data/benchmarks/concretize_test.rb +26 -0
- data/benchmarks/extconf.rb +10 -0
- data/benchmarks/tak_rb.rb +7 -0
- data/benchmarks/tak_so.rb +7 -0
- data/benchmarks/tak_source.rb +16 -0
- data/bin/rb2cx +162 -0
- data/doc/eval2c.txt +246 -0
- data/doc/gen_html.rb +26 -0
- data/doc/html_template +10 -0
- data/doc/index.txt +169 -0
- data/doc/limitations.txt +529 -0
- data/doc/optimizations.txt +185 -0
- data/doc/rb2cx.txt +130 -0
- data/doc/style.css +27 -0
- data/lib/concretizer.rb +3 -0
- data/lib/ruby2cext/c_function.rb +617 -0
- data/lib/ruby2cext/common_node_comp.rb +1412 -0
- data/lib/ruby2cext/compiler.rb +311 -0
- data/lib/ruby2cext/concretize.rb +269 -0
- data/lib/ruby2cext/error.rb +15 -0
- data/lib/ruby2cext/eval2c.rb +126 -0
- data/lib/ruby2cext/parser.rb +36 -0
- data/lib/ruby2cext/plugin.rb +24 -0
- data/lib/ruby2cext/plugins/builtin_methods.rb +817 -0
- data/lib/ruby2cext/plugins/cache_call.rb +293 -0
- data/lib/ruby2cext/plugins/case_optimize.rb +102 -0
- data/lib/ruby2cext/plugins/const_cache.rb +36 -0
- data/lib/ruby2cext/plugins/direct_self_call.rb +70 -0
- data/lib/ruby2cext/plugins/inline_builtin.rb +797 -0
- data/lib/ruby2cext/plugins/inline_methods.rb +68 -0
- data/lib/ruby2cext/plugins/ivar_cache.rb +147 -0
- data/lib/ruby2cext/plugins/require_include.rb +69 -0
- data/lib/ruby2cext/plugins/util.rb +154 -0
- data/lib/ruby2cext/plugins/warnings.rb +121 -0
- data/lib/ruby2cext/scopes.rb +225 -0
- data/lib/ruby2cext/str_to_c_strlit.rb +12 -0
- data/lib/ruby2cext/tools.rb +80 -0
- data/lib/ruby2cext/version.rb +22 -0
- data/results +68 -0
- data/setup.rb +1585 -0
- data/stuff/builtin_methods.rb +69 -0
- data/stuff/builtin_methods_test.rb +37 -0
- data/test/bootstrap.rb +10 -0
- data/test/causes_crash_all_opts.rb +1165 -0
- data/test/eval2c/test_eval2c.rb +37 -0
- data/test/temp_17.rb +16 -0
- data/test/temp_18.rb +8 -0
- data/test/temp_19.rb +8 -0
- data/test/temp_2.rb +7 -0
- data/test/temp_20.rb +5 -0
- data/test/temp_21.rb +161 -0
- data/test/temp_22.rb +7 -0
- data/test/temp_23.rb +7 -0
- data/test/temp_24.rb +219 -0
- data/test/temp_25.rb +7 -0
- data/test/temp_26.rb +11 -0
- data/test/temp_27.rb +11 -0
- data/test/temp_28.rb +9 -0
- data/test/temp_29.rb +9 -0
- data/test/temp_3.rb +0 -0
- data/test/temp_30.rb +0 -0
- data/test/temp_31.rb +10 -0
- data/test/temp_32.rb +10 -0
- data/test/temp_33.rb +15 -0
- data/test/temp_34.rb +15 -0
- data/test/temp_35.rb +7 -0
- data/test/temp_36.rb +7 -0
- data/test/temp_37.rb +10 -0
- data/test/temp_38.rb +10 -0
- data/test/temp_39.rb +0 -0
- data/test/temp_4.rb +7 -0
- data/test/temp_40.rb +50 -0
- data/test/temp_41.rb +50 -0
- data/test/temp_42.rb +8 -0
- data/test/temp_43.rb +8 -0
- data/test/temp_44.rb +0 -0
- data/test/temp_48.rb +7 -0
- data/test/temp_49.rb +7 -0
- data/test/temp_5.rb +7 -0
- data/test/temp_59.rb +7 -0
- data/test/temp_6.rb +7 -0
- data/test/temp_60.rb +7 -0
- data/test/temp_68.rb +239 -0
- data/test/temp_7.rb +7 -0
- data/test/temp_70.rb +7 -0
- data/test/temp_71.rb +7 -0
- data/test/temp_72.rb +13 -0
- data/test/temp_73.rb +7 -0
- data/test/temp_74.rb +7 -0
- data/test/temp_76.rb +7 -0
- data/test/temp_77.rb +13 -0
- data/test/temp_79.rb +7 -0
- data/test/temp_8.rb +14 -0
- data/test/temp_81.rb +14 -0
- data/test/temp_83.rb +0 -0
- data/test/temp_84.rb +7 -0
- data/test/temp_85.rb +7 -0
- data/test/temp_86.rb +14 -0
- data/test/temp_87.rb +7 -0
- data/test/temp_88.rb +7 -0
- data/test/temp_89.rb +7 -0
- data/test/temp_9.rb +14 -0
- data/test/temp_90.rb +0 -0
- data/test/temp_91.rb +7 -0
- data/test/temp_92.rb +7 -0
- data/test/temp_93.rb +7 -0
- data/test/temp_94.rb +7 -0
- data/test/temp_95.rb +7 -0
- data/test/temp_96.rb +0 -0
- data/test/temp_97.rb +0 -0
- data/test/temp_98.rb +7 -0
- data/test/temp_99.rb +7 -0
- data/test/test_concretize.rb +132 -0
- data/test/test_concretize_all.rb +15 -0
- data/test/test_crystalize_block.rb +73 -0
- data/test/test_files/test.rb +615 -0
- data/test/test_files/vmode_test.rb +73 -0
- data/test/test_files/warn_test.rb +35 -0
- data/test/test_syntax.rb +25 -0
- metadata +268 -0
data/test/temp_7.rb
ADDED
data/test/temp_70.rb
ADDED
data/test/temp_71.rb
ADDED
data/test/temp_72.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# concretize temp file: autogenerated: Tue Nov 10 13:59:16 -0700 2009
|
2
|
+
module Kernel
|
3
|
+
public
|
4
|
+
def __DIR__
|
5
|
+
dir = if /^(.+)?:\d+/ =~ caller[0] then
|
6
|
+
File.expand_path(File.dirname($1), BASE_DIR)
|
7
|
+
else
|
8
|
+
nil
|
9
|
+
end
|
10
|
+
dir = (dir + "/") if dir
|
11
|
+
dir
|
12
|
+
end
|
13
|
+
end
|
data/test/temp_73.rb
ADDED
data/test/temp_74.rb
ADDED
data/test/temp_76.rb
ADDED
data/test/temp_77.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# concretize temp file: autogenerated: Tue Nov 10 14:03:45 -0700 2009
|
2
|
+
module Kernel
|
3
|
+
public
|
4
|
+
def __DIR__
|
5
|
+
dir = if /^(.+)?:\d+/ =~ caller[0] then
|
6
|
+
File.expand_path(File.dirname($1), BASE_DIR)
|
7
|
+
else
|
8
|
+
nil
|
9
|
+
end
|
10
|
+
dir = (dir + "/") if dir
|
11
|
+
dir
|
12
|
+
end
|
13
|
+
end
|
data/test/temp_79.rb
ADDED
data/test/temp_8.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# concretize temp file: autogenerated: Tue Nov 10 14:11:00 -0700 2009
|
2
|
+
class Object
|
3
|
+
public
|
4
|
+
def _dbg
|
5
|
+
require("rubygems")
|
6
|
+
require("pp")
|
7
|
+
begin
|
8
|
+
(require("ruby-debug")
|
9
|
+
debugger)
|
10
|
+
rescue LoadError => e
|
11
|
+
throw("unable to load ruby-debug gem for _dbg... #{e}")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/test/temp_81.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# concretize temp file: autogenerated: Tue Nov 10 14:15:39 -0700 2009
|
2
|
+
class Child < Parent
|
3
|
+
public
|
4
|
+
def go
|
5
|
+
# do nothing
|
6
|
+
end
|
7
|
+
end
|
8
|
+
# concretize temp file: autogenerated: Tue Nov 10 14:15:39 -0700 2009
|
9
|
+
class Parent < Object
|
10
|
+
public
|
11
|
+
def go_parent
|
12
|
+
# do nothing
|
13
|
+
end
|
14
|
+
end
|
data/test/temp_83.rb
ADDED
File without changes
|
data/test/temp_84.rb
ADDED
data/test/temp_85.rb
ADDED
data/test/temp_86.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# concretize temp file: autogenerated: Tue Nov 10 14:15:40 -0700 2009
|
2
|
+
module M
|
3
|
+
public
|
4
|
+
def method_2
|
5
|
+
# do nothing
|
6
|
+
end
|
7
|
+
end
|
8
|
+
# concretize temp file: autogenerated: Tue Nov 10 14:15:40 -0700 2009
|
9
|
+
module M
|
10
|
+
public
|
11
|
+
def go_m(a)
|
12
|
+
# do nothing
|
13
|
+
end
|
14
|
+
end
|
data/test/temp_87.rb
ADDED
data/test/temp_88.rb
ADDED
data/test/temp_89.rb
ADDED
data/test/temp_9.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# concretize temp file: autogenerated: Tue Nov 10 14:11:00 -0700 2009
|
2
|
+
class Object
|
3
|
+
public
|
4
|
+
def _dbg
|
5
|
+
require("rubygems")
|
6
|
+
require("pp")
|
7
|
+
begin
|
8
|
+
(require("ruby-debug")
|
9
|
+
debugger)
|
10
|
+
rescue LoadError => e
|
11
|
+
throw("unable to load ruby-debug gem for _dbg... #{e}")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/test/temp_90.rb
ADDED
File without changes
|
data/test/temp_91.rb
ADDED
data/test/temp_92.rb
ADDED
data/test/temp_93.rb
ADDED
data/test/temp_94.rb
ADDED
data/test/temp_95.rb
ADDED
data/test/temp_96.rb
ADDED
File without changes
|
data/test/temp_97.rb
ADDED
File without changes
|
data/test/temp_98.rb
ADDED
data/test/temp_99.rb
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/bootstrap'
|
2
|
+
|
3
|
+
class F
|
4
|
+
def go; end
|
5
|
+
end
|
6
|
+
|
7
|
+
F.concretize!
|
8
|
+
assert F.instance_method(:go).arity == -1
|
9
|
+
|
10
|
+
include Ruby2CExtension
|
11
|
+
# TODO retain visibility right (protected...optionally)
|
12
|
+
|
13
|
+
Dir['temp*'].each{|f| File.delete f} rescue nil # LTODO these don't all delete right at the end...can I avoid that tho?
|
14
|
+
|
15
|
+
class A
|
16
|
+
def go a
|
17
|
+
23
|
18
|
+
end
|
19
|
+
end
|
20
|
+
a = A.new
|
21
|
+
start_time = Benchmark.realtime { 1000000.times { a.go 3 }}
|
22
|
+
|
23
|
+
|
24
|
+
# make sure it gets the guts of a method
|
25
|
+
raise unless A.instance_method(:go).arity == 1
|
26
|
+
rb = Concretize.c_ify! A, :go, true
|
27
|
+
raise "bad rb" unless rb.include? "23"
|
28
|
+
raise "bad rb" unless rb.include? "class"
|
29
|
+
|
30
|
+
|
31
|
+
rb = Concretize.c_ify! A, :go
|
32
|
+
raise "should have concretized" unless A.instance_method(:go).arity == -1
|
33
|
+
|
34
|
+
# test: class with one ruby, one C should translate the ruby to C
|
35
|
+
|
36
|
+
class B
|
37
|
+
def go a
|
38
|
+
32
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
assert B.instance_method(:go).arity == 1
|
43
|
+
|
44
|
+
assert Concretize.c_ify_class!(B)
|
45
|
+
assert !Concretize.c_ify_class!(B) # should be all done...
|
46
|
+
|
47
|
+
assert B.instance_method(:go).arity == -1
|
48
|
+
|
49
|
+
|
50
|
+
assert B.public_instance_methods.grep(/go/).length == 1# it should be public...I think
|
51
|
+
|
52
|
+
class DD
|
53
|
+
def go a, b
|
54
|
+
34
|
55
|
+
end
|
56
|
+
end
|
57
|
+
assert DD.instance_method(:go).arity == 2
|
58
|
+
DD.concretize!
|
59
|
+
assert DD.instance_method(:go).arity == -1
|
60
|
+
|
61
|
+
DD.new.go 3, 4 # shouldn't raise :)
|
62
|
+
|
63
|
+
|
64
|
+
# test some ancestry shtuff
|
65
|
+
|
66
|
+
class Parent
|
67
|
+
def go_parent
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class Child < Parent
|
72
|
+
def go
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
assert Child.ancestors[0..1] == [Child, Parent]
|
77
|
+
|
78
|
+
# TODO test: if two descend from real_c_klass normal c_klass they both get all of normal's methods
|
79
|
+
|
80
|
+
ruby = Concretize.c_ify! Child, :go, true
|
81
|
+
assert ruby.include?('Child')
|
82
|
+
assert ruby.include?('< Parent')
|
83
|
+
assert Child.new.respond_to?( :go_parent )
|
84
|
+
assert Child.new.respond_to?( :go )
|
85
|
+
|
86
|
+
Child.concretize!
|
87
|
+
assert Child.ancestors[0..1] == [Child, Parent]
|
88
|
+
|
89
|
+
module M; def go_m a; end;
|
90
|
+
|
91
|
+
def method_2; end
|
92
|
+
end
|
93
|
+
|
94
|
+
class IM; include M;
|
95
|
+
end;
|
96
|
+
|
97
|
+
rubify = Concretize.c_ify! M, :method_2, true
|
98
|
+
assert rubify =~ /module M/
|
99
|
+
assert rubify !~ /</ # can't do module M < something
|
100
|
+
assert rubify =~ /public/
|
101
|
+
|
102
|
+
|
103
|
+
IM.new.go_m 2
|
104
|
+
assert IM.instance_method(:go_m).arity == 1
|
105
|
+
IM.concretize!
|
106
|
+
assert IM.instance_method(:go_m).arity == -1
|
107
|
+
|
108
|
+
|
109
|
+
class Object
|
110
|
+
def should_not_descend
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
rubify = Concretize.c_ify! Object, :should_not_descend, true
|
115
|
+
assert rubify !~ /</ # can't do class Object < something no no
|
116
|
+
assert rubify =~ /public/
|
117
|
+
|
118
|
+
|
119
|
+
class Normal
|
120
|
+
def normal_should_descend
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
rubify = Concretize.c_ify! Normal, :normal_should_descend, true
|
125
|
+
assert rubify =~ /</ # Normal < Object
|
126
|
+
assert rubify =~ /public/
|
127
|
+
|
128
|
+
optimized_time = Benchmark.realtime { 1000000.times { a.go 3 }}
|
129
|
+
|
130
|
+
puts 'started as', start_time, 'optimized as', optimized_time
|
131
|
+
|
132
|
+
puts 'overall concretize success'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/bootstrap'
|
2
|
+
|
3
|
+
class C
|
4
|
+
def go a
|
5
|
+
33
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
include Ruby2CExtension
|
10
|
+
|
11
|
+
assert C.instance_method(:go).arity == 1
|
12
|
+
assert String.instance_method(:to_c_strlit).arity == 0
|
13
|
+
puts 'cified these', Concretize.concretize_all!.inspect
|
14
|
+
assert C.instance_method(:go).arity == -1
|
15
|
+
assert String.instance_method(:to_c_strlit).arity == -1 # this one should have been concretized, too
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'frubygems'
|
2
|
+
require 'sane'
|
3
|
+
require_rel 'bootstrap'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
include Ruby2CExtension
|
7
|
+
|
8
|
+
# test cache
|
9
|
+
times = []
|
10
|
+
2.times { |n|
|
11
|
+
|
12
|
+
# ltodo test that between runs it caches and stores
|
13
|
+
# reset AA's method
|
14
|
+
class AA
|
15
|
+
def go
|
16
|
+
33
|
17
|
+
end
|
18
|
+
end
|
19
|
+
assert AA.instance_method(:go).arity == 0
|
20
|
+
|
21
|
+
start = Time.now
|
22
|
+
|
23
|
+
if n == 0
|
24
|
+
$old = Concretize.good_codes.dup
|
25
|
+
Concretize.good_codes.clear # allow it to do something with the re-concretize
|
26
|
+
Concretize.c_ify! AA, :go, true
|
27
|
+
assert Concretize.cache_hits == 0
|
28
|
+
assert AA.instance_method(:go).arity == -1
|
29
|
+
else
|
30
|
+
Concretize.c_ify! AA, :go, true
|
31
|
+
assert Concretize.cache_hits > 0
|
32
|
+
assert AA.instance_method(:go).arity == 0 # it doesn't run it just returns us the cached value
|
33
|
+
Concretize.good_codes.merge $old # keep it around
|
34
|
+
end
|
35
|
+
|
36
|
+
times << Time.now - start
|
37
|
+
}
|
38
|
+
puts times
|
39
|
+
|
40
|
+
|
41
|
+
# now test crystalize
|
42
|
+
|
43
|
+
class A
|
44
|
+
def go
|
45
|
+
33
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class B
|
50
|
+
def go
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
assert A.instance_method(:go).arity == 0
|
55
|
+
assert B.instance_method(:go).arity == 0
|
56
|
+
# LTODO should [?] not crystalize internal classes?
|
57
|
+
Ruby2CExtension::Concretize.crystalize_after_first_time_through {
|
58
|
+
A.new.go
|
59
|
+
}
|
60
|
+
assert A.instance_method(:go).arity == -1
|
61
|
+
assert B.instance_method(:go).arity == 0 # b should still be 0
|
62
|
+
|
63
|
+
class C
|
64
|
+
def go
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
#Ruby2CExtension::Concretize.crystalize_after
|
69
|
+
#1000000.times { B.new.go }
|
70
|
+
#assert B.instance_method(:go).arity == -1 # should now be -1
|
71
|
+
#assert C.instance_method(:go).arity == 0 # should not have been crystalized
|
72
|
+
|
73
|
+
# TODO should ignore it after first time through...
|