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,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+'#-',nil)
|
16
|
+
expected_type = operation_type[operation_type.index('->')+3..-1]
|
17
|
+
w = -x
|
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,157 @@
|
|
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
|
+
#puts "Arg1= #{x} and type = #{type_one}"
|
14
|
+
#puts "Arg2= #{y} and type = #{type_two}"
|
15
|
+
operation_type = query(type_one+'#next',nil)
|
16
|
+
expected_type = operation_type[operation_type.index('->')+3..-1]
|
17
|
+
w = x.next
|
18
|
+
#puts "here1"
|
19
|
+
test_result = w.is_a?(Object.const_get(expected_type))
|
20
|
+
if !test_result
|
21
|
+
puts "Arg1= #{x} (type: #{type_one})"
|
22
|
+
#puts "Arg2= #{y} (type: #{type_two})"
|
23
|
+
puts "Res= #{w}"
|
24
|
+
puts "Expected type: #{expected_type}"
|
25
|
+
puts "Received type: #{w.class}"
|
26
|
+
end
|
27
|
+
#puts test_result
|
28
|
+
return test_result
|
29
|
+
end
|
30
|
+
|
31
|
+
def gen_fixnum()
|
32
|
+
return Random.rand(MIN_FIXNUM..MAX_FIXNUM)
|
33
|
+
end
|
34
|
+
|
35
|
+
def gen_bignum()
|
36
|
+
r = Random.rand()
|
37
|
+
if r<0.5
|
38
|
+
return Random.rand(MAX_FIXNUM+1..MAX_FIXNUM*1000)
|
39
|
+
else
|
40
|
+
return -1*Random.rand(MAX_FIXNUM+1..MAX_FIXNUM*1000)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def gen_float()
|
45
|
+
r = Random.rand()
|
46
|
+
if r<0.5
|
47
|
+
return Float::MAX*Random.rand
|
48
|
+
else
|
49
|
+
return -1*Float::MAX*Random.rand
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def gen_bigdec()
|
54
|
+
r = Random.rand()
|
55
|
+
if r<0.33
|
56
|
+
return BigDecimal.new(gen_fixnum())
|
57
|
+
elsif r<0.66
|
58
|
+
return BigDecimal.new(gen_bignum())
|
59
|
+
else
|
60
|
+
return BigDecimal.new(gen_float(),0)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def gen_complex()
|
65
|
+
x = gen_number(0.2,0.2,0.1,0.05,0.05,0.3,0,0.1)
|
66
|
+
#puts x
|
67
|
+
y = gen_number(0.2,0.2,0.1,0.05,0.05,0.3,0,0.1)
|
68
|
+
#puts y
|
69
|
+
return Complex(x,y)
|
70
|
+
end
|
71
|
+
|
72
|
+
def gen_rational()
|
73
|
+
x = gen_fixnum()
|
74
|
+
y = gen_fixnum()
|
75
|
+
return Rational(x,y)
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
def gen_number(probFixnum,probBignum,probBigDec,probInf,probNAN,probFloat,probComplex,probRational)
|
80
|
+
r = Random.rand()
|
81
|
+
if r<probFixnum then
|
82
|
+
#Fixnum type
|
83
|
+
x = gen_fixnum()
|
84
|
+
elsif r<(probFixnum+probBignum)
|
85
|
+
x = gen_bignum()
|
86
|
+
elsif r<(probFixnum+probBignum+probBigDec)
|
87
|
+
#BigDecimal type
|
88
|
+
x = gen_bigdec()
|
89
|
+
elsif r<(probFixnum+probBignum+probBigDec+probInf)
|
90
|
+
x=Float::INFINITY
|
91
|
+
elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN)
|
92
|
+
x=Float::NAN
|
93
|
+
elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat)
|
94
|
+
#Random Float type
|
95
|
+
x = gen_float()
|
96
|
+
elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat+probComplex)
|
97
|
+
x= gen_complex()
|
98
|
+
elsif (probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat+probComplex+probRational)
|
99
|
+
x = gen_rational()
|
100
|
+
end
|
101
|
+
return x
|
102
|
+
end
|
103
|
+
|
104
|
+
def rounds(x)
|
105
|
+
counter = 0
|
106
|
+
for i in 0..x
|
107
|
+
b= test()
|
108
|
+
if (!b) then
|
109
|
+
counter=counter+1
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
return counter
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
def query(q,y)
|
118
|
+
$__rdl_contract_switch.off {
|
119
|
+
if q =~ /^(\w+(#|\.))?(\w+(!|\?|=)?|!|~|\+|\*\*|-|\*|\/|%|<<|>>|&|\||\^|<|<=|=>|>|==|===|!=|=~|!~|<=>|\[\]|\[\]=)$/
|
120
|
+
klass = nil
|
121
|
+
klass_pref = nil
|
122
|
+
meth = nil
|
123
|
+
if q =~ /(.+)#(.+)/
|
124
|
+
klass = $1
|
125
|
+
klass_pref = "#{klass}#"
|
126
|
+
meth = $2.to_sym
|
127
|
+
elsif q =~ /(.+)\.(.+)/
|
128
|
+
klass_pref = "#{$1}."
|
129
|
+
klass = RDL::Util.add_singleton_marker($1)
|
130
|
+
meth = $2.to_sym
|
131
|
+
else
|
132
|
+
klass = self.class.to_s
|
133
|
+
klass_pref = "#{klass}#"
|
134
|
+
meth = q.to_sym
|
135
|
+
end
|
136
|
+
if RDL::Wrap.has_contracts?(klass, meth, :type)
|
137
|
+
typs = RDL::Wrap.get_contracts(klass, meth, :type)
|
138
|
+
typs.each { |t|
|
139
|
+
#puts "#{klass_pref}#{meth}: #{t}"
|
140
|
+
t_string = "#{t}"
|
141
|
+
#puts t_string
|
142
|
+
t_string =~ /\((\w*)\)(.+)/
|
143
|
+
if $1==""
|
144
|
+
return t_string
|
145
|
+
end
|
146
|
+
#return "#{t}"
|
147
|
+
}
|
148
|
+
|
149
|
+
else
|
150
|
+
#puts "No type for #{klass_pref}#{meth}"
|
151
|
+
end
|
152
|
+
else
|
153
|
+
#puts "Not implemented"
|
154
|
+
end
|
155
|
+
}
|
156
|
+
end
|
157
|
+
|
@@ -0,0 +1,157 @@
|
|
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,0,0,0.05,0.05,0.9,0,0)
|
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+'#next_float',nil)
|
16
|
+
expected_type = operation_type[operation_type.index('->')+3..-1]
|
17
|
+
w = x.next_float
|
18
|
+
#puts "here1"
|
19
|
+
test_result = w.is_a?(Object.const_get(expected_type))
|
20
|
+
if !test_result
|
21
|
+
puts "Arg1= #{x} (type: #{type_one})"
|
22
|
+
#puts "Arg2= #{y} (type: #{type_two})"
|
23
|
+
puts "Res= #{w}"
|
24
|
+
puts "Expected type: #{expected_type}"
|
25
|
+
puts "Received type: #{w.class}"
|
26
|
+
end
|
27
|
+
#puts test_result
|
28
|
+
return test_result
|
29
|
+
end
|
30
|
+
|
31
|
+
def gen_fixnum()
|
32
|
+
return Random.rand(MIN_FIXNUM..MAX_FIXNUM)
|
33
|
+
end
|
34
|
+
|
35
|
+
def gen_bignum()
|
36
|
+
r = Random.rand()
|
37
|
+
if r<0.5
|
38
|
+
return Random.rand(MAX_FIXNUM+1..MAX_FIXNUM*1000)
|
39
|
+
else
|
40
|
+
return -1*Random.rand(MAX_FIXNUM+1..MAX_FIXNUM*1000)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def gen_float()
|
45
|
+
r = Random.rand()
|
46
|
+
if r<0.5
|
47
|
+
return Float::MAX*Random.rand
|
48
|
+
else
|
49
|
+
return -1*Float::MAX*Random.rand
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def gen_bigdec()
|
54
|
+
r = Random.rand()
|
55
|
+
if r<0.33
|
56
|
+
return BigDecimal.new(gen_fixnum())
|
57
|
+
elsif r<0.66
|
58
|
+
return BigDecimal.new(gen_bignum())
|
59
|
+
else
|
60
|
+
return BigDecimal.new(gen_float(),0)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def gen_complex()
|
65
|
+
x = gen_number(0.2,0.2,0.2,0,0,0.3,0,0.1)
|
66
|
+
#puts x
|
67
|
+
y = gen_number(0.2,0.2,0.1,0.05,0.05,0.3,0,0.1)
|
68
|
+
#puts y
|
69
|
+
return Complex(x,y)
|
70
|
+
end
|
71
|
+
|
72
|
+
def gen_rational()
|
73
|
+
x = gen_fixnum()
|
74
|
+
y = gen_fixnum()
|
75
|
+
return Rational(x,y)
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
def gen_number(probFixnum,probBignum,probBigDec,probInf,probNAN,probFloat,probComplex,probRational)
|
80
|
+
r = Random.rand()
|
81
|
+
if r<probFixnum then
|
82
|
+
#Fixnum type
|
83
|
+
x = gen_fixnum()
|
84
|
+
elsif r<(probFixnum+probBignum)
|
85
|
+
x = gen_bignum()
|
86
|
+
elsif r<(probFixnum+probBignum+probBigDec)
|
87
|
+
#BigDecimal type
|
88
|
+
x = gen_bigdec()
|
89
|
+
elsif r<(probFixnum+probBignum+probBigDec+probInf)
|
90
|
+
x=Float::INFINITY
|
91
|
+
elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN)
|
92
|
+
x=Float::NAN
|
93
|
+
elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat)
|
94
|
+
#Random Float type
|
95
|
+
x = gen_float()
|
96
|
+
elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat+probComplex)
|
97
|
+
x= gen_complex()
|
98
|
+
elsif (probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat+probComplex+probRational)
|
99
|
+
x = gen_rational()
|
100
|
+
end
|
101
|
+
return x
|
102
|
+
end
|
103
|
+
|
104
|
+
def rounds(x)
|
105
|
+
counter = 0
|
106
|
+
for i in 0..x
|
107
|
+
b= test()
|
108
|
+
if (!b) then
|
109
|
+
counter=counter+1
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
return counter
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
def query(q,y)
|
118
|
+
$__rdl_contract_switch.off {
|
119
|
+
if q =~ /^(\w+(#|\.))?(\w+(!|\?|=)?|!|~|\+|\*\*|-|\*|\/|%|<<|>>|&|\||\^|<|<=|=>|>|==|===|!=|=~|!~|<=>|\[\]|\[\]=)$/
|
120
|
+
klass = nil
|
121
|
+
klass_pref = nil
|
122
|
+
meth = nil
|
123
|
+
if q =~ /(.+)#(.+)/
|
124
|
+
klass = $1
|
125
|
+
klass_pref = "#{klass}#"
|
126
|
+
meth = $2.to_sym
|
127
|
+
elsif q =~ /(.+)\.(.+)/
|
128
|
+
klass_pref = "#{$1}."
|
129
|
+
klass = RDL::Util.add_singleton_marker($1)
|
130
|
+
meth = $2.to_sym
|
131
|
+
else
|
132
|
+
klass = self.class.to_s
|
133
|
+
klass_pref = "#{klass}#"
|
134
|
+
meth = q.to_sym
|
135
|
+
end
|
136
|
+
if RDL::Wrap.has_contracts?(klass, meth, :type)
|
137
|
+
typs = RDL::Wrap.get_contracts(klass, meth, :type)
|
138
|
+
typs.each { |t|
|
139
|
+
#puts "#{klass_pref}#{meth}: #{t}"
|
140
|
+
t_string = "#{t}"
|
141
|
+
#puts t_string
|
142
|
+
t_string =~ /\((\w*)\)(.+)/
|
143
|
+
if $1==""
|
144
|
+
return t_string
|
145
|
+
end
|
146
|
+
#return "#{t}"
|
147
|
+
}
|
148
|
+
|
149
|
+
else
|
150
|
+
#puts "No type for #{klass_pref}#{meth}"
|
151
|
+
end
|
152
|
+
else
|
153
|
+
#puts "Not implemented"
|
154
|
+
end
|
155
|
+
}
|
156
|
+
end
|
157
|
+
|