fastruby 0.0.19 → 0.0.20

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 (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
@@ -0,0 +1,146 @@
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 "fastruby/sexp_extension"
22
+
23
+ class Fixnum
24
+ fastruby(:fastruby_only => true, :skip_reduce => true) do
25
+ def times
26
+ unless block_given?
27
+ return _static{rb_enumeratorize(self, _dynamic{:times}, inline_c("0"), inline_c("0") ) }
28
+ end
29
+
30
+ if self._class == Fixnum
31
+ i = 0
32
+ while _static{FIX2LONG(i) < FIX2LONG(self)}
33
+ yield(i)
34
+ i = _static{LONG2FIX(FIX2LONG(i)+1)}
35
+ end
36
+ else
37
+ i = 0
38
+ while i < self
39
+ yield(i)
40
+ i = i + 1
41
+ end
42
+ end
43
+ end
44
+
45
+ def upto(x)
46
+ unless block_given?
47
+ return _static{rb_enumeratorize(self, _dynamic{:upto}, inline_c("1"), c_address_of(x)) }
48
+ end
49
+ if self._class == Fixnum
50
+ if x._class == Fixnum
51
+ i = self
52
+ while _static{FIX2LONG(i) <= FIX2LONG(x)}
53
+ yield(i)
54
+ i = _static{LONG2FIX(FIX2LONG(i)+1)}
55
+ end
56
+
57
+ return self
58
+ end
59
+ end
60
+
61
+ i = self
62
+ while i <= x
63
+ yield(i)
64
+ i = i + 1
65
+ end
66
+
67
+ self
68
+ end
69
+
70
+ def downto(x)
71
+ unless block_given?
72
+ return _static{rb_enumeratorize(self, _dynamic{:downto}, inline_c("1"), c_address_of(x)) }
73
+ end
74
+
75
+ if self._class == Fixnum
76
+ if x._class == Fixnum
77
+ i = self
78
+ while _static{FIX2LONG(i) >= FIX2LONG(x)}
79
+ yield(i)
80
+ i = _static{LONG2FIX(FIX2LONG(i)-1)}
81
+ end
82
+
83
+ return self
84
+ end
85
+ end
86
+
87
+ i = self
88
+ while i >= x
89
+ yield(i)
90
+ i = i - 1
91
+ end
92
+
93
+ self
94
+ end
95
+
96
+ if RUBY_VERSION =~ /^1\\.9/
97
+ def +(b)
98
+ if b._class == Fixnum
99
+ _static{LONG2NUM(FIX2LONG(self)+FIX2LONG(b))}
100
+ elsif b._class == Bignum
101
+ _static{rb_big_plus(b,self)}
102
+ elsif b._class == Float
103
+ _static{DBL2NUM(FIX2LONG(self) + RFLOAT_VALUE(b))}
104
+ else
105
+ _static{rb_num_coerce_bin(self, b, inline_c("'+'"))}
106
+ end
107
+ end
108
+
109
+ def -(b)
110
+ if b._class == Fixnum
111
+ _static{LONG2NUM(FIX2LONG(self)-FIX2LONG(b))}
112
+ elsif b._class == Bignum
113
+ _static{rb_big_minus(rb_int2big(FIX2LONG(self)),b)}
114
+ elsif b._class == Float
115
+ _static{DBL2NUM(FIX2LONG(self) - RFLOAT_VALUE(b))}
116
+ else
117
+ _static{rb_num_coerce_bin(self, b, inline_c("'-'"))}
118
+ end
119
+ end
120
+
121
+ def >(y)
122
+ if y._class == Fixnum
123
+ _static{FIX2LONG(self)>FIX2LONG(y) ? true: false }
124
+ elsif y._class == Bignum
125
+ _static{FIX2INT(rb_big_cmp(rb_int2big(FIX2LONG(self)), y)) > 0 ? true : false}
126
+ elsif y._class == Float
127
+ _static{FIX2LONG(self) > RFLOAT_VALUE(y) ? true : false}
128
+ else
129
+ _static{rb_num_coerce_relop(self, y, inline_c("'>'"))}
130
+ end
131
+ end
132
+
133
+ def <(y)
134
+ if y._class == Fixnum
135
+ _static{FIX2LONG(self)<FIX2LONG(y) ? true: false }
136
+ elsif y._class == Bignum
137
+ _static{FIX2INT(rb_big_cmp(rb_int2big(FIX2LONG(self)), y)) < 0 ? true : false}
138
+ elsif y._class == Float
139
+ _static{FIX2LONG(self) < RFLOAT_VALUE(y) ? true : false}
140
+ else
141
+ _static{rb_num_coerce_relop(self, y, inline_c("'<'"))}
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,96 @@
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
+ class Integer
22
+ fastruby(:fastruby_only => true, :skip_reduce => true) do
23
+ def times
24
+ unless block_given?
25
+ return _static{rb_enumeratorize(self, _dynamic{:times}, inline_c("0"), inline_c("0") ) }
26
+ end
27
+
28
+ if self._class == Fixnum
29
+ i = 0
30
+ while _static{FIX2LONG(i) < FIX2LONG(self)}
31
+ yield(i)
32
+ i = _static{LONG2FIX(FIX2LONG(i)+1)}
33
+ end
34
+ else
35
+ i = 0
36
+ while i < self
37
+ yield(i)
38
+ i = i + 1
39
+ end
40
+ end
41
+ end
42
+
43
+ def upto(x)
44
+ unless block_given?
45
+ return _static{rb_enumeratorize(self, _dynamic{:upto}, inline_c("1"), c_address_of(x)) }
46
+ end
47
+
48
+ if self._class == Fixnum
49
+ if x._class == Fixnum
50
+ i = self
51
+ while _static{FIX2LONG(i) <= FIX2LONG(x)}
52
+ yield(i)
53
+ i = _static{LONG2FIX(FIX2LONG(i)+1)}
54
+ end
55
+
56
+ return self
57
+ end
58
+ end
59
+
60
+ i = self
61
+ while i <= x
62
+ yield(i)
63
+ i = i + 1
64
+ end
65
+
66
+ self
67
+ end
68
+
69
+ def downto(x)
70
+ unless block_given?
71
+ return _static{rb_enumeratorize(self, _dynamic{:downto}, inline_c("1"), c_address_of(x)) }
72
+ end
73
+
74
+ if self._class == Fixnum
75
+ if x._class == Fixnum
76
+ i = self
77
+ while _static{FIX2LONG(i) >= FIX2LONG(x)}
78
+ yield(i)
79
+ i = _static{LONG2FIX(FIX2LONG(i)-1)}
80
+ end
81
+
82
+ return self
83
+ end
84
+ end
85
+
86
+ i = self
87
+ while i >= x
88
+ yield(i)
89
+ i = i - 1
90
+ end
91
+
92
+ self
93
+ end
94
+
95
+ end
96
+ end
@@ -0,0 +1,96 @@
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
+ class Integer
22
+ fastruby(:fastruby_only => true, :skip_reduce => true) do
23
+ def times
24
+ unless block_given?
25
+ return _static{rb_enumeratorize(self, _dynamic{:times}, inline_c("0"), inline_c("0") ) }
26
+ end
27
+
28
+ if self._class == Fixnum
29
+ i = 0
30
+ while _static{FIX2LONG(i) < FIX2LONG(self)}
31
+ yield(i)
32
+ i = _static{LONG2FIX(FIX2LONG(i)+1)}
33
+ end
34
+ else
35
+ i = 0
36
+ while i < self
37
+ yield(i)
38
+ i = i + 1
39
+ end
40
+ end
41
+ end
42
+
43
+ def uptox(x)
44
+ unless block_given?
45
+ return _static{rb_enumeratorize(self, _dynamic{:upto}, inline_c("1"), c_address_of(x)) }
46
+ end
47
+
48
+ if self._class == Fixnum
49
+ if x._class == Fixnum
50
+ i = self
51
+ while _static{FIX2LONG(i) <= FIX2LONG(x)}
52
+ yield(i)
53
+ i = _static{LONG2FIX(FIX2LONG(i)+1)}
54
+ end
55
+
56
+ return self
57
+ end
58
+ end
59
+
60
+ i = self
61
+ while i <= x
62
+ yield(i)
63
+ i = i + 1
64
+ end
65
+
66
+ self
67
+ end
68
+
69
+ def downto(x)
70
+ unless block_given?
71
+ return _static{rb_enumeratorize(self, _dynamic{:downto}, inline_c("1"), c_address_of(x)) }
72
+ end
73
+
74
+ if self._class == Fixnum
75
+ if x._class == Fixnum
76
+ i = self
77
+ while _static{FIX2LONG(i) >= FIX2LONG(x)}
78
+ yield(i)
79
+ i = _static{LONG2FIX(FIX2LONG(i)-1)}
80
+ end
81
+
82
+ return self
83
+ end
84
+ end
85
+
86
+ i = self
87
+ while i >= x
88
+ yield(i)
89
+ i = i - 1
90
+ end
91
+
92
+ self
93
+ end
94
+
95
+ end
96
+ end
@@ -0,0 +1,23 @@
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
+ Dir.glob(FastRuby.fastruby_load_path + "/fastruby/corelib/**/*.rb").each do |path|
22
+ require path
23
+ end
@@ -0,0 +1,23 @@
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
+ Dir.glob(FastRuby.fastruby_load_path + "/fastruby/stdlib/**/*.rb").each do |path|
22
+ require path
23
+ end
@@ -61,7 +61,9 @@ module FastRuby
61
61
  def self.get_locals(tree)
62
62
  processor = GetLocalsProcessor.new
63
63
  processor.process(tree)
64
- processor.locals
64
+ ret_locals = processor.locals
65
+ ret_locals << :self
66
+ ret_locals
65
67
  end
66
68
  end
67
69
  end
@@ -18,11 +18,11 @@ you should have received a copy of the gnu general public license
18
18
  along with fastruby. if not, see <http://www.gnu.org/licenses/>.
19
19
 
20
20
  =end
21
- require "logger"
22
-
23
21
  module FastRuby
24
22
  module SingletonLogger
25
23
  def logger
24
+ require "logger" unless defined? Logger
25
+
26
26
  unless @logger
27
27
  @logger = Logger.new(ENV['FASTRUBY_LOG'] || "/dev/stdout")
28
28
  @logger.level = (ENV['FASTRUBY_LOG_LEVEL']||"2").to_i
@@ -0,0 +1,31 @@
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 "define_method_handler"
22
+
23
+ module FastRuby
24
+ class Inferencer
25
+ define_method_handler(:infer, :priority => 100) {|tree|
26
+ [ eval(tree[3].last.last.to_s) ]
27
+ }.condition{|tree|
28
+ tree.node_type == :call && tree[2] == :infer
29
+ }
30
+ end
31
+ end
@@ -0,0 +1,42 @@
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 "set"
22
+ require "sexp"
23
+ require "define_method_handler"
24
+
25
+ module FastRuby
26
+ class Inferencer
27
+ attr_accessor :infer_self
28
+
29
+ define_infer_for(:lit) do |tree|
30
+ [ tree[1].class ]
31
+ end
32
+
33
+ define_infer_for(:str) do |tree|
34
+ [ String ]
35
+ end
36
+
37
+ define_infer_for(:self) do |tree|
38
+ next [] unless @infer_self
39
+ [ @infer_self ]
40
+ end
41
+ end
42
+ end