rdl 1.1.0 → 1.1.1.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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGES.md +25 -0
- data/README.md +104 -64
- data/extras/type_tests/%.rb +171 -0
- data/extras/type_tests/&.rb +159 -0
- data/extras/type_tests/**.rb +222 -0
- data/extras/type_tests/*.rb +177 -0
- data/extras/type_tests/+.rb +170 -0
- data/extras/type_tests/-.rb +171 -0
- data/extras/type_tests/1scomp.rb +157 -0
- data/extras/type_tests/<.rb +170 -0
- data/extras/type_tests/<<.rb +159 -0
- data/extras/type_tests/>>.rb +159 -0
- data/extras/type_tests/[].rb +163 -0
- data/extras/type_tests/^.rb +159 -0
- data/extras/type_tests/abs.rb +155 -0
- data/extras/type_tests/abs2.rb +164 -0
- data/extras/type_tests/angle.rb +157 -0
- data/extras/type_tests/arg.rb +157 -0
- data/extras/type_tests/bit_length.rb +157 -0
- data/extras/type_tests/ceil.rb +157 -0
- data/extras/type_tests/ceilRational.rb +160 -0
- data/extras/type_tests/conj.rb +158 -0
- data/extras/type_tests/defwhere.rb +86 -0
- data/extras/type_tests/denominator.rb +157 -0
- data/extras/type_tests/div.rb +172 -0
- data/extras/type_tests/divslash.rb +179 -0
- data/extras/type_tests/even?.rb +157 -0
- data/extras/type_tests/fdiv.rb +244 -0
- data/extras/type_tests/finite?.rb +157 -0
- data/extras/type_tests/floor.rb +157 -0
- data/extras/type_tests/floorRational.rb +161 -0
- data/extras/type_tests/hash.rb +157 -0
- data/extras/type_tests/imag.rb +158 -0
- data/extras/type_tests/infinite?.rb +157 -0
- data/extras/type_tests/modulo.rb +171 -0
- data/extras/type_tests/nan?.rb +157 -0
- data/extras/type_tests/neg.rb +155 -0
- data/extras/type_tests/next.rb +157 -0
- data/extras/type_tests/next_float.rb +157 -0
- data/extras/type_tests/numerator.rb +157 -0
- data/extras/type_tests/phase.rb +157 -0
- data/extras/type_tests/prev_float.rb +157 -0
- data/extras/type_tests/quo.rb +179 -0
- data/extras/type_tests/rationalize.rb +157 -0
- data/extras/type_tests/rationalizeArg.rb +198 -0
- data/extras/type_tests/real.rb +157 -0
- data/extras/type_tests/real?.rb +157 -0
- data/extras/type_tests/round.rb +157 -0
- data/extras/type_tests/roundArg.rb +169 -0
- data/extras/type_tests/size.rb +157 -0
- data/extras/type_tests/to_c.rb +157 -0
- data/extras/type_tests/to_f.rb +155 -0
- data/extras/type_tests/to_i.rb +157 -0
- data/extras/type_tests/to_r.rb +157 -0
- data/extras/type_tests/to_s.rb +157 -0
- data/extras/type_tests/truncate.rb +157 -0
- data/extras/type_tests/truncateArg.rb +166 -0
- data/extras/type_tests/type tests +1 -0
- data/extras/type_tests/zero?.rb +155 -0
- data/extras/type_tests/|.rb +159 -0
- data/lib/rdl/contracts/and.rb +1 -1
- data/lib/rdl/contracts/flat.rb +2 -2
- data/lib/rdl/contracts/proc.rb +2 -1
- data/lib/rdl/types/.#lexer.rex +1 -0
- data/lib/rdl/types/dependent_arg.rb +47 -0
- data/lib/rdl/types/finitehash.rb +5 -5
- data/lib/rdl/types/generic.rb +3 -3
- data/lib/rdl/types/lexer.rex +5 -2
- data/lib/rdl/types/lexer.rex.rb +3 -0
- data/lib/rdl/types/method.rb +144 -15
- data/lib/rdl/types/nominal.rb +1 -1
- data/lib/rdl/types/parser.racc +6 -1
- data/lib/rdl/types/parser.tab.rb +272 -245
- data/lib/rdl/types/tuple.rb +1 -1
- data/lib/rdl/types/type_inferencer.rb +7 -7
- data/lib/rdl/wrap.rb +16 -11
- data/rdl.gemspec +3 -3
- data/test/test_dsl.rb +4 -5
- data/test/test_le.rb +5 -5
- data/test/test_lib_types.rb +34 -34
- data/test/test_member.rb +3 -3
- data/test/test_type_contract.rb +63 -1
- data/test/test_types.rb +2 -0
- data/types/ruby-2.x/_aliases.rb +2 -2
- data/types/ruby-2.x/bigdecimal.rb +246 -12
- data/types/ruby-2.x/bignum.rb +253 -0
- data/types/ruby-2.x/complex.rb +111 -22
- data/types/ruby-2.x/fixnum.rb +238 -31
- data/types/ruby-2.x/float.rb +217 -35
- data/types/ruby-2.x/integer.rb +17 -16
- data/types/ruby-2.x/numeric.rb +31 -21
- data/types/ruby-2.x/rational.rb +196 -18
- metadata +67 -4
@@ -0,0 +1 @@
|
|
1
|
+
this directory contains random testing for numeric subclass method types
|
@@ -0,0 +1,155 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bigdecimal'
|
4
|
+
require 'rdl'
|
5
|
+
require 'rdl_types'
|
6
|
+
|
7
|
+
MAX_FIXNUM = 2**(0.size*8-2)-1 #Largest fixnum. -2 since 1 bit used for sign, 1 bit used as int marker.
|
8
|
+
MIN_FIXNUM = -(2**(0.size*8-2)) #Smallest fixnum.
|
9
|
+
|
10
|
+
def test()
|
11
|
+
x = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
|
12
|
+
type_one = x.class.to_s
|
13
|
+
#puts "Arg1= #{x} and type = #{type_one}"
|
14
|
+
#puts "Arg2= #{y} and type = #{type_two}"
|
15
|
+
operation_type = query(type_one+'#zero?',nil)
|
16
|
+
expected_type = operation_type[operation_type.index('->')+3..-1]
|
17
|
+
w = x.zero?
|
18
|
+
test_result = w.is_a?(Object.const_get(expected_type))
|
19
|
+
if !test_result
|
20
|
+
puts "Arg1= #{x} (type: #{type_one})"
|
21
|
+
puts "Arg2= #{y} (type: #{type_two})"
|
22
|
+
puts "Res= #{w}"
|
23
|
+
puts "Expected type: #{expected_type}"
|
24
|
+
puts "Received type: #{w.class}"
|
25
|
+
end
|
26
|
+
#puts test_result
|
27
|
+
return test_result
|
28
|
+
end
|
29
|
+
|
30
|
+
def gen_fixnum()
|
31
|
+
return Random.rand(MIN_FIXNUM..MAX_FIXNUM)
|
32
|
+
end
|
33
|
+
|
34
|
+
def gen_bignum()
|
35
|
+
r = Random.rand()
|
36
|
+
if r<0.5
|
37
|
+
return Random.rand(MAX_FIXNUM+1..MAX_FIXNUM*1000)
|
38
|
+
else
|
39
|
+
return -1*Random.rand(MAX_FIXNUM+1..MAX_FIXNUM*1000)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def gen_float()
|
44
|
+
r = Random.rand()
|
45
|
+
if r<0.5
|
46
|
+
return Float::MAX*Random.rand
|
47
|
+
else
|
48
|
+
return -1*Float::MAX*Random.rand
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def gen_bigdec()
|
53
|
+
r = Random.rand()
|
54
|
+
if r<0.33
|
55
|
+
return BigDecimal.new(gen_fixnum())
|
56
|
+
elsif r<0.66
|
57
|
+
return BigDecimal.new(gen_bignum())
|
58
|
+
else
|
59
|
+
return BigDecimal.new(gen_float(),0)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def gen_complex()
|
64
|
+
x = gen_number(0.2,0.2,0.1,0.05,0.05,0.3,0,0.1)
|
65
|
+
#puts x
|
66
|
+
y = gen_number(0.2,0.2,0.1,0.05,0.05,0.3,0,0.1)
|
67
|
+
#puts y
|
68
|
+
return Complex(x,y)
|
69
|
+
end
|
70
|
+
|
71
|
+
def gen_rational()
|
72
|
+
x = gen_fixnum()
|
73
|
+
y = gen_fixnum()
|
74
|
+
return Rational(x,y)
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
def gen_number(probFixnum,probBignum,probBigDec,probInf,probNAN,probFloat,probComplex,probRational)
|
79
|
+
r = Random.rand()
|
80
|
+
if r<probFixnum then
|
81
|
+
#Fixnum type
|
82
|
+
x = gen_fixnum()
|
83
|
+
elsif r<(probFixnum+probBignum)
|
84
|
+
x = gen_bignum()
|
85
|
+
elsif r<(probFixnum+probBignum+probBigDec)
|
86
|
+
#BigDecimal type
|
87
|
+
x = gen_bigdec()
|
88
|
+
elsif r<(probFixnum+probBignum+probBigDec+probInf)
|
89
|
+
x=Float::INFINITY
|
90
|
+
elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN)
|
91
|
+
x=Float::NAN
|
92
|
+
elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat)
|
93
|
+
#Random Float type
|
94
|
+
x = gen_float()
|
95
|
+
elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat+probComplex)
|
96
|
+
x= gen_complex()
|
97
|
+
elsif (probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat+probComplex+probRational)
|
98
|
+
x = gen_rational()
|
99
|
+
end
|
100
|
+
return x
|
101
|
+
end
|
102
|
+
|
103
|
+
def rounds(x)
|
104
|
+
counter = 0
|
105
|
+
for i in 0..x
|
106
|
+
b= test()
|
107
|
+
if (!b) then
|
108
|
+
counter=counter+1
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
return counter
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
def query(q,y)
|
117
|
+
$__rdl_contract_switch.off {
|
118
|
+
if q =~ /^(\w+(#|\.))?(\w+(!|\?|=)?|!|~|\+|\*\*|-|\*|\/|%|<<|>>|&|\||\^|<|<=|=>|>|==|===|!=|=~|!~|<=>|\[\]|\[\]=)$/
|
119
|
+
klass = nil
|
120
|
+
klass_pref = nil
|
121
|
+
meth = nil
|
122
|
+
if q =~ /(.+)#(.+)/
|
123
|
+
klass = $1
|
124
|
+
klass_pref = "#{klass}#"
|
125
|
+
meth = $2.to_sym
|
126
|
+
elsif q =~ /(.+)\.(.+)/
|
127
|
+
klass_pref = "#{$1}."
|
128
|
+
klass = RDL::Util.add_singleton_marker($1)
|
129
|
+
meth = $2.to_sym
|
130
|
+
else
|
131
|
+
klass = self.class.to_s
|
132
|
+
klass_pref = "#{klass}#"
|
133
|
+
meth = q.to_sym
|
134
|
+
end
|
135
|
+
if RDL::Wrap.has_contracts?(klass, meth, :type)
|
136
|
+
typs = RDL::Wrap.get_contracts(klass, meth, :type)
|
137
|
+
typs.each { |t|
|
138
|
+
#puts "#{klass_pref}#{meth}: #{t}"
|
139
|
+
t_string = "#{t}"
|
140
|
+
t_string =~ /\((\w*)\)(.+)/
|
141
|
+
if $1==""
|
142
|
+
return t_string
|
143
|
+
end
|
144
|
+
#return "#{t}"
|
145
|
+
}
|
146
|
+
|
147
|
+
else
|
148
|
+
#puts "No type for #{klass_pref}#{meth}"
|
149
|
+
end
|
150
|
+
else
|
151
|
+
#puts "Not implemented"
|
152
|
+
end
|
153
|
+
}
|
154
|
+
end
|
155
|
+
|
@@ -0,0 +1,159 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bigdecimal'
|
4
|
+
require 'rdl'
|
5
|
+
require 'rdl_types'
|
6
|
+
|
7
|
+
MAX_FIXNUM = 2**(0.size*8-2)-1 #Largest fixnum. -2 since 1 bit used for sign, 1 bit used as int marker.
|
8
|
+
MIN_FIXNUM = -(2**(0.size*8-2)) #Smallest fixnum.
|
9
|
+
|
10
|
+
def test()
|
11
|
+
x = gen_number(0.5,0.5,0,0,0,0,0,0)
|
12
|
+
type_one = x.class.to_s
|
13
|
+
y = gen_number(0.5,0.5,0,0,0,0,0,0)
|
14
|
+
type_two = y.class.to_s
|
15
|
+
#puts "Arg1= #{x} and type = #{type_one}"
|
16
|
+
#puts "Arg2= #{y} and type = #{type_two}"
|
17
|
+
operation_type = query(type_one+'#|',y)
|
18
|
+
expected_type = operation_type[operation_type.index('->')+3..-1]
|
19
|
+
w = x|y
|
20
|
+
#puts "here"
|
21
|
+
test_result = w.is_a?(Object.const_get(expected_type))
|
22
|
+
if !test_result
|
23
|
+
puts "Arg1= #{x} (type: #{type_one})"
|
24
|
+
puts "Arg2= #{y} (type: #{type_two})"
|
25
|
+
puts "Res= #{w}"
|
26
|
+
puts "Expected type: #{expected_type}"
|
27
|
+
puts "Received type: #{w.class}"
|
28
|
+
end
|
29
|
+
#puts test_result
|
30
|
+
return test_result
|
31
|
+
end
|
32
|
+
|
33
|
+
def gen_fixnum()
|
34
|
+
return Random.rand(MIN_FIXNUM..MAX_FIXNUM)
|
35
|
+
end
|
36
|
+
|
37
|
+
def gen_bignum()
|
38
|
+
r = Random.rand()
|
39
|
+
if r<0.5
|
40
|
+
return Random.rand(MAX_FIXNUM+1..MAX_FIXNUM*1000)
|
41
|
+
else
|
42
|
+
return -1*Random.rand(MAX_FIXNUM+1..MAX_FIXNUM*1000)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def gen_float()
|
47
|
+
r = Random.rand()
|
48
|
+
if r<0.5
|
49
|
+
return Float::MAX*Random.rand
|
50
|
+
else
|
51
|
+
return -1*Float::MAX*Random.rand
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def gen_bigdec()
|
56
|
+
r = Random.rand()
|
57
|
+
if r<0.33
|
58
|
+
return BigDecimal.new(gen_fixnum())
|
59
|
+
elsif r<0.66
|
60
|
+
return BigDecimal.new(gen_bignum())
|
61
|
+
else
|
62
|
+
return BigDecimal.new(gen_float(),0)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def gen_complex()
|
67
|
+
x = gen_number(0.2,0.2,0.1,0.05,0.05,0.3,0,0.1)
|
68
|
+
#puts x
|
69
|
+
y = gen_number(0.2,0.2,0.1,0.05,0.05,0.3,0,0.1)
|
70
|
+
#puts y
|
71
|
+
return Complex(x,y)
|
72
|
+
end
|
73
|
+
|
74
|
+
def gen_rational()
|
75
|
+
x = gen_fixnum()
|
76
|
+
y = gen_fixnum()
|
77
|
+
return Rational(x,y)
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
def gen_number(probFixnum,probBignum,probBigDec,probInf,probNAN,probFloat,probComplex,probRational)
|
82
|
+
r = Random.rand()
|
83
|
+
if r<probFixnum then
|
84
|
+
#Fixnum type
|
85
|
+
x = gen_fixnum()
|
86
|
+
elsif r<(probFixnum+probBignum)
|
87
|
+
x = gen_bignum()
|
88
|
+
elsif r<(probFixnum+probBignum+probBigDec)
|
89
|
+
#BigDecimal type
|
90
|
+
x = gen_bigdec()
|
91
|
+
elsif r<(probFixnum+probBignum+probBigDec+probInf)
|
92
|
+
x=Float::INFINITY
|
93
|
+
elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN)
|
94
|
+
x=Float::NAN
|
95
|
+
elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat)
|
96
|
+
#Random Float type
|
97
|
+
x = gen_float()
|
98
|
+
elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat+probComplex)
|
99
|
+
x= gen_complex()
|
100
|
+
elsif (probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat+probComplex+probRational)
|
101
|
+
x = gen_rational()
|
102
|
+
end
|
103
|
+
return x
|
104
|
+
end
|
105
|
+
|
106
|
+
def rounds(x)
|
107
|
+
counter = 0
|
108
|
+
for i in 0..x
|
109
|
+
b= test()
|
110
|
+
if (!b) then
|
111
|
+
counter=counter+1
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
return counter
|
116
|
+
end
|
117
|
+
|
118
|
+
def query(q,y)
|
119
|
+
$__rdl_contract_switch.off {
|
120
|
+
if q =~ /^(\w+(#|\.))?(\w+(!|\?|=)?|!|~|\+|\*\*|-|\*|\/|%|<<|>>|&|\||\^|<|<=|=>|>|==|===|!=|=~|!~|<=>|\[\]|\[\]=)$/
|
121
|
+
klass = nil
|
122
|
+
klass_pref = nil
|
123
|
+
meth = nil
|
124
|
+
if q =~ /(.+)#(.+)/
|
125
|
+
klass = $1
|
126
|
+
klass_pref = "#{klass}#"
|
127
|
+
meth = $2.to_sym
|
128
|
+
elsif q =~ /(.+)\.(.+)/
|
129
|
+
klass_pref = "#{$1}."
|
130
|
+
klass = RDL::Util.add_singleton_marker($1)
|
131
|
+
meth = $2.to_sym
|
132
|
+
else
|
133
|
+
klass = self.class.to_s
|
134
|
+
klass_pref = "#{klass}#"
|
135
|
+
meth = q.to_sym
|
136
|
+
end
|
137
|
+
if RDL::Wrap.has_contracts?(klass, meth, :type)
|
138
|
+
typs = RDL::Wrap.get_contracts(klass, meth, :type)
|
139
|
+
typs.each { |t|
|
140
|
+
#puts "#{klass_pref}#{meth}: #{t}"
|
141
|
+
t_string = "#{t}"
|
142
|
+
t_string =~ /\((\w*)\)(.+)/
|
143
|
+
|
144
|
+
#puts y
|
145
|
+
if y.is_a?(Object.const_get($1))
|
146
|
+
return t_string
|
147
|
+
end
|
148
|
+
#return "#{t}"
|
149
|
+
}
|
150
|
+
nil
|
151
|
+
else
|
152
|
+
#puts "No type for #{klass_pref}#{meth}"
|
153
|
+
end
|
154
|
+
else
|
155
|
+
#puts "Not implemented"
|
156
|
+
end
|
157
|
+
}
|
158
|
+
end
|
159
|
+
|
data/lib/rdl/contracts/and.rb
CHANGED
data/lib/rdl/contracts/flat.rb
CHANGED
@@ -12,7 +12,7 @@ module RDL::Contract
|
|
12
12
|
if (@pred &&
|
13
13
|
((@pred.arity < 0) ? (@pred.arity.abs - 1) <= v.size : @pred.arity == v.size)) then
|
14
14
|
unless blk ? slf.instance_exec(*v, blk, &@pred) : slf.instance_exec(*v, &@pred) # TODO: Fix blk
|
15
|
-
# unless blk ? pred.call(*v, &blk) : pred.call(*v)
|
15
|
+
# unless blk ? pred.call(*v, &blk) : pred.call(*v)
|
16
16
|
raise ContractError,
|
17
17
|
"#{v.inspect} does not satisfy #{self.to_s}"
|
18
18
|
end
|
@@ -28,4 +28,4 @@ module RDL::Contract
|
|
28
28
|
@desc
|
29
29
|
end
|
30
30
|
end
|
31
|
-
end
|
31
|
+
end
|
data/lib/rdl/contracts/proc.rb
CHANGED
@@ -7,6 +7,7 @@ module RDL::Contract
|
|
7
7
|
@post_cond = post_cond
|
8
8
|
end
|
9
9
|
|
10
|
+
|
10
11
|
def wrap(slf, &blk)
|
11
12
|
Proc.new {|*v, &other_blk|
|
12
13
|
@pre_cond.check(slf, *v, &other_blk)
|
@@ -21,4 +22,4 @@ module RDL::Contract
|
|
21
22
|
"(#{@pre_cond}) -> (#{@post_cond})"
|
22
23
|
end
|
23
24
|
end
|
24
|
-
end
|
25
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
milod@ubuntu.47783:1458260004
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require_relative 'type'
|
2
|
+
|
3
|
+
module RDL::Type
|
4
|
+
class DependentArgType < Type
|
5
|
+
attr_reader :name
|
6
|
+
attr_reader :type
|
7
|
+
attr_reader :predicate
|
8
|
+
|
9
|
+
# Note: Named argument types aren't hashconsed.
|
10
|
+
|
11
|
+
def initialize(name, type, predicate)
|
12
|
+
@name = name
|
13
|
+
@type = type
|
14
|
+
/\{\{(.+)\}\}/ =~ predicate
|
15
|
+
@predicate = $1
|
16
|
+
raise RuntimeError, "Attempt to create annotated type with non-type" unless type.is_a? Type
|
17
|
+
raise RuntimeError, "Attempt to create doubly annotated type" if (type.is_a? AnnotatedArgType)||(type.is_a? DependentArgType)
|
18
|
+
super()
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
"#{@type.to_s} #{@name} {{#{@predicate}}}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def eql?(other)
|
26
|
+
self == other
|
27
|
+
end
|
28
|
+
|
29
|
+
def ==(other) # :nodoc:
|
30
|
+
return (other.instance_of? DependentArgType) && (other.name == @name) && (other.type == @type)
|
31
|
+
end
|
32
|
+
|
33
|
+
# doesn't have a match method - queries shouldn't have annotations in them
|
34
|
+
|
35
|
+
def hash # :nodoc:
|
36
|
+
return (57 + @name.hash) * @type.hash
|
37
|
+
end
|
38
|
+
|
39
|
+
def member?(obj, *args)
|
40
|
+
@type.member?(obj, *args)
|
41
|
+
end
|
42
|
+
|
43
|
+
def instantiate(inst)
|
44
|
+
return DependentArgType.new(@name, @type.instantiate(inst),@predicate)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/rdl/types/finitehash.rb
CHANGED
@@ -14,8 +14,8 @@ module RDL::Type
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.new(elts)
|
17
|
-
|
18
|
-
return
|
17
|
+
ct = @@cache[elts]
|
18
|
+
return ct if ct
|
19
19
|
t = FiniteHashType.__new__(elts)
|
20
20
|
return (@@cache[elts] = t) # assignment evaluates to t
|
21
21
|
end
|
@@ -73,8 +73,8 @@ module RDL::Type
|
|
73
73
|
}
|
74
74
|
|
75
75
|
# Check that any remaining types are optional
|
76
|
-
rest.each_pair { |k,
|
77
|
-
return false unless
|
76
|
+
rest.each_pair { |k, vt|
|
77
|
+
return false unless vt.instance_of? OptionalType
|
78
78
|
}
|
79
79
|
end
|
80
80
|
|
@@ -83,7 +83,7 @@ module RDL::Type
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def hash
|
86
|
-
|
86
|
+
229 * @elts.hash
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end
|
data/lib/rdl/types/generic.rb
CHANGED
@@ -48,7 +48,7 @@ module RDL::Type
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def <=(other)
|
51
|
-
formals, variance,
|
51
|
+
formals, variance, _ = $__rdl_type_params[base.name]
|
52
52
|
# do check here to avoid hiding errors if generic type written
|
53
53
|
# with wrong number of parameters but never checked against
|
54
54
|
# instantiated instances
|
@@ -88,7 +88,7 @@ module RDL::Type
|
|
88
88
|
|
89
89
|
def member?(obj, *args)
|
90
90
|
raise "No type parameters defined for #{base.name}" unless $__rdl_type_params[base.name]
|
91
|
-
formals = $__rdl_type_params[base.name][0]
|
91
|
+
# formals = $__rdl_type_params[base.name][0]
|
92
92
|
t = RDL::Util.rdl_type obj
|
93
93
|
return t <= self if t
|
94
94
|
return false unless base.member?(obj, *args)
|
@@ -100,7 +100,7 @@ module RDL::Type
|
|
100
100
|
end
|
101
101
|
|
102
102
|
def hash
|
103
|
-
|
103
|
+
(61 + @base.hash) * @params.hash
|
104
104
|
end
|
105
105
|
end
|
106
106
|
end
|