rdl 1.1.1 → 2.0.0.rc1

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 (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,19 +1,23 @@
1
1
  require 'minitest/autorun'
2
- require_relative '../lib/rdl.rb'
2
+ $LOAD_PATH << File.dirname(__FILE__) + "/../lib"
3
+ require 'rdl'
3
4
 
4
5
  class TestTypes < Minitest::Test
5
6
  include RDL::Type
6
7
 
8
+ class A; end
9
+ class B; end
10
+ class C; end
11
+
7
12
  def test_nil_top
8
- tnil = NilType.new
9
- tnil2 = NilType.new
10
- assert(tnil.equal? tnil2)
11
- tnil3 = NominalType.new :NilClass
12
- assert(tnil.equal? tnil3)
13
+ tnil = NominalType.new :NilClass
14
+ assert_equal $__rdl_nil_type, tnil
15
+ tnil2 = SingletonType.new nil
16
+ assert_equal $__rdl_nil_type, tnil2
13
17
  ttop = TopType.new
14
18
  ttop2 = TopType.new
15
- assert_same ttop, ttop2
16
- assert (tnil != ttop)
19
+ assert_equal ttop, ttop2
20
+ assert ($__rdl_nil_type != ttop)
17
21
  end
18
22
 
19
23
  def test_nominal
@@ -21,8 +25,8 @@ class TestTypes < Minitest::Test
21
25
  ta2 = NominalType.new :A
22
26
  ta3 = NominalType.new "A"
23
27
  tb = NominalType.new :B
24
- assert_same ta, ta2
25
- assert_same ta, ta3
28
+ assert_equal ta, ta2
29
+ assert_equal ta, ta3
26
30
  assert (ta != tb)
27
31
  assert_equal "A", ta.name
28
32
  end
@@ -32,7 +36,7 @@ class TestTypes < Minitest::Test
32
36
  ta2 = SingletonType.new :A
33
37
  tb = SingletonType.new :B
34
38
  tan = NominalType.new :A
35
- assert_same ta, ta2
39
+ assert_equal ta, ta2
36
40
  assert (ta != tb)
37
41
  assert_equal :A, ta.val
38
42
  assert (ta != tan)
@@ -44,36 +48,34 @@ class TestTypes < Minitest::Test
44
48
  ta3 = VarType.new "A"
45
49
  tb = VarType.new :B
46
50
  tan = NominalType.new :A
47
- assert_same ta, ta2
48
- assert_same ta, ta3
51
+ assert_equal ta, ta2
52
+ assert_equal ta, ta3
49
53
  assert (ta != tb)
50
54
  assert_equal :A, ta.name
51
55
  assert (ta != tan)
52
56
  end
53
57
 
54
58
  def u_or_i(c)
55
- tnil = NilType.new
56
- ttop = TopType.new
57
- ta = NominalType.new :A
58
- tb = NominalType.new :B
59
- tc = NominalType.new :C
59
+ ta = NominalType.new A
60
+ tb = NominalType.new B
61
+ tc = NominalType.new C
60
62
  t1 = c.new ta, tb
61
63
  assert_equal 2, t1.types.length
62
64
  t2 = c.new tb, ta
63
- assert_same t1, t2
64
- t3 = c.new ttop, ttop
65
- assert_same t3, ttop
66
- t4 = c.new ttop, tnil, ttop, tnil
67
- assert_same t4, ttop
68
- t5 = c.new tnil, tnil
69
- assert_same t5, tnil
65
+ assert_equal t1, t2
66
+ t3 = c.new $__rdl_top_type, $__rdl_top_type
67
+ assert_equal t3, $__rdl_top_type
68
+ t4 = c.new $__rdl_top_type, $__rdl_nil_type, $__rdl_top_type, $__rdl_nil_type
69
+ assert_equal t4, $__rdl_top_type
70
+ t5 = c.new $__rdl_nil_type, $__rdl_nil_type
71
+ assert_equal t5, $__rdl_nil_type
70
72
  t6 = c.new ta, tb, tc
71
73
  assert_equal 3, t6.types.length
72
74
  t7 = c.new ta, (c.new tb, tc)
73
- assert_same t6, t7
75
+ assert_equal t6, t7
74
76
  t8 = c.new (c.new tc, tb), (c.new ta)
75
- assert_same t6, t8
76
- assert (t1 != tnil)
77
+ assert_equal t6, t8
78
+ assert (t1 != $__rdl_nil_type)
77
79
  end
78
80
 
79
81
  def test_union_intersection
@@ -82,37 +84,34 @@ class TestTypes < Minitest::Test
82
84
  end
83
85
 
84
86
  def test_optional
85
- tnil = NilType.new
86
87
  ta = NominalType.new :A
87
- t1 = OptionalType.new tnil
88
- assert_equal tnil, t1.type
89
- t2 = OptionalType.new tnil
90
- assert_same t1, t2
88
+ t1 = OptionalType.new $__rdl_nil_type
89
+ assert_equal $__rdl_nil_type, t1.type
90
+ t2 = OptionalType.new $__rdl_nil_type
91
+ assert_equal t1, t2
91
92
  t3 = OptionalType.new ta
92
93
  assert (t1 != t3)
93
94
  end
94
95
 
95
96
  def test_vararg
96
- tnil = NilType.new
97
97
  ta = NominalType.new :A
98
- t1 = VarargType.new tnil
99
- assert_equal tnil, t1.type
100
- t2 = VarargType.new tnil
101
- assert_same t1, t2
98
+ t1 = VarargType.new $__rdl_nil_type
99
+ assert_equal $__rdl_nil_type, t1.type
100
+ t2 = VarargType.new $__rdl_nil_type
101
+ assert_equal t1, t2
102
102
  t3 = VarargType.new ta
103
103
  assert (t1 != t3)
104
104
  end
105
105
 
106
106
  def test_method
107
- tnil = NilType.new
108
107
  ta = NominalType.new :A
109
108
  tb = NominalType.new :B
110
109
  tc = NominalType.new :C
111
- t1 = MethodType.new [ta, tb, tc], nil, tnil
110
+ t1 = MethodType.new [ta, tb, tc], nil, $__rdl_nil_type
112
111
  assert_equal [ta, tb, tc], t1.args
113
112
  assert_nil t1.block
114
- assert_equal tnil, t1.ret
115
- t2 = MethodType.new [tnil], t1, tnil
113
+ assert_equal $__rdl_nil_type, t1.ret
114
+ t2 = MethodType.new [$__rdl_nil_type], t1, $__rdl_nil_type
116
115
  assert_equal t1, t2.block
117
116
  end
118
117
 
@@ -124,7 +123,7 @@ class TestTypes < Minitest::Test
124
123
  assert_equal thash, t1.base
125
124
  assert_equal [ta, tb], t1.params
126
125
  t2 = GenericType.new thash, ta, tb
127
- assert_same t1, t2
126
+ assert_equal t1, t2
128
127
  t3 = GenericType.new thash, tb, ta
129
128
  assert (t1 != t3)
130
129
  tavar = VarType.new :a
@@ -134,11 +133,10 @@ class TestTypes < Minitest::Test
134
133
  end
135
134
 
136
135
  def test_structural
137
- tnil = NilType.new
138
136
  ta = NominalType.new :A
139
137
  tb = NominalType.new :B
140
138
  tc = NominalType.new :C
141
- tm1 = MethodType.new [ta, tb, tc], nil, tnil
139
+ tm1 = MethodType.new [ta, tb, tc], nil, $__rdl_nil_type
142
140
  tm2 = MethodType.new [ta], tm1, tb
143
141
  t1 = StructuralType.new(m1: tm1, m2: tm2)
144
142
  assert_equal tm1, t1.methods[:m1]
@@ -158,10 +156,8 @@ class TestTypes < Minitest::Test
158
156
  end
159
157
 
160
158
  def test_instantiate
161
- tnil = NilType.new
162
- ttop = TopType.new
163
- tA = NominalType.new :A
164
- tB = NominalType.new :B
159
+ tA = NominalType.new A
160
+ tB = NominalType.new B
165
161
  toptionalA = OptionalType.new tA
166
162
  tvarargA = VarargType.new tA
167
163
  tannotatedA = AnnotatedArgType.new("arg", tA)
@@ -188,15 +184,15 @@ class TestTypes < Minitest::Test
188
184
  tmethAAB = MethodType.new([tA, tA], nil, tB)
189
185
  tmethaab = MethodType.new([ta, ta], nil, tb)
190
186
  tmethstringstringfixnum = MethodType.new([tstring, tstring], nil, tfixnum)
191
- tmethbAABn = MethodType.new([], tmethAAB, tnil)
192
- tmethbaabn = MethodType.new([], tmethaab, tnil)
193
- tmethbssfn = MethodType.new([], tmethstringstringfixnum, tnil)
187
+ tmethbAABn = MethodType.new([], tmethAAB, $__rdl_nil_type)
188
+ tmethbaabn = MethodType.new([], tmethaab, $__rdl_nil_type)
189
+ tmethbssfn = MethodType.new([], tmethstringstringfixnum, $__rdl_nil_type)
194
190
  tstructorig = StructuralType.new(m1: tmethAAB, m2: tmethaab,
195
191
  m3: tmethbAABn, m4: tmethbaabn)
196
192
  tstructinst = StructuralType.new(m1: tmethAAB, m2: tmethstringstringfixnum,
197
193
  m3: tmethbAABn, m4: tmethbssfn)
198
- assert_equal tnil, tnil.instantiate(inst)
199
- assert_equal ttop, ttop.instantiate(inst)
194
+ assert_equal $__rdl_nil_type, $__rdl_nil_type.instantiate(inst)
195
+ assert_equal $__rdl_top_type, $__rdl_top_type.instantiate(inst)
200
196
  assert_equal tA, tA.instantiate(inst)
201
197
  assert_equal toptionalA, toptionalA.instantiate(inst)
202
198
  assert_equal tvarargA, tvarargA.instantiate(inst)
@@ -1,5 +1,6 @@
1
1
  require 'minitest/autorun'
2
- require_relative '../lib/rdl.rb'
2
+ $LOAD_PATH << File.dirname(__FILE__) + "/../lib"
3
+ require 'rdl'
3
4
 
4
5
  class TestWrap < Minitest::Test
5
6
  class C
@@ -1,4 +1,15 @@
1
- type_alias '%real', 'Integer or Float or Rational or BigDecimal'
1
+ if defined? BigDecimal
2
+ type_alias '%real', 'Fixnum or Bignum or Float or Rational or BigDecimal'
3
+ type_alias '%numeric', 'Fixnum or Bignum or Float or Rational or BigDecimal or Complex'
4
+ else
5
+ type_alias '%real', 'Fixnum or Bignum or Float or Rational'
6
+ type_alias '%numeric', 'Fixnum or Bignum or Float or Rational'
7
+ end
2
8
  type_alias '%string', '[to_str: () -> String]'
3
- type_alias '%path', '%string or Pathname'
9
+ type_alias '%integer', 'Fixnum or Bignum'
10
+ if defined? Pathname
11
+ type_alias '%path', '%string or Pathname'
12
+ else
13
+ type_alias '%path', '%string'
14
+ end
4
15
  type_alias '%open_args', '{external_encoding: ?String, internal_encoding: ?String, encoding: ?String, textmode: ?%any, binmode: ?%any, autoclose: ?%any, mode: ?String}'
@@ -1,20 +1,18 @@
1
1
  class BigDecimal < Numeric
2
2
  rdl_nowrap
3
3
 
4
- type :%, '(Numeric) -> BigDecimal'
4
+ type :%, '(%numeric) -> BigDecimal'
5
5
  pre(:%) { |x| x!=0&&(if x.is_a?(Float) then x!=Float::INFINITY && !x.nan? else true end)}
6
6
 
7
- type :+, '(Integer) -> BigDecimal'
8
- type :+, '(Float) -> BigDecimal'
9
- pre(:+) { |x| x!=Float::INFINITY && !(x.nan?)}
7
+ type :+, '(%integer) -> BigDecimal'
8
+ type :+, '(Float x {{ !x.infinite? && !x.nan? }}) -> BigDecimal'
10
9
  type :+, '(Rational) -> BigDecimal'
11
10
  type :+, '(BigDecimal) -> BigDecimal'
12
11
  type :+, '(Complex) -> Complex'
13
12
  pre(:+) { |x| if x.real.is_a?(Float) then x.real!=Float::INFINITY && !(x.real.nan?) else true end}
14
13
 
15
- type :-, '(Integer) -> BigDecimal'
16
- type :-, '(Float) -> BigDecimal'
17
- pre(:-) { |x| x!=Float::INFINITY && !(x.nan?)}
14
+ type :-, '(%integer) -> BigDecimal'
15
+ type :-, '(Float x {{ !x.infinite? && !x.nan? }}) -> BigDecimal'
18
16
  type :-, '(Rational) -> BigDecimal'
19
17
  type :-, '(BigDecimal) -> BigDecimal'
20
18
  type :-, '(Complex) -> Complex'
@@ -22,15 +20,14 @@ class BigDecimal < Numeric
22
20
 
23
21
  type :-, '() -> BigDecimal'
24
22
 
25
- type :*, '(Integer) -> BigDecimal'
26
- type :*, '(Float) -> BigDecimal'
27
- pre(:*) { |x| x!=Float::INFINITY && !(x.nan?)}
23
+ type :*, '(%integer) -> BigDecimal'
24
+ type :*, '(Float x {{ !x.infinite? && !x.nan? }}) -> BigDecimal'
28
25
  type :*, '(Rational) -> BigDecimal'
29
26
  type :*, '(BigDecimal) -> BigDecimal'
30
27
  type :*, '(Complex) -> Complex'
31
28
  pre(:*) { |x| 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}
32
29
 
33
- type :**, '(Integer) -> BigDecimal'
30
+ type :**, '(%integer) -> BigDecimal'
34
31
  type :**, '(Float) -> BigDecimal'
35
32
  pre(:**) { |x| x!=Float::INFINITY && !x.nan? && if(self<0) then x<=-1||x>=0 else true end}
36
33
  type :**, '(Rational) -> BigDecimal'
@@ -38,38 +35,30 @@ class BigDecimal < Numeric
38
35
  type :**, '(BigDecimal) -> BigDecimal'
39
36
  pre(:**) { |x| x!=BigDecimal::INFINITY && if(self<0) then x<=-1||x>=0 else true end}
40
37
 
41
- type :/, '(Integer) -> BigDecimal'
42
- pre(:/) { |x| x!=0}
43
- type :/, '(Float) -> BigDecimal'
44
- pre(:/) { |x| x!=0 && x!=Float::INFINITY && !(x.nan?)}
45
- type :/, '(Rational) -> BigDecimal'
46
- pre(:/) { |x| x!=0}
47
- type :/, '(BigDecimal) -> BigDecimal'
48
- pre(:/) { |x| x!=0}
49
- type :/, '(Complex) -> Complex'
50
- pre(:/) { |x| x!=0 && if x.real.is_a?(Float) then x.real!=Float::INFINITY && !(x.real.nan?) else true end && if x.imaginary.is_a?(Float) then x.imaginary!=Float::INFINITY && !(x.imaginary.nan?) else true end && if (x.real.is_a?(Rational)) then !x.imaginary.nan? else true end}
51
-
52
- type :<, '(Integer) -> %bool'
53
- type :<, '(Float) -> %bool'
54
- pre(:<) { |x| !x.nan? && x!=Float::INFINITY}
38
+ type :/, '(%integer x {{ x!=0 }}) -> BigDecimal'
39
+ type :/, '(Float x {{ x!=0 && !x.infinite? && !x.nan? }}) -> BigDecimal'
40
+ type :/, '(Rational x {{ x!=0 }}) -> BigDecimal'
41
+ type :/, '(BigDecimal x {{ x!=0 }}) -> BigDecimal'
42
+ type :/, '(Complex x {{ x!=0 }}) -> Complex'
43
+ pre(:/) { |x| if x.real.is_a?(Float) then x.real!=Float::INFINITY && !(x.real.nan?) else true end && if x.imaginary.is_a?(Float) then x.imaginary!=Float::INFINITY && !(x.imaginary.nan?) else true end && if (x.real.is_a?(Rational)) then !x.imaginary.nan? else true end}
44
+
45
+ type :<, '(%integer) -> %bool'
46
+ type :<, '(Float x {{ !x.nan? && !x.infinite? }}) -> %bool'
55
47
  type :<, '(Rational) -> %bool'
56
48
  type :<, '(BigDecimal) -> %bool'
57
49
 
58
- type :<=, '(Integer) -> %bool'
59
- type :<=, '(Float) -> %bool'
60
- pre(:<=) { |x| !x.nan? && x!=Float::INFINITY}
50
+ type :<=, '(%integer) -> %bool'
51
+ type :<=, '(Float x {{ !x.nan? && !x.infinite }}) -> %bool'
61
52
  type :<=, '(Rational) -> %bool'
62
53
  type :<=, '(BigDecimal) -> %bool'
63
54
 
64
- type :>, '(Integer) -> %bool'
65
- type :>, '(Float) -> %bool'
66
- pre(:>) { |x| !x.nan? && x!=Float::INFINITY}
55
+ type :>, '(%integer) -> %bool'
56
+ type :>, '(Float x {{ !x.nan? && !x.infinite? }}) -> %bool'
67
57
  type :>, '(Rational) -> %bool'
68
58
  type :>, '(BigDecimal) -> %bool'
69
59
 
70
- type :>=, '(Integer) -> %bool'
71
- type :>=, '(Float) -> %bool'
72
- pre(:>=) { |x| !x.nan? && x!=Float::INFINITY}
60
+ type :>=, '(%integer) -> %bool'
61
+ type :>=, '(Float x {{ !x.nan? && !x.infinite? }}) -> %bool'
73
62
  type :>=, '(Rational) -> %bool'
74
63
  type :>=, '(BigDecimal) -> %bool'
75
64
 
@@ -79,7 +68,7 @@ class BigDecimal < Numeric
79
68
  type :===, '(Object) -> %bool'
80
69
  pre(:===) { |x| if (x.is_a?(Float)) then (!x.nan? && x!=Float::INFINITY) else true end}
81
70
 
82
- type :<=>, '(Integer) -> Object'
71
+ type :<=>, '(%integer) -> Object'
83
72
  post(:<=>) { |r,x| r == -1 || r==0 || r==1}
84
73
  type :<=>, '(Float) -> Object'
85
74
  pre(:<=>) { |x| !x.nan? && x!=Float::INFINITY}
@@ -89,38 +78,31 @@ class BigDecimal < Numeric
89
78
  type :<=>, '(BigDecimal) -> Object'
90
79
  post(:<=>) { |r,x| r == -1 || r==0 || r==1}
91
80
 
92
- type :abs, '() -> BigDecimal'
93
- post(:abs) { |r,x| r >= 0 }
81
+ type :abs, '() -> BigDecimal r {{ r>=0 }}'
94
82
 
95
- type :abs2, '() -> BigDecimal'
96
- post(:abs2) { |r,x| r >= 0 }
83
+ type :abs2, '() -> BigDecimal r {{ r>=0 }}'
97
84
 
98
- type :angle, '() -> Numeric'
85
+ type :angle, '() -> %numeric'
99
86
  post(:angle) { |r,x| r == 0 || r == Math::PI}
100
87
 
101
- type :arg, '() -> Numeric'
88
+ type :arg, '() -> %numeric'
102
89
  post(:arg) { |r,x| r == 0 || r == Math::PI}
103
90
 
104
- type :ceil, '() -> Integer'
91
+ type :ceil, '() -> %integer'
105
92
  pre(:ceil) { !self.ininite? && !self.nan?}
106
93
 
107
94
  type :conj, '() -> BigDecimal'
108
95
  type :conjugate, '() -> BigDecimal'
109
96
 
110
- type :denominator, '() -> Integer'
97
+ type :denominator, '() -> %integer'
111
98
  pre(:denominator) { !self.ininite? && !self.nan?}
112
99
  post(:denominator) { |r,x| r>0}
113
100
 
114
- type :div, '(Fixnum) -> Integer'
115
- pre(:div) { |x| x!=0 && !self.infinite? && !self.nan?}
116
- type :div, '(Bignum) -> Integer'
117
- pre(:div) { |x| x!=0 && !self.infinite? && !self.nan?}
118
- type :div, '(Float) -> Integer'
119
- pre(:div) { |x| x!=0 && !x.nan? && x!=Float::INFINITY && !self.infinite? && !self.nan?}
120
- type :div, '(Rational) -> Integer'
121
- pre(:div) { |x| x!=0 && !self.infinite? && !self.nan?}
122
- type :div, '(BigDecimal) -> Integer'
123
- pre(:div) { |x| x!=0 && !x.nan? && !self.infinite? && !self.nan?}
101
+ type :div, '(Fixnum x {{ x!=0 && !self.infinite? && !self.nan? }}) -> %integer'
102
+ type :div, '(Bignum x {{ x!=0 && !self.infinite? && !self.nan? }}) -> %integer'
103
+ type :div, '(Float x {{ x!=0 && !self.infinite? && !self.nan? && !x.infinite? && !x.nan? }}) -> %integer'
104
+ type :div, '(Rational x {{ x!=0 && !self.infinite? && !self.nan? }}) -> %integer'
105
+ type :div, '(BigDecimal x {{ x!=0 && !self.infinite? && !self.nan? && !x.infinite? && !x.nan? }}) -> %integer'
124
106
 
125
107
  type :divmod, '(%real) -> [%real, %real]'
126
108
  pre(:divmod) { |x| x!=0 && if x.is_a?(Float) then !x.nan? && x!=Float::INFINITY else true end}
@@ -128,7 +110,7 @@ class BigDecimal < Numeric
128
110
  type :equal?, '(Object) -> %bool'
129
111
  type :eql?, '(Object) -> %bool'
130
112
 
131
- type :fdiv, '(Integer) -> Float'
113
+ type :fdiv, '(%integer) -> Float'
132
114
  type :fdiv, '(Float) -> Float'
133
115
  type :fdiv, '(Rational) -> Float'
134
116
  type :fdiv, '(BigDecimal) -> BigDecimal'
@@ -137,50 +119,43 @@ class BigDecimal < Numeric
137
119
 
138
120
  type :finite?, '() -> %bool'
139
121
 
140
- type :floor, '() -> Integer'
122
+ type :floor, '() -> %integer'
141
123
  pre(:floor) { !self.infinite? && !self.nan?}
142
124
 
143
- type :hash, '() -> Integer'
125
+ type :hash, '() -> %integer'
144
126
 
145
- type :imag, '() -> Fixnum'
146
- post(:imag) { |r,x| r == 0 }
147
- type :imaginary, '() -> Fixnum'
148
- post(:imaginary) { |r,x| r == 0 }
127
+ type :imag, '() -> Fixnum r {{ r==0 }}'
128
+ type :imaginary, '() -> Fixnum r {{ r==0 }}'
149
129
 
150
130
  type :infinite?, '() -> %bool'
151
131
 
152
132
  type :to_s, '() -> String'
153
133
  type :inspect, '() -> String'
154
134
 
155
- type :magnitude, '() -> BigDecimal'
156
- post(:magnitude) { |r,x| r>0}
135
+ type :magnitude, '() -> BigDecimal r {{ r>=0 }}'
157
136
 
158
- type :modulo, '(Numeric) -> BigDecimal'
137
+ type :modulo, '(%numeric) -> BigDecimal'
159
138
  pre(:modulo) { |x| x!=0&&(if x.is_a?(Float) then x!=Float::INFINITY && !x.nan? else true end)}
160
139
 
161
140
  type :nan?, '() -> %bool'
162
141
 
163
- type :numerator, '() -> Integer'
142
+ type :numerator, '() -> %integer'
164
143
  pre(:numerator) { !self.infinite? && !self.nan?}
165
144
 
166
- type :phase, '() -> Numeric'
145
+ type :phase, '() -> %numeric'
167
146
 
168
- type :quo, '(Integer) -> BigDecimal'
169
- pre(:quo) { |x| x!=0}
170
- type :quo, '(Float) -> BigDecimal'
171
- pre(:quo) { |x| x!=0 && x!=Float::INFINITY && !x.nan?}
172
- type :quo, '(Rational) -> BigDecimal'
173
- pre(:quo) { |x| x!=0}
174
- type :quo, '(BigDecimal) -> BigDecimal'
175
- pre(:quo) { |x| x!=0}
147
+ type :quo, '(%integer x {{ x!=0 }}) -> BigDecimal'
148
+ type :quo, '(Float x {{ x!=0 && !x.infinite? && !x.nan?}}) -> BigDecimal'
149
+ type :quo, '(Rational x {{ x!=0 }}) -> BigDecimal'
150
+ type :quo, '(BigDecimal x {{ x!=0 }}) -> BigDecimal'
176
151
  type :quo, '(Complex) -> Complex'
177
152
  pre(:quo) { |x| x!=0 && if x.real.is_a?(Float) then x.real!=Float::INFINITY && !(x.real.nan?) else true end && if x.imaginary.is_a?(Float) then x.imaginary!=Float::INFINITY && !(x.imaginary.nan?) else true end && if (x.real.is_a?(Rational)) then !x.imaginary.nan? else true end}
178
153
 
179
154
  type :real, '() -> BigDecimal'
180
155
 
181
- type :real?, '() -> TrueClass'
156
+ type :real?, '() -> true'
182
157
 
183
- type :round, '() -> Integer'
158
+ type :round, '() -> %integer'
184
159
  pre(:round) { !self.infinite? && !self.nan?}
185
160
 
186
161
  type :round, '(Fixnum) -> BigDecimal' #Also, x must be in range [-2**31, 2**31].
@@ -188,26 +163,26 @@ class BigDecimal < Numeric
188
163
  type :to_f, '() -> Float'
189
164
  pre(:to_f) { self<=Float::MAX}
190
165
 
191
- type :to_i, '() -> Integer'
166
+ type :to_i, '() -> %integer'
192
167
  pre(:to_i) { !self.infinite? && !self.nan?}
193
- type :to_int, '() -> Integer'
168
+ type :to_int, '() -> %integer'
194
169
  pre(:to_int) { !self.infinite? && !self.nan?}
195
170
 
196
171
  type :to_r, '() -> Rational'
197
172
  pre(:to_r) { !self.infinite? && !self.nan?}
198
173
 
199
- type :to_c, '() -> Complex'
174
+ type :to_c, '() -> Complex r {{ r.imaginary == 0 }}'
200
175
  post(:to_c) { |r,x| r.imaginary == 0 }
201
176
 
202
- type :truncate, '() -> Integer'
177
+ type :truncate, '() -> %integer'
203
178
 
204
179
  type :truncate, '(Fixnum) -> Rational' #Also, x must be in range [-2**31, 2**31].
205
180
 
206
181
  type :zero?, '() -> %bool'
207
182
 
208
- type :precs, '() -> [Integer, Integer]'
183
+ type :precs, '() -> [%integer, %integer]'
209
184
 
210
- type :split, '() -> [Fixnum, String, Integer, Integer]'
185
+ type :split, '() -> [Fixnum, String, %integer, %integer]'
211
186
 
212
187
  type :remainder, '(%real) -> BigDecimal'
213
188
  pre(:remainder) { |x| if x.is_a?(Float) then !x.infinite? && !x.nan? else true end}
@@ -216,7 +191,7 @@ class BigDecimal < Numeric
216
191
 
217
192
  type :frac, '() -> BigDecimal'
218
193
 
219
- type :power, '(Integer) -> BigDecimal'
194
+ type :power, '(%integer) -> BigDecimal'
220
195
  type :power, '(Float) -> BigDecimal'
221
196
  pre(:power) { |x| x!=Float::INFINITY && !x.nan? && if(self<0) then x<=-1||x>=0 else true end}
222
197
  type :power, '(Rational) -> BigDecimal'
@@ -226,7 +201,7 @@ class BigDecimal < Numeric
226
201
 
227
202
  type :nonzero?, '() -> Object'
228
203
 
229
- type :exponent, '() -> Integer'
204
+ type :exponent, '() -> %integer'
230
205
 
231
206
  type :sign, '() -> Fixnum'
232
207
 
@@ -237,13 +212,13 @@ class BigDecimal < Numeric
237
212
 
238
213
  type :add, '(%real, Fixnum) -> BigDecimal'
239
214
  pre(:add) { |x,y| if x.is_a?(Float) then !x.infinite? && !x.nan? else true end}
240
-
215
+
241
216
  type :sub, '(%real, Fixnum) -> BigDecimal'
242
217
  pre(:sub) { |x,y| if x.is_a?(Float) then !x.infinite? && !x.nan? else true end}
243
218
 
244
219
  type :mult, '(%real, Fixnum) -> BigDecimal'
245
220
  pre(:mult) { |x,y| if x.is_a?(Float) then !x.infinite? && !x.nan? else true end}
246
-
221
+
247
222
  type :coerce, '(%real) -> [BigDecimal, BigDecimal]'
248
223
  pre(:coerce) { |x| if x.is_a?(Float) then !x.nan? && !x.finite? else true end}
249
224
  end