forked from skulpt/skulpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumtype.js
672 lines (547 loc) · 19.3 KB
/
numtype.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
/**
* @constructor
* Sk.builtin.numtype
*
* @description
* Abstract class for Python numeric types.
*
* @extends {Sk.builtin.object}
*
* @return {undefined} Cannot instantiate a Sk.builtin.numtype object
*/
Sk.builtin.numtype = function () {
throw new Sk.builtin.ExternalError("Cannot instantiate abstract Sk.builtin.numtype class");
};
Sk.abstr.setUpInheritance("NumericType", Sk.builtin.numtype, Sk.builtin.object);
Sk.builtin.numtype.sk$abstract = true;
/**
* Python wrapper of `__abs__` method.
*
* @name __abs__
* @instance
* @memberOf Sk.builtin.numtype.prototype
*/
Sk.builtin.numtype.prototype["__abs__"] = new Sk.builtin.func(function (self) {
if (self.nb$abs === undefined) {
throw new Sk.builtin.NotImplementedError("__abs__ is not yet implemented");
}
Sk.builtin.pyCheckArgsLen("__abs__", arguments.length, 0, 0, false, true);
return self.nb$abs();
});
/**
* Python wrapper of `__neg__` method.
*
* @name __neg__
* @instance
* @memberOf Sk.builtin.numtype.prototype
*/
Sk.builtin.numtype.prototype["__neg__"] = new Sk.builtin.func(function (self) {
if (self.nb$negative === undefined) {
throw new Sk.builtin.NotImplementedError("__neg__ is not yet implemented");
}
Sk.builtin.pyCheckArgsLen("__neg__", arguments.length, 0, 0, false, true);
return self.nb$negative();
});
/**
* Python wrapper of `__pos__` method.
*
* @name __pos__
* @instance
* @memberOf Sk.builtin.numtype.prototype
*/
Sk.builtin.numtype.prototype["__pos__"] = new Sk.builtin.func(function (self) {
if (self.nb$positive === undefined) {
throw new Sk.builtin.NotImplementedError("__pos__ is not yet implemented");
}
Sk.builtin.pyCheckArgsLen("__pos__", arguments.length, 0, 0, false, true);
return self.nb$positive();
});
/**
* Python wrapper of `__int__` method.
*
* @name __int__
* @instance
* @memberOf Sk.builtin.numtype.prototype
*/
Sk.builtin.numtype.prototype["__int__"] = new Sk.builtin.func(function (self) {
if (self.nb$int_ === undefined) {
throw new Sk.builtin.NotImplementedError("__int__ is not yet implemented");
}
Sk.builtin.pyCheckArgsLen("__int__", arguments.length, 0, 0, false, true);
return self.nb$int_();
});
/**
* Python wrapper of `__long__` method.
*
* @name __long__
* @instance
* @memberOf Sk.builtin.numtype.prototype
*/
Sk.builtin.numtype.prototype["__long__"] = new Sk.builtin.func(function (self) {
if (self.nb$lng === undefined) {
throw new Sk.builtin.NotImplementedError("__long__ is not yet implemented");
}
Sk.builtin.pyCheckArgsLen("__long__", arguments.length, 0, 0, false, true);
return self.nb$lng();
});
/**
* Python wrapper of `__float__` method.
*
* @name __float__
* @instance
* @memberOf Sk.builtin.numtype.prototype
*/
Sk.builtin.numtype.prototype["__float__"] = new Sk.builtin.func(function (self) {
if (self.nb$float_ === undefined) {
throw new Sk.builtin.NotImplementedError("__float__ is not yet implemented");
}
Sk.builtin.pyCheckArgsLen("__float__", arguments.length, 0, 0, false, true);
return self.nb$float_();
});
/**
* Python wrapper of `__add__` method.
*
* @name __add__
* @instance
* @memberOf Sk.builtin.numtype.prototype
*/
Sk.builtin.numtype.prototype["__add__"] = new Sk.builtin.func(function (self, other) {
if (self.nb$add === undefined) {
throw new Sk.builtin.NotImplementedError("__add__ is not yet implemented");
}
Sk.builtin.pyCheckArgsLen("__add__", arguments.length, 1, 1, false, true);
return self.nb$add(other);
});
/**
* Python wrapper of `__radd__` method.
*
* @name __radd__
* @instance
* @memberOf Sk.builtin.numtype.prototype
*/
Sk.builtin.numtype.prototype["__radd__"] = new Sk.builtin.func(function (self, other) {
if (self.nb$reflected_add === undefined) {
throw new Sk.builtin.NotImplementedError("__radd__ is not yet implemented");
}
Sk.builtin.pyCheckArgsLen("__radd__", arguments.length, 1, 1, false, true);
return self.nb$reflected_add(other);
});
/**
* Python wrapper of `__sub__` method.
*
* @name __sub__
* @instance
* @memberOf Sk.builtin.numtype.prototype
*/
Sk.builtin.numtype.prototype["__sub__"] = new Sk.builtin.func(function (self, other) {
if (self.nb$subtract === undefined) {
throw new Sk.builtin.NotImplementedError("__sub__ is not yet implemented");
}
Sk.builtin.pyCheckArgsLen("__sub__", arguments.length, 1, 1, false, true);
return self.nb$subtract(other);
});
/**
* Python wrapper of `__rsub__` method.
*
* @name __rsub__
* @instance
* @memberOf Sk.builtin.numtype.prototype
*/
Sk.builtin.numtype.prototype["__rsub__"] = new Sk.builtin.func(function (self, other) {
if (self.nb$reflected_subtract === undefined) {
throw new Sk.builtin.NotImplementedError("__rsub__ is not yet implemented");
}
Sk.builtin.pyCheckArgsLen("__rsub__", arguments.length, 1, 1, false, true);
return self.nb$reflected_subtract(other);
});
/**
* Python wrapper of `__mul__` method.
*
* @name __mul__
* @instance
* @memberOf Sk.builtin.numtype.prototype
*/
Sk.builtin.numtype.prototype["__mul__"] = new Sk.builtin.func(function (self, other) {
if (self.nb$multiply === undefined) {
throw new Sk.builtin.NotImplementedError("__mul__ is not yet implemented");
}
Sk.builtin.pyCheckArgsLen("__mul__", arguments.length, 1, 1, false, true);
return self.nb$multiply(other);
});
/**
* Python wrapper of `__rmul__` method.
*
* @name __rmul__
* @instance
* @memberOf Sk.builtin.numtype.prototype
*/
Sk.builtin.numtype.prototype["__rmul__"] = new Sk.builtin.func(function (self, other) {
if (self.nb$reflected_multiply === undefined) {
throw new Sk.builtin.NotImplementedError("__rmul__ is not yet implemented");
}
Sk.builtin.pyCheckArgsLen("__rmul__", arguments.length, 1, 1, false, true);
return self.nb$reflected_multiply(other);
});
/**
* Python wrapper of `__div__` method.
*
* @name __div__
* @instance
* @memberOf Sk.builtin.numtype.prototype
*/
Sk.builtin.numtype.prototype["__div__"] = new Sk.builtin.func(function (self, other) {
if (self.nb$divide === undefined) {
throw new Sk.builtin.NotImplementedError("__div__ is not yet implemented");
}
Sk.builtin.pyCheckArgsLen("__div__", arguments.length, 1, 1, false, true);
return self.nb$divide(other);
});
/**
* Python wrapper of `__rdiv__` method.
*
* @name __rdiv__
* @instance
* @memberOf Sk.builtin.numtype.prototype
*/
Sk.builtin.numtype.prototype["__rdiv__"] = new Sk.builtin.func(function (self, other) {
if (self.nb$reflected_divide === undefined) {
throw new Sk.builtin.NotImplementedError("__rdiv__ is not yet implemented");
}
Sk.builtin.pyCheckArgsLen("__rdiv__", arguments.length, 1, 1, false, true);
return self.nb$reflected_divide(other);
});
/**
* Python wrapper of `__floordiv__` method.
*
* @name __floordiv__
* @instance
* @memberOf Sk.builtin.numtype.prototype
*/
Sk.builtin.numtype.prototype["__floordiv__"] = new Sk.builtin.func(function (self, other) {
if (self.nb$floor_divide === undefined) {
throw new Sk.builtin.NotImplementedError("__floordiv__ is not yet implemented");
}
Sk.builtin.pyCheckArgsLen("__floordiv__", arguments.length, 1, 1, false, true);
return self.nb$floor_divide(other);
});
/**
* Python wrapper of `__rfloordiv__` method.
*
* @name __rfloordiv__
* @instance
* @memberOf Sk.builtin.numtype.prototype
*/
Sk.builtin.numtype.prototype["__rfloordiv__"] = new Sk.builtin.func(function (self, other) {
if (self.nb$reflected_floor_divide === undefined) {
throw new Sk.builtin.NotImplementedError("__rfloordiv__ is not yet implemented");
}
Sk.builtin.pyCheckArgsLen("__rfloordiv__", arguments.length, 1, 1, false, true);
return self.nb$reflected_floor_divide(other);
});
/**
* Python wrapper of `__mod__` method.
*
* @name __mod__
* @instance
* @memberOf Sk.builtin.numtype.prototype
*/
Sk.builtin.numtype.prototype["__mod__"] = new Sk.builtin.func(function (self, other) {
if (self.nb$remainder === undefined) {
throw new Sk.builtin.NotImplementedError("__mod__ is not yet implemented");
}
Sk.builtin.pyCheckArgsLen("__mod__", arguments.length, 1, 1, false, true);
return self.nb$remainder(other);
});
/**
* Python wrapper of `__rmod__` method.
*
* @name __rmod__
* @instance
* @memberOf Sk.builtin.numtype.prototype
*/
Sk.builtin.numtype.prototype["__rmod__"] = new Sk.builtin.func(function (self, other) {
if (self.nb$reflected_remainder === undefined) {
throw new Sk.builtin.NotImplementedError("__rmod__ is not yet implemented");
}
Sk.builtin.pyCheckArgsLen("__rmod__", arguments.length, 1, 1, false, true);
return self.nb$reflected_remainder(other);
});
/**
* Python wrapper of `__divmod__` method.
*
* @name __divmod__
* @instance
* @memberOf Sk.builtin.numtype.prototype
*/
Sk.builtin.numtype.prototype["__divmod__"] = new Sk.builtin.func(function (self, other) {
if (self.nb$divmod === undefined) {
throw new Sk.builtin.NotImplementedError("__divmod__ is not yet implemented");
}
Sk.builtin.pyCheckArgsLen("__divmod__", arguments.length, 1, 1, false, true);
return self.nb$divmod(other);
});
/**
* Python wrapper of `__rdivmod__` method.
*
* @name __rdivmod__
* @instance
* @memberOf Sk.builtin.numtype.prototype
*/
Sk.builtin.numtype.prototype["__rdivmod__"] = new Sk.builtin.func(function (self, other) {
if (self.nb$reflected_divmod === undefined) {
throw new Sk.builtin.NotImplementedError("__rdivmod__ is not yet implemented");
}
Sk.builtin.pyCheckArgsLen("__rdivmod__", arguments.length, 1, 1, false, true);
return self.nb$reflected_divmod(other);
});
/**
* Python wrapper of `__pow__` method.
*
* @name __pow__
* @instance
* @memberOf Sk.builtin.numtype.prototype
*/
Sk.builtin.numtype.prototype["__pow__"] = new Sk.builtin.func(function (self, other) {
if (self.nb$power === undefined) {
throw new Sk.builtin.NotImplementedError("__pow__ is not yet implemented");
}
Sk.builtin.pyCheckArgsLen("__pow__", arguments.length, 1, 1, false, true);
return self.nb$power(other);
});
/**
* Python wrapper of `__rpow__` method.
*
* @name __rpow__
* @instance
* @memberOf Sk.builtin.numtype.prototype
*/
Sk.builtin.numtype.prototype["__rpow__"] = new Sk.builtin.func(function (self, other) {
if (self.nb$reflected_power === undefined) {
throw new Sk.builtin.NotImplementedError("__rpow__ is not yet implemented");
}
Sk.builtin.pyCheckArgsLen("__rpow__", arguments.length, 1, 1, false, true);
return self.nb$reflected_power(other);
});
/**
* Python wrapper of `__coerce__` method.
*
* @name __coerce__
* @instance
* @memberOf Sk.builtin.numtype.prototype
*/
Sk.builtin.numtype.prototype["__coerce__"] = new Sk.builtin.func(function (self, other) {
throw new Sk.builtin.NotImplementedError("__coerce__ is not yet implemented");
});
/**
* Add a Python object to this instance and return the result (i.e. this + other).
*
* Returns NotImplemented if addition between this type and other type is unsupported.
*
* Javscript function, returns Python object.
*
* @param {!Sk.builtin.object} other The Python object to add.
* @return {(Sk.builtin.numtype|Sk.builtin.NotImplemented)} The result of the addition.
*/
Sk.builtin.numtype.prototype.nb$add = function (other) {
return Sk.builtin.NotImplemented.NotImplemented$;
};
Sk.builtin.numtype.prototype.nb$reflected_add = function (other) {
return Sk.builtin.NotImplemented.NotImplemented$;
};
Sk.builtin.numtype.prototype.nb$inplace_add = function (other) {
return Sk.builtin.NotImplemented.NotImplemented$;
};
/**
* Subtract a Python object from this instance and return the result (i.e. this - other).
*
* Returns NotImplemented if subtraction between this type and other type is unsupported.
*
* Javscript function, returns Python object.
*
* @param {!Sk.builtin.object} other The Python object to subtract.
* @return {(Sk.builtin.numtype|Sk.builtin.NotImplemented)} The result of the subtraction.
*/
Sk.builtin.numtype.prototype.nb$subtract = function (other) {
return Sk.builtin.NotImplemented.NotImplemented$;
};
Sk.builtin.numtype.prototype.nb$reflected_subtract = function (other) {
return Sk.builtin.NotImplemented.NotImplemented$;
};
Sk.builtin.numtype.prototype.nb$inplace_subtract = function (other) {
return Sk.builtin.NotImplemented.NotImplemented$;
};
/**
* Multiply this instance by a Python object and return the result (i.e. this * other).
*
* Returns NotImplemented if multiplication between this type and other type is unsupported.
*
* Javscript function, returns Python object.
*
* @param {!Sk.builtin.object} other The multiplier, which must be a Python object.
* @return {(Sk.builtin.numtype|Sk.builtin.NotImplemented)} The result of the multiplication
*/
Sk.builtin.numtype.prototype.nb$multiply = function (other) {
return Sk.builtin.NotImplemented.NotImplemented$;
};
Sk.builtin.numtype.prototype.nb$reflected_multiply = function (other) {
return Sk.builtin.NotImplemented.NotImplemented$;
};
Sk.builtin.numtype.prototype.nb$inplace_multiply = function (other) {
return Sk.builtin.NotImplemented.NotImplemented$;
};
/**
* Divide this instance by a Python object and return the result (i.e this / other).
*
* Returns NotImplemented if division between this type and other type is unsupported.
*
* Javscript function, returns Python object.
*
* @param {!Sk.builtin.object} other The divisor, which must be a Python object.
* @return {(Sk.builtin.numtype|Sk.builtin.NotImplemented)} The result of the division
*/
Sk.builtin.numtype.prototype.nb$divide = function (other) {
return Sk.builtin.NotImplemented.NotImplemented$;
};
Sk.builtin.numtype.prototype.nb$reflected_divide = function (other) {
return Sk.builtin.NotImplemented.NotImplemented$;
};
Sk.builtin.numtype.prototype.nb$inplace_divide = function (other) {
return Sk.builtin.NotImplemented.NotImplemented$;
};
/**
* Floor divide this instance by a Python object and return the result (i.e. this // other).
*
* Returns NotImplemented if floor division between this type and other type is unsupported.
*
* Javscript function, returns Python object.
*
* @param {!Sk.builtin.object} other The divisor, which must be a Python object.
* @return {(Sk.builtin.numtype|Sk.builtin.NotImplemented)} The result of the floor division
*/
Sk.builtin.numtype.prototype.nb$floor_divide = function (other) {
return Sk.builtin.NotImplemented.NotImplemented$;
};
Sk.builtin.numtype.prototype.nb$reflected_floor_divide = function (other) {
return Sk.builtin.NotImplemented.NotImplemented$;
};
Sk.builtin.numtype.prototype.nb$inplace_floor_divide = function (other) {
return Sk.builtin.NotImplemented.NotImplemented$;
};
/**
* Modulo this instance by a Python object and return the result (i.e. this % other).
*
* Returns NotImplemented if modulation between this type and other type is unsupported.
*
* Javscript function, returns Python object.
*
* @param {!Sk.builtin.object} other The divisor, which must be a Python object.
* @return {(Sk.builtin.numtype|Sk.builtin.NotImplemented)} The result of the modulation
*/
Sk.builtin.numtype.prototype.nb$remainder = function (other) {
return Sk.builtin.NotImplemented.NotImplemented$;
};
Sk.builtin.numtype.prototype.nb$reflected_remainder = function (other) {
return Sk.builtin.NotImplemented.NotImplemented$;
};
Sk.builtin.numtype.prototype.nb$inplace_remainder = function (other) {
return Sk.builtin.NotImplemented.NotImplemented$;
};
/**
* Compute the quotient and the remainder of this instance and a given Python object and return the result.
*
* Returns NotImplemented if division or modulo operations between this type and other type are unsupported.
*
* Javscript function, returns Python object.
*
* @param {!Sk.builtin.object} other The divisor, which must be a Python object.
* @return {(Sk.builtin.tuple|Sk.builtin.NotImplemented)} The result of the operation.
* If both operations are supported, a Python tuple containing (quotient, remainder) in that order.
*/
Sk.builtin.numtype.prototype.nb$divmod = function (other) {
return Sk.builtin.NotImplemented.NotImplemented$;
};
Sk.builtin.numtype.prototype.nb$reflected_divmod = function (other) {
return Sk.builtin.NotImplemented.NotImplemented$;
};
/**
* Raise this instance by a Python object, optionally modulo the exponent, and return the final result.
*
* If mod is undefined, return this \*\* other. Else, return (this \*\* other) % mod.
*
* Returns NotImplemented if exponentiation or modulation between this type and other type is unsupported.
*
* Javscript function, returns Python object.
*
* @param {!Sk.builtin.object} other The exponent, which must be a Python object.
* @param {!Sk.builtin.object=} mod The optional divisor, which must be a Python object if defined.
* @return {(Sk.builtin.numtype|Sk.builtin.NotImplemented)} The result of the exponentiation.
*/
Sk.builtin.numtype.prototype.nb$power = function (other, mod) {
return Sk.builtin.NotImplemented.NotImplemented$;
};
Sk.builtin.numtype.prototype.nb$reflected_power = function (other, mod) {
return Sk.builtin.NotImplemented.NotImplemented$;
};
Sk.builtin.numtype.prototype.nb$inplace_power = function (other) {
return Sk.builtin.NotImplemented.NotImplemented$;
};
/**
* Compute the absolute value of this instance and return.
*
* Javascript function, returns Python object.
*
* @return {(Sk.builtin.numtype|Sk.builtin.NotImplemented)} The absolute value
*/
Sk.builtin.numtype.prototype.nb$abs = function () {
return Sk.builtin.NotImplemented.NotImplemented$;
};
/**
* Compute the unary negative of this instance (i.e. -this).
*
* Javscript function, returns Python object.
*
* @return {(Sk.builtin.numtype|Sk.builtin.NotImplemented)} A copy of this instance with the value negated
*/
Sk.builtin.numtype.prototype.nb$negative = function () {
return Sk.builtin.NotImplemented.NotImplemented$;
};
/**
* Compute the unary positive of this instance (i.e. +this).
*
* Javscript function, returns Python object.
*
* @return {(Sk.builtin.numtype|Sk.builtin.NotImplemented)} A copy of this instance with the value unchanged
*/
Sk.builtin.numtype.prototype.nb$positive = function () {
return Sk.builtin.NotImplemented.NotImplemented$;
};
/**
* Determine if this instance is nonzero.
*
* Javscript function, returns Javascript object or Sk.builtin.NotImplemented.
*
* @return {(boolean|Sk.builtin.NotImplemented)} true if this instance is not equal to zero, false otherwise
*/
Sk.builtin.numtype.prototype.nb$nonzero = function () {
return Sk.builtin.NotImplemented.NotImplemented$;
};
/**
* Determine if this instance is negative.
*
* Javscript function, returns Javascript object or Sk.builtin.NotImplemented.
*
* @return {(boolean|Sk.builtin.NotImplemented)} true if this instance is negative, false otherwise
*/
Sk.builtin.numtype.prototype.nb$isnegative = function () {
return Sk.builtin.NotImplemented.NotImplemented$;
};
/**
* Determine if this instance is positive.
*
* Javscript function, returns Javascript object or Sk.builtin.NotImplemented.
*
* @return {(boolean|Sk.builtin.NotImplemented)} true if this instance is positive, false otherwise
*/
Sk.builtin.numtype.prototype.nb$ispositive = function () {
return Sk.builtin.NotImplemented.NotImplemented$;
};