Skip to content
Permalink
Newer
Older
100644 694 lines (589 sloc) 21.3 KB
Sep 5, 2014
1
;(function($B){
2
3
eval($B.InjectBuiltins())
4
5
var object = _b_.object, $N = _b_.None
Sep 5, 2014
6
7
function $err(op,other){
8
var msg = "unsupported operand type(s) for "+op
9
msg += ": 'int' and '"+$B.get_class(other).__name__+"'"
10
throw _b_.TypeError.$factory(msg)
Sep 5, 2014
11
}
12
13
// dictionary for built-in class 'int'
Sep 5, 2014
14
var $IntDict = {__class__:$B.$type,
15
__name__:'int',
Dec 6, 2015
17
$native:true,
18
$descriptors:{'numerator':true,
20
'imag':true,
21
'real':true}
Sep 5, 2014
22
}
23
24
$IntDict.from_bytes = function() {
25
var $=$B.args("from_bytes", 3,
26
{bytes:null, byteorder:null, signed:null}, ['bytes', 'byteorder', 'signed'],
27
arguments, {signed:False}, null, null)
Sep 5, 2014
28
29
var x = $.bytes,
30
byteorder = $.byteorder,
31
signed = $.signed
32
var _bytes, _len
33
if (isinstance(x, [_b_.list, _b_.tuple])) {
34
_bytes=x
35
_len=len(x)
Jan 14, 2015
36
} else if (isinstance(x, [_b_.bytes, _b_.bytearray])) {
37
_bytes=x.source
38
_len=x.source.length
Jan 14, 2015
39
} else {
40
_b_.TypeError.$factory("Error! " + _b_.type(x) + " is not supported in int.from_bytes. fix me!")
Sep 5, 2014
41
}
42
43
switch(byteorder) {
44
case 'big':
45
var num = _bytes[_len - 1];
46
var _mult=256
47
for (var i = (_len - 2); i >= 0; i--) {
48
// For operations, use the functions that can take or return
49
// big integers
50
num = $B.add($B.mul(_mult, _bytes[i]), num)
51
_mult = $B.mul(_mult,256)
Jan 14, 2015
53
if (!signed) return num
54
if (_bytes[0] < 128) return num
55
return $B.sub(num, _mult)
56
case 'little':
57
var num = _bytes[0]
58
if (num >= 128) num = num - 256
59
var _mult=256
60
for (var i = 1; i < _len; i++) {
61
num = $B.add($B.mul(_mult, _bytes[i]), num)
62
_mult = $B.mul(_mult,256)
Jan 14, 2015
64
if (!signed) return num
65
if (_bytes[_len - 1] < 128) return num
66
return $B.sub(num, _mult)
Sep 5, 2014
67
}
68
69
throw _b_.ValueError.$factory("byteorder must be either 'little' or 'big'");
Sep 5, 2014
70
}
71
72
$IntDict.to_bytes = function(length, byteorder, star) {
73
//var len = x.length
74
throw _b_.NotImplementedError.$factory("int.to_bytes is not implemented yet")
Sep 5, 2014
75
}
76
77
78
//$IntDict.__and__ = function(self,other){return self & other} // bitwise AND
79
80
$IntDict.__abs__ = function(self){return abs(self)}
81
Sep 5, 2014
82
$IntDict.__bool__ = function(self){return new Boolean(self.valueOf())}
83
84
$IntDict.__ceil__ = function(self){return Math.ceil(self)}
85
Sep 5, 2014
86
//is this a duplicate?
87
$IntDict.__class__ = $B.$type
88
89
$IntDict.__divmod__ = function(self, other){return divmod(self, other)}
90
Sep 5, 2014
91
$IntDict.__eq__ = function(self,other){
92
// compare object "self" to class "int"
93
if(other===undefined) return self===int
94
if(isinstance(other,int)) return self.valueOf()==other.valueOf()
95
if(isinstance(other,_b_.float)) return self.valueOf()==other.valueOf()
Sep 5, 2014
96
if(isinstance(other,_b_.complex)){
97
if (other.$imag != 0) return False
98
return self.valueOf() == other.$real
Sep 5, 2014
99
}
100
101
if (hasattr(other, '__eq__')) return getattr(other, '__eq__')(self)
102
Sep 5, 2014
103
return self.valueOf()===other
104
}
105
106
$IntDict.__float__ = function(self){
107
return new Number(self)
108
}
109
110
function preformat(self, fmt){
111
if(fmt.empty){return _b_.str(self)}
112
if(fmt.type && 'bcdoxXn'.indexOf(fmt.type)==-1){
113
throw _b_.ValueError.$factory("Unknown format code '"+fmt.type+
114
"' for object of type 'int'")
115
}
117
switch(fmt.type){
118
case undefined:
119
case 'd':
120
return self.toString()
121
case 'b':
122
return (fmt.alternate ? '0b' : '') + self.toString(2)
123
case 'c':
124
return _b_.chr(self)
125
case 'o':
126
return (fmt.alternate ? '0o' : '') + self.toString(8)
128
return (fmt.alternate ? '0x' : '') + self.toString(16)
130
return (fmt.alternate ? '0X' : '') + self.toString(16).toUpperCase()
131
case 'n':
132
return self // fix me
133
}
135
return res
136
}
137
138
Sep 5, 2014
139
$IntDict.__format__ = function(self,format_spec){
140
var fmt = new $B.parse_format_spec(format_spec)
141
if(fmt.type && 'eEfFgG%'.indexOf(fmt.type)!=-1){
142
// Call __format__ on float(self)
143
return _b_.float.$dict.__format__(self, format_spec)
145
fmt.align = fmt.align || '>'
146
var res = preformat(self, fmt)
147
if(fmt.comma){
148
var sign = res[0]=='-' ? '-' : '',
149
rest = res.substr(sign.length),
150
len = rest.length,
151
nb = Math.ceil(rest.length/3),
152
chunks = []
153
for(var i=0;i<nb;i++){
154
chunks.push(rest.substring(len-3*i-3, len-3*i))
155
}
156
chunks.reverse()
157
res = sign+chunks.join(',')
158
}
159
return $B.format_width(res, fmt)
Sep 5, 2014
160
}
161
162
//$IntDict.__float__ = function(self){return float(self)}
163
Sep 5, 2014
164
$IntDict.__floordiv__ = function(self,other){
165
if(isinstance(other,int)){
166
if(other==0) throw ZeroDivisionError.$factory('division by zero')
Sep 5, 2014
167
return Math.floor(self/other)
168
}
169
if(isinstance(other,_b_.float)){
170
if(!other.valueOf()) throw ZeroDivisionError.$factory('division by zero')
171
return Math.floor(self/other)
Sep 5, 2014
172
}
173
if(hasattr(other,'__rfloordiv__')){
174
return getattr(other,'__rfloordiv__')(self)
175
}
176
$err("//",other)
177
}
178
179
$IntDict.__hash__ = function(self){
180
if (self === undefined) {
181
return $IntDict.__hashvalue__ || $B.$py_next_hash-- // for hash of int type (not instance of int)
182
}
183
184
return self.valueOf()
185
}
Sep 5, 2014
186
187
//$IntDict.__ior__ = function(self,other){return self | other} // bitwise OR
188
189
$IntDict.__index__ = function(self){return self}
190
191
$IntDict.__init__ = function(self,value){
192
if(value===undefined){value=0}
193
self.toString = function(){return value}
194
//self.valueOf = function(){return value}
Sep 5, 2014
196
}
197
198
$IntDict.__int__ = function(self){return self}
199
200
$IntDict.__invert__ = function(self){return ~self}
201
202
// bitwise left shift
203
$IntDict.__lshift__ = function(self,other){
204
if(isinstance(other, int)){
205
return int($B.LongInt.$dict.__lshift__($B.LongInt(self), $B.LongInt(other)))
206
}
207
var rlshift = getattr(other, '__rlshift__', null)
208
if(rlshift!==null){return rlshift(self)}
209
$err('<<', other)
210
}
211
Sep 5, 2014
212
$IntDict.__mod__ = function(self,other) {
213
// can't use Javascript % because it works differently for negative numbers
214
if(isinstance(other,_b_.tuple) && other.length==1) other=other[0]
215
if(isinstance(other,[int, _b_.float, bool])){
216
if(other===false){other=0}else if(other===true){other=1}
217
if(other==0){throw _b_.ZeroDivisionError.$factory(
218
"integer division or modulo by zero")}
219
return (self%other+other)%other
Sep 5, 2014
220
}
221
if(hasattr(other,'__rmod__')) return getattr(other,'__rmod__')(self)
222
$err('%',other)
223
}
224
Sep 5, 2014
226
227
$IntDict.__mul__ = function(self,other){
228
Sep 5, 2014
229
var val = self.valueOf()
Jan 22, 2015
230
231
// this will be quick check, so lets do it early.
232
if(typeof other==="string") {
233
return other.repeat(val)
234
}
235
236
if(isinstance(other,int)){
237
var res = self*other
238
if(res>$B.min_int && res<$B.max_int){return res}
239
else{return int($B.LongInt.$dict.__mul__($B.LongInt(self),
240
$B.LongInt(other)))}
242
if(isinstance(other,_b_.float)){
243
return new Number(self*other)
Sep 5, 2014
245
if(isinstance(other,_b_.bool)){
246
if (other.valueOf()) return self
Jan 22, 2015
247
return int(0)
Sep 5, 2014
248
}
249
if(isinstance(other,_b_.complex)){
250
return $B.make_complex($IntDict.__mul__(self, other.$real),
251
$IntDict.__mul__(self, other.$imag))
Sep 5, 2014
252
}
253
if(isinstance(other,[_b_.list,_b_.tuple])){
254
var res = []
255
// make temporary copy of list
256
var $temp = other.slice(0,other.length)
257
for(var i=0;i<val;i++) res=res.concat($temp)
258
if(isinstance(other,_b_.tuple)) res=_b_.tuple(res)
259
return res
260
}
261
if(hasattr(other,'__rmul__')) return getattr(other,'__rmul__')(self)
262
$err("*",other)
263
}
264
265
$IntDict.__name__ = 'int'
266
267
$IntDict.__neg__ = function(self){return -self}
268
269
$IntDict.__new__ = function(cls){
270
if(cls===undefined){throw _b_.TypeError.$factory('int.__new__(): not enough arguments')}
271
return {__class__:cls.$factory ? cls : cls.$dict}
Sep 5, 2014
272
}
273
274
$IntDict.__pos__ = function(self){return self}
Sep 5, 2014
275
May 19, 2017
276
$IntDict.__pow__ = function(self,other,z){
Sep 5, 2014
277
if(isinstance(other, int)) {
Feb 9, 2015
278
switch(other.valueOf()) {
279
case 0:
280
return int(1)
281
case 1:
282
return int(self.valueOf())
283
}
May 19, 2017
284
if(z !== undefined && z !== null){
285
// If z is provided, the algorithm is faster than computing
286
// self ** other then applying the modulo z
287
var res = (self % z + z) % z
288
for(var i=1; i<other; i++){
289
res *= self
290
res = (res % z + z) % z
291
}
292
return res
293
}
294
var res = Math.pow(self.valueOf(),other.valueOf())
295
if(res>$B.min_int && res<$B.max_int){return res}
May 19, 2017
296
else if(res !== Infinity && !isFinite(res)){return res}
297
else{
298
return int($B.LongInt.$dict.__pow__($B.LongInt(self),
May 19, 2017
299
$B.LongInt(other)))
300
}
Sep 5, 2014
301
}
302
if(isinstance(other, _b_.float)) {
303
if(self>=0){return new Number(Math.pow(self, other.valueOf()))}
304
else{
305
// use complex power
306
return _b_.complex.__pow__($B.make_complex(self, 0), other)
308
}else if(isinstance(other, _b_.complex)){
309
var preal = Math.pow(self, other.$real),
310
ln = Math.log(self)
311
return $B.make_complex(preal*Math.cos(ln), preal*Math.sin(ln))
Sep 5, 2014
312
}
313
if(hasattr(other,'__rpow__')) return getattr(other,'__rpow__')(self)
314
$err("**",other)
315
}
316
317
$IntDict.__repr__ = function(self){
318
if(self===int) return "<class 'int'>"
319
return self.toString()
320
}
321
322
// bitwise right shift
323
$IntDict.__rshift__ = function(self,other){
324
if(isinstance(other, int)){
325
return int($B.LongInt.$dict.__rshift__($B.LongInt(self), $B.LongInt(other)))
326
}
327
var rrshift = getattr(other, '__rrshift__', null)
328
if(rrshift!==null){return rrshift(self)}
329
$err('>>', other)
330
}
Sep 5, 2014
331
332
$IntDict.__setattr__ = function(self,attr,value){
333
if(typeof self=="number"){
334
if($IntDict[attr]===undefined){
335
throw _b_.AttributeError.$factory("'int' object has no attribute '"+attr+"'")
337
throw _b_.AttributeError.$factory("'int' object attribute '"+attr+"' is read-only")
Sep 5, 2014
339
}
340
// subclasses of int can have attributes set
341
self[attr] = value
Sep 5, 2014
343
}
344
345
$IntDict.__str__ = $IntDict.__repr__
346
347
$IntDict.__truediv__ = function(self,other){
348
if(isinstance(other,int)){
349
if(other==0) throw ZeroDivisionError.$factory('division by zero')
350
if(other.__class__==$B.LongInt.$dict){return new Number(self/parseInt(other.value))}
351
return new Number(self/other)
Sep 5, 2014
352
}
353
if(isinstance(other,_b_.float)){
354
if(!other.valueOf()) throw ZeroDivisionError.$factory('division by zero')
355
return new Number(self/other)
Sep 5, 2014
356
}
357
if(isinstance(other,_b_.complex)){
358
var cmod = other.$real*other.$real+other.$imag*other.$imag
359
if(cmod==0) throw ZeroDivisionError.$factory('division by zero')
360
return $B.make_complex(self*other.$real/cmod,-self*other.$imag/cmod)
Sep 5, 2014
361
}
362
if(hasattr(other,'__rtruediv__')) return getattr(other,'__rtruediv__')(self)
363
$err("/",other)
364
}
365
366
//$IntDict.__xor__ = function(self,other){return self ^ other} // bitwise XOR
367
368
$IntDict.bit_length = function(self){
369
s = bin(self)
370
s = getattr(s,'lstrip')('-0b') // remove leading zeros and minus sign
371
return s.length // len('100101') --> 6
372
}
373
374
// descriptors
375
$IntDict.numerator = function(self){return self}
376
$IntDict.denominator = function(self){return int(1)}
377
$IntDict.imag = function(self){return int(0)}
378
$IntDict.real = function(self){return self}
379
381
$B.max_int32= (1<<30) * 2 - 1
382
$B.min_int32= - $B.max_int32
383
384
// code for operands & | ^
Sep 5, 2014
385
var $op_func = function(self,other){
Jun 7, 2015
386
if(isinstance(other,int)) {
387
if(other.__class__===$B.LongInt.$dict){
388
return $B.LongInt.$dict.__sub__($B.LongInt(self), $B.LongInt(other))
389
}
390
if (self > $B.max_int32 || self < $B.min_int32 ||
391
other > $B.max_int32 || other < $B.min_int32) {
392
return $B.LongInt.$dict.__sub__($B.LongInt(self), $B.LongInt(other))
393
}
394
return self-other
Jun 7, 2015
395
}
Sep 5, 2014
396
if(isinstance(other,_b_.bool)) return self-other
397
if(hasattr(other,'__rsub__')) return getattr(other,'__rsub__')(self)
398
$err("-",other)
399
}
400
401
$op_func += '' // source code
402
var $ops = {'&':'and','|':'or','^':'xor'}
Sep 5, 2014
403
for(var $op in $ops){
404
var opf = $op_func.replace(/-/gm,$op)
405
opf = opf.replace(new RegExp('sub','gm'),$ops[$op])
406
eval('$IntDict.__'+$ops[$op]+'__ = '+opf)
407
}
408
409
// code for + and -
410
var $op_func = function(self,other){
411
if(isinstance(other,int)){
412
if(typeof other=='number'){
413
var res = self.valueOf()-other.valueOf()
414
if(res>=$B.min_int && res<=$B.max_int){return res}
415
else{return $B.LongInt.$dict.__sub__($B.LongInt(self),
416
$B.LongInt(other))}
417
}else if(typeof other=="boolean"){
418
return other ? self-1 : self
419
}else{
420
return $B.LongInt.$dict.__sub__($B.LongInt(self),
421
$B.LongInt(other))
Sep 5, 2014
423
}
424
if(isinstance(other,_b_.float)){
425
return new Number(self-other)
Sep 5, 2014
426
}
427
if(isinstance(other,_b_.complex)){
428
return $B.make_complex(self-other.$real,-other.$imag)
Sep 5, 2014
429
}
430
if(isinstance(other,_b_.bool)){
431
var bool_value=0;
432
if(other.valueOf()) bool_value=1;
Sep 5, 2014
434
}
435
if(isinstance(other,_b_.complex)){
436
return $B.make_complex(self.valueOf() - other.$real, other.$imag)
Sep 5, 2014
437
}
438
if(hasattr(other,'__rsub__')) return getattr(other,'__rsub__')(self)
439
throw $err('-',other)
440
}
441
$op_func += '' // source code
442
var $ops = {'+':'add','-':'sub'}
443
for(var $op in $ops){
444
var opf = $op_func.replace(/-/gm,$op)
445
opf = opf.replace(new RegExp('sub','gm'),$ops[$op])
446
eval('$IntDict.__'+$ops[$op]+'__ = '+opf)
447
}
448
449
// comparison methods
450
var $comp_func = function(self,other){
451
if (other.__class__ === $B.LongInt.$dict) {
452
return $B.LongInt.$dict.__lt__(other, $B.LongInt(self))
453
}
Sep 5, 2014
454
if(isinstance(other,int)) return self.valueOf() > other.valueOf()
455
if(isinstance(other,_b_.float)) return self.valueOf() > other.valueOf()
Sep 5, 2014
456
if(isinstance(other,_b_.bool)) {
457
return self.valueOf() > _b_.bool.$dict.__hash__(other)
458
}
459
if (hasattr(other, '__int__') || hasattr(other, '__index__')) {
460
return $IntDict.__gt__(self, $B.$GetInt(other))
461
}
463
// See if other has the opposite operator, eg < for >
464
var inv_op = getattr(other, '__lt__', null)
465
if(inv_op !== null){return inv_op(self)}
466
467
throw _b_.TypeError.$factory(
468
"unorderable types: int() > "+$B.get_class(other).__name__+"()")
Sep 5, 2014
469
}
470
$comp_func += '' // source code
Sep 5, 2014
472
for(var $op in $B.$comps){
473
eval("$IntDict.__"+$B.$comps[$op]+'__ = '+
474
$comp_func.replace(/>/gm,$op).
475
replace(/__gt__/gm,'__'+$B.$comps[$op]+'__').
476
replace(/__lt__/, '__'+$B.$inv_comps[$op]+'__'))
Sep 5, 2014
477
}
478
479
// add "reflected" methods
480
$B.make_rmethods($IntDict)
481
482
var $valid_digits=function(base) {
483
var digits=''
484
if (base === 0) return '0'
485
if (base < 10) {
486
for (var i=0; i < base; i++) digits+=String.fromCharCode(i+48)
487
return digits
488
}
489
490
var digits='0123456789'
491
// A = 65 (10 + 55)
492
for (var i=10; i < base; i++) digits+=String.fromCharCode(i+55)
493
return digits
494
}
495
Dec 26, 2014
496
var int = function(value, base){
497
// int() with no argument returns 0
498
if(value===undefined){return 0}
500
// int() of an integer returns the integer if base is undefined
501
if(typeof value=='number' &&
502
(base===undefined || base==10)){return parseInt(value)}
Dec 28, 2014
504
if(base!==undefined){
505
if(!isinstance(value,[_b_.str,_b_.bytes,_b_.bytearray])){
506
throw TypeError.$factory("int() can't convert non-string with explicit base")
Dec 28, 2014
507
}
508
}
509
510
if(isinstance(value,_b_.complex)){
511
throw TypeError.$factory("can't convert complex to int")
Dec 28, 2014
512
}
513
514
var $ns=$B.args('int',2,{x:null,base:null},['x','base'],arguments,
515
{'base':10},'null','null')
516
var value = $ns['x']
517
var base = $ns['base']
519
if(isinstance(value, _b_.float) && base===10){
520
if(value<$B.min_int || value>$B.max_int){
521
return $B.LongInt.$dict.$from_float(value)
522
}
523
else{return value>0 ? Math.floor(value) : Math.ceil(value)}
Sep 5, 2014
525
Dec 26, 2014
526
if (!(base >=2 && base <= 36)) {
527
// throw error (base must be 0, or 2-36)
528
if (base != 0) throw _b_.ValueError.$factory("invalid base")
Dec 26, 2014
529
}
530
531
if (typeof value == 'number'){
532
533
if(base==10){
534
if(value < $B.min_int || value > $B.max_int) return $B.LongInt(value)
535
return value
536
}else if(value.toString().search('e')>-1){
Dec 26, 2014
537
// can't convert to another base if value is too big
538
throw _b_.OverflowError.$factory("can't convert to base "+base)
Dec 26, 2014
539
}else{
540
var res=parseInt(value, base)
541
if(res < $B.min_int || res > $B.max_int) return $B.LongInt(value,base)
542
return res
Dec 26, 2014
543
}
544
}
Sep 5, 2014
545
546
if(value===true) return Number(1)
547
if(value===false) return Number(0)
548
if(value.__class__===$B.LongInt.$dict){
549
var z = parseInt(value.value)
550
if(z>$B.min_int && z<$B.max_int){return z}
551
else{return value}
552
}
Sep 5, 2014
553
Jan 22, 2015
554
base=$B.$GetInt(base)
Sep 5, 2014
555
556
if(isinstance(value, _b_.str)) value=value.valueOf()
557
if(typeof value=="string") {
558
var _value=value.trim() // remove leading/trailing whitespace
559
if (_value.length == 2 && base==0 && (_value=='0b' || _value=='0o' || _value=='0x')) {
560
throw _b_.ValueError.$factory('invalid value')
Sep 5, 2014
561
}
562
if (_value.length >2) {
563
var _pre=_value.substr(0,2).toUpperCase()
Sep 5, 2014
564
if (base == 0) {
565
if (_pre == '0B') base=2
566
if (_pre == '0O') base=8
567
if (_pre == '0X') base=16
568
}
569
if (_pre=='0B' || _pre=='0O' || _pre=='0X') {
Sep 5, 2014
571
}
572
}
573
var _digits=$valid_digits(base)
574
var _re=new RegExp('^[+-]?['+_digits+']+$', 'i')
576
throw _b_.ValueError.$factory(
577
"invalid literal for int() with base "+base +": '"+_b_.str(value)+"'")
Sep 5, 2014
578
}
579
if(base <= 10 && !isFinite(value)) {
580
throw _b_.ValueError.$factory(
581
"invalid literal for int() with base "+base +": '"+_b_.str(value)+"'")
583
var res=parseInt(_value, base)
584
if(res < $B.min_int || res > $B.max_int) return $B.LongInt(_value, base)
585
return res
Sep 5, 2014
586
}
588
if(isinstance(value,[_b_.bytes,_b_.bytearray])){
589
var _digits = $valid_digits(base)
590
for(var i=0;i<value.source.length;i++){
591
if(_digits.indexOf(String.fromCharCode(value.source[i]))==-1){
592
throw _b_.ValueError.$factory("invalid literal for int() with base "+
593
base +": "+_b_.repr(value))
594
}
595
}
596
return Number(parseInt(getattr(value,'decode')('latin-1'), base))
597
}
Sep 5, 2014
598
599
if(hasattr(value, '__int__')) return getattr(value,'__int__')()
600
if(hasattr(value, '__index__')) return getattr(value,'__index__')()
601
if(hasattr(value, '__trunc__')) {
602
var res = getattr(value,'__trunc__')(),
603
int_func = _b_.getattr(res, '__int__', null)
604
if(int_func===null){
605
throw TypeError.$factory('__trunc__ returned non-Integral (type '+
606
$B.get_class(res).__name__+')')
607
}
608
var res=int_func()
609
if(isinstance(res, int)){return res}
610
throw TypeError.$factory('__trunc__ returned non-Integral (type '+
611
$B.get_class(res).__name__+')')
612
}
Sep 5, 2014
613
614
throw _b_.TypeError.$factory("int() argument must be a string, a bytes-like "+
615
"object or a number, not '"+$B.get_class(value).__name__+"'")
Sep 5, 2014
616
}
617
int.$dict = $IntDict
618
int.__class__ = $B.$factory
619
$IntDict.$factory = int
620
621
$B.set_func_names(int.$dict, "__builtins__")
622
Sep 5, 2014
623
_b_.int = int
624
625
// Boolean type
626
var $BoolDict = _b_.bool.$dict
627
628
$BoolDict.__add__ = function(self,other){
629
return (other ? 1 : 0)+(self ? 1 : 0)
630
}
631
632
$BoolDict.__and__ = function(self, other){
633
return bool($IntDict.__and__(self, other))
634
}
635
636
$BoolDict.__eq__ = function(self,other){
637
return self ? bool(other) : !bool(other)
638
}
639
640
$BoolDict.__ne__ = function(self,other){
641
return self ? !bool(other) : bool(other)
642
}
643
644
$BoolDict.__ge__ = function(self,other){
645
return _b_.int.$dict.__ge__($BoolDict.__hash__(self),other)
646
}
647
648
$BoolDict.__gt__ = function(self,other){
649
return _b_.int.$dict.__gt__($BoolDict.__hash__(self),other)
650
}
651
652
$BoolDict.__hash__ = $BoolDict.__index__= $BoolDict.__int__=function(self) {
653
if(self.valueOf()) return 1
654
return 0
655
}
656
657
$BoolDict.__le__ = function(self,other){return !$BoolDict.__gt__(self,other)}
658
659
$BoolDict.__lshift__ = function(self,other){return self.valueOf() << other}
660
661
$BoolDict.__lt__ = function(self,other){return !$BoolDict.__ge__(self,other)}
662
663
$BoolDict.__mul__ = function(self,other){
665
}
666
667
$BoolDict.__neg__ = function(self){return -$B.int_or_bool(self)}
668
669
$BoolDict.__or__ = function(self, other){
670
return bool($IntDict.__or__(self, other))
671
}
672
673
$BoolDict.__pos__ = $B.int_or_bool
674
675
$BoolDict.__repr__ = $BoolDict.__str__ = function(self){
676
return self ? "True" : "False"
677
}
678
679
$BoolDict.__setattr__ = function(self, attr){
680
return no_set_attr($BoolDict, attr)
681
}
682
683
$BoolDict.__sub__ = function(self,other){
684
return (self ? 1 : 0) - (other ? 1 : 0)
685
}
686
687
$BoolDict.__xor__ = function(self, other) {
688
return self.valueOf() != other.valueOf()
689
}
690
691
692
$BoolDict.__mro__ = [$IntDict, _b_.object]
Sep 5, 2014
694
})(__BRYTHON__)