@@ -116,14 +116,23 @@ fn int_eq(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
116
116
let result = if objtype:: isinstance ( other, & vm. ctx . int_type ( ) ) {
117
117
let other = BigInt :: from_pyobj ( other) ;
118
118
zelf == other
119
- } else if objtype:: isinstance ( other, & vm. ctx . float_type ( ) ) {
120
- let other_float = objfloat:: get_value ( other) ;
119
+ } else {
120
+ return Ok ( vm. ctx . not_implemented ( ) ) ;
121
+ } ;
122
+ Ok ( vm. ctx . new_bool ( result) )
123
+ }
121
124
122
- if let ( Some ( zelf_float) , Some ( other_int) ) = ( zelf. to_f64 ( ) , other_float. to_bigint ( ) ) {
123
- zelf_float == other_float && zelf == other_int
124
- } else {
125
- false
126
- }
125
+ fn int_ne ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
126
+ arg_check ! (
127
+ vm,
128
+ args,
129
+ required = [ ( zelf, Some ( vm. ctx. int_type( ) ) ) , ( other, None ) ]
130
+ ) ;
131
+
132
+ let zelf = BigInt :: from_pyobj ( zelf) ;
133
+ let result = if objtype:: isinstance ( other, & vm. ctx . int_type ( ) ) {
134
+ let other = BigInt :: from_pyobj ( other) ;
135
+ zelf != other
127
136
} else {
128
137
return Ok ( vm. ctx . not_implemented ( ) ) ;
129
138
} ;
@@ -134,11 +143,13 @@ fn int_lt(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
134
143
arg_check ! (
135
144
vm,
136
145
args,
137
- required = [
138
- ( zelf, Some ( vm. ctx. int_type( ) ) ) ,
139
- ( other, Some ( vm. ctx. int_type( ) ) )
140
- ]
146
+ required = [ ( zelf, Some ( vm. ctx. int_type( ) ) ) , ( other, None ) ]
141
147
) ;
148
+
149
+ if !objtype:: isinstance ( other, & vm. ctx . int_type ( ) ) {
150
+ return Ok ( vm. ctx . not_implemented ( ) ) ;
151
+ }
152
+
142
153
let zelf = BigInt :: from_pyobj ( zelf) ;
143
154
let other = BigInt :: from_pyobj ( other) ;
144
155
let result = zelf < other;
@@ -149,11 +160,13 @@ fn int_le(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
149
160
arg_check ! (
150
161
vm,
151
162
args,
152
- required = [
153
- ( zelf, Some ( vm. ctx. int_type( ) ) ) ,
154
- ( other, Some ( vm. ctx. int_type( ) ) )
155
- ]
163
+ required = [ ( zelf, Some ( vm. ctx. int_type( ) ) ) , ( other, None ) ]
156
164
) ;
165
+
166
+ if !objtype:: isinstance ( other, & vm. ctx . int_type ( ) ) {
167
+ return Ok ( vm. ctx . not_implemented ( ) ) ;
168
+ }
169
+
157
170
let zelf = BigInt :: from_pyobj ( zelf) ;
158
171
let other = BigInt :: from_pyobj ( other) ;
159
172
let result = zelf <= other;
@@ -164,11 +177,13 @@ fn int_gt(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
164
177
arg_check ! (
165
178
vm,
166
179
args,
167
- required = [
168
- ( zelf, Some ( vm. ctx. int_type( ) ) ) ,
169
- ( other, Some ( vm. ctx. int_type( ) ) )
170
- ]
180
+ required = [ ( zelf, Some ( vm. ctx. int_type( ) ) ) , ( other, None ) ]
171
181
) ;
182
+
183
+ if !objtype:: isinstance ( other, & vm. ctx . int_type ( ) ) {
184
+ return Ok ( vm. ctx . not_implemented ( ) ) ;
185
+ }
186
+
172
187
let zelf = BigInt :: from_pyobj ( zelf) ;
173
188
let other = BigInt :: from_pyobj ( other) ;
174
189
let result = zelf > other;
@@ -179,11 +194,13 @@ fn int_ge(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
179
194
arg_check ! (
180
195
vm,
181
196
args,
182
- required = [
183
- ( zelf, Some ( vm. ctx. int_type( ) ) ) ,
184
- ( other, Some ( vm. ctx. int_type( ) ) )
185
- ]
197
+ required = [ ( zelf, Some ( vm. ctx. int_type( ) ) ) , ( other, None ) ]
186
198
) ;
199
+
200
+ if !objtype:: isinstance ( other, & vm. ctx . int_type ( ) ) {
201
+ return Ok ( vm. ctx . not_implemented ( ) ) ;
202
+ }
203
+
187
204
let zelf = BigInt :: from_pyobj ( zelf) ;
188
205
let other = BigInt :: from_pyobj ( other) ;
189
206
let result = zelf >= other;
@@ -570,6 +587,7 @@ Base 0 means to interpret the base from the string as an integer literal.
570
587
let int_type = & context. int_type ;
571
588
572
589
context. set_attr ( & int_type, "__eq__" , context. new_rustfunc ( int_eq) ) ;
590
+ context. set_attr ( & int_type, "__ne__" , context. new_rustfunc ( int_ne) ) ;
573
591
context. set_attr ( & int_type, "__lt__" , context. new_rustfunc ( int_lt) ) ;
574
592
context. set_attr ( & int_type, "__le__" , context. new_rustfunc ( int_le) ) ;
575
593
context. set_attr ( & int_type, "__gt__" , context. new_rustfunc ( int_gt) ) ;
0 commit comments