fastruby 0.0.19 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/CHANGELOG +8 -0
  2. data/{README → README.rdoc} +6 -1
  3. data/Rakefile +7 -7
  4. data/benchmarks/benchmark.rb~ +14 -2
  5. data/ext/fastruby_base/fastruby_base.inl +8 -4
  6. data/lib/fastruby/builder/inference_updater.rb +76 -0
  7. data/lib/fastruby/builder/inference_updater.rb~ +76 -0
  8. data/lib/fastruby/builder/inferencer.rb +38 -0
  9. data/lib/fastruby/{inliner → builder}/inliner.rb +16 -27
  10. data/lib/fastruby/builder/inliner.rb~ +60 -0
  11. data/lib/fastruby/builder/locals_inference.rb +53 -0
  12. data/lib/fastruby/builder/lvar_type.rb +43 -0
  13. data/lib/fastruby/builder/lvar_type.rb~ +44 -0
  14. data/lib/fastruby/builder/pipeline.rb +43 -0
  15. data/lib/fastruby/builder/pipeline.rb~ +43 -0
  16. data/lib/fastruby/{reductor → builder}/reductor.rb +6 -3
  17. data/lib/fastruby/builder/reductor.rb~ +42 -0
  18. data/lib/fastruby/builder.rb +73 -25
  19. data/lib/fastruby/builder.rb~ +311 -0
  20. data/lib/fastruby/corelib/fixnum.rb +75 -0
  21. data/lib/fastruby/corelib/fixnum.rb~ +146 -0
  22. data/lib/fastruby/corelib/integer.rb +96 -0
  23. data/lib/fastruby/corelib/integer.rb~ +96 -0
  24. data/lib/fastruby/corelib.rb +23 -0
  25. data/lib/fastruby/corelib.rb~ +23 -0
  26. data/lib/fastruby/getlocals.rb +3 -1
  27. data/lib/fastruby/logging.rb +2 -2
  28. data/lib/fastruby/modules/inferencer/infer.rb +31 -0
  29. data/lib/fastruby/modules/inferencer/literal.rb +42 -0
  30. data/lib/fastruby/modules/inliner/call.rb +327 -0
  31. data/lib/fastruby/{inliner/modules/call.rb → modules/inliner/call.rb~} +14 -24
  32. data/lib/fastruby/modules/inliner/defn.rb +41 -0
  33. data/lib/fastruby/modules/inliner/defn.rb~ +29 -0
  34. data/lib/fastruby/modules/inliner/recursive.rb +40 -0
  35. data/lib/fastruby/{inliner/modules/recursive.rb → modules/inliner/recursive.rb~} +1 -1
  36. data/lib/fastruby/modules/lvar_type/call.rb +36 -0
  37. data/lib/fastruby/modules/lvar_type/call.rb~ +36 -0
  38. data/lib/fastruby/modules/lvar_type/defn.rb +42 -0
  39. data/lib/fastruby/modules/lvar_type/defn.rb~ +42 -0
  40. data/lib/fastruby/modules/lvar_type/lasgn.rb +41 -0
  41. data/lib/fastruby/modules/lvar_type/lasgn.rb~ +42 -0
  42. data/lib/fastruby/modules/lvar_type/recursive.rb +33 -0
  43. data/lib/fastruby/modules/lvar_type/recursive.rb~ +33 -0
  44. data/lib/fastruby/{reductor/modules → modules/reductor}/case.rb +0 -0
  45. data/lib/fastruby/modules/reductor/fastruby_flag.rb +33 -0
  46. data/lib/fastruby/{reductor/modules → modules/reductor}/for.rb +0 -0
  47. data/lib/fastruby/{reductor/modules → modules/reductor}/nontree.rb +0 -0
  48. data/lib/fastruby/modules/reductor/nontree.rb~ +32 -0
  49. data/lib/fastruby/{reductor/modules → modules/reductor}/recursive.rb +1 -1
  50. data/lib/fastruby/modules/reductor/recursive.rb~ +31 -0
  51. data/lib/fastruby/{translator/modules → modules/translator}/block.rb +0 -0
  52. data/lib/fastruby/modules/translator/call.rb +344 -0
  53. data/lib/fastruby/{translator/modules/call.rb → modules/translator/call.rb~} +24 -3
  54. data/lib/fastruby/{translator/modules → modules/translator}/defn.rb +10 -9
  55. data/lib/fastruby/modules/translator/defn.rb~ +267 -0
  56. data/lib/fastruby/{translator/modules → modules/translator}/directive.rb +3 -1
  57. data/lib/fastruby/modules/translator/directive.rb~ +44 -0
  58. data/lib/fastruby/{translator/modules → modules/translator}/exceptions.rb +3 -1
  59. data/lib/fastruby/modules/translator/exceptions.rb~ +120 -0
  60. data/lib/fastruby/{translator/modules → modules/translator}/flow.rb +0 -0
  61. data/lib/fastruby/modules/translator/iter.rb +745 -0
  62. data/lib/fastruby/{translator/modules/iter.rb → modules/translator/iter.rb~} +103 -48
  63. data/lib/fastruby/modules/translator/literal.rb +150 -0
  64. data/lib/fastruby/{translator/modules/literal.rb → modules/translator/literal.rb~} +3 -3
  65. data/lib/fastruby/{translator/modules → modules/translator}/logical.rb +0 -0
  66. data/lib/fastruby/{translator/modules → modules/translator}/method_group.rb +0 -0
  67. data/lib/fastruby/{translator/modules → modules/translator}/nonlocal.rb +18 -6
  68. data/lib/fastruby/modules/translator/nonlocal.rb~ +298 -0
  69. data/lib/fastruby/modules/translator/static.rb +290 -0
  70. data/lib/fastruby/{translator/modules/static.rb → modules/translator/static.rb~} +66 -17
  71. data/lib/fastruby/modules/translator/variable.rb +280 -0
  72. data/lib/fastruby/{translator/modules/variable.rb → modules/translator/variable.rb~} +14 -44
  73. data/lib/fastruby/modules.rb +30 -0
  74. data/lib/fastruby/object.rb +42 -6
  75. data/lib/fastruby/object.rb~ +159 -0
  76. data/lib/fastruby/set_tree.rb +7 -11
  77. data/lib/fastruby/set_tree.rb~ +71 -0
  78. data/lib/fastruby/sexp_extension.rb +29 -7
  79. data/lib/fastruby/sexp_extension.rb~ +262 -0
  80. data/lib/fastruby/translator/scope_mode_helper.rb~ +138 -0
  81. data/lib/fastruby/translator/translator.rb +87 -92
  82. data/lib/fastruby/translator/translator.rb~ +1600 -0
  83. data/lib/fastruby/translator/translator_modules.rb +3 -1
  84. data/lib/fastruby/translator/translator_modules.rb~ +53 -0
  85. data/lib/fastruby.rb +3 -1
  86. data/lib/fastruby.rb~ +3 -1
  87. data/lib/fastruby_only/base.rb +1 -0
  88. data/spec/corelib/numeric/fixnum_spec.rb +110 -0
  89. data/spec/corelib/numeric/fixnum_spec.rb~ +104 -0
  90. data/spec/corelib/numeric/integer_spec.rb +173 -0
  91. data/spec/corelib/numeric/integer_spec.rb~ +173 -0
  92. data/spec/fastruby_only/base_spec.rb +74 -0
  93. data/spec/graph/base_spec.rb +2 -1
  94. data/spec/graph/base_spec.rb~ +35 -0
  95. data/spec/graph/path_spec.rb +2 -2
  96. data/spec/graph/path_spec.rb~ +48 -0
  97. data/spec/graph/vertex_spec.rb +2 -1
  98. data/spec/graph/vertex_spec.rb~ +58 -0
  99. data/spec/reductor/base_spec.rb +1 -1
  100. data/spec/ruby/block/lambda_spec.rb~ +163 -0
  101. data/spec/ruby/block/proc_as_block_spec.rb~ +69 -1
  102. data/spec/ruby/block_spec.rb~ +2 -494
  103. data/spec/ruby/call/base_call_spec.rb +1 -1
  104. data/spec/ruby/call/base_call_spec.rb~ +2 -60
  105. data/spec/ruby/defn/replacement_spec.rb +26 -14
  106. data/spec/ruby/defn/replacement_spec.rb~ +13 -3
  107. data/spec/ruby/exception/internal_ex_spec.rb~ +86 -0
  108. data/spec/ruby/integrity_spec.rb~ +35 -1
  109. data/spec/ruby/variable_spec.rb~ +31 -0
  110. data/spec/scope_mode/flow_spec.rb +1 -1
  111. data/spec/scope_mode/flow_spec.rb~ +109 -0
  112. data/spec/sugar/base_spec.rb +29 -0
  113. data/spec/sugar/base_spec.rb~ +16 -0
  114. metadata +100 -43
  115. data/spec/fastruby/inliner/modules/call_spec.rb +0 -0
  116. data/spec/fastruby/translator/modules/nonlocal_spec.rb +0 -0
  117. data/spec/fastruby/translator/translator_spec.rb +0 -0
  118. data/spec/ruby/block/arguments_spec.rb~ +0 -214
  119. data/spec/ruby/block/break_spec.rb~ +0 -236
  120. data/spec/ruby/block/next_spec.rb~ +0 -85
  121. data/spec/ruby/block/retry_spec.rb~ +0 -43
@@ -41,7 +41,9 @@ module FastRuby
41
41
  end
42
42
 
43
43
  def load_under(dir)
44
- each_under(dir, &method(:require))
44
+ each_under(dir) do |path|
45
+ require path
46
+ end
45
47
  end
46
48
  end
47
49
  end
@@ -0,0 +1,53 @@
1
+ =begin
2
+
3
+ This file is part of the fastruby project, http://github.com/tario/fastruby
4
+
5
+ Copyright (c) 2011 Roberto Dario Seminara <robertodarioseminara@gmail.com>
6
+
7
+ fastruby is free software: you can redistribute it and/or modify
8
+ it under the terms of the gnu general public license as published by
9
+ the free software foundation, either version 3 of the license, or
10
+ (at your option) any later version.
11
+
12
+ fastruby is distributed in the hope that it will be useful,
13
+ but without any warranty; without even the implied warranty of
14
+ merchantability or fitness for a particular purpose. see the
15
+ gnu general public license for more details.
16
+
17
+ you should have received a copy of the gnu general public license
18
+ along with fastruby. if not, see <http://www.gnu.org/licenses/>.
19
+
20
+ =end
21
+ require "singleton"
22
+
23
+ module FastRuby
24
+ class TranslatorModules
25
+ include Singleton
26
+
27
+ attr_accessor :modls
28
+
29
+ def initialize
30
+ @modls = Array.new
31
+ end
32
+
33
+ def register_translator_module(modl)
34
+ @modls << modl
35
+ end
36
+
37
+ def each_under(dir)
38
+ Dir.glob(dir + "/*.rb") do |x|
39
+ yield x
40
+ end
41
+ end
42
+
43
+ def load_under(dir)
44
+ each_under(dir, &method(:require))
45
+ end
46
+ end
47
+ end
48
+
49
+ module Kernel
50
+ def register_translator_module(modl)
51
+ FastRuby::TranslatorModules.instance.register_translator_module(modl)
52
+ end
53
+ end
data/lib/fastruby.rb CHANGED
@@ -32,5 +32,7 @@ class Object
32
32
  end
33
33
 
34
34
  module FastRuby
35
- VERSION = "0.0.19" unless defined? FastRuby::VERSION
35
+ VERSION = "0.0.20" unless defined? FastRuby::VERSION
36
36
  end
37
+
38
+ require "fastruby/corelib"
data/lib/fastruby.rb~ CHANGED
@@ -32,5 +32,7 @@ class Object
32
32
  end
33
33
 
34
34
  module FastRuby
35
- VERSION = "0.0.18" unless defined? FastRuby::VERSION
35
+ VERSION = "0.0.19" unless defined? FastRuby::VERSION
36
36
  end
37
+
38
+ require "fastruby/corelib"
@@ -0,0 +1 @@
1
+ |*x| tree = x.first;
@@ -0,0 +1,110 @@
1
+ require "fastruby"
2
+
3
+ describe FastRuby, "fastruby fixnum corelib" do
4
+
5
+ $fixnum_class_num = 0
6
+ def self.test_op_with_type(recv, op, parameter, expected = recv.send(op, parameter))
7
+ _classname = "FXNUMTEST#{$fixnum_class_num}"
8
+
9
+ it "receiver #{recv}.#{op}(#{parameter}) should return #{expected} #{expected.class}" do
10
+ fastruby(
11
+ "class #{_classname}
12
+ def foo(parameter)
13
+ #{recv}.#{op}(parameter)
14
+ end
15
+ end
16
+ "
17
+
18
+ )
19
+
20
+ eval(_classname).new.foo(parameter).should be == expected
21
+ end
22
+
23
+ $fixnum_class_num = $fixnum_class_num + 1
24
+ end
25
+
26
+ def self.test_op(recv, op, parameter, expected = recv.send(op, parameter))
27
+ _classname = "FXNUMTEST#{$fixnum_class_num}"
28
+
29
+ it "receiver #{recv}.#{op}(#{parameter}) should return #{expected} #{expected.class}" do
30
+ fastruby(
31
+ "class #{_classname}
32
+ def foo(parameter)
33
+ #{recv}.#{op}(parameter.call)
34
+ end
35
+ end
36
+ "
37
+
38
+ )
39
+
40
+ eval(_classname).new.foo( lambda{parameter} ).should be == expected
41
+ end
42
+
43
+ $fixnum_class_num = $fixnum_class_num + 1
44
+ end
45
+
46
+ def self.test_unary_op(recv, op, expected = recv.send(op))
47
+ _classname = "FXNUMTEST#{$fixnum_class_num}"
48
+
49
+ it "receiver #{recv}.#{op} should return #{expected} #{expected.class}" do
50
+ fastruby(
51
+ "class #{_classname}
52
+ def foo
53
+ #{recv}.#{op}
54
+ end
55
+ end
56
+ "
57
+
58
+ )
59
+
60
+ eval(_classname).new.foo.should be == expected
61
+ end
62
+ $fixnum_class_num = $fixnum_class_num + 1
63
+ end
64
+
65
+
66
+ class CustomValue
67
+ def method_missing(m,x)
68
+ 42
69
+ end
70
+ def <(x)
71
+ true
72
+ end
73
+
74
+ def >(x)
75
+ false
76
+ end
77
+
78
+ def coerce(other)
79
+ return self, other
80
+ end
81
+ end
82
+
83
+
84
+ test_methods = [:-@, :abs, :to_f, :size, :zero?, :odd?, :even?, :succ]
85
+ if RUBY_VERSION =~ /^1\\.9/
86
+ test_methods << :magnitude
87
+ end
88
+
89
+ test_methods.each do |op|
90
+ test_unary_op(31,op)
91
+ test_unary_op(-31,op)
92
+ end
93
+
94
+ #TODO: upto, downto, succ, next, pred, chr
95
+
96
+ [:+, :-, :<, :>, :/,:div,:%,:modulo,:divmod,:fdiv,:**,:==,:===,:<=>,:>=,:<=].each do |op|
97
+ [1,1.1,10**10,CustomValue.new].each do |value|
98
+ test_op_with_type(1,op,value)
99
+ test_op(1,op,value)
100
+ end
101
+ end
102
+
103
+ [:&,:|,:^,:[],:<<,:>>].each do |op|
104
+ [1,2,3].each do |value|
105
+ test_op_with_type(1,op,value)
106
+ test_op(1,op,value)
107
+ end
108
+ end
109
+
110
+ end
@@ -0,0 +1,104 @@
1
+ require "fastruby"
2
+
3
+ describe FastRuby, "fastruby fixnum corelib" do
4
+
5
+ $fixnum_class_num = 0
6
+ def self.test_op_with_type(recv, op, parameter, expected = recv.send(op, parameter))
7
+ _classname = "FXNUMTEST#{$fixnum_class_num}"
8
+
9
+ it "receiver #{recv}.#{op}(#{parameter}) should return #{expected} #{expected.class}" do
10
+ fastruby(
11
+ "class #{_classname}
12
+ def foo(parameter)
13
+ #{recv}.#{op}(parameter)
14
+ end
15
+ end
16
+ "
17
+
18
+ )
19
+
20
+ eval(_classname).new.foo(parameter).should be == expected
21
+ end
22
+
23
+ $fixnum_class_num = $fixnum_class_num + 1
24
+ end
25
+
26
+ def self.test_op(recv, op, parameter, expected = recv.send(op, parameter))
27
+ _classname = "FXNUMTEST#{$fixnum_class_num}"
28
+
29
+ it "receiver #{recv}.#{op}(#{parameter}) should return #{expected} #{expected.class}" do
30
+ fastruby(
31
+ "class #{_classname}
32
+ def foo(parameter)
33
+ #{recv}.#{op}(parameter.call)
34
+ end
35
+ end
36
+ "
37
+
38
+ )
39
+
40
+ eval(_classname).new.foo( lambda{parameter} ).should be == expected
41
+ end
42
+
43
+ $fixnum_class_num = $fixnum_class_num + 1
44
+ end
45
+
46
+ def self.test_unary_op(recv, op, expected = recv.send(op))
47
+ _classname = "FXNUMTEST#{$fixnum_class_num}"
48
+
49
+ it "receiver #{recv}.#{op} should return #{expected} #{expected.class}" do
50
+ fastruby(
51
+ "class #{_classname}
52
+ def foo
53
+ #{recv}.#{op}
54
+ end
55
+ end
56
+ "
57
+
58
+ )
59
+
60
+ eval(_classname).new.foo.should be == expected
61
+ end
62
+ $fixnum_class_num = $fixnum_class_num + 1
63
+ end
64
+
65
+
66
+ class CustomValue
67
+ def method_missing(m,x)
68
+ 42
69
+ end
70
+ def <(x)
71
+ true
72
+ end
73
+
74
+ def >(x)
75
+ false
76
+ end
77
+
78
+ def coerce(other)
79
+ return self, other
80
+ end
81
+ end
82
+
83
+ [:-@, :abs, :magnitude, :to_f, :size, :zero?, :odd?, :even?, :succ].each do |op|
84
+ test_unary_op(31,op)
85
+ test_unary_op(-31,op)
86
+ end
87
+
88
+ #TODO: upto, downto, succ, next, pred, chr
89
+
90
+ [:+, :-, :<, :>, :/,:div,:%,:modulo,:divmod,:fdiv,:**,:==,:===,:<=>,:>=,:<=].each do |op|
91
+ [1,1.1,10**10,CustomValue.new].each do |value|
92
+ test_op_with_type(1,op,value)
93
+ test_op(1,op,value)
94
+ end
95
+ end
96
+
97
+ [:&,:|,:^,:[],:<<,:>>].each do |op|
98
+ [1,2,3].each do |value|
99
+ test_op_with_type(1,op,value)
100
+ test_op(1,op,value)
101
+ end
102
+ end
103
+
104
+ end
@@ -0,0 +1,173 @@
1
+ require "fastruby"
2
+
3
+ describe FastRuby, "fastruby integer corelib" do
4
+
5
+ $fixnum_class_num = 0
6
+ def self.test_op(recv, op, parameter, expected = recv.send(op, parameter))
7
+ _classname = "INTEGERNUMTEST#{$fixnum_class_num}"
8
+
9
+ it "receiver #{recv}.#{op}(#{parameter}) should return #{expected} #{expected.class}" do
10
+ fastruby(
11
+ "class #{_classname}
12
+ def foo(parameter)
13
+ #{recv}.#{op}(parameter.call)
14
+ end
15
+ end
16
+ "
17
+
18
+ )
19
+
20
+ eval(_classname).new.foo( lambda{parameter} ).should be == expected
21
+ end
22
+
23
+ $fixnum_class_num = $fixnum_class_num + 1
24
+ end
25
+
26
+ def self.test_op_block(recv, op, argument)
27
+ _classname = "INTEGERNUMTEST#{$fixnum_class_num}"
28
+
29
+ expected = Array.new
30
+ recv.send(op, argument, &expected.method(:<<))
31
+
32
+ it "receiver #{recv}.#{op} should return #{expected} #{expected.class}" do
33
+ fastruby(
34
+ "class #{_classname}
35
+ def foo(argument)
36
+ #{recv}.#{op}(argument.call) do |x|
37
+ yield(x)
38
+ end
39
+ end
40
+ end
41
+ "
42
+
43
+ )
44
+
45
+ returned = Array.new
46
+ eval(_classname).new.foo(lambda{argument},&returned.method(:<<))
47
+
48
+ returned.should be == expected
49
+ end
50
+ $fixnum_class_num = $fixnum_class_num + 1
51
+ end
52
+
53
+ def self.test_op_enumerator(recv, op, parameter)
54
+
55
+ expected = Array.new
56
+ recv.send(op, parameter).each(&expected.method(:<<))
57
+
58
+ _classname = "INTEGERNUMTEST#{$fixnum_class_num}"
59
+
60
+ it "receiver #{recv}.#{op}(#{parameter}) should return #{expected} #{expected.class}" do
61
+ fastruby(
62
+ "class #{_classname}
63
+ def foo(parameter)
64
+ #{recv}.#{op}(parameter.call)
65
+ end
66
+ end
67
+ "
68
+
69
+ )
70
+
71
+ returned_array = Array.new
72
+ eval(_classname).new.foo( lambda{parameter} ).each(&returned_array.method(:<<))
73
+
74
+ returned_array.should be == expected
75
+ end
76
+
77
+ $fixnum_class_num = $fixnum_class_num + 1
78
+ end
79
+
80
+
81
+ def self.test_unary_op_block(recv, op)
82
+ _classname = "INTEGERNUMTEST#{$fixnum_class_num}"
83
+
84
+ expected = Array.new
85
+ recv.send(op, &expected.method(:<<))
86
+
87
+ it "receiver #{recv}.#{op} should return #{expected} #{expected.class}" do
88
+ fastruby(
89
+ "class #{_classname}
90
+ def foo
91
+ #{recv}.#{op} do |x| yield(x) end
92
+ end
93
+ end
94
+ "
95
+
96
+ )
97
+
98
+ returned = Array.new
99
+ eval(_classname).new.foo do |x| returned << x end
100
+ returned.should be == expected
101
+ end
102
+ $fixnum_class_num = $fixnum_class_num + 1
103
+ end
104
+
105
+ def self.test_unary_op(recv, op, expected = recv.send(op))
106
+ _classname = "INTEGERNUMTEST#{$fixnum_class_num}"
107
+
108
+ it "receiver #{recv}.#{op} should return #{expected} #{expected.class}" do
109
+ fastruby(
110
+ "class #{_classname}
111
+ def foo
112
+ #{recv}.#{op}
113
+ end
114
+ end
115
+ "
116
+
117
+ )
118
+
119
+ eval(_classname).new.foo.should be == expected
120
+ end
121
+ $fixnum_class_num = $fixnum_class_num + 1
122
+ end
123
+
124
+ def self.test_unary_op_enumerator(recv, op)
125
+
126
+ expected = Array.new
127
+ recv.send(op).each(&expected.method(:<<))
128
+
129
+ _classname = "INTEGERNUMTEST#{$fixnum_class_num}"
130
+
131
+ it "receiver #{recv}.#{op} should return #{expected} #{expected.class}" do
132
+ fastruby(
133
+ "class #{_classname}
134
+ def foo
135
+ #{recv}.#{op}
136
+ end
137
+ end
138
+ "
139
+
140
+ )
141
+
142
+ returned_array = Array.new
143
+ eval(_classname).new.foo.each(&returned_array.method(:<<))
144
+
145
+ returned_array.should be == expected
146
+ end
147
+ $fixnum_class_num = $fixnum_class_num + 1
148
+ end
149
+
150
+ [:integer?, :odd?, :even?, :succ, :next, :pred, :chr, :ord, :to_i, :to_int, :floor, :ceil, :truncate, :round].each do |op|
151
+ test_unary_op(32,op)
152
+ test_unary_op(77,op)
153
+ end
154
+
155
+ [:times].each do |op|
156
+ test_unary_op_enumerator(77, op)
157
+ test_unary_op_block(77, op)
158
+ end
159
+
160
+ test_op_block(77, :upto, 90)
161
+ test_op_block(77, :downto, 60)
162
+ test_op_enumerator(77, :upto, 90)
163
+ test_op_enumerator(77, :downto, 60)
164
+
165
+ it "1.upto(3).to_a should be [1,2,3]" do
166
+ 1.upto(3).to_a.should be == [1,2,3]
167
+ end
168
+
169
+ it "3.downto(1).to_a should be [3,2,1]" do
170
+ 3.downto(1).to_a.should be == [3,2,1]
171
+ end
172
+
173
+ end
@@ -0,0 +1,173 @@
1
+ require "fastruby"
2
+
3
+ describe FastRuby, "fastruby integer corelib" do
4
+
5
+ $fixnum_class_num = 0
6
+ def self.test_op(recv, op, parameter, expected = recv.send(op, parameter))
7
+ _classname = "INTEGERNUMTEST#{$fixnum_class_num}"
8
+
9
+ it "receiver #{recv}.#{op}(#{parameter}) should return #{expected} #{expected.class}" do
10
+ fastruby(
11
+ "class #{_classname}
12
+ def foo(parameter)
13
+ #{recv}.#{op}(parameter.call)
14
+ end
15
+ end
16
+ "
17
+
18
+ )
19
+
20
+ eval(_classname).new.foo( lambda{parameter} ).should be == expected
21
+ end
22
+
23
+ $fixnum_class_num = $fixnum_class_num + 1
24
+ end
25
+
26
+ def self.test_op_block(recv, op, argument)
27
+ _classname = "INTEGERNUMTEST#{$fixnum_class_num}"
28
+
29
+ expected = Array.new
30
+ recv.send(op, argument, &expected.method(:<<))
31
+
32
+ it "receiver #{recv}.#{op} should return #{expected} #{expected.class}" do
33
+ fastruby(
34
+ "class #{_classname}
35
+ def foo(argument)
36
+ #{recv}.#{op}(argument.call) do |x|
37
+ yield(x)
38
+ end
39
+ end
40
+ end
41
+ "
42
+
43
+ )
44
+
45
+ returned = Array.new
46
+ eval(_classname).new.foo(lambda{argument},&returned.method(:<<))
47
+
48
+ returned.should be == expected
49
+ end
50
+ $fixnum_class_num = $fixnum_class_num + 1
51
+ end
52
+
53
+ def self.test_op_enumerator(recv, op, parameter)
54
+
55
+ expected = Array.new
56
+ recv.send(op, parameter).each(&expected.method(:<<))
57
+
58
+ _classname = "INTEGERNUMTEST#{$fixnum_class_num}"
59
+
60
+ it "receiver #{recv}.#{op}(#{parameter}) should return #{expected} #{expected.class}" do
61
+ fastruby(
62
+ "class #{_classname}
63
+ def foo(parameter)
64
+ #{recv}.#{op}(parameter.call)
65
+ end
66
+ end
67
+ "
68
+
69
+ )
70
+
71
+ returned_array = Array.new
72
+ eval(_classname).new.foo( lambda{parameter} ).each(&returned_array.method(:<<))
73
+
74
+ returned_array.should be == expected
75
+ end
76
+
77
+ $fixnum_class_num = $fixnum_class_num + 1
78
+ end
79
+
80
+
81
+ def self.test_unary_op_block(recv, op)
82
+ _classname = "INTEGERNUMTEST#{$fixnum_class_num}"
83
+
84
+ expected = Array.new
85
+ recv.send(op, &expected.method(:<<))
86
+
87
+ it "receiver #{recv}.#{op} should return #{expected} #{expected.class}" do
88
+ fastruby(
89
+ "class #{_classname}
90
+ def foo
91
+ #{recv}.#{op} do |x| yield(x) end
92
+ end
93
+ end
94
+ "
95
+
96
+ )
97
+
98
+ returned = Array.new
99
+ eval(_classname).new.foo do |x| returned << x end
100
+ returned.should be == expected
101
+ end
102
+ $fixnum_class_num = $fixnum_class_num + 1
103
+ end
104
+
105
+ def self.test_unary_op(recv, op, expected = recv.send(op))
106
+ _classname = "INTEGERNUMTEST#{$fixnum_class_num}"
107
+
108
+ it "receiver #{recv}.#{op} should return #{expected} #{expected.class}" do
109
+ fastruby(
110
+ "class #{_classname}
111
+ def foo
112
+ #{recv}.#{op}
113
+ end
114
+ end
115
+ "
116
+
117
+ )
118
+
119
+ eval(_classname).new.foo.should be == expected
120
+ end
121
+ $fixnum_class_num = $fixnum_class_num + 1
122
+ end
123
+
124
+ def self.test_unary_op_enumerator(recv, op)
125
+
126
+ expected = Array.new
127
+ recv.send(op).each(&expected.method(:<<))
128
+
129
+ _classname = "INTEGERNUMTEST#{$fixnum_class_num}"
130
+
131
+ it "receiver #{recv}.#{op} should return #{expected} #{expected.class}" do
132
+ fastruby(
133
+ "class #{_classname}
134
+ def foo
135
+ #{recv}.#{op}
136
+ end
137
+ end
138
+ "
139
+
140
+ )
141
+
142
+ returned_array = Array.new
143
+ eval(_classname).new.foo.each(&returned_array.method(:<<))
144
+
145
+ returned_array.should be == expected
146
+ end
147
+ $fixnum_class_num = $fixnum_class_num + 1
148
+ end
149
+
150
+ [:integer?, :odd?, :even?, :succ, :next, :pred, :chr, :ord, :to_i, :to_int, :floor, :ceil, :truncate, :round].each do |op|
151
+ test_unary_op(32,op)
152
+ test_unary_op(77,op)
153
+ end
154
+
155
+ [:times].each do |op|
156
+ test_unary_op_enumerator(77, op)
157
+ test_unary_op_block(77, op)
158
+ end
159
+
160
+ test_op_block(77, :upto, 90)
161
+ test_op_block(77, :downto, 60)
162
+ test_op_enumerator(77, :upto, 90)
163
+ test_op_enumerator(77, :downto, 60)
164
+
165
+ it "1.upto(3).to_a should be [1,2,3]" do
166
+ 1.upto(3).to_a.should be == [1,2,3]
167
+ end
168
+
169
+ it "3.downto(1).to_a should be [3,2,1]" do
170
+ 3.downto(1).to_a.should be == [3,2,1]
171
+ end
172
+
173
+ end