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.
- checksums.yaml +4 -4
- data/CHANGES.md +6 -0
- data/README.md +211 -32
- data/gemfiles/Gemfile.travis +1 -1
- data/lib/rdl.rb +85 -18
- data/lib/rdl/info.rb +74 -0
- data/lib/rdl/query.rb +8 -9
- data/lib/rdl/typecheck.rb +1057 -0
- data/lib/rdl/types/annotated_arg.rb +5 -5
- data/lib/rdl/types/{nil.rb → bot.rb} +9 -13
- data/lib/rdl/types/dependent_arg.rb +5 -5
- data/lib/rdl/types/dots_query.rb +2 -0
- data/lib/rdl/types/finitehash.rb +67 -24
- data/lib/rdl/types/generic.rb +13 -21
- data/lib/rdl/types/intersection.rb +9 -8
- data/lib/rdl/types/method.rb +30 -32
- data/lib/rdl/types/nominal.rb +22 -16
- data/lib/rdl/types/optional.rb +8 -22
- data/lib/rdl/types/parser.racc +8 -3
- data/lib/rdl/types/parser.tab.rb +131 -118
- data/lib/rdl/types/singleton.rb +15 -10
- data/lib/rdl/types/structural.rb +6 -6
- data/lib/rdl/types/top.rb +6 -6
- data/lib/rdl/types/tuple.rb +56 -24
- data/lib/rdl/types/type.rb +9 -0
- data/lib/rdl/types/type_inferencer.rb +1 -1
- data/lib/rdl/types/union.rb +52 -26
- data/lib/rdl/types/var.rb +7 -6
- data/lib/rdl/types/vararg.rb +5 -6
- data/lib/rdl/types/wild_query.rb +9 -2
- data/lib/rdl/util.rb +9 -7
- data/lib/rdl/wrap.rb +90 -72
- data/lib/rdl_types.rb +2 -2
- data/rdl.gemspec +6 -8
- data/test/test_alias.rb +4 -3
- data/test/test_contract.rb +5 -4
- data/test/test_dsl.rb +2 -1
- data/test/test_generic.rb +30 -26
- data/test/test_intersection.rb +3 -3
- data/test/test_le.rb +129 -61
- data/test/test_lib_types.rb +3 -2
- data/test/test_member.rb +33 -46
- data/test/test_parser.rb +113 -116
- data/test/test_query.rb +2 -1
- data/test/test_rdl.rb +64 -6
- data/test/test_rdl_type.rb +3 -2
- data/test/test_type_contract.rb +30 -12
- data/test/test_typecheck.rb +893 -0
- data/test/test_types.rb +50 -54
- data/test/test_wrap.rb +2 -1
- data/types/ruby-2.x/_aliases.rb +13 -2
- data/types/ruby-2.x/bigdecimal.rb +60 -85
- data/types/ruby-2.x/bignum.rb +80 -119
- data/types/ruby-2.x/complex.rb +33 -40
- data/types/ruby-2.x/fixnum.rb +81 -120
- data/types/ruby-2.x/float.rb +79 -116
- data/types/ruby-2.x/integer.rb +187 -22
- data/types/ruby-2.x/nil.rb +12 -0
- data/types/ruby-2.x/numeric.rb +38 -38
- data/types/ruby-2.x/object.rb +3 -3
- data/types/ruby-2.x/random.rb +2 -0
- data/types/ruby-2.x/range.rb +20 -19
- data/types/ruby-2.x/rational.rb +40 -40
- data/types/ruby-2.x/regexp.rb +4 -4
- data/types/ruby-2.x/string.rb +15 -17
- metadata +17 -16
- data/lib/rdl/types/.#lexer.rex +0 -1
data/types/ruby-2.x/integer.rb
CHANGED
@@ -1,32 +1,197 @@
|
|
1
1
|
class Integer < Numeric
|
2
2
|
rdl_nowrap
|
3
3
|
|
4
|
-
type
|
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, '(
|
9
|
-
type :downto, '(
|
156
|
+
type :downto, '(%integer) { (%integer) -> %any } -> %integer'
|
157
|
+
type :downto, '(%integer limit) -> Enumerator<%integer>'
|
10
158
|
type :even?, '() -> %bool'
|
11
|
-
type :gcd, '(
|
12
|
-
type :gcdlcm, '(
|
13
|
-
type :floor, '() ->
|
14
|
-
type :
|
15
|
-
type :
|
16
|
-
type :
|
17
|
-
type :
|
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, '() ->
|
20
|
-
type :
|
21
|
-
type :
|
22
|
-
type :
|
23
|
-
type :
|
24
|
-
type :
|
25
|
-
type :
|
26
|
-
type :
|
27
|
-
type :
|
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, '() ->
|
30
|
-
type :upto, '(
|
31
|
-
type :upto, '(
|
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
|
data/types/ruby-2.x/numeric.rb
CHANGED
@@ -1,56 +1,56 @@
|
|
1
1
|
class Numeric
|
2
2
|
rdl_nowrap
|
3
3
|
|
4
|
-
type :%, '(
|
4
|
+
type :%, '(%numeric) -> %numeric'
|
5
5
|
pre(:%) { |x| x!=0}
|
6
|
-
type :+, '(
|
7
|
-
type :-, '() ->
|
8
|
-
type :<=>, '(
|
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, '() ->
|
10
|
+
type :abs, '() -> %numeric'
|
11
11
|
post(:abs) { |r,x| r >= 0 }
|
12
|
-
type :abs2, '() ->
|
12
|
+
type :abs2, '() -> %numeric'
|
13
13
|
post(:abs2) { |r,x| r >= 0 }
|
14
|
-
type :angle, '() ->
|
15
|
-
type :arg, '() ->
|
16
|
-
type :ceil, '() ->
|
17
|
-
type :coerce, '(
|
18
|
-
type :conj, '() ->
|
19
|
-
type :conjugate, '() ->
|
20
|
-
type :denominator, '() ->
|
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, '(
|
22
|
+
type :div, '(%numeric) -> %integer'
|
23
23
|
pre(:div) { |x| x!=0}
|
24
|
-
type :divmod, '(
|
24
|
+
type :divmod, '(%numeric) -> [%numeric, %numeric]'
|
25
25
|
pre(:divmod) { |x| x!=0 }
|
26
|
-
type :eql?, '(
|
27
|
-
type :fdiv, '(
|
28
|
-
type :floor, '() ->
|
26
|
+
type :eql?, '(%numeric) -> %bool'
|
27
|
+
type :fdiv, '(%numeric) -> %numeric'
|
28
|
+
type :floor, '() -> %integer'
|
29
29
|
type :i, '() -> Complex'
|
30
|
-
type :imag, '() ->
|
31
|
-
type :imaginary, '() ->
|
30
|
+
type :imag, '() -> %numeric'
|
31
|
+
type :imaginary, '() -> %numeric'
|
32
32
|
type :integer?, '() -> %bool'
|
33
|
-
type :magnitude, '() ->
|
34
|
-
type :modulo, '(
|
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, '() ->
|
38
|
-
type :phase, '() ->
|
39
|
-
type :polar, '() -> [
|
40
|
-
type :quo, '(
|
41
|
-
type :real, '() ->
|
42
|
-
type :real?, '() ->
|
43
|
-
type :rect, '() -> [
|
44
|
-
type :rectangular, '() -> [
|
45
|
-
type :remainder, '(
|
46
|
-
type :round, '(
|
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, '(
|
49
|
-
type :step, '(
|
50
|
-
type :step, '(
|
51
|
-
type :step, '(
|
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, '() ->
|
54
|
-
type :truncate, '() ->
|
53
|
+
type :to_int, '() -> %integer'
|
54
|
+
type :truncate, '() -> %integer'
|
55
55
|
type :zero?, '() -> %bool'
|
56
56
|
end
|
data/types/ruby-2.x/object.rb
CHANGED
@@ -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, '() ->
|
29
|
+
type :clone, '() -> self'
|
30
30
|
# type :define_singleton_method, '(XXXX : *XXXX)') # TODO
|
31
31
|
type :display, '(IO port) -> nil'
|
32
|
-
type :dup, '() ->
|
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
|
-
|
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>'
|
data/types/ruby-2.x/random.rb
CHANGED
data/types/ruby-2.x/range.rb
CHANGED
@@ -1,38 +1,39 @@
|
|
1
1
|
class Range
|
2
2
|
rdl_nowrap
|
3
3
|
|
4
|
-
|
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, '() ->
|
11
|
-
type :bsearch, '() { (
|
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<
|
15
|
-
type :end, '() ->
|
15
|
+
type :each, '() -> Enumerator<t>'
|
16
|
+
type :end, '() -> t'
|
16
17
|
rdl_alias :eql?, :==
|
17
18
|
type :exclude_end?, '() -> %bool'
|
18
|
-
type :first, '() ->
|
19
|
-
type :first, '(Fixnum n) -> Array<
|
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, '() ->
|
24
|
-
type :last, '(Fixnum n) -> Array<
|
25
|
-
type :max, '() ->
|
26
|
-
type :max, '() { (
|
27
|
-
type :max, '(Fixnum n) -> Array<
|
28
|
-
type :max, '(Fixnum n) { (
|
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, '() ->
|
31
|
-
type :min, '() { (
|
32
|
-
type :min, '(Fixnum n) -> Array<
|
33
|
-
type :min, '(Fixnum n) { (
|
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) { (
|
36
|
-
type :step, '(?Fixnum n) -> Enumerator<
|
36
|
+
type :step, '(?Fixnum n) { (t) -> %any } -> self'
|
37
|
+
type :step, '(?Fixnum n) -> Enumerator<t>'
|
37
38
|
type :to_s, '() -> String'
|
38
39
|
end
|
data/types/ruby-2.x/rational.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
class Rational < Numeric
|
2
2
|
rdl_nowrap
|
3
3
|
|
4
|
-
type :%, '(
|
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 :*, '(
|
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 :+, '(
|
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 :-, '(
|
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 :**, '(
|
35
|
-
type :**, '(Float) ->
|
36
|
-
type :**, '(Rational) ->
|
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 :/, '(
|
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 :<, '(
|
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 :<=, '(
|
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 :>, '(
|
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 :>=, '(
|
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 :<=>, '(
|
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, '() ->
|
99
|
+
type :angle, '() -> %numeric'
|
100
100
|
post(:angle) { |r,x| r == 0 || r == Math::PI}
|
101
101
|
|
102
|
-
type :arg, '() ->
|
102
|
+
type :arg, '() -> %numeric'
|
103
103
|
post(:arg) { |r,x| r == 0 || r == Math::PI}
|
104
104
|
|
105
|
-
type :div, '(Fixnum) ->
|
105
|
+
type :div, '(Fixnum) -> %integer'
|
106
106
|
pre(:div) { |x| x!=0}
|
107
|
-
type :div, '(Bignum) ->
|
107
|
+
type :div, '(Bignum) -> %integer'
|
108
108
|
pre(:div) { |x| x!=0}
|
109
|
-
type :div, '(Float) ->
|
109
|
+
type :div, '(Float) -> %integer'
|
110
110
|
pre(:div) { |x| x!=0 && !x.nan?}
|
111
|
-
type :div, '(Rational) ->
|
111
|
+
type :div, '(Rational) -> %integer'
|
112
112
|
pre(:div) { |x| x!=0}
|
113
|
-
type :div, '(BigDecimal) ->
|
113
|
+
type :div, '(BigDecimal) -> %integer'
|
114
114
|
pre(:div) { |x| x!=0 && !x.nan?}
|
115
115
|
|
116
|
-
type :modulo, '(
|
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, '() ->
|
126
|
-
type :ceil, '(
|
125
|
+
type :ceil, '() -> %integer'
|
126
|
+
type :ceil, '(%integer) -> %numeric'
|
127
127
|
|
128
|
-
type :denominator, '() ->
|
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, '(
|
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, '() ->
|
143
|
+
type :floor, '() -> %integer'
|
144
144
|
|
145
|
-
type :floor, '(
|
145
|
+
type :floor, '(%integer) -> %numeric'
|
146
146
|
|
147
|
-
type :hash, '() ->
|
147
|
+
type :hash, '() -> %integer'
|
148
148
|
|
149
149
|
type :inspect, '() -> String'
|
150
150
|
|
151
|
-
type :numerator, '() ->
|
151
|
+
type :numerator, '() -> %integer'
|
152
152
|
|
153
|
-
type :phase, '() ->
|
153
|
+
type :phase, '() -> %numeric'
|
154
154
|
|
155
|
-
type :quo, '(
|
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, '(
|
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, '() ->
|
171
|
+
type :round, '() -> %integer'
|
172
172
|
|
173
|
-
type :round, '(
|
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, '() ->
|
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, '() ->
|
184
|
+
type :truncate, '() -> %integer'
|
185
185
|
|
186
|
-
type :truncate, '(
|
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?, '() ->
|
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, '(
|
205
|
+
type :coerce, '(%integer) -> [Rational, Rational]'
|
206
206
|
type :coerce, '(Float) -> [Float, Float]'
|
207
207
|
type :coerce, '(Rational) -> [Rational, Rational]'
|
208
|
-
type :coerce, '(Complex) -> [
|
208
|
+
type :coerce, '(Complex) -> [%numeric, %numeric]'
|
209
209
|
end
|