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.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/CHANGES.md +25 -0
  4. data/README.md +104 -64
  5. data/extras/type_tests/%.rb +171 -0
  6. data/extras/type_tests/&.rb +159 -0
  7. data/extras/type_tests/**.rb +222 -0
  8. data/extras/type_tests/*.rb +177 -0
  9. data/extras/type_tests/+.rb +170 -0
  10. data/extras/type_tests/-.rb +171 -0
  11. data/extras/type_tests/1scomp.rb +157 -0
  12. data/extras/type_tests/<.rb +170 -0
  13. data/extras/type_tests/<<.rb +159 -0
  14. data/extras/type_tests/>>.rb +159 -0
  15. data/extras/type_tests/[].rb +163 -0
  16. data/extras/type_tests/^.rb +159 -0
  17. data/extras/type_tests/abs.rb +155 -0
  18. data/extras/type_tests/abs2.rb +164 -0
  19. data/extras/type_tests/angle.rb +157 -0
  20. data/extras/type_tests/arg.rb +157 -0
  21. data/extras/type_tests/bit_length.rb +157 -0
  22. data/extras/type_tests/ceil.rb +157 -0
  23. data/extras/type_tests/ceilRational.rb +160 -0
  24. data/extras/type_tests/conj.rb +158 -0
  25. data/extras/type_tests/defwhere.rb +86 -0
  26. data/extras/type_tests/denominator.rb +157 -0
  27. data/extras/type_tests/div.rb +172 -0
  28. data/extras/type_tests/divslash.rb +179 -0
  29. data/extras/type_tests/even?.rb +157 -0
  30. data/extras/type_tests/fdiv.rb +244 -0
  31. data/extras/type_tests/finite?.rb +157 -0
  32. data/extras/type_tests/floor.rb +157 -0
  33. data/extras/type_tests/floorRational.rb +161 -0
  34. data/extras/type_tests/hash.rb +157 -0
  35. data/extras/type_tests/imag.rb +158 -0
  36. data/extras/type_tests/infinite?.rb +157 -0
  37. data/extras/type_tests/modulo.rb +171 -0
  38. data/extras/type_tests/nan?.rb +157 -0
  39. data/extras/type_tests/neg.rb +155 -0
  40. data/extras/type_tests/next.rb +157 -0
  41. data/extras/type_tests/next_float.rb +157 -0
  42. data/extras/type_tests/numerator.rb +157 -0
  43. data/extras/type_tests/phase.rb +157 -0
  44. data/extras/type_tests/prev_float.rb +157 -0
  45. data/extras/type_tests/quo.rb +179 -0
  46. data/extras/type_tests/rationalize.rb +157 -0
  47. data/extras/type_tests/rationalizeArg.rb +198 -0
  48. data/extras/type_tests/real.rb +157 -0
  49. data/extras/type_tests/real?.rb +157 -0
  50. data/extras/type_tests/round.rb +157 -0
  51. data/extras/type_tests/roundArg.rb +169 -0
  52. data/extras/type_tests/size.rb +157 -0
  53. data/extras/type_tests/to_c.rb +157 -0
  54. data/extras/type_tests/to_f.rb +155 -0
  55. data/extras/type_tests/to_i.rb +157 -0
  56. data/extras/type_tests/to_r.rb +157 -0
  57. data/extras/type_tests/to_s.rb +157 -0
  58. data/extras/type_tests/truncate.rb +157 -0
  59. data/extras/type_tests/truncateArg.rb +166 -0
  60. data/extras/type_tests/type tests +1 -0
  61. data/extras/type_tests/zero?.rb +155 -0
  62. data/extras/type_tests/|.rb +159 -0
  63. data/lib/rdl/contracts/and.rb +1 -1
  64. data/lib/rdl/contracts/flat.rb +2 -2
  65. data/lib/rdl/contracts/proc.rb +2 -1
  66. data/lib/rdl/types/.#lexer.rex +1 -0
  67. data/lib/rdl/types/dependent_arg.rb +47 -0
  68. data/lib/rdl/types/finitehash.rb +5 -5
  69. data/lib/rdl/types/generic.rb +3 -3
  70. data/lib/rdl/types/lexer.rex +5 -2
  71. data/lib/rdl/types/lexer.rex.rb +3 -0
  72. data/lib/rdl/types/method.rb +144 -15
  73. data/lib/rdl/types/nominal.rb +1 -1
  74. data/lib/rdl/types/parser.racc +6 -1
  75. data/lib/rdl/types/parser.tab.rb +272 -245
  76. data/lib/rdl/types/tuple.rb +1 -1
  77. data/lib/rdl/types/type_inferencer.rb +7 -7
  78. data/lib/rdl/wrap.rb +16 -11
  79. data/rdl.gemspec +3 -3
  80. data/test/test_dsl.rb +4 -5
  81. data/test/test_le.rb +5 -5
  82. data/test/test_lib_types.rb +34 -34
  83. data/test/test_member.rb +3 -3
  84. data/test/test_type_contract.rb +63 -1
  85. data/test/test_types.rb +2 -0
  86. data/types/ruby-2.x/_aliases.rb +2 -2
  87. data/types/ruby-2.x/bigdecimal.rb +246 -12
  88. data/types/ruby-2.x/bignum.rb +253 -0
  89. data/types/ruby-2.x/complex.rb +111 -22
  90. data/types/ruby-2.x/fixnum.rb +238 -31
  91. data/types/ruby-2.x/float.rb +217 -35
  92. data/types/ruby-2.x/integer.rb +17 -16
  93. data/types/ruby-2.x/numeric.rb +31 -21
  94. data/types/ruby-2.x/rational.rb +196 -18
  95. metadata +67 -4
@@ -0,0 +1,177 @@
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
+ if type_one=="BigDecimal"
14
+ y = gen_number(0.25,0.25,0.2,0,0,0.2,0,0.1)
15
+ type_two = y.class.to_s
16
+ elsif x.is_a?(Float)&&(x==Float::INFINITY|| x.nan?)
17
+ y = gen_number(0.25,0.25,0,0.1,0.1,0.2,0,0.1)
18
+ type_two = y.class.to_s
19
+ elsif x.is_a?(Complex)
20
+ y = gen_number(0.3,0.3,0,0,0,0.3,0,0.1)
21
+ type_two = y.class.to_s
22
+ else
23
+ y = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
24
+ type_two = y.class.to_s
25
+ end
26
+ #puts "Arg1= #{x} and type = #{type_one}"
27
+ #puts "Arg2= #{y} and type = #{type_two}"
28
+ operation_type = query(type_one+'#*',y)
29
+ expected_type = operation_type[operation_type.index('->')+3..-1]
30
+ w = x*y
31
+ #puts "here"
32
+ test_result = w.is_a?(Object.const_get(expected_type))
33
+ if !test_result
34
+ puts "Arg1= #{x} (type: #{type_one})"
35
+ puts "Arg2= #{y} (type: #{type_two})"
36
+ puts "Res= #{w}"
37
+ puts "Expected type: #{expected_type}"
38
+ puts "Received type: #{w.class}"
39
+ end
40
+ #puts test_result
41
+ return test_result
42
+ end
43
+
44
+ def gen_fixnum()
45
+ return Random.rand(MIN_FIXNUM..MAX_FIXNUM)
46
+ end
47
+
48
+ def gen_bignum()
49
+ r = Random.rand()
50
+ if r<0.5
51
+ return Random.rand(MAX_FIXNUM+1..MAX_FIXNUM*1000)
52
+ else
53
+ return -1*Random.rand(MAX_FIXNUM+1..MAX_FIXNUM*1000)
54
+ end
55
+ end
56
+
57
+ def gen_float()
58
+ r = Random.rand()
59
+ if r<0.5
60
+ return Float::MAX*Random.rand
61
+ else
62
+ return -1*Float::MAX*Random.rand
63
+ end
64
+ end
65
+
66
+ def gen_bigdec()
67
+ r = Random.rand()
68
+ if r<0.33
69
+ return BigDecimal.new(gen_fixnum())
70
+ elsif r<0.66
71
+ return BigDecimal.new(gen_bignum())
72
+ else
73
+ return BigDecimal.new(gen_float(),0)
74
+ end
75
+ end
76
+
77
+ def gen_complex()
78
+ x = gen_number(0.25,0.25,0.1,0.05,0.05,0.2,0,0.1)
79
+ #puts x
80
+ if x.is_a?(BigDecimal)
81
+ y = gen_number(0.25,0.25,0.2,0,0,0.2,0,0.1)
82
+ elsif x.is_a?(Float)&&(x==Float::INFINITY|| x.nan?)
83
+ y = gen_number(0.25,0.25,0,0.1,0.1,0.2,0,0.1)
84
+ else
85
+ y = gen_number(0.2,0.2,0.1,0.05,0.05,0.3,0,0.1)
86
+ #puts y
87
+ end
88
+ return Complex(x,y)
89
+ end
90
+
91
+ def gen_rational()
92
+ x = gen_fixnum()
93
+ y = gen_fixnum()
94
+ return Rational(x,y)
95
+ end
96
+
97
+
98
+ def gen_number(probFixnum,probBignum,probBigDec,probInf,probNAN,probFloat,probComplex,probRational)
99
+ r = Random.rand()
100
+ if r<probFixnum then
101
+ #Fixnum type
102
+ x = gen_fixnum()
103
+ elsif r<(probFixnum+probBignum)
104
+ x = gen_bignum()
105
+ elsif r<(probFixnum+probBignum+probBigDec)
106
+ #BigDecimal type
107
+ x = gen_bigdec()
108
+ elsif r<(probFixnum+probBignum+probBigDec+probInf)
109
+ x=Float::INFINITY
110
+ elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN)
111
+ x=Float::NAN
112
+ elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat)
113
+ #Random Float type
114
+ x = gen_float()
115
+ elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat+probComplex)
116
+ x= gen_complex()
117
+ elsif (probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat+probComplex+probRational)
118
+ x = gen_rational()
119
+ end
120
+ return x
121
+ end
122
+
123
+ def rounds(x)
124
+ counter = 0
125
+ for i in 0..x
126
+ b= test()
127
+ if (!b) then
128
+ counter=counter+1
129
+ end
130
+
131
+ end
132
+ return counter
133
+ end
134
+
135
+
136
+ def query(q,y)
137
+ $__rdl_contract_switch.off {
138
+ if q =~ /^(\w+(#|\.))?(\w+(!|\?|=)?|!|~|\+|\*\*|-|\*|\/|%|<<|>>|&|\||\^|<|<=|=>|>|==|===|!=|=~|!~|<=>|\[\]|\[\]=)$/
139
+ klass = nil
140
+ klass_pref = nil
141
+ meth = nil
142
+ if q =~ /(.+)#(.+)/
143
+ klass = $1
144
+ klass_pref = "#{klass}#"
145
+ meth = $2.to_sym
146
+ elsif q =~ /(.+)\.(.+)/
147
+ klass_pref = "#{$1}."
148
+ klass = RDL::Util.add_singleton_marker($1)
149
+ meth = $2.to_sym
150
+ else
151
+ klass = self.class.to_s
152
+ klass_pref = "#{klass}#"
153
+ meth = q.to_sym
154
+ end
155
+ if RDL::Wrap.has_contracts?(klass, meth, :type)
156
+ typs = RDL::Wrap.get_contracts(klass, meth, :type)
157
+ typs.each { |t|
158
+ #puts "#{klass_pref}#{meth}: #{t}"
159
+ t_string = "#{t}"
160
+ t_string =~ /\((\w*)\)(.+)/
161
+
162
+ #puts y
163
+ if y.is_a?(Object.const_get($1))
164
+ return t_string
165
+ end
166
+ #return "#{t}"
167
+ }
168
+ nil
169
+ else
170
+ #puts "No type for #{klass_pref}#{meth}"
171
+ end
172
+ else
173
+ #puts "Not implemented"
174
+ end
175
+ }
176
+ end
177
+
@@ -0,0 +1,170 @@
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
+ if type_one=="BigDecimal"
14
+ y = gen_number(0.25,0.25,0.2,0,0,0.2,0,0.1)
15
+ type_two = y.class.to_s
16
+ elsif x.is_a?(Float)&&(x==Float::INFINITY|| x.nan?)
17
+ y = gen_number(0.2,0.2,0,0.1,0.1,0.3,0,0.1)
18
+ type_two = y.class.to_s
19
+ elsif x.is_a?(Complex)
20
+ y = gen_number(0.3,0.3,0,0,0,0.3,0,0.1)
21
+ type_two = y.class.to_s
22
+ else
23
+ y = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
24
+ type_two = y.class.to_s
25
+ end
26
+ #puts "Arg1= #{x} and type = #{type_one}"
27
+ #puts "Arg2= #{y} and type = #{type_two}"
28
+ operation_type = query(type_one+'#+',y)
29
+ expected_type = operation_type[operation_type.index('->')+3..-1]
30
+ w = x+y
31
+ test_result = w.is_a?(Object.const_get(expected_type))
32
+ if !test_result
33
+ puts "Arg1= #{x} (type: #{type_one})"
34
+ puts "Arg2= #{y} (type: #{type_two})"
35
+ puts "Res= #{w}"
36
+ puts "Expected type: #{expected_type}"
37
+ puts "Received type: #{w.class}"
38
+ end
39
+ #puts test_result
40
+ return test_result
41
+ end
42
+
43
+ def gen_fixnum()
44
+ return Random.rand(MIN_FIXNUM..MAX_FIXNUM)
45
+ end
46
+
47
+ def gen_bignum()
48
+ r = Random.rand()
49
+ if r<0.5
50
+ return Random.rand(MAX_FIXNUM+1..MAX_FIXNUM*1000)
51
+ else
52
+ return -1*Random.rand(MAX_FIXNUM+1..MAX_FIXNUM*1000)
53
+ end
54
+ end
55
+
56
+ def gen_float()
57
+ r = Random.rand()
58
+ if r<0.5
59
+ return Float::MAX*Random.rand
60
+ else
61
+ return -1*Float::MAX*Random.rand
62
+ end
63
+ end
64
+
65
+ def gen_bigdec()
66
+ r = Random.rand()
67
+ if r<0.33
68
+ return BigDecimal.new(gen_fixnum())
69
+ elsif r<0.66
70
+ return BigDecimal.new(gen_bignum())
71
+ else
72
+ return BigDecimal.new(gen_float(),0)
73
+ end
74
+ end
75
+
76
+ def gen_complex()
77
+ x = gen_number(0.2,0.2,0.1,0.05,0.05,0.3,0,0.1)
78
+ #puts x
79
+ y = gen_number(0.2,0.2,0.1,0.05,0.05,0.3,0,0.1)
80
+ #puts y
81
+ return Complex(x,y)
82
+ end
83
+
84
+ def gen_rational()
85
+ x = gen_fixnum()
86
+ y = gen_fixnum()
87
+ return Rational(x,y)
88
+ end
89
+
90
+
91
+ def gen_number(probFixnum,probBignum,probBigDec,probInf,probNAN,probFloat,probComplex,probRational)
92
+ r = Random.rand()
93
+ if r<probFixnum then
94
+ #Fixnum type
95
+ x = gen_fixnum()
96
+ elsif r<(probFixnum+probBignum)
97
+ x = gen_bignum()
98
+ elsif r<(probFixnum+probBignum+probBigDec)
99
+ #BigDecimal type
100
+ x = gen_bigdec()
101
+ elsif r<(probFixnum+probBignum+probBigDec+probInf)
102
+ x=Float::INFINITY
103
+ elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN)
104
+ x=Float::NAN
105
+ elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat)
106
+ #Random Float type
107
+ x = gen_float()
108
+ elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat+probComplex)
109
+ x= gen_complex()
110
+ elsif (probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat+probComplex+probRational)
111
+ x = gen_rational()
112
+ end
113
+ return x
114
+ end
115
+
116
+ def rounds(x)
117
+ counter = 0
118
+ for i in 0..x
119
+ b= test()
120
+ if (!b) then
121
+ counter=counter+1
122
+ end
123
+
124
+ end
125
+ return counter
126
+ end
127
+
128
+
129
+ def query(q,y)
130
+ $__rdl_contract_switch.off {
131
+ if q =~ /^(\w+(#|\.))?(\w+(!|\?|=)?|!|~|\+|\*\*|-|\*|\/|%|<<|>>|&|\||\^|<|<=|=>|>|==|===|!=|=~|!~|<=>|\[\]|\[\]=)$/
132
+ klass = nil
133
+ klass_pref = nil
134
+ meth = nil
135
+ if q =~ /(.+)#(.+)/
136
+ klass = $1
137
+ klass_pref = "#{klass}#"
138
+ meth = $2.to_sym
139
+ elsif q =~ /(.+)\.(.+)/
140
+ klass_pref = "#{$1}."
141
+ klass = RDL::Util.add_singleton_marker($1)
142
+ meth = $2.to_sym
143
+ else
144
+ klass = self.class.to_s
145
+ klass_pref = "#{klass}#"
146
+ meth = q.to_sym
147
+ end
148
+ if RDL::Wrap.has_contracts?(klass, meth, :type)
149
+ typs = RDL::Wrap.get_contracts(klass, meth, :type)
150
+ typs.each { |t|
151
+ #puts "#{klass_pref}#{meth}: #{t}"
152
+ t_string = "#{t}"
153
+ t_string =~ /\((\w*)\)(.+)/
154
+
155
+ #puts y
156
+ if y.is_a?(Object.const_get($1))
157
+ return t_string
158
+ end
159
+ #return "#{t}"
160
+ }
161
+ nil
162
+ else
163
+ #puts "No type for #{klass_pref}#{meth}"
164
+ end
165
+ else
166
+ #puts "Not implemented"
167
+ end
168
+ }
169
+ end
170
+
@@ -0,0 +1,171 @@
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
+ if type_one=="BigDecimal"
14
+ y = gen_number(0.25,0.25,0.2,0,0,0.2,0,0.1)
15
+ type_two = y.class.to_s
16
+ elsif x.is_a?(Float)&&(x==Float::INFINITY|| x.nan?)
17
+ y = gen_number(0.2,0.2,0,0.1,0.1,0.3,0,0.1)
18
+ type_two = y.class.to_s
19
+ elsif x.is_a?(Complex)
20
+ y = gen_number(0.3,0.3,0,0,0,0.3,0,0.1)
21
+ type_two = y.class.to_s
22
+ else
23
+ y = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
24
+ type_two = y.class.to_s
25
+ end
26
+ #puts "Arg1= #{x} and type = #{type_one}"
27
+ #puts "Arg2= #{y} and type = #{type_two}"
28
+ operation_type = query(type_one+'#-',y)
29
+ expected_type = operation_type[operation_type.index('->')+3..-1]
30
+ w = x-y
31
+ test_result = w.is_a?(Object.const_get(expected_type))
32
+ if !test_result
33
+ puts "Arg1= #{x} (type: #{type_one})"
34
+ puts "Arg2= #{y} (type: #{type_two})"
35
+ puts "Res= #{w}"
36
+ puts "Expected type: #{expected_type}"
37
+ puts "Received type: #{w.class}"
38
+ end
39
+ #puts test_result
40
+ return test_result
41
+ end
42
+
43
+ def gen_fixnum()
44
+ return Random.rand(MIN_FIXNUM..MAX_FIXNUM)
45
+ end
46
+
47
+ def gen_bignum()
48
+ r = Random.rand()
49
+ if r<0.5
50
+ return Random.rand(MAX_FIXNUM+1..MAX_FIXNUM*1000)
51
+ else
52
+ return -1*Random.rand(MAX_FIXNUM+1..MAX_FIXNUM*1000)
53
+ end
54
+ end
55
+
56
+ def gen_float()
57
+ r = Random.rand()
58
+ if r<0.5
59
+ return Float::MAX*Random.rand
60
+ else
61
+ return -1*Float::MAX*Random.rand
62
+ end
63
+ end
64
+
65
+ def gen_bigdec()
66
+ r = Random.rand()
67
+ if r<0.33
68
+ return BigDecimal.new(gen_fixnum())
69
+ elsif r<0.66
70
+ return BigDecimal.new(gen_bignum())
71
+ else
72
+ return BigDecimal.new(gen_float(),0)
73
+ end
74
+ end
75
+
76
+ def gen_complex()
77
+ x = gen_number(0.2,0.2,0.1,0.05,0.05,0.3,0,0.1)
78
+ #puts x
79
+ y = gen_number(0.2,0.2,0.1,0.05,0.05,0.3,0,0.1)
80
+ #puts y
81
+ return Complex(x,y)
82
+ end
83
+
84
+ def gen_rational()
85
+ x = gen_fixnum()
86
+ y = gen_fixnum()
87
+ return Rational(x,y)
88
+ end
89
+
90
+
91
+ def gen_number(probFixnum,probBignum,probBigDec,probInf,probNAN,probFloat,probComplex,probRational)
92
+ r = Random.rand()
93
+ if r<probFixnum then
94
+ #Fixnum type
95
+ x = gen_fixnum()
96
+ elsif r<(probFixnum+probBignum)
97
+ x = gen_bignum()
98
+ elsif r<(probFixnum+probBignum+probBigDec)
99
+ #BigDecimal type
100
+ x = gen_bigdec()
101
+ elsif r<(probFixnum+probBignum+probBigDec+probInf)
102
+ x=Float::INFINITY
103
+ elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN)
104
+ x=Float::NAN
105
+ elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat)
106
+ #Random Float type
107
+ x = gen_float()
108
+ elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat+probComplex)
109
+ x= gen_complex()
110
+ elsif (probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat+probComplex+probRational)
111
+ x = gen_rational()
112
+ end
113
+ return x
114
+ end
115
+
116
+ def rounds(x)
117
+ counter = 0
118
+ for i in 0..x
119
+ b= test()
120
+ if (!b) then
121
+ counter=counter+1
122
+ end
123
+
124
+ end
125
+ return counter
126
+ end
127
+
128
+
129
+ def query(q,y)
130
+ $__rdl_contract_switch.off {
131
+ if q =~ /^(\w+(#|\.))?(\w+(!|\?|=)?|!|~|\+|\*\*|-|\*|\/|%|<<|>>|&|\||\^|<|<=|=>|>|==|===|!=|=~|!~|<=>|\[\]|\[\]=)$/
132
+ klass = nil
133
+ klass_pref = nil
134
+ meth = nil
135
+ if q =~ /(.+)#(.+)/
136
+ klass = $1
137
+ klass_pref = "#{klass}#"
138
+ meth = $2.to_sym
139
+ elsif q =~ /(.+)\.(.+)/
140
+ klass_pref = "#{$1}."
141
+ klass = RDL::Util.add_singleton_marker($1)
142
+ meth = $2.to_sym
143
+ else
144
+ klass = self.class.to_s
145
+ klass_pref = "#{klass}#"
146
+ meth = q.to_sym
147
+ end
148
+ if RDL::Wrap.has_contracts?(klass, meth, :type)
149
+ typs = RDL::Wrap.get_contracts(klass, meth, :type)
150
+ typs.each { |t|
151
+ #puts "#{klass_pref}#{meth}: #{t}"
152
+ t_string = "#{t}"
153
+ t_string =~ /\((\w*)\)(.+)/
154
+ if $1!=""
155
+ #catch negative sign case
156
+ if y.is_a?(Object.const_get($1))
157
+ return t_string
158
+ end
159
+ end
160
+ #return "#{t}"
161
+ }
162
+
163
+ else
164
+ #puts "No type for #{klass_pref}#{meth}"
165
+ end
166
+ else
167
+ #puts "Not implemented"
168
+ end
169
+ }
170
+ end
171
+