rdl 1.1.1 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +6 -0
  3. data/README.md +211 -32
  4. data/gemfiles/Gemfile.travis +1 -1
  5. data/lib/rdl.rb +85 -18
  6. data/lib/rdl/info.rb +74 -0
  7. data/lib/rdl/query.rb +8 -9
  8. data/lib/rdl/typecheck.rb +1057 -0
  9. data/lib/rdl/types/annotated_arg.rb +5 -5
  10. data/lib/rdl/types/{nil.rb → bot.rb} +9 -13
  11. data/lib/rdl/types/dependent_arg.rb +5 -5
  12. data/lib/rdl/types/dots_query.rb +2 -0
  13. data/lib/rdl/types/finitehash.rb +67 -24
  14. data/lib/rdl/types/generic.rb +13 -21
  15. data/lib/rdl/types/intersection.rb +9 -8
  16. data/lib/rdl/types/method.rb +30 -32
  17. data/lib/rdl/types/nominal.rb +22 -16
  18. data/lib/rdl/types/optional.rb +8 -22
  19. data/lib/rdl/types/parser.racc +8 -3
  20. data/lib/rdl/types/parser.tab.rb +131 -118
  21. data/lib/rdl/types/singleton.rb +15 -10
  22. data/lib/rdl/types/structural.rb +6 -6
  23. data/lib/rdl/types/top.rb +6 -6
  24. data/lib/rdl/types/tuple.rb +56 -24
  25. data/lib/rdl/types/type.rb +9 -0
  26. data/lib/rdl/types/type_inferencer.rb +1 -1
  27. data/lib/rdl/types/union.rb +52 -26
  28. data/lib/rdl/types/var.rb +7 -6
  29. data/lib/rdl/types/vararg.rb +5 -6
  30. data/lib/rdl/types/wild_query.rb +9 -2
  31. data/lib/rdl/util.rb +9 -7
  32. data/lib/rdl/wrap.rb +90 -72
  33. data/lib/rdl_types.rb +2 -2
  34. data/rdl.gemspec +6 -8
  35. data/test/test_alias.rb +4 -3
  36. data/test/test_contract.rb +5 -4
  37. data/test/test_dsl.rb +2 -1
  38. data/test/test_generic.rb +30 -26
  39. data/test/test_intersection.rb +3 -3
  40. data/test/test_le.rb +129 -61
  41. data/test/test_lib_types.rb +3 -2
  42. data/test/test_member.rb +33 -46
  43. data/test/test_parser.rb +113 -116
  44. data/test/test_query.rb +2 -1
  45. data/test/test_rdl.rb +64 -6
  46. data/test/test_rdl_type.rb +3 -2
  47. data/test/test_type_contract.rb +30 -12
  48. data/test/test_typecheck.rb +893 -0
  49. data/test/test_types.rb +50 -54
  50. data/test/test_wrap.rb +2 -1
  51. data/types/ruby-2.x/_aliases.rb +13 -2
  52. data/types/ruby-2.x/bigdecimal.rb +60 -85
  53. data/types/ruby-2.x/bignum.rb +80 -119
  54. data/types/ruby-2.x/complex.rb +33 -40
  55. data/types/ruby-2.x/fixnum.rb +81 -120
  56. data/types/ruby-2.x/float.rb +79 -116
  57. data/types/ruby-2.x/integer.rb +187 -22
  58. data/types/ruby-2.x/nil.rb +12 -0
  59. data/types/ruby-2.x/numeric.rb +38 -38
  60. data/types/ruby-2.x/object.rb +3 -3
  61. data/types/ruby-2.x/random.rb +2 -0
  62. data/types/ruby-2.x/range.rb +20 -19
  63. data/types/ruby-2.x/rational.rb +40 -40
  64. data/types/ruby-2.x/regexp.rb +4 -4
  65. data/types/ruby-2.x/string.rb +15 -17
  66. metadata +17 -16
  67. data/lib/rdl/types/.#lexer.rex +0 -1
@@ -1,32 +1,197 @@
1
1
  class Integer < Numeric
2
2
  rdl_nowrap
3
3
 
4
- type :ceil, '() -> Integer'
4
+ type :%, '(Fixnum x {{ x!=0 }}) -> Fixnum'
5
+ type :%, '(Bignum x {{ x!=0 }}) -> %integer'
6
+ type :%, '(Float x {{ x!=0 }}) -> Float'
7
+ type :%, '(Rational x {{ x!=0 }}) -> Rational'
8
+ type :%, '(BigDecimal x {{ x!=0 }}) -> BigDecimal'
9
+
10
+ type :&, '(%integer) -> Fixnum'
11
+
12
+ type :*, '(%integer) -> %integer'
13
+ type :*, '(Float) -> Float'
14
+ type :*, '(Rational) -> Rational'
15
+ type :*, '(BigDecimal) -> BigDecimal'
16
+ type :*, '(Complex) -> Complex'
17
+ pre(:*) { |x| if (x.real.is_a?(BigDecimal)||x.imaginary.is_a?(BigDecimal)) then (if x.real.is_a?(Float) then (x.real!=Float::INFINITY && !(x.real.nan?)) elsif(x.imaginary.is_a?(Float)) then x.imaginary!=Float::INFINITY && !(x.imaginary.nan?) else true end) else true end} #can't have a complex with part BigDecimal, other part infinity/NAN
18
+
19
+ type :**, '(%integer) -> %numeric'
20
+ type :**, '(Float) -> %numeric'
21
+ type :**, '(Rational) -> %numeric'
22
+ type :**, '(BigDecimal) -> BigDecimal'
23
+ pre(:**) { |x| x!=BigDecimal::INFINITY && if self<0 then x<=-1||x>=0 else true end}
24
+ post(:**) { |r,x| r.real?}
25
+ type :**, '(Complex) -> Complex'
26
+ pre(:**) { |x| x!=0 && if (x.real.is_a?(BigDecimal)||x.imaginary.is_a?(BigDecimal)) then (if x.real.is_a?(Float) then (x.real!=Float::INFINITY && !(x.real.nan?)) elsif(x.imaginary.is_a?(Float)) then x.imaginary!=Float::INFINITY && !(x.imaginary.nan?) else true end) else true end}
27
+
28
+ type :+, '(%integer) -> %integer'
29
+ type :+, '(Float) -> Float'
30
+ type :+, '(Rational) -> Rational'
31
+ type :+, '(BigDecimal) -> BigDecimal'
32
+ type :+, '(Complex) -> Complex'
33
+
34
+ type :-, '(%integer) -> %integer'
35
+ type :-, '(Float) -> Float'
36
+ type :-, '(Rational) -> Rational'
37
+ type :-, '(BigDecimal) -> BigDecimal'
38
+ type :-, '(Complex) -> Complex'
39
+
40
+ type :-, '() -> %integer'
41
+
42
+ type :/, '(%integer x {{ x!=0 }}) -> %integer'
43
+ type :/, '(Float x {{ x!=0 }}) -> Float'
44
+ type :/, '(Rational x {{ x!=0 }}) -> Rational'
45
+ type :/, '(BigDecimal x {{ x!=0 }}) -> BigDecimal'
46
+ type :/, '(Complex x {{ x!=0 }}) -> Complex'
47
+ pre(:/) { |x| x!=0 && if (x.real.is_a?(BigDecimal)||x.imaginary.is_a?(BigDecimal)) then (if x.real.is_a?(Float) then (x.real!=Float::INFINITY && !(x.real.nan?)) elsif(x.imaginary.is_a?(Float)) then x.imaginary!=Float::INFINITY && !(x.imaginary.nan?) else true end) else true end && if (x.real.is_a?(Rational) && x.imaginary.is_a?(Float)) then !x.imaginary.nan? else true end}
48
+
49
+ type :<, '(%integer) -> %bool'
50
+ type :<, '(Float) -> %bool'
51
+ type :<, '(Rational) -> %bool'
52
+ type :<, '(BigDecimal) -> %bool'
53
+
54
+ type :<<, '(Fixnum) -> %integer'
55
+
56
+ type :<=, '(%integer) -> %bool'
57
+ type :<=, '(Float) -> %bool'
58
+ type :<=, '(Rational) -> %bool'
59
+ type :<=, '(BigDecimal) -> %bool'
60
+
61
+ type :<=>, '(%integer) -> Object'
62
+ post(:<=>) { |r,x| r == -1 || r==0 || r==1}
63
+ type :<=>, '(Float) -> Object'
64
+ post(:<=>) { |r,x| r == -1 || r==0 || r==1}
65
+ type :<=>, '(Rational) -> Object'
66
+ post(:<=>) { |r,x| r == -1 || r==0 || r==1}
67
+ type :<=>, '(BigDecimal) -> Object'
68
+ post(:<=>) { |r,x| r == -1 || r==0 || r==1}
69
+
70
+ type :==, '(Object) -> %bool'
71
+
72
+ type :===, '(Object) -> %bool'
73
+
74
+ type :>, '(%integer) -> %bool'
75
+ type :>, '(Float) -> %bool'
76
+ type :>, '(Rational) -> %bool'
77
+ type :>, '(BigDecimal) -> %bool'
78
+
79
+ type :>=, '(%integer) -> %bool'
80
+ type :>=, '(Float) -> %bool'
81
+ type :>=, '(Rational) -> %bool'
82
+ type :>=, '(BigDecimal) -> %bool'
83
+
84
+ type :>>, '(%integer) -> %integer r {{ r>=0 }}'
85
+
86
+ type :[], '(%integer) -> Fixnum'
87
+ post(:[]) { |r,x| r == 0 || r==1}
88
+ type :[], '(Rational) -> Fixnum'
89
+ post(:[]) { |r,x| r == 0 || r==1}
90
+ type :[], '(Float) -> Fixnum'
91
+ pre(:[]) { |x| x!=Float::INFINITY && !x.nan? }
92
+ post(:[]) { |r,x| r == 0 || r==1}
93
+ type :[], '(BigDecimal) -> Fixnum'
94
+ pre(:[]) { |x| x!=BigDecimal::INFINITY && !x.nan? }
95
+ post(:[]) { |r,x| r == 0 || r==1}
96
+
97
+ type :^, '(%integer) -> %integer'
98
+
99
+ type :|, '(%integer) -> %integer'
100
+
101
+ type :~, '() -> %integer'
102
+
103
+ type :abs, '() -> %integer r {{ r>=0 }}'
104
+
105
+ type :bit_length, '() -> %integer r {{ r>=0 }}'
106
+
107
+ type :div, '(%integer x {{ x!=0 }}) -> %integer'
108
+ type :div, '(Float x {{ x!=0 && !x.nan? }}) -> %integer'
109
+ type :div, '(Rational x {{ x!=0 }}) -> %integer'
110
+ type :div, '(BigDecimal x {{ x!=0 && !x.nan? }}) -> %integer'
111
+
112
+ type :divmod, '(%real x {{ x!=0 }}) -> [%real, %real]'
113
+ pre(:divmod) { |x| if x.is_a?(Float) then !x.nan? else true end}
114
+
115
+ type :fdiv, '(%integer) -> Float'
116
+ type :fdiv, '(Float) -> Float'
117
+ type :fdiv, '(Rational) -> Float'
118
+ type :fdiv, '(BigDecimal) -> BigDecimal'
119
+ type :fdiv, '(Complex) -> Complex'
120
+ pre(:fdiv) { |x| if (x.real.is_a?(BigDecimal)||x.imaginary.is_a?(BigDecimal)) then (if x.real.is_a?(Float) then (x.real!=Float::INFINITY && !(x.real.nan?)) elsif(x.imaginary.is_a?(Float)) then x.imaginary!=Float::INFINITY && !(x.imaginary.nan?) else true end) else true end && if (x.real.is_a?(Rational) && x.imaginary.is_a?(Float)) then !x.imaginary.nan? else true end}
121
+
122
+ type :to_s, '() -> String'
123
+ type :inspect, '() -> String'
124
+
125
+ type :magnitude, '() -> %integer r {{ r>=0 }}'
126
+
127
+ type :modulo, '(Fixnum x {{ x!=0 }}) -> Fixnum'
128
+ type :modulo, '(Bignum x {{ x!=0 }}) -> %integer'
129
+ type :modulo, '(Float x {{ x!=0 }}) -> Float'
130
+ type :modulo, '(Rational x {{ x!=0 }}) -> Rational'
131
+ type :modulo, '(BigDecimal x {{ x!=0 }}) -> BigDecimal'
132
+
133
+ type :quo, '(%integer x {{ x!=0 }}) -> Rational'
134
+ type :quo, '(Float x {{ x!=0 }}) -> Float'
135
+ type :quo, '(Rational x {{ x!=0 }}) -> Rational'
136
+ type :quo, '(BigDecimal x {{ x!=0 }}) -> BigDecimal'
137
+ type :quo, '(Complex x {{ x!=0 }}) -> Complex'
138
+ pre(:quo) { |x| if (x.real.is_a?(BigDecimal)||x.imaginary.is_a?(BigDecimal)) then (if x.real.is_a?(Float) then (x.real!=Float::INFINITY && !(x.real.nan?)) elsif(x.imaginary.is_a?(Float)) then x.imaginary!=Float::INFINITY && !(x.imaginary.nan?) else true end) else true end && if (x.real.is_a?(Rational) && x.imaginary.is_a?(Float)) then !x.imaginary.nan? else true end}
139
+
140
+ type :abs2, '() -> %integer r {{ r>=0 }}'
141
+ type :angle, '() -> %numeric'
142
+ post(:angle) { |r,x| r == 0 || r == Math::PI}
143
+ type :arg, '() -> %numeric'
144
+ post(:arg) { |r,x| r == 0 || r == Math::PI}
145
+ type :equal?, '(Object) -> %bool'
146
+ type :eql?, '(Object) -> %bool'
147
+ type :hash, '() -> %integer'
148
+ type :ceil, '() -> %integer'
5
149
  type :chr, '(Encoding) -> String'
150
+ type :coerce, '(%numeric) -> [%real, %real]'
151
+ pre(:coerce) { |x| if x.is_a?(Complex) then x.imaginary==0 else true end}
152
+ type :conj, '() -> %integer'
153
+ type :conjugate, '() -> %integer'
6
154
  type :denominator, '() -> Fixnum'
7
155
  post(:denominator) { |r,x| r == 1 }
8
- type :downto, '(Integer) { (Integer) -> %any } -> Integer'
9
- type :downto, '(Integer limit) -> Enumerator<Integer>'
156
+ type :downto, '(%integer) { (%integer) -> %any } -> %integer'
157
+ type :downto, '(%integer limit) -> Enumerator<%integer>'
10
158
  type :even?, '() -> %bool'
11
- type :gcd, '(Integer) -> Integer'
12
- type :gcdlcm, '(Integer) -> [Integer, Integer]'
13
- type :floor, '() -> Integer'
14
- type :integer?, '() -> TrueClass'
15
- type :lcm, '(Integer) -> Integer'
16
- type :next, '() -> Integer'
17
- type :numerator, '() -> Integer'
159
+ type :gcd, '(%integer) -> %integer'
160
+ type :gcdlcm, '(%integer) -> [%integer, %integer]'
161
+ type :floor, '() -> %integer'
162
+ type :imag, '() -> Fixnum r {{ r==0 }}'
163
+ type :imaginary, '() -> Fixnum r {{ r==0 }}'
164
+ type :integer?, '() -> true'
165
+ type :lcm, '(%integer) -> %integer'
166
+ type :next, '() -> %integer'
167
+ type :numerator, '() -> %integer'
18
168
  type :odd?, '() -> %bool'
19
- type :ord, '() -> Integer'
20
- type :pred, '() -> Integer'
21
- type :rationalize, '(Numeric) -> Rational'
22
- type :round, '(Numeric) -> Numeric'
23
- type :succ, '() -> Integer'
24
- type :times, '() { (Integer) -> %any } -> Integer'
25
- type :times, '() -> Enumerator<Integer>'
26
- type :to_i, '() -> Integer'
27
- type :to_int, '() -> Integer'
169
+ type :ord, '() -> %integer'
170
+ type :phase, '() -> %numeric'
171
+ type :pred, '() -> %integer'
172
+ type :rationalize, '() -> Rational'
173
+ type :rationalize, '(%numeric) -> Rational'
174
+ type :real, '() -> %integer'
175
+ type :real?, '() -> true'
176
+ type :remainder, '(Fixnum x {{ x!=0 }}) -> Fixnum r {{ r>=0 }}'
177
+ type :remainder, '(Bignum x {{ x!=0 }}) -> Fixnum r {{ r>=0 }}'
178
+ type :remainder, '(Float x {{ x!=0 }}) -> Float'
179
+ type :remainder, '(Rational x {{ x!=0 }}) -> Rational r {{ r>=0 }}'
180
+ type :remainder, '(BigDecimal x {{ x!=0 }}) -> BigDecimal'
181
+ type :round, '() -> %integer'
182
+ type :round, '(%numeric) -> %numeric'
183
+ pre(:round) { |x| x!=0 && if x.is_a?(Complex) then x.imaginary==0 && (if x.real.is_a?(Float)||x.real.is_a?(BigDecimal) then !x.real.infinite? && !x.real.nan? else true end) elsif x.is_a?(Float) then x!=Float::INFINITY && !x.nan? elsif x.is_a?(BigDecimal) then x!=BigDecimal::INFINITY && !x.nan? else true end} #Also, x must be in range [-2**31, 2**31].
184
+ type :size, '() -> %integer'
185
+ type :succ, '() -> %integer'
186
+ type :times, '() { (%integer) -> %any } -> %integer'
187
+ type :times, '() -> Enumerator<%integer>'
188
+ type :to_c, '() -> Complex r {{ r.imaginary==0 }}'
189
+ type :to_f, '() -> Float'
190
+ type :to_i, '() -> %integer'
191
+ type :to_int, '() -> %integer'
28
192
  type :to_r, '() -> Rational'
29
- type :truncate, '() -> Integer'
30
- type :upto, '(Integer) { (Integer) -> %any } -> Integer'
31
- type :upto, '(Integer) -> Enumerator<Integer>'
193
+ type :truncate, '() -> %integer'
194
+ type :upto, '(%integer) { (%integer) -> %any } -> %integer'
195
+ type :upto, '(%integer) -> Enumerator<%integer>'
196
+ type :zero?, '() -> %bool'
32
197
  end
@@ -0,0 +1,12 @@
1
+ class NilClass
2
+ rdl_nowrap
3
+ type :&, '(%any obj) -> false'
4
+ type :'^', '(%any obj) -> %bool'
5
+ type :|, '(%any obj) -> %bool'
6
+ type :rationalize, '() -> Rational'
7
+ type :to_a, '() -> []'
8
+ type :to_c, '() -> Complex'
9
+ type :to_f, '() -> 0.0'
10
+ type :to_h, '() -> {}'
11
+ type :to_r, '() -> Rational'
12
+ end
@@ -1,56 +1,56 @@
1
1
  class Numeric
2
2
  rdl_nowrap
3
3
 
4
- type :%, '(Numeric) -> Numeric'
4
+ type :%, '(%numeric) -> %numeric'
5
5
  pre(:%) { |x| x!=0}
6
- type :+, '(Numeric) -> Numeric'
7
- type :-, '() -> Numeric'
8
- type :<=>, '(Numeric) -> Object'
6
+ type :+, '(%numeric) -> %numeric'
7
+ type :-, '() -> %numeric'
8
+ type :<=>, '(%numeric) -> Object'
9
9
  post(:<=>) { |r,x| r == -1 || r==0 || r==1 || r==nil}
10
- type :abs, '() -> Numeric'
10
+ type :abs, '() -> %numeric'
11
11
  post(:abs) { |r,x| r >= 0 }
12
- type :abs2, '() -> Numeric'
12
+ type :abs2, '() -> %numeric'
13
13
  post(:abs2) { |r,x| r >= 0 }
14
- type :angle, '() -> Numeric'
15
- type :arg, '() -> Numeric'
16
- type :ceil, '() -> Integer'
17
- type :coerce, '(Numeric) -> [Numeric, Numeric]'
18
- type :conj, '() -> Numeric'
19
- type :conjugate, '() -> Numeric'
20
- type :denominator, '() -> Integer'
14
+ type :angle, '() -> %numeric'
15
+ type :arg, '() -> %numeric'
16
+ type :ceil, '() -> %integer'
17
+ type :coerce, '(%numeric) -> [%numeric, %numeric]'
18
+ type :conj, '() -> %numeric'
19
+ type :conjugate, '() -> %numeric'
20
+ type :denominator, '() -> %integer'
21
21
  post(:denominator) { |r,x| r >= 0 }
22
- type :div, '(Numeric) -> Integer'
22
+ type :div, '(%numeric) -> %integer'
23
23
  pre(:div) { |x| x!=0}
24
- type :divmod, '(Numeric) -> [Numeric, Numeric]'
24
+ type :divmod, '(%numeric) -> [%numeric, %numeric]'
25
25
  pre(:divmod) { |x| x!=0 }
26
- type :eql?, '(Numeric) -> %bool'
27
- type :fdiv, '(Numeric) -> Numeric'
28
- type :floor, '() -> Integer'
26
+ type :eql?, '(%numeric) -> %bool'
27
+ type :fdiv, '(%numeric) -> %numeric'
28
+ type :floor, '() -> %integer'
29
29
  type :i, '() -> Complex'
30
- type :imag, '() -> Numeric'
31
- type :imaginary, '() -> Numeric'
30
+ type :imag, '() -> %numeric'
31
+ type :imaginary, '() -> %numeric'
32
32
  type :integer?, '() -> %bool'
33
- type :magnitude, '() -> Numeric'
34
- type :modulo, '(Numeric) -> %real'
33
+ type :magnitude, '() -> %numeric'
34
+ type :modulo, '(%numeric) -> %real'
35
35
  pre(:modulo) { |x| x!=0 }
36
36
  type :nonzero?, '() -> self or nil'
37
- type :numerator, '() -> Integer'
38
- type :phase, '() -> Numeric'
39
- type :polar, '() -> [Numeric, Numeric]'
40
- type :quo, '(Numeric) -> Numeric'
41
- type :real, '() -> Numeric'
42
- type :real?, '() -> Numeric'
43
- type :rect, '() -> [Numeric, Numeric]'
44
- type :rectangular, '() -> [Numeric, Numeric]'
45
- type :remainder, '(Numeric) -> %real'
46
- type :round, '(Numeric) -> Numeric'
37
+ type :numerator, '() -> %integer'
38
+ type :phase, '() -> %numeric'
39
+ type :polar, '() -> [%numeric, %numeric]'
40
+ type :quo, '(%numeric) -> %numeric'
41
+ type :real, '() -> %numeric'
42
+ type :real?, '() -> %numeric'
43
+ type :rect, '() -> [%numeric, %numeric]'
44
+ type :rectangular, '() -> [%numeric, %numeric]'
45
+ type :remainder, '(%numeric) -> %real'
46
+ type :round, '(%numeric) -> %numeric'
47
47
  type :singleton_method_added, '(Symbol) -> TypeError'
48
- type :step, '(Numeric) { (Numeric) -> %any } -> Numeric'
49
- type :step, '(Numeric) -> Enumerator<Numeric>'
50
- type :step, '(Numeric, Numeric) { (Numeric) -> %any } -> Numeric'
51
- type :step, '(Numeric, Numeric) -> Enumerator<Numeric>'
48
+ type :step, '(%numeric) { (%numeric) -> %any } -> %numeric'
49
+ type :step, '(%numeric) -> Enumerator<%numeric>'
50
+ type :step, '(%numeric, %numeric) { (%numeric) -> %any } -> %numeric'
51
+ type :step, '(%numeric, %numeric) -> Enumerator<%numeric>'
52
52
  type :to_c, '() -> Complex'
53
- type :to_int, '() -> Integer'
54
- type :truncate, '() -> Integer'
53
+ type :to_int, '() -> %integer'
54
+ type :truncate, '() -> %integer'
55
55
  type :zero?, '() -> %bool'
56
56
  end
@@ -26,10 +26,10 @@ class Object
26
26
  type :===, '(%any other) -> %bool'
27
27
  type :=~, '(%any other) -> nil'
28
28
  type :class, '() -> Class'
29
- type :clone, '() -> %any'
29
+ type :clone, '() -> self'
30
30
  # type :define_singleton_method, '(XXXX : *XXXX)') # TODO
31
31
  type :display, '(IO port) -> nil'
32
- type :dup, '() -> %any an_object'
32
+ type :dup, '() -> self an_object'
33
33
  type :enum_for, '(?Symbol method, *%any args) -> Enumerator<%any>'
34
34
  type :enum_for, '(?Symbol method, *%any args) { (*%any args) -> %any } -> Enumerator<%any>'
35
35
  type :eql?, '(%any other) -> %bool'
@@ -55,7 +55,7 @@ class Object
55
55
  type :public_send, '(Symbol or String, *%any args) -> %any'
56
56
  type :remove_instance_variable, '(Symbol) -> %any'
57
57
  # type :respond_to?, '(Symbol or String, ?%bool include_all) -> %bool'
58
- # type :send, '(Symbol or String, *%any args) -> %any' # Can't wrap this, used outside wrap switch
58
+ type :send, '(Symbol or String, *%any args) -> %any', wrap: false # Can't wrap this, used outside wrap switch
59
59
  type :singleton_class, '() -> Class'
60
60
  type :singleton_method, '(Symbol) -> Method'
61
61
  type :singleton_methods, '(?%bool all) -> Array<Symbol>'
@@ -1,3 +1,5 @@
1
+ require_relative 'range.rb'
2
+
1
3
  class Random
2
4
  rdl_nowrap
3
5
 
@@ -1,38 +1,39 @@
1
1
  class Range
2
2
  rdl_nowrap
3
3
 
4
- type_params([:t], nil) { |t| t.member?(self.begin) && t.member?(self.end) } # TODO: And instantiated if t instantiated
4
+ # Range is immutable, so covariant
5
+ type_params([:t], nil, variance: [:+]) { |t| t.member?(self.begin) && t.member?(self.end) } # TODO: And instantiated if t instantiated
5
6
 
6
7
  # TODO: Parse error
7
8
  # type 'self.new', '(begin: [<=> : (u, u) -> Fixnum], end: [<=>, (u, u) -> Fixnum], exclude_end: ?%bool) -> Range<u>'
8
9
  type :==, '(%any obj) -> %bool'
9
10
  type :===, '(%any obj) -> %bool'
10
- type :begin, '() -> u'
11
- type :bsearch, '() { (u) -> %bool } -> u or nil'
11
+ type :begin, '() -> t'
12
+ type :bsearch, '() { (t) -> %bool } -> u or nil'
12
13
  type :cover?, '(%any obj) -> %bool'
13
14
  type :each, '() { (t) -> %any } -> self'
14
- type :each, '() -> Enumerator<u>'
15
- type :end, '() -> u'
15
+ type :each, '() -> Enumerator<t>'
16
+ type :end, '() -> t'
16
17
  rdl_alias :eql?, :==
17
18
  type :exclude_end?, '() -> %bool'
18
- type :first, '() -> u'
19
- type :first, '(Fixnum n) -> Array<u>'
19
+ type :first, '() -> t'
20
+ type :first, '(Fixnum n) -> Array<t>'
20
21
  type :hash, '() -> Fixnum'
21
22
  type :include?, '(%any obj) -> %bool'
22
23
  type :inspect, '() -> String'
23
- type :last, '() -> u'
24
- type :last, '(Fixnum n) -> Array<u>'
25
- type :max, '() -> u'
26
- type :max, '() { (u, u) -> Fixnum } -> u'
27
- type :max, '(Fixnum n) -> Array<u>'
28
- type :max, '(Fixnum n) { (u, u) -> Fixnum } -> Array<u>'
24
+ type :last, '() -> t'
25
+ type :last, '(Fixnum n) -> Array<t>'
26
+ type :max, '() -> t'
27
+ type :max, '() { (t, t) -> Fixnum } -> t'
28
+ type :max, '(Fixnum n) -> Array<t>'
29
+ type :max, '(Fixnum n) { (t, t) -> Fixnum } -> Array<t>'
29
30
  rdl_alias :member?, :include
30
- type :min, '() -> u'
31
- type :min, '() { (u, u) -> Fixnum } -> u'
32
- type :min, '(Fixnum n) -> Array<u>'
33
- type :min, '(Fixnum n) { (u, u) -> Fixnum } -> Array<u>'
31
+ type :min, '() -> t'
32
+ type :min, '() { (t, t) -> Fixnum } -> t'
33
+ type :min, '(Fixnum n) -> Array<t>'
34
+ type :min, '(Fixnum n) { (t, t) -> Fixnum } -> Array<t>'
34
35
  type :size, '() -> Fixnum or nil'
35
- type :step, '(?Fixnum n) { (u) -> %any } -> self'
36
- type :step, '(?Fixnum n) -> Enumerator<u>'
36
+ type :step, '(?Fixnum n) { (t) -> %any } -> self'
37
+ type :step, '(?Fixnum n) -> Enumerator<t>'
37
38
  type :to_s, '() -> String'
38
39
  end
@@ -1,7 +1,7 @@
1
1
  class Rational < Numeric
2
2
  rdl_nowrap
3
3
 
4
- type :%, '(Integer) -> Rational'
4
+ type :%, '(%integer) -> Rational'
5
5
  pre(:%) { |x| x!=0}
6
6
  type :%, '(Float) -> Float'
7
7
  pre(:%) { |x| x!=0&&!x.nan?}
@@ -10,20 +10,20 @@ class Rational < Numeric
10
10
  type :%, '(BigDecimal) -> BigDecimal'
11
11
  pre(:%) { |x| x!=0&&!x.nan?}
12
12
 
13
- type :*, '(Integer) -> Rational'
13
+ type :*, '(%integer) -> Rational'
14
14
  type :*, '(Float) -> Float'
15
15
  type :*, '(Rational) -> Rational'
16
16
  type :*, '(BigDecimal) -> BigDecimal'
17
17
  type :*, '(Complex) -> Complex'
18
18
  pre(:*) { |x| if (x.real.is_a?(BigDecimal)||x.imaginary.is_a?(BigDecimal)) then (if x.real.is_a?(Float) then (x.real!=Float::INFINITY && !(x.real.nan?)) elsif(x.imaginary.is_a?(Float)) then x.imaginary!=Float::INFINITY && !(x.imaginary.nan?) else true end) else true end} #can't have a complex with part BigDecimal, other part infinity/NAN
19
19
 
20
- type :+, '(Integer) -> Rational'
20
+ type :+, '(%integer) -> Rational'
21
21
  type :+, '(Float) -> Float'
22
22
  type :+, '(Rational) -> Rational'
23
23
  type :+, '(BigDecimal) -> BigDecimal'
24
24
  type :+, '(Complex) -> Complex'
25
25
 
26
- type :-, '(Integer) -> Rational'
26
+ type :-, '(%integer) -> Rational'
27
27
  type :-, '(Float) -> Float'
28
28
  type :-, '(Rational) -> Rational'
29
29
  type :-, '(BigDecimal) -> BigDecimal'
@@ -31,16 +31,16 @@ class Rational < Numeric
31
31
 
32
32
  type :-, '() -> Rational'
33
33
 
34
- type :**, '(Integer) -> Numeric'
35
- type :**, '(Float) -> Numeric'
36
- type :**, '(Rational) -> Numeric'
34
+ type :**, '(%integer) -> %numeric'
35
+ type :**, '(Float) -> %numeric'
36
+ type :**, '(Rational) -> %numeric'
37
37
  type :**, '(BigDecimal) -> BigDecimal'
38
38
  pre(:**) { |x| x!=BigDecimal::INFINITY && if self<0 then x<=-1||x>=0 else true end}
39
39
  post(:**) { |r,x| r.real?}
40
40
  type :**, '(Complex) -> Complex'
41
41
  pre(:**) { |x| x!=0 && if (x.real.is_a?(BigDecimal)||x.imaginary.is_a?(BigDecimal)) then (if x.real.is_a?(Float) then (x.real!=Float::INFINITY && !(x.real.nan?)) elsif(x.imaginary.is_a?(Float)) then x.imaginary!=Float::INFINITY && !(x.imaginary.nan?) else true end) else true end}
42
42
 
43
- type :/, '(Integer) -> Rational'
43
+ type :/, '(%integer) -> Rational'
44
44
  pre(:/) { |x| x!=0}
45
45
  type :/, '(Float) -> Float'
46
46
  pre(:/) { |x| x!=0}
@@ -51,35 +51,35 @@ class Rational < Numeric
51
51
  type :/, '(Complex) -> Complex'
52
52
  pre(:/) { |x| x!=0 && if (x.real.is_a?(BigDecimal)||x.imaginary.is_a?(BigDecimal)) then (if x.real.is_a?(Float) then (x.real!=Float::INFINITY && !(x.real.nan?)) elsif(x.imaginary.is_a?(Float)) then x.imaginary!=Float::INFINITY && !(x.imaginary.nan?) else true end) else true end && if (x.real.is_a?(Rational) && x.imaginary.is_a?(Float)) then !x.imaginary.nan? else true end}
53
53
 
54
- type :<, '(Integer) -> %bool'
54
+ type :<, '(%integer) -> %bool'
55
55
  type :<, '(Float) -> %bool'
56
56
  pre(:<) { |x| !x.nan?}
57
57
  type :<, '(Rational) -> %bool'
58
58
  type :<, '(BigDecimal) -> %bool'
59
59
  pre(:<) { |x| !x.nan?}
60
60
 
61
- type :<=, '(Integer) -> %bool'
61
+ type :<=, '(%integer) -> %bool'
62
62
  type :<=, '(Float) -> %bool'
63
63
  pre(:<=) { |x| !x.nan?}
64
64
  type :<=, '(Rational) -> %bool'
65
65
  type :<=, '(BigDecimal) -> %bool'
66
66
  pre(:<=) { |x| !x.nan?}
67
67
 
68
- type :>, '(Integer) -> %bool'
68
+ type :>, '(%integer) -> %bool'
69
69
  type :>, '(Float) -> %bool'
70
70
  pre(:>) { |x| !x.nan?}
71
71
  type :>, '(Rational) -> %bool'
72
72
  type :>, '(BigDecimal) -> %bool'
73
73
  pre(:>) { |x| !x.nan?}
74
74
 
75
- type :>=, '(Integer) -> %bool'
75
+ type :>=, '(%integer) -> %bool'
76
76
  type :>=, '(Float) -> %bool'
77
77
  pre(:>=) { |x| !x.nan?}
78
78
  type :>=, '(Rational) -> %bool'
79
79
  type :>=, '(BigDecimal) -> %bool'
80
80
  pre(:>=) { |x| !x.nan?}
81
81
 
82
- type :<=>, '(Integer) -> Object'
82
+ type :<=>, '(%integer) -> Object'
83
83
  post(:<=>) { |r,x| r == -1 || r==0 || r==1}
84
84
  type :<=>, '(Float) -> Object'
85
85
  post(:<=>) { |r,x| r == -1 || r==0 || r==1}
@@ -96,24 +96,24 @@ class Rational < Numeric
96
96
  type :abs2, '() -> Rational'
97
97
  post(:abs2) { |r,x| r >= 0 }
98
98
 
99
- type :angle, '() -> Numeric'
99
+ type :angle, '() -> %numeric'
100
100
  post(:angle) { |r,x| r == 0 || r == Math::PI}
101
101
 
102
- type :arg, '() -> Numeric'
102
+ type :arg, '() -> %numeric'
103
103
  post(:arg) { |r,x| r == 0 || r == Math::PI}
104
104
 
105
- type :div, '(Fixnum) -> Integer'
105
+ type :div, '(Fixnum) -> %integer'
106
106
  pre(:div) { |x| x!=0}
107
- type :div, '(Bignum) -> Integer'
107
+ type :div, '(Bignum) -> %integer'
108
108
  pre(:div) { |x| x!=0}
109
- type :div, '(Float) -> Integer'
109
+ type :div, '(Float) -> %integer'
110
110
  pre(:div) { |x| x!=0 && !x.nan?}
111
- type :div, '(Rational) -> Integer'
111
+ type :div, '(Rational) -> %integer'
112
112
  pre(:div) { |x| x!=0}
113
- type :div, '(BigDecimal) -> Integer'
113
+ type :div, '(BigDecimal) -> %integer'
114
114
  pre(:div) { |x| x!=0 && !x.nan?}
115
115
 
116
- type :modulo, '(Integer) -> Rational'
116
+ type :modulo, '(%integer) -> Rational'
117
117
  pre(:modulo) { |x| x!=0}
118
118
  type :modulo, '(Float) -> Float'
119
119
  pre(:modulo) { |x| x!=0&&!x.nan?}
@@ -122,10 +122,10 @@ class Rational < Numeric
122
122
  type :modulo, '(BigDecimal) -> BigDecimal'
123
123
  pre(:modulo) { |x| x!=0&&!x.nan?}
124
124
 
125
- type :ceil, '() -> Integer'
126
- type :ceil, '(Integer) -> Numeric'
125
+ type :ceil, '() -> %integer'
126
+ type :ceil, '(%integer) -> %numeric'
127
127
 
128
- type :denominator, '() -> Integer'
128
+ type :denominator, '() -> %integer'
129
129
  post(:denominator) { |r,x| r > 0 }
130
130
 
131
131
  type :divmod, '(%real) -> [%real, %real]'
@@ -133,26 +133,26 @@ class Rational < Numeric
133
133
 
134
134
  type :equal?, '(Object) -> %bool'
135
135
 
136
- type :fdiv, '(Integer) -> Float'
136
+ type :fdiv, '(%integer) -> Float'
137
137
  type :fdiv, '(Float) -> Float'
138
138
  type :fdiv, '(Rational) -> Float'
139
139
  type :fdiv, '(BigDecimal) -> Float'
140
140
  type :fdiv, '(Complex) -> Float'
141
141
  pre(:fdiv) { |x| x.imaginary==0 && x.real.class != Float}
142
142
 
143
- type :floor, '() -> Integer'
143
+ type :floor, '() -> %integer'
144
144
 
145
- type :floor, '(Integer) -> Numeric'
145
+ type :floor, '(%integer) -> %numeric'
146
146
 
147
- type :hash, '() -> Integer'
147
+ type :hash, '() -> %integer'
148
148
 
149
149
  type :inspect, '() -> String'
150
150
 
151
- type :numerator, '() -> Integer'
151
+ type :numerator, '() -> %integer'
152
152
 
153
- type :phase, '() -> Numeric'
153
+ type :phase, '() -> %numeric'
154
154
 
155
- type :quo, '(Integer) -> Rational'
155
+ type :quo, '(%integer) -> Rational'
156
156
  pre(:quo) { |x| x!=0}
157
157
  type :quo, '(Float) -> Float'
158
158
  pre(:quo) { |x| x!=0}
@@ -165,25 +165,25 @@ class Rational < Numeric
165
165
 
166
166
  type :rationalize, '() -> Rational'
167
167
 
168
- type :rationalize, '(Numeric) -> Rational'
168
+ type :rationalize, '(%numeric) -> Rational'
169
169
  pre(:quo) { |x| if x.is_a?(Float) then x!=Float::INFINITY && !x.nan? else true end}
170
170
 
171
- type :round, '() -> Integer'
171
+ type :round, '() -> %integer'
172
172
 
173
- type :round, '(Integer) -> Numeric'
173
+ type :round, '(%integer) -> %numeric'
174
174
 
175
175
  type :to_f, '() -> Float'
176
176
  pre(:to_f) { self<=Float::MAX}
177
177
 
178
- type :to_i, '() -> Integer'
178
+ type :to_i, '() -> %integer'
179
179
 
180
180
  type :to_r, '() -> Rational'
181
181
 
182
182
  type :to_s, '() -> String'
183
183
 
184
- type :truncate, '() -> Integer'
184
+ type :truncate, '() -> %integer'
185
185
 
186
- type :truncate, '(Integer) -> Rational'
186
+ type :truncate, '(%integer) -> Rational'
187
187
 
188
188
  type :zero?, '() -> %bool'
189
189
 
@@ -197,13 +197,13 @@ class Rational < Numeric
197
197
 
198
198
  type :real, '() -> Rational'
199
199
 
200
- type :real?, '() -> TrueClass'
200
+ type :real?, '() -> true'
201
201
 
202
202
  type :to_c, '() -> Complex'
203
203
  post(:to_c) { |r,x| r.imaginary == 0 }
204
204
 
205
- type :coerce, '(Integer) -> [Rational, Rational]'
205
+ type :coerce, '(%integer) -> [Rational, Rational]'
206
206
  type :coerce, '(Float) -> [Float, Float]'
207
207
  type :coerce, '(Rational) -> [Rational, Rational]'
208
- type :coerce, '(Complex) -> [Numeric, Numeric]'
208
+ type :coerce, '(Complex) -> [%numeric, %numeric]'
209
209
  end