Nuitka
The Python compiler
Loading...
Searching...
No Matches
HelpersOperationBinaryLshift.c
1// Copyright 2025, Kay Hayen, mailto:kay.hayen@gmail.com find license text at end of file
2
3/* WARNING, this code is GENERATED. Modify the template HelperOperationBinary.c.j2 instead! */
4
5/* This file is included from another C file, help IDEs to still parse it on its own. */
6#ifdef __IDE_ONLY__
7#include "nuitka/prelude.h"
8#endif
9
10/* C helpers for type specialized "<<" (LSHIFT) operations */
11
12/* Code referring to "LONG" corresponds to Python2 'long', Python3 'int' and "LONG" to Python2 'long', Python3 'int'. */
13static PyObject *_BINARY_OPERATION_LSHIFT_OBJECT_LONG_LONG(PyObject *operand1, PyObject *operand2) {
14 CHECK_OBJECT(operand1);
15 assert(PyLong_CheckExact(operand1));
16 CHECK_OBJECT(operand2);
17 assert(PyLong_CheckExact(operand2));
18
19 PyObject *result;
20
21 // Not every code path will make use of all possible results.
22#if defined(_MSC_VER)
23#pragma warning(push)
24#pragma warning(disable : 4101)
25#endif
26 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
27 NUITKA_MAY_BE_UNUSED long clong_result;
28#if defined(_MSC_VER)
29#pragma warning(pop)
30#endif
31
32 PyObject *x = PyLong_Type.tp_as_number->nb_lshift(operand1, operand2);
33 assert(x != Py_NotImplemented);
34
35 obj_result = x;
36 goto exit_result_object;
37
38exit_result_object:
39 if (unlikely(obj_result == NULL)) {
40 goto exit_result_exception;
41 }
42 result = obj_result;
43 goto exit_result_ok;
44
45exit_result_ok:
46 return result;
47
48exit_result_exception:
49 return NULL;
50}
51
52PyObject *BINARY_OPERATION_LSHIFT_OBJECT_LONG_LONG(PyObject *operand1, PyObject *operand2) {
53 return _BINARY_OPERATION_LSHIFT_OBJECT_LONG_LONG(operand1, operand2);
54}
55
56/* Code referring to "OBJECT" corresponds to any Python object and "LONG" to Python2 'long', Python3 'int'. */
57static HEDLEY_NEVER_INLINE PyObject *__BINARY_OPERATION_LSHIFT_OBJECT_OBJECT_LONG(PyObject *operand1,
58 PyObject *operand2) {
59 PyTypeObject *type1 = Py_TYPE(operand1);
60
61#if defined(_MSC_VER)
62#pragma warning(push)
63#pragma warning(disable : 4101)
64#endif
65 NUITKA_MAY_BE_UNUSED bool cbool_result;
66 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
67#if defined(_MSC_VER)
68#pragma warning(pop)
69#endif
70
71 binaryfunc slot1 =
72 (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_lshift : NULL;
73 binaryfunc slot2 = NULL;
74
75 if (!(type1 == &PyLong_Type)) {
76 // Different types, need to consider second value slot.
77
78 slot2 = PyLong_Type.tp_as_number->nb_lshift;
79
80 if (slot1 == slot2) {
81 slot2 = NULL;
82 }
83 }
84
85 if (slot1 != NULL) {
86 PyObject *x = slot1(operand1, operand2);
87
88 if (x != Py_NotImplemented) {
89 obj_result = x;
90 goto exit_binary_result_object;
91 }
92
93 Py_DECREF_IMMORTAL(x);
94 }
95
96 if (slot2 != NULL) {
97 PyObject *x = slot2(operand1, operand2);
98
99 if (x != Py_NotImplemented) {
100 obj_result = x;
101 goto exit_binary_result_object;
102 }
103
104 Py_DECREF_IMMORTAL(x);
105 }
106
107#if PYTHON_VERSION < 0x300
108 if (!NEW_STYLE_NUMBER_TYPE(type1) || !1) {
109 coercion c1 =
110 (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_coerce : NULL;
111
112 if (c1 != NULL) {
113 PyObject *coerced1 = operand1;
114 PyObject *coerced2 = operand2;
115
116 int err = c1(&coerced1, &coerced2);
117
118 if (unlikely(err < 0)) {
119 goto exit_binary_exception;
120 }
121
122 if (err == 0) {
123 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
124
125 if (likely(mv == NULL)) {
126 binaryfunc slot = mv->nb_lshift;
127
128 if (likely(slot != NULL)) {
129 PyObject *x = slot(coerced1, coerced2);
130
131 Py_DECREF(coerced1);
132 Py_DECREF(coerced2);
133
134 obj_result = x;
135 goto exit_binary_result_object;
136 }
137 }
138
139 // nb_coerce took a reference.
140 Py_DECREF(coerced1);
141 Py_DECREF(coerced2);
142 }
143 }
144 coercion c2 = PyLong_Type.tp_as_number->nb_coerce;
145
146 if (c2 != NULL) {
147 PyObject *coerced1 = operand1;
148 PyObject *coerced2 = operand2;
149
150 int err = c2(&coerced2, &coerced1);
151
152 if (unlikely(err < 0)) {
153 goto exit_binary_exception;
154 }
155
156 if (err == 0) {
157 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
158
159 if (likely(mv == NULL)) {
160 binaryfunc slot = mv->nb_lshift;
161
162 if (likely(slot != NULL)) {
163 PyObject *x = slot(coerced1, coerced2);
164
165 Py_DECREF(coerced1);
166 Py_DECREF(coerced2);
167
168 obj_result = x;
169 goto exit_binary_result_object;
170 }
171 }
172
173 // nb_coerce took a reference.
174 Py_DECREF(coerced1);
175 Py_DECREF(coerced2);
176 }
177 }
178 }
179#endif
180
181#if PYTHON_VERSION < 0x300
182 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for <<: '%s' and 'long'", type1->tp_name);
183#else
184 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for <<: '%s' and 'int'", type1->tp_name);
185#endif
186 goto exit_binary_exception;
187
188exit_binary_result_object:
189 return obj_result;
190
191exit_binary_exception:
192 return NULL;
193}
194static PyObject *_BINARY_OPERATION_LSHIFT_OBJECT_OBJECT_LONG(PyObject *operand1, PyObject *operand2) {
195 CHECK_OBJECT(operand1);
196 CHECK_OBJECT(operand2);
197 assert(PyLong_CheckExact(operand2));
198
199 PyTypeObject *type1 = Py_TYPE(operand1);
200
201 if (type1 == &PyLong_Type) {
202 PyObject *result;
203
204 // return _BINARY_OPERATION_LSHIFT_OBJECT_LONG_LONG(operand1, operand2);
205
206 // Not every code path will make use of all possible results.
207#if defined(_MSC_VER)
208#pragma warning(push)
209#pragma warning(disable : 4101)
210#endif
211 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
212 NUITKA_MAY_BE_UNUSED long clong_result;
213#if defined(_MSC_VER)
214#pragma warning(pop)
215#endif
216
217 PyObject *x = PyLong_Type.tp_as_number->nb_lshift(operand1, operand2);
218 assert(x != Py_NotImplemented);
219
220 obj_result = x;
221 goto exit_result_object;
222
223 exit_result_object:
224 if (unlikely(obj_result == NULL)) {
225 goto exit_result_exception;
226 }
227 result = obj_result;
228 goto exit_result_ok;
229
230 exit_result_ok:
231 return result;
232
233 exit_result_exception:
234 return NULL;
235 }
236
237 return __BINARY_OPERATION_LSHIFT_OBJECT_OBJECT_LONG(operand1, operand2);
238}
239
240PyObject *BINARY_OPERATION_LSHIFT_OBJECT_OBJECT_LONG(PyObject *operand1, PyObject *operand2) {
241 return _BINARY_OPERATION_LSHIFT_OBJECT_OBJECT_LONG(operand1, operand2);
242}
243
244/* Code referring to "LONG" corresponds to Python2 'long', Python3 'int' and "OBJECT" to any Python object. */
245static HEDLEY_NEVER_INLINE PyObject *__BINARY_OPERATION_LSHIFT_OBJECT_LONG_OBJECT(PyObject *operand1,
246 PyObject *operand2) {
247 PyTypeObject *type2 = Py_TYPE(operand2);
248
249#if defined(_MSC_VER)
250#pragma warning(push)
251#pragma warning(disable : 4101)
252#endif
253 NUITKA_MAY_BE_UNUSED bool cbool_result;
254 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
255#if defined(_MSC_VER)
256#pragma warning(pop)
257#endif
258
259 binaryfunc slot1 = PyLong_Type.tp_as_number->nb_lshift;
260 binaryfunc slot2 = NULL;
261
262 if (!(&PyLong_Type == type2)) {
263 // Different types, need to consider second value slot.
264
265 slot2 = (type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_lshift : NULL;
266
267 if (slot1 == slot2) {
268 slot2 = NULL;
269 }
270 }
271
272 if (slot1 != NULL) {
273 if (slot2 != NULL) {
274 if (Nuitka_Type_IsSubtype(type2, &PyLong_Type)) {
275 PyObject *x = slot2(operand1, operand2);
276
277 if (x != Py_NotImplemented) {
278 obj_result = x;
279 goto exit_binary_result_object;
280 }
281
282 Py_DECREF_IMMORTAL(x);
283 slot2 = NULL;
284 }
285 }
286
287 PyObject *x = slot1(operand1, operand2);
288
289 if (x != Py_NotImplemented) {
290 obj_result = x;
291 goto exit_binary_result_object;
292 }
293
294 Py_DECREF_IMMORTAL(x);
295 }
296
297 if (slot2 != NULL) {
298 PyObject *x = slot2(operand1, operand2);
299
300 if (x != Py_NotImplemented) {
301 obj_result = x;
302 goto exit_binary_result_object;
303 }
304
305 Py_DECREF_IMMORTAL(x);
306 }
307
308#if PYTHON_VERSION < 0x300
309 if (!1 || !NEW_STYLE_NUMBER_TYPE(type2)) {
310 coercion c1 = PyLong_Type.tp_as_number->nb_coerce;
311
312 if (c1 != NULL) {
313 PyObject *coerced1 = operand1;
314 PyObject *coerced2 = operand2;
315
316 int err = c1(&coerced1, &coerced2);
317
318 if (unlikely(err < 0)) {
319 goto exit_binary_exception;
320 }
321
322 if (err == 0) {
323 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
324
325 if (likely(mv == NULL)) {
326 binaryfunc slot = mv->nb_lshift;
327
328 if (likely(slot != NULL)) {
329 PyObject *x = slot(coerced1, coerced2);
330
331 Py_DECREF(coerced1);
332 Py_DECREF(coerced2);
333
334 obj_result = x;
335 goto exit_binary_result_object;
336 }
337 }
338
339 // nb_coerce took a reference.
340 Py_DECREF(coerced1);
341 Py_DECREF(coerced2);
342 }
343 }
344 coercion c2 =
345 (type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_coerce : NULL;
346
347 if (c2 != NULL) {
348 PyObject *coerced1 = operand1;
349 PyObject *coerced2 = operand2;
350
351 int err = c2(&coerced2, &coerced1);
352
353 if (unlikely(err < 0)) {
354 goto exit_binary_exception;
355 }
356
357 if (err == 0) {
358 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
359
360 if (likely(mv == NULL)) {
361 binaryfunc slot = mv->nb_lshift;
362
363 if (likely(slot != NULL)) {
364 PyObject *x = slot(coerced1, coerced2);
365
366 Py_DECREF(coerced1);
367 Py_DECREF(coerced2);
368
369 obj_result = x;
370 goto exit_binary_result_object;
371 }
372 }
373
374 // nb_coerce took a reference.
375 Py_DECREF(coerced1);
376 Py_DECREF(coerced2);
377 }
378 }
379 }
380#endif
381
382#if PYTHON_VERSION < 0x300
383 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for <<: 'long' and '%s'", type2->tp_name);
384#else
385 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for <<: 'int' and '%s'", type2->tp_name);
386#endif
387 goto exit_binary_exception;
388
389exit_binary_result_object:
390 return obj_result;
391
392exit_binary_exception:
393 return NULL;
394}
395static PyObject *_BINARY_OPERATION_LSHIFT_OBJECT_LONG_OBJECT(PyObject *operand1, PyObject *operand2) {
396 CHECK_OBJECT(operand1);
397 assert(PyLong_CheckExact(operand1));
398 CHECK_OBJECT(operand2);
399
400 PyTypeObject *type2 = Py_TYPE(operand2);
401
402 if (&PyLong_Type == type2) {
403 PyObject *result;
404
405 // return _BINARY_OPERATION_LSHIFT_OBJECT_LONG_LONG(operand1, operand2);
406
407 // Not every code path will make use of all possible results.
408#if defined(_MSC_VER)
409#pragma warning(push)
410#pragma warning(disable : 4101)
411#endif
412 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
413 NUITKA_MAY_BE_UNUSED long clong_result;
414#if defined(_MSC_VER)
415#pragma warning(pop)
416#endif
417
418 PyObject *x = PyLong_Type.tp_as_number->nb_lshift(operand1, operand2);
419 assert(x != Py_NotImplemented);
420
421 obj_result = x;
422 goto exit_result_object;
423
424 exit_result_object:
425 if (unlikely(obj_result == NULL)) {
426 goto exit_result_exception;
427 }
428 result = obj_result;
429 goto exit_result_ok;
430
431 exit_result_ok:
432 return result;
433
434 exit_result_exception:
435 return NULL;
436 }
437
438 return __BINARY_OPERATION_LSHIFT_OBJECT_LONG_OBJECT(operand1, operand2);
439}
440
441PyObject *BINARY_OPERATION_LSHIFT_OBJECT_LONG_OBJECT(PyObject *operand1, PyObject *operand2) {
442 return _BINARY_OPERATION_LSHIFT_OBJECT_LONG_OBJECT(operand1, operand2);
443}
444
445/* Code referring to "LONG" corresponds to Python2 'long', Python3 'int' and "LONG" to Python2 'long', Python3 'int'. */
446static nuitka_bool _BINARY_OPERATION_LSHIFT_NBOOL_LONG_LONG(PyObject *operand1, PyObject *operand2) {
447 CHECK_OBJECT(operand1);
448 assert(PyLong_CheckExact(operand1));
449 CHECK_OBJECT(operand2);
450 assert(PyLong_CheckExact(operand2));
451
452 nuitka_bool result;
453
454 // Not every code path will make use of all possible results.
455#if defined(_MSC_VER)
456#pragma warning(push)
457#pragma warning(disable : 4101)
458#endif
459 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
460 NUITKA_MAY_BE_UNUSED long clong_result;
461#if defined(_MSC_VER)
462#pragma warning(pop)
463#endif
464
465 PyObject *x = PyLong_Type.tp_as_number->nb_lshift(operand1, operand2);
466 assert(x != Py_NotImplemented);
467
468 obj_result = x;
469 goto exit_result_object;
470
471exit_result_object:
472 if (unlikely(obj_result == NULL)) {
473 goto exit_result_exception;
474 }
475 result = CHECK_IF_TRUE(obj_result) ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
476 Py_DECREF(obj_result);
477 goto exit_result_ok;
478
479exit_result_ok:
480 return result;
481
482exit_result_exception:
483 return NUITKA_BOOL_EXCEPTION;
484}
485
486nuitka_bool BINARY_OPERATION_LSHIFT_NBOOL_LONG_LONG(PyObject *operand1, PyObject *operand2) {
487 return _BINARY_OPERATION_LSHIFT_NBOOL_LONG_LONG(operand1, operand2);
488}
489
490/* Code referring to "OBJECT" corresponds to any Python object and "LONG" to Python2 'long', Python3 'int'. */
491static HEDLEY_NEVER_INLINE nuitka_bool __BINARY_OPERATION_LSHIFT_NBOOL_OBJECT_LONG(PyObject *operand1,
492 PyObject *operand2) {
493 PyTypeObject *type1 = Py_TYPE(operand1);
494
495#if defined(_MSC_VER)
496#pragma warning(push)
497#pragma warning(disable : 4101)
498#endif
499 NUITKA_MAY_BE_UNUSED bool cbool_result;
500 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
501#if defined(_MSC_VER)
502#pragma warning(pop)
503#endif
504
505 binaryfunc slot1 =
506 (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_lshift : NULL;
507 binaryfunc slot2 = NULL;
508
509 if (!(type1 == &PyLong_Type)) {
510 // Different types, need to consider second value slot.
511
512 slot2 = PyLong_Type.tp_as_number->nb_lshift;
513
514 if (slot1 == slot2) {
515 slot2 = NULL;
516 }
517 }
518
519 if (slot1 != NULL) {
520 PyObject *x = slot1(operand1, operand2);
521
522 if (x != Py_NotImplemented) {
523 obj_result = x;
524 goto exit_binary_result_object;
525 }
526
527 Py_DECREF_IMMORTAL(x);
528 }
529
530 if (slot2 != NULL) {
531 PyObject *x = slot2(operand1, operand2);
532
533 if (x != Py_NotImplemented) {
534 obj_result = x;
535 goto exit_binary_result_object;
536 }
537
538 Py_DECREF_IMMORTAL(x);
539 }
540
541#if PYTHON_VERSION < 0x300
542 if (!NEW_STYLE_NUMBER_TYPE(type1) || !1) {
543 coercion c1 =
544 (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_coerce : NULL;
545
546 if (c1 != NULL) {
547 PyObject *coerced1 = operand1;
548 PyObject *coerced2 = operand2;
549
550 int err = c1(&coerced1, &coerced2);
551
552 if (unlikely(err < 0)) {
553 goto exit_binary_exception;
554 }
555
556 if (err == 0) {
557 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
558
559 if (likely(mv == NULL)) {
560 binaryfunc slot = mv->nb_lshift;
561
562 if (likely(slot != NULL)) {
563 PyObject *x = slot(coerced1, coerced2);
564
565 Py_DECREF(coerced1);
566 Py_DECREF(coerced2);
567
568 obj_result = x;
569 goto exit_binary_result_object;
570 }
571 }
572
573 // nb_coerce took a reference.
574 Py_DECREF(coerced1);
575 Py_DECREF(coerced2);
576 }
577 }
578 coercion c2 = PyLong_Type.tp_as_number->nb_coerce;
579
580 if (c2 != NULL) {
581 PyObject *coerced1 = operand1;
582 PyObject *coerced2 = operand2;
583
584 int err = c2(&coerced2, &coerced1);
585
586 if (unlikely(err < 0)) {
587 goto exit_binary_exception;
588 }
589
590 if (err == 0) {
591 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
592
593 if (likely(mv == NULL)) {
594 binaryfunc slot = mv->nb_lshift;
595
596 if (likely(slot != NULL)) {
597 PyObject *x = slot(coerced1, coerced2);
598
599 Py_DECREF(coerced1);
600 Py_DECREF(coerced2);
601
602 obj_result = x;
603 goto exit_binary_result_object;
604 }
605 }
606
607 // nb_coerce took a reference.
608 Py_DECREF(coerced1);
609 Py_DECREF(coerced2);
610 }
611 }
612 }
613#endif
614
615#if PYTHON_VERSION < 0x300
616 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for <<: '%s' and 'long'", type1->tp_name);
617#else
618 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for <<: '%s' and 'int'", type1->tp_name);
619#endif
620 goto exit_binary_exception;
621
622exit_binary_result_object:
623 if (unlikely(obj_result == NULL)) {
624 return NUITKA_BOOL_EXCEPTION;
625 }
626
627 {
628 nuitka_bool r = CHECK_IF_TRUE(obj_result) ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
629 Py_DECREF(obj_result);
630 return r;
631 }
632
633exit_binary_exception:
634 return NUITKA_BOOL_EXCEPTION;
635}
636static nuitka_bool _BINARY_OPERATION_LSHIFT_NBOOL_OBJECT_LONG(PyObject *operand1, PyObject *operand2) {
637 CHECK_OBJECT(operand1);
638 CHECK_OBJECT(operand2);
639 assert(PyLong_CheckExact(operand2));
640
641 PyTypeObject *type1 = Py_TYPE(operand1);
642
643 if (type1 == &PyLong_Type) {
644 nuitka_bool result;
645
646 // return _BINARY_OPERATION_LSHIFT_NBOOL_LONG_LONG(operand1, operand2);
647
648 // Not every code path will make use of all possible results.
649#if defined(_MSC_VER)
650#pragma warning(push)
651#pragma warning(disable : 4101)
652#endif
653 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
654 NUITKA_MAY_BE_UNUSED long clong_result;
655#if defined(_MSC_VER)
656#pragma warning(pop)
657#endif
658
659 PyObject *x = PyLong_Type.tp_as_number->nb_lshift(operand1, operand2);
660 assert(x != Py_NotImplemented);
661
662 obj_result = x;
663 goto exit_result_object;
664
665 exit_result_object:
666 if (unlikely(obj_result == NULL)) {
667 goto exit_result_exception;
668 }
669 result = CHECK_IF_TRUE(obj_result) ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
670 Py_DECREF(obj_result);
671 goto exit_result_ok;
672
673 exit_result_ok:
674 return result;
675
676 exit_result_exception:
677 return NUITKA_BOOL_EXCEPTION;
678 }
679
680 return __BINARY_OPERATION_LSHIFT_NBOOL_OBJECT_LONG(operand1, operand2);
681}
682
683nuitka_bool BINARY_OPERATION_LSHIFT_NBOOL_OBJECT_LONG(PyObject *operand1, PyObject *operand2) {
684 return _BINARY_OPERATION_LSHIFT_NBOOL_OBJECT_LONG(operand1, operand2);
685}
686
687/* Code referring to "LONG" corresponds to Python2 'long', Python3 'int' and "OBJECT" to any Python object. */
688static HEDLEY_NEVER_INLINE nuitka_bool __BINARY_OPERATION_LSHIFT_NBOOL_LONG_OBJECT(PyObject *operand1,
689 PyObject *operand2) {
690 PyTypeObject *type2 = Py_TYPE(operand2);
691
692#if defined(_MSC_VER)
693#pragma warning(push)
694#pragma warning(disable : 4101)
695#endif
696 NUITKA_MAY_BE_UNUSED bool cbool_result;
697 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
698#if defined(_MSC_VER)
699#pragma warning(pop)
700#endif
701
702 binaryfunc slot1 = PyLong_Type.tp_as_number->nb_lshift;
703 binaryfunc slot2 = NULL;
704
705 if (!(&PyLong_Type == type2)) {
706 // Different types, need to consider second value slot.
707
708 slot2 = (type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_lshift : NULL;
709
710 if (slot1 == slot2) {
711 slot2 = NULL;
712 }
713 }
714
715 if (slot1 != NULL) {
716 if (slot2 != NULL) {
717 if (Nuitka_Type_IsSubtype(type2, &PyLong_Type)) {
718 PyObject *x = slot2(operand1, operand2);
719
720 if (x != Py_NotImplemented) {
721 obj_result = x;
722 goto exit_binary_result_object;
723 }
724
725 Py_DECREF_IMMORTAL(x);
726 slot2 = NULL;
727 }
728 }
729
730 PyObject *x = slot1(operand1, operand2);
731
732 if (x != Py_NotImplemented) {
733 obj_result = x;
734 goto exit_binary_result_object;
735 }
736
737 Py_DECREF_IMMORTAL(x);
738 }
739
740 if (slot2 != NULL) {
741 PyObject *x = slot2(operand1, operand2);
742
743 if (x != Py_NotImplemented) {
744 obj_result = x;
745 goto exit_binary_result_object;
746 }
747
748 Py_DECREF_IMMORTAL(x);
749 }
750
751#if PYTHON_VERSION < 0x300
752 if (!1 || !NEW_STYLE_NUMBER_TYPE(type2)) {
753 coercion c1 = PyLong_Type.tp_as_number->nb_coerce;
754
755 if (c1 != NULL) {
756 PyObject *coerced1 = operand1;
757 PyObject *coerced2 = operand2;
758
759 int err = c1(&coerced1, &coerced2);
760
761 if (unlikely(err < 0)) {
762 goto exit_binary_exception;
763 }
764
765 if (err == 0) {
766 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
767
768 if (likely(mv == NULL)) {
769 binaryfunc slot = mv->nb_lshift;
770
771 if (likely(slot != NULL)) {
772 PyObject *x = slot(coerced1, coerced2);
773
774 Py_DECREF(coerced1);
775 Py_DECREF(coerced2);
776
777 obj_result = x;
778 goto exit_binary_result_object;
779 }
780 }
781
782 // nb_coerce took a reference.
783 Py_DECREF(coerced1);
784 Py_DECREF(coerced2);
785 }
786 }
787 coercion c2 =
788 (type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_coerce : NULL;
789
790 if (c2 != NULL) {
791 PyObject *coerced1 = operand1;
792 PyObject *coerced2 = operand2;
793
794 int err = c2(&coerced2, &coerced1);
795
796 if (unlikely(err < 0)) {
797 goto exit_binary_exception;
798 }
799
800 if (err == 0) {
801 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
802
803 if (likely(mv == NULL)) {
804 binaryfunc slot = mv->nb_lshift;
805
806 if (likely(slot != NULL)) {
807 PyObject *x = slot(coerced1, coerced2);
808
809 Py_DECREF(coerced1);
810 Py_DECREF(coerced2);
811
812 obj_result = x;
813 goto exit_binary_result_object;
814 }
815 }
816
817 // nb_coerce took a reference.
818 Py_DECREF(coerced1);
819 Py_DECREF(coerced2);
820 }
821 }
822 }
823#endif
824
825#if PYTHON_VERSION < 0x300
826 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for <<: 'long' and '%s'", type2->tp_name);
827#else
828 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for <<: 'int' and '%s'", type2->tp_name);
829#endif
830 goto exit_binary_exception;
831
832exit_binary_result_object:
833 if (unlikely(obj_result == NULL)) {
834 return NUITKA_BOOL_EXCEPTION;
835 }
836
837 {
838 nuitka_bool r = CHECK_IF_TRUE(obj_result) ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
839 Py_DECREF(obj_result);
840 return r;
841 }
842
843exit_binary_exception:
844 return NUITKA_BOOL_EXCEPTION;
845}
846static nuitka_bool _BINARY_OPERATION_LSHIFT_NBOOL_LONG_OBJECT(PyObject *operand1, PyObject *operand2) {
847 CHECK_OBJECT(operand1);
848 assert(PyLong_CheckExact(operand1));
849 CHECK_OBJECT(operand2);
850
851 PyTypeObject *type2 = Py_TYPE(operand2);
852
853 if (&PyLong_Type == type2) {
854 nuitka_bool result;
855
856 // return _BINARY_OPERATION_LSHIFT_NBOOL_LONG_LONG(operand1, operand2);
857
858 // Not every code path will make use of all possible results.
859#if defined(_MSC_VER)
860#pragma warning(push)
861#pragma warning(disable : 4101)
862#endif
863 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
864 NUITKA_MAY_BE_UNUSED long clong_result;
865#if defined(_MSC_VER)
866#pragma warning(pop)
867#endif
868
869 PyObject *x = PyLong_Type.tp_as_number->nb_lshift(operand1, operand2);
870 assert(x != Py_NotImplemented);
871
872 obj_result = x;
873 goto exit_result_object;
874
875 exit_result_object:
876 if (unlikely(obj_result == NULL)) {
877 goto exit_result_exception;
878 }
879 result = CHECK_IF_TRUE(obj_result) ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
880 Py_DECREF(obj_result);
881 goto exit_result_ok;
882
883 exit_result_ok:
884 return result;
885
886 exit_result_exception:
887 return NUITKA_BOOL_EXCEPTION;
888 }
889
890 return __BINARY_OPERATION_LSHIFT_NBOOL_LONG_OBJECT(operand1, operand2);
891}
892
893nuitka_bool BINARY_OPERATION_LSHIFT_NBOOL_LONG_OBJECT(PyObject *operand1, PyObject *operand2) {
894 return _BINARY_OPERATION_LSHIFT_NBOOL_LONG_OBJECT(operand1, operand2);
895}
896
897#if PYTHON_VERSION < 0x300
898/* Code referring to "INT" corresponds to Python2 'int' and "INT" to Python2 'int'. */
899static PyObject *_BINARY_OPERATION_LSHIFT_OBJECT_INT_INT(PyObject *operand1, PyObject *operand2) {
900 CHECK_OBJECT(operand1);
901 assert(PyInt_CheckExact(operand1));
902 CHECK_OBJECT(operand2);
903 assert(PyInt_CheckExact(operand2));
904
905 PyObject *result;
906
907 // Not every code path will make use of all possible results.
908#if defined(_MSC_VER)
909#pragma warning(push)
910#pragma warning(disable : 4101)
911#endif
912 NUITKA_MAY_BE_UNUSED bool cbool_result;
913 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
914 NUITKA_MAY_BE_UNUSED long clong_result;
915 NUITKA_MAY_BE_UNUSED double cfloat_result;
916#if defined(_MSC_VER)
917#pragma warning(pop)
918#endif
919
920 CHECK_OBJECT(operand1);
921 assert(PyInt_CheckExact(operand1));
922 CHECK_OBJECT(operand2);
923 assert(PyInt_CheckExact(operand2));
924
925 const long a = PyInt_AS_LONG(operand1);
926 const long b = PyInt_AS_LONG(operand2);
927
928 if (unlikely(b < 0)) {
929 PyThreadState *tstate = PyThreadState_GET();
930
931 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ValueError, "negative shift count");
932 goto exit_result_exception;
933 }
934 /* Short cut for zero shift or shifting zero. */
935 if (a == 0 || b == 0) {
936 goto exit_result_ok_left;
937 } else if (b >= LONG_BIT) {
938 PyObject *operand1_long = Nuitka_PyLong_FromLong(a);
939 PyObject *operand2_long = Nuitka_PyLong_FromLong(b);
940
941 // TODO: Change this to using CLONG once we specialize that too.
942 PyObject *r = _BINARY_OPERATION_LSHIFT_OBJECT_LONG_LONG(operand1_long, operand2_long);
943
944 Py_DECREF(operand1_long);
945 Py_DECREF(operand2_long);
946
947 obj_result = r;
948 goto exit_result_object;
949 } else {
950 long c = a << b;
951
952 if (a != Py_ARITHMETIC_RIGHT_SHIFT(long, c, b)) {
953 PyObject *operand1_long = Nuitka_PyLong_FromLong(a);
954 PyObject *operand2_long = Nuitka_PyLong_FromLong(b);
955
956 // TODO: Change this to using CLONG once we specialize that too.
957 PyObject *r = _BINARY_OPERATION_LSHIFT_OBJECT_LONG_LONG(operand1_long, operand2_long);
958
959 Py_DECREF(operand1_long);
960 Py_DECREF(operand2_long);
961
962 obj_result = r;
963 goto exit_result_object;
964 } else {
965 clong_result = c;
966 goto exit_result_ok_clong;
967 }
968 }
969
970exit_result_ok_clong:
971 result = Nuitka_PyInt_FromLong(clong_result);
972 goto exit_result_ok;
973
974exit_result_ok_left:
975 result = operand1;
976 Py_INCREF(result);
977 goto exit_result_ok;
978
979exit_result_object:
980 if (unlikely(obj_result == NULL)) {
981 goto exit_result_exception;
982 }
983 result = obj_result;
984 goto exit_result_ok;
985
986exit_result_ok:
987 return result;
988
989exit_result_exception:
990 return NULL;
991}
992
993PyObject *BINARY_OPERATION_LSHIFT_OBJECT_INT_INT(PyObject *operand1, PyObject *operand2) {
994 return _BINARY_OPERATION_LSHIFT_OBJECT_INT_INT(operand1, operand2);
995}
996#endif
997
998#if PYTHON_VERSION < 0x300
999/* Code referring to "OBJECT" corresponds to any Python object and "INT" to Python2 'int'. */
1000static HEDLEY_NEVER_INLINE PyObject *__BINARY_OPERATION_LSHIFT_OBJECT_OBJECT_INT(PyObject *operand1,
1001 PyObject *operand2) {
1002 PyTypeObject *type1 = Py_TYPE(operand1);
1003
1004#if defined(_MSC_VER)
1005#pragma warning(push)
1006#pragma warning(disable : 4101)
1007#endif
1008 NUITKA_MAY_BE_UNUSED bool cbool_result;
1009 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1010#if defined(_MSC_VER)
1011#pragma warning(pop)
1012#endif
1013
1014 binaryfunc slot1 =
1015 (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_lshift : NULL;
1016 binaryfunc slot2 = NULL;
1017
1018 if (!(type1 == &PyInt_Type)) {
1019 // Different types, need to consider second value slot.
1020
1021 slot2 = PyInt_Type.tp_as_number->nb_lshift;
1022
1023 if (slot1 == slot2) {
1024 slot2 = NULL;
1025 }
1026 }
1027
1028 if (slot1 != NULL) {
1029 PyObject *x = slot1(operand1, operand2);
1030
1031 if (x != Py_NotImplemented) {
1032 obj_result = x;
1033 goto exit_binary_result_object;
1034 }
1035
1036 Py_DECREF_IMMORTAL(x);
1037 }
1038
1039 if (slot2 != NULL) {
1040 PyObject *x = slot2(operand1, operand2);
1041
1042 if (x != Py_NotImplemented) {
1043 obj_result = x;
1044 goto exit_binary_result_object;
1045 }
1046
1047 Py_DECREF_IMMORTAL(x);
1048 }
1049
1050#if PYTHON_VERSION < 0x300
1051 if (!NEW_STYLE_NUMBER_TYPE(type1) || !1) {
1052 coercion c1 =
1053 (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_coerce : NULL;
1054
1055 if (c1 != NULL) {
1056 PyObject *coerced1 = operand1;
1057 PyObject *coerced2 = operand2;
1058
1059 int err = c1(&coerced1, &coerced2);
1060
1061 if (unlikely(err < 0)) {
1062 goto exit_binary_exception;
1063 }
1064
1065 if (err == 0) {
1066 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
1067
1068 if (likely(mv == NULL)) {
1069 binaryfunc slot = mv->nb_lshift;
1070
1071 if (likely(slot != NULL)) {
1072 PyObject *x = slot(coerced1, coerced2);
1073
1074 Py_DECREF(coerced1);
1075 Py_DECREF(coerced2);
1076
1077 obj_result = x;
1078 goto exit_binary_result_object;
1079 }
1080 }
1081
1082 // nb_coerce took a reference.
1083 Py_DECREF(coerced1);
1084 Py_DECREF(coerced2);
1085 }
1086 }
1087 coercion c2 = PyInt_Type.tp_as_number->nb_coerce;
1088
1089 if (c2 != NULL) {
1090 PyObject *coerced1 = operand1;
1091 PyObject *coerced2 = operand2;
1092
1093 int err = c2(&coerced2, &coerced1);
1094
1095 if (unlikely(err < 0)) {
1096 goto exit_binary_exception;
1097 }
1098
1099 if (err == 0) {
1100 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
1101
1102 if (likely(mv == NULL)) {
1103 binaryfunc slot = mv->nb_lshift;
1104
1105 if (likely(slot != NULL)) {
1106 PyObject *x = slot(coerced1, coerced2);
1107
1108 Py_DECREF(coerced1);
1109 Py_DECREF(coerced2);
1110
1111 obj_result = x;
1112 goto exit_binary_result_object;
1113 }
1114 }
1115
1116 // nb_coerce took a reference.
1117 Py_DECREF(coerced1);
1118 Py_DECREF(coerced2);
1119 }
1120 }
1121 }
1122#endif
1123
1124 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for <<: '%s' and 'int'", type1->tp_name);
1125 goto exit_binary_exception;
1126
1127exit_binary_result_object:
1128 return obj_result;
1129
1130exit_binary_exception:
1131 return NULL;
1132}
1133static PyObject *_BINARY_OPERATION_LSHIFT_OBJECT_OBJECT_INT(PyObject *operand1, PyObject *operand2) {
1134 CHECK_OBJECT(operand1);
1135 CHECK_OBJECT(operand2);
1136 assert(PyInt_CheckExact(operand2));
1137
1138 PyTypeObject *type1 = Py_TYPE(operand1);
1139
1140 if (type1 == &PyInt_Type) {
1141 PyObject *result;
1142
1143 // return _BINARY_OPERATION_LSHIFT_OBJECT_INT_INT(operand1, operand2);
1144
1145 // Not every code path will make use of all possible results.
1146#if defined(_MSC_VER)
1147#pragma warning(push)
1148#pragma warning(disable : 4101)
1149#endif
1150 NUITKA_MAY_BE_UNUSED bool cbool_result;
1151 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1152 NUITKA_MAY_BE_UNUSED long clong_result;
1153 NUITKA_MAY_BE_UNUSED double cfloat_result;
1154#if defined(_MSC_VER)
1155#pragma warning(pop)
1156#endif
1157
1158 CHECK_OBJECT(operand1);
1159 assert(PyInt_CheckExact(operand1));
1160 CHECK_OBJECT(operand2);
1161 assert(PyInt_CheckExact(operand2));
1162
1163 const long a = PyInt_AS_LONG(operand1);
1164 const long b = PyInt_AS_LONG(operand2);
1165
1166 if (unlikely(b < 0)) {
1167 PyThreadState *tstate = PyThreadState_GET();
1168
1169 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ValueError, "negative shift count");
1170 goto exit_result_exception;
1171 }
1172 /* Short cut for zero shift or shifting zero. */
1173 if (a == 0 || b == 0) {
1174 goto exit_result_ok_left;
1175 } else if (b >= LONG_BIT) {
1176 PyObject *operand1_long = Nuitka_PyLong_FromLong(a);
1177 PyObject *operand2_long = Nuitka_PyLong_FromLong(b);
1178
1179 // TODO: Change this to using CLONG once we specialize that too.
1180 PyObject *r = _BINARY_OPERATION_LSHIFT_OBJECT_LONG_LONG(operand1_long, operand2_long);
1181
1182 Py_DECREF(operand1_long);
1183 Py_DECREF(operand2_long);
1184
1185 obj_result = r;
1186 goto exit_result_object;
1187 } else {
1188 long c = a << b;
1189
1190 if (a != Py_ARITHMETIC_RIGHT_SHIFT(long, c, b)) {
1191 PyObject *operand1_long = Nuitka_PyLong_FromLong(a);
1192 PyObject *operand2_long = Nuitka_PyLong_FromLong(b);
1193
1194 // TODO: Change this to using CLONG once we specialize that too.
1195 PyObject *r = _BINARY_OPERATION_LSHIFT_OBJECT_LONG_LONG(operand1_long, operand2_long);
1196
1197 Py_DECREF(operand1_long);
1198 Py_DECREF(operand2_long);
1199
1200 obj_result = r;
1201 goto exit_result_object;
1202 } else {
1203 clong_result = c;
1204 goto exit_result_ok_clong;
1205 }
1206 }
1207
1208 exit_result_ok_clong:
1209 result = Nuitka_PyInt_FromLong(clong_result);
1210 goto exit_result_ok;
1211
1212 exit_result_ok_left:
1213 result = operand1;
1214 Py_INCREF(result);
1215 goto exit_result_ok;
1216
1217 exit_result_object:
1218 if (unlikely(obj_result == NULL)) {
1219 goto exit_result_exception;
1220 }
1221 result = obj_result;
1222 goto exit_result_ok;
1223
1224 exit_result_ok:
1225 return result;
1226
1227 exit_result_exception:
1228 return NULL;
1229 }
1230
1231 return __BINARY_OPERATION_LSHIFT_OBJECT_OBJECT_INT(operand1, operand2);
1232}
1233
1234PyObject *BINARY_OPERATION_LSHIFT_OBJECT_OBJECT_INT(PyObject *operand1, PyObject *operand2) {
1235 return _BINARY_OPERATION_LSHIFT_OBJECT_OBJECT_INT(operand1, operand2);
1236}
1237#endif
1238
1239#if PYTHON_VERSION < 0x300
1240/* Code referring to "INT" corresponds to Python2 'int' and "OBJECT" to any Python object. */
1241static HEDLEY_NEVER_INLINE PyObject *__BINARY_OPERATION_LSHIFT_OBJECT_INT_OBJECT(PyObject *operand1,
1242 PyObject *operand2) {
1243 PyTypeObject *type2 = Py_TYPE(operand2);
1244
1245#if defined(_MSC_VER)
1246#pragma warning(push)
1247#pragma warning(disable : 4101)
1248#endif
1249 NUITKA_MAY_BE_UNUSED bool cbool_result;
1250 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1251#if defined(_MSC_VER)
1252#pragma warning(pop)
1253#endif
1254
1255 binaryfunc slot1 = PyInt_Type.tp_as_number->nb_lshift;
1256 binaryfunc slot2 = NULL;
1257
1258 if (!(&PyInt_Type == type2)) {
1259 // Different types, need to consider second value slot.
1260
1261 slot2 = (type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_lshift : NULL;
1262
1263 if (slot1 == slot2) {
1264 slot2 = NULL;
1265 }
1266 }
1267
1268 if (slot1 != NULL) {
1269 if (slot2 != NULL) {
1270 if (Nuitka_Type_IsSubtype(type2, &PyInt_Type)) {
1271 PyObject *x = slot2(operand1, operand2);
1272
1273 if (x != Py_NotImplemented) {
1274 obj_result = x;
1275 goto exit_binary_result_object;
1276 }
1277
1278 Py_DECREF_IMMORTAL(x);
1279 slot2 = NULL;
1280 }
1281 }
1282
1283 PyObject *x = slot1(operand1, operand2);
1284
1285 if (x != Py_NotImplemented) {
1286 obj_result = x;
1287 goto exit_binary_result_object;
1288 }
1289
1290 Py_DECREF_IMMORTAL(x);
1291 }
1292
1293 if (slot2 != NULL) {
1294 PyObject *x = slot2(operand1, operand2);
1295
1296 if (x != Py_NotImplemented) {
1297 obj_result = x;
1298 goto exit_binary_result_object;
1299 }
1300
1301 Py_DECREF_IMMORTAL(x);
1302 }
1303
1304#if PYTHON_VERSION < 0x300
1305 if (!1 || !NEW_STYLE_NUMBER_TYPE(type2)) {
1306 coercion c1 = PyInt_Type.tp_as_number->nb_coerce;
1307
1308 if (c1 != NULL) {
1309 PyObject *coerced1 = operand1;
1310 PyObject *coerced2 = operand2;
1311
1312 int err = c1(&coerced1, &coerced2);
1313
1314 if (unlikely(err < 0)) {
1315 goto exit_binary_exception;
1316 }
1317
1318 if (err == 0) {
1319 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
1320
1321 if (likely(mv == NULL)) {
1322 binaryfunc slot = mv->nb_lshift;
1323
1324 if (likely(slot != NULL)) {
1325 PyObject *x = slot(coerced1, coerced2);
1326
1327 Py_DECREF(coerced1);
1328 Py_DECREF(coerced2);
1329
1330 obj_result = x;
1331 goto exit_binary_result_object;
1332 }
1333 }
1334
1335 // nb_coerce took a reference.
1336 Py_DECREF(coerced1);
1337 Py_DECREF(coerced2);
1338 }
1339 }
1340 coercion c2 =
1341 (type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_coerce : NULL;
1342
1343 if (c2 != NULL) {
1344 PyObject *coerced1 = operand1;
1345 PyObject *coerced2 = operand2;
1346
1347 int err = c2(&coerced2, &coerced1);
1348
1349 if (unlikely(err < 0)) {
1350 goto exit_binary_exception;
1351 }
1352
1353 if (err == 0) {
1354 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
1355
1356 if (likely(mv == NULL)) {
1357 binaryfunc slot = mv->nb_lshift;
1358
1359 if (likely(slot != NULL)) {
1360 PyObject *x = slot(coerced1, coerced2);
1361
1362 Py_DECREF(coerced1);
1363 Py_DECREF(coerced2);
1364
1365 obj_result = x;
1366 goto exit_binary_result_object;
1367 }
1368 }
1369
1370 // nb_coerce took a reference.
1371 Py_DECREF(coerced1);
1372 Py_DECREF(coerced2);
1373 }
1374 }
1375 }
1376#endif
1377
1378 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for <<: 'int' and '%s'", type2->tp_name);
1379 goto exit_binary_exception;
1380
1381exit_binary_result_object:
1382 return obj_result;
1383
1384exit_binary_exception:
1385 return NULL;
1386}
1387static PyObject *_BINARY_OPERATION_LSHIFT_OBJECT_INT_OBJECT(PyObject *operand1, PyObject *operand2) {
1388 CHECK_OBJECT(operand1);
1389 assert(PyInt_CheckExact(operand1));
1390 CHECK_OBJECT(operand2);
1391
1392 PyTypeObject *type2 = Py_TYPE(operand2);
1393
1394 if (&PyInt_Type == type2) {
1395 PyObject *result;
1396
1397 // return _BINARY_OPERATION_LSHIFT_OBJECT_INT_INT(operand1, operand2);
1398
1399 // Not every code path will make use of all possible results.
1400#if defined(_MSC_VER)
1401#pragma warning(push)
1402#pragma warning(disable : 4101)
1403#endif
1404 NUITKA_MAY_BE_UNUSED bool cbool_result;
1405 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1406 NUITKA_MAY_BE_UNUSED long clong_result;
1407 NUITKA_MAY_BE_UNUSED double cfloat_result;
1408#if defined(_MSC_VER)
1409#pragma warning(pop)
1410#endif
1411
1412 CHECK_OBJECT(operand1);
1413 assert(PyInt_CheckExact(operand1));
1414 CHECK_OBJECT(operand2);
1415 assert(PyInt_CheckExact(operand2));
1416
1417 const long a = PyInt_AS_LONG(operand1);
1418 const long b = PyInt_AS_LONG(operand2);
1419
1420 if (unlikely(b < 0)) {
1421 PyThreadState *tstate = PyThreadState_GET();
1422
1423 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ValueError, "negative shift count");
1424 goto exit_result_exception;
1425 }
1426 /* Short cut for zero shift or shifting zero. */
1427 if (a == 0 || b == 0) {
1428 goto exit_result_ok_left;
1429 } else if (b >= LONG_BIT) {
1430 PyObject *operand1_long = Nuitka_PyLong_FromLong(a);
1431 PyObject *operand2_long = Nuitka_PyLong_FromLong(b);
1432
1433 // TODO: Change this to using CLONG once we specialize that too.
1434 PyObject *r = _BINARY_OPERATION_LSHIFT_OBJECT_LONG_LONG(operand1_long, operand2_long);
1435
1436 Py_DECREF(operand1_long);
1437 Py_DECREF(operand2_long);
1438
1439 obj_result = r;
1440 goto exit_result_object;
1441 } else {
1442 long c = a << b;
1443
1444 if (a != Py_ARITHMETIC_RIGHT_SHIFT(long, c, b)) {
1445 PyObject *operand1_long = Nuitka_PyLong_FromLong(a);
1446 PyObject *operand2_long = Nuitka_PyLong_FromLong(b);
1447
1448 // TODO: Change this to using CLONG once we specialize that too.
1449 PyObject *r = _BINARY_OPERATION_LSHIFT_OBJECT_LONG_LONG(operand1_long, operand2_long);
1450
1451 Py_DECREF(operand1_long);
1452 Py_DECREF(operand2_long);
1453
1454 obj_result = r;
1455 goto exit_result_object;
1456 } else {
1457 clong_result = c;
1458 goto exit_result_ok_clong;
1459 }
1460 }
1461
1462 exit_result_ok_clong:
1463 result = Nuitka_PyInt_FromLong(clong_result);
1464 goto exit_result_ok;
1465
1466 exit_result_ok_left:
1467 result = operand1;
1468 Py_INCREF(result);
1469 goto exit_result_ok;
1470
1471 exit_result_object:
1472 if (unlikely(obj_result == NULL)) {
1473 goto exit_result_exception;
1474 }
1475 result = obj_result;
1476 goto exit_result_ok;
1477
1478 exit_result_ok:
1479 return result;
1480
1481 exit_result_exception:
1482 return NULL;
1483 }
1484
1485 return __BINARY_OPERATION_LSHIFT_OBJECT_INT_OBJECT(operand1, operand2);
1486}
1487
1488PyObject *BINARY_OPERATION_LSHIFT_OBJECT_INT_OBJECT(PyObject *operand1, PyObject *operand2) {
1489 return _BINARY_OPERATION_LSHIFT_OBJECT_INT_OBJECT(operand1, operand2);
1490}
1491#endif
1492
1493#if PYTHON_VERSION < 0x300
1494/* Code referring to "INT" corresponds to Python2 'int' and "INT" to Python2 'int'. */
1495static nuitka_bool _BINARY_OPERATION_LSHIFT_NBOOL_INT_INT(PyObject *operand1, PyObject *operand2) {
1496 CHECK_OBJECT(operand1);
1497 assert(PyInt_CheckExact(operand1));
1498 CHECK_OBJECT(operand2);
1499 assert(PyInt_CheckExact(operand2));
1500
1501 nuitka_bool result;
1502
1503 // Not every code path will make use of all possible results.
1504#if defined(_MSC_VER)
1505#pragma warning(push)
1506#pragma warning(disable : 4101)
1507#endif
1508 NUITKA_MAY_BE_UNUSED bool cbool_result;
1509 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1510 NUITKA_MAY_BE_UNUSED long clong_result;
1511 NUITKA_MAY_BE_UNUSED double cfloat_result;
1512#if defined(_MSC_VER)
1513#pragma warning(pop)
1514#endif
1515
1516 CHECK_OBJECT(operand1);
1517 assert(PyInt_CheckExact(operand1));
1518 CHECK_OBJECT(operand2);
1519 assert(PyInt_CheckExact(operand2));
1520
1521 const long a = PyInt_AS_LONG(operand1);
1522 const long b = PyInt_AS_LONG(operand2);
1523
1524 if (unlikely(b < 0)) {
1525 PyThreadState *tstate = PyThreadState_GET();
1526
1527 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ValueError, "negative shift count");
1528 goto exit_result_exception;
1529 }
1530 /* Short cut for zero shift or shifting zero. */
1531 if (a == 0 || b == 0) {
1532 goto exit_result_ok_left;
1533 } else if (b >= LONG_BIT) {
1534 PyObject *operand1_long = Nuitka_PyLong_FromLong(a);
1535 PyObject *operand2_long = Nuitka_PyLong_FromLong(b);
1536
1537 // TODO: Change this to using CLONG once we specialize that too.
1538 PyObject *r = _BINARY_OPERATION_LSHIFT_OBJECT_LONG_LONG(operand1_long, operand2_long);
1539
1540 Py_DECREF(operand1_long);
1541 Py_DECREF(operand2_long);
1542
1543 obj_result = r;
1544 goto exit_result_object;
1545 } else {
1546 long c = a << b;
1547
1548 if (a != Py_ARITHMETIC_RIGHT_SHIFT(long, c, b)) {
1549 PyObject *operand1_long = Nuitka_PyLong_FromLong(a);
1550 PyObject *operand2_long = Nuitka_PyLong_FromLong(b);
1551
1552 // TODO: Change this to using CLONG once we specialize that too.
1553 PyObject *r = _BINARY_OPERATION_LSHIFT_OBJECT_LONG_LONG(operand1_long, operand2_long);
1554
1555 Py_DECREF(operand1_long);
1556 Py_DECREF(operand2_long);
1557
1558 obj_result = r;
1559 goto exit_result_object;
1560 } else {
1561 clong_result = c;
1562 goto exit_result_ok_clong;
1563 }
1564 }
1565
1566exit_result_ok_clong:
1567 result = clong_result != 0 ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
1568 goto exit_result_ok;
1569
1570exit_result_ok_left:
1571 result = PyInt_AS_LONG(operand1) != 0 ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
1572 goto exit_result_ok;
1573
1574exit_result_object:
1575 if (unlikely(obj_result == NULL)) {
1576 goto exit_result_exception;
1577 }
1578 result = CHECK_IF_TRUE(obj_result) ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
1579 Py_DECREF(obj_result);
1580 goto exit_result_ok;
1581
1582exit_result_ok:
1583 return result;
1584
1585exit_result_exception:
1586 return NUITKA_BOOL_EXCEPTION;
1587}
1588
1589nuitka_bool BINARY_OPERATION_LSHIFT_NBOOL_INT_INT(PyObject *operand1, PyObject *operand2) {
1590 return _BINARY_OPERATION_LSHIFT_NBOOL_INT_INT(operand1, operand2);
1591}
1592#endif
1593
1594#if PYTHON_VERSION < 0x300
1595/* Code referring to "OBJECT" corresponds to any Python object and "INT" to Python2 'int'. */
1596static HEDLEY_NEVER_INLINE nuitka_bool __BINARY_OPERATION_LSHIFT_NBOOL_OBJECT_INT(PyObject *operand1,
1597 PyObject *operand2) {
1598 PyTypeObject *type1 = Py_TYPE(operand1);
1599
1600#if defined(_MSC_VER)
1601#pragma warning(push)
1602#pragma warning(disable : 4101)
1603#endif
1604 NUITKA_MAY_BE_UNUSED bool cbool_result;
1605 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1606#if defined(_MSC_VER)
1607#pragma warning(pop)
1608#endif
1609
1610 binaryfunc slot1 =
1611 (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_lshift : NULL;
1612 binaryfunc slot2 = NULL;
1613
1614 if (!(type1 == &PyInt_Type)) {
1615 // Different types, need to consider second value slot.
1616
1617 slot2 = PyInt_Type.tp_as_number->nb_lshift;
1618
1619 if (slot1 == slot2) {
1620 slot2 = NULL;
1621 }
1622 }
1623
1624 if (slot1 != NULL) {
1625 PyObject *x = slot1(operand1, operand2);
1626
1627 if (x != Py_NotImplemented) {
1628 obj_result = x;
1629 goto exit_binary_result_object;
1630 }
1631
1632 Py_DECREF_IMMORTAL(x);
1633 }
1634
1635 if (slot2 != NULL) {
1636 PyObject *x = slot2(operand1, operand2);
1637
1638 if (x != Py_NotImplemented) {
1639 obj_result = x;
1640 goto exit_binary_result_object;
1641 }
1642
1643 Py_DECREF_IMMORTAL(x);
1644 }
1645
1646#if PYTHON_VERSION < 0x300
1647 if (!NEW_STYLE_NUMBER_TYPE(type1) || !1) {
1648 coercion c1 =
1649 (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_coerce : NULL;
1650
1651 if (c1 != NULL) {
1652 PyObject *coerced1 = operand1;
1653 PyObject *coerced2 = operand2;
1654
1655 int err = c1(&coerced1, &coerced2);
1656
1657 if (unlikely(err < 0)) {
1658 goto exit_binary_exception;
1659 }
1660
1661 if (err == 0) {
1662 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
1663
1664 if (likely(mv == NULL)) {
1665 binaryfunc slot = mv->nb_lshift;
1666
1667 if (likely(slot != NULL)) {
1668 PyObject *x = slot(coerced1, coerced2);
1669
1670 Py_DECREF(coerced1);
1671 Py_DECREF(coerced2);
1672
1673 obj_result = x;
1674 goto exit_binary_result_object;
1675 }
1676 }
1677
1678 // nb_coerce took a reference.
1679 Py_DECREF(coerced1);
1680 Py_DECREF(coerced2);
1681 }
1682 }
1683 coercion c2 = PyInt_Type.tp_as_number->nb_coerce;
1684
1685 if (c2 != NULL) {
1686 PyObject *coerced1 = operand1;
1687 PyObject *coerced2 = operand2;
1688
1689 int err = c2(&coerced2, &coerced1);
1690
1691 if (unlikely(err < 0)) {
1692 goto exit_binary_exception;
1693 }
1694
1695 if (err == 0) {
1696 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
1697
1698 if (likely(mv == NULL)) {
1699 binaryfunc slot = mv->nb_lshift;
1700
1701 if (likely(slot != NULL)) {
1702 PyObject *x = slot(coerced1, coerced2);
1703
1704 Py_DECREF(coerced1);
1705 Py_DECREF(coerced2);
1706
1707 obj_result = x;
1708 goto exit_binary_result_object;
1709 }
1710 }
1711
1712 // nb_coerce took a reference.
1713 Py_DECREF(coerced1);
1714 Py_DECREF(coerced2);
1715 }
1716 }
1717 }
1718#endif
1719
1720 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for <<: '%s' and 'int'", type1->tp_name);
1721 goto exit_binary_exception;
1722
1723exit_binary_result_object:
1724 if (unlikely(obj_result == NULL)) {
1725 return NUITKA_BOOL_EXCEPTION;
1726 }
1727
1728 {
1729 nuitka_bool r = CHECK_IF_TRUE(obj_result) ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
1730 Py_DECREF(obj_result);
1731 return r;
1732 }
1733
1734exit_binary_exception:
1735 return NUITKA_BOOL_EXCEPTION;
1736}
1737static nuitka_bool _BINARY_OPERATION_LSHIFT_NBOOL_OBJECT_INT(PyObject *operand1, PyObject *operand2) {
1738 CHECK_OBJECT(operand1);
1739 CHECK_OBJECT(operand2);
1740 assert(PyInt_CheckExact(operand2));
1741
1742 PyTypeObject *type1 = Py_TYPE(operand1);
1743
1744 if (type1 == &PyInt_Type) {
1745 nuitka_bool result;
1746
1747 // return _BINARY_OPERATION_LSHIFT_NBOOL_INT_INT(operand1, operand2);
1748
1749 // Not every code path will make use of all possible results.
1750#if defined(_MSC_VER)
1751#pragma warning(push)
1752#pragma warning(disable : 4101)
1753#endif
1754 NUITKA_MAY_BE_UNUSED bool cbool_result;
1755 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1756 NUITKA_MAY_BE_UNUSED long clong_result;
1757 NUITKA_MAY_BE_UNUSED double cfloat_result;
1758#if defined(_MSC_VER)
1759#pragma warning(pop)
1760#endif
1761
1762 CHECK_OBJECT(operand1);
1763 assert(PyInt_CheckExact(operand1));
1764 CHECK_OBJECT(operand2);
1765 assert(PyInt_CheckExact(operand2));
1766
1767 const long a = PyInt_AS_LONG(operand1);
1768 const long b = PyInt_AS_LONG(operand2);
1769
1770 if (unlikely(b < 0)) {
1771 PyThreadState *tstate = PyThreadState_GET();
1772
1773 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ValueError, "negative shift count");
1774 goto exit_result_exception;
1775 }
1776 /* Short cut for zero shift or shifting zero. */
1777 if (a == 0 || b == 0) {
1778 goto exit_result_ok_left;
1779 } else if (b >= LONG_BIT) {
1780 PyObject *operand1_long = Nuitka_PyLong_FromLong(a);
1781 PyObject *operand2_long = Nuitka_PyLong_FromLong(b);
1782
1783 // TODO: Change this to using CLONG once we specialize that too.
1784 PyObject *r = _BINARY_OPERATION_LSHIFT_OBJECT_LONG_LONG(operand1_long, operand2_long);
1785
1786 Py_DECREF(operand1_long);
1787 Py_DECREF(operand2_long);
1788
1789 obj_result = r;
1790 goto exit_result_object;
1791 } else {
1792 long c = a << b;
1793
1794 if (a != Py_ARITHMETIC_RIGHT_SHIFT(long, c, b)) {
1795 PyObject *operand1_long = Nuitka_PyLong_FromLong(a);
1796 PyObject *operand2_long = Nuitka_PyLong_FromLong(b);
1797
1798 // TODO: Change this to using CLONG once we specialize that too.
1799 PyObject *r = _BINARY_OPERATION_LSHIFT_OBJECT_LONG_LONG(operand1_long, operand2_long);
1800
1801 Py_DECREF(operand1_long);
1802 Py_DECREF(operand2_long);
1803
1804 obj_result = r;
1805 goto exit_result_object;
1806 } else {
1807 clong_result = c;
1808 goto exit_result_ok_clong;
1809 }
1810 }
1811
1812 exit_result_ok_clong:
1813 result = clong_result != 0 ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
1814 goto exit_result_ok;
1815
1816 exit_result_ok_left:
1817 result = PyInt_AS_LONG(operand1) != 0 ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
1818 goto exit_result_ok;
1819
1820 exit_result_object:
1821 if (unlikely(obj_result == NULL)) {
1822 goto exit_result_exception;
1823 }
1824 result = CHECK_IF_TRUE(obj_result) ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
1825 Py_DECREF(obj_result);
1826 goto exit_result_ok;
1827
1828 exit_result_ok:
1829 return result;
1830
1831 exit_result_exception:
1832 return NUITKA_BOOL_EXCEPTION;
1833 }
1834
1835 return __BINARY_OPERATION_LSHIFT_NBOOL_OBJECT_INT(operand1, operand2);
1836}
1837
1838nuitka_bool BINARY_OPERATION_LSHIFT_NBOOL_OBJECT_INT(PyObject *operand1, PyObject *operand2) {
1839 return _BINARY_OPERATION_LSHIFT_NBOOL_OBJECT_INT(operand1, operand2);
1840}
1841#endif
1842
1843#if PYTHON_VERSION < 0x300
1844/* Code referring to "INT" corresponds to Python2 'int' and "OBJECT" to any Python object. */
1845static HEDLEY_NEVER_INLINE nuitka_bool __BINARY_OPERATION_LSHIFT_NBOOL_INT_OBJECT(PyObject *operand1,
1846 PyObject *operand2) {
1847 PyTypeObject *type2 = Py_TYPE(operand2);
1848
1849#if defined(_MSC_VER)
1850#pragma warning(push)
1851#pragma warning(disable : 4101)
1852#endif
1853 NUITKA_MAY_BE_UNUSED bool cbool_result;
1854 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1855#if defined(_MSC_VER)
1856#pragma warning(pop)
1857#endif
1858
1859 binaryfunc slot1 = PyInt_Type.tp_as_number->nb_lshift;
1860 binaryfunc slot2 = NULL;
1861
1862 if (!(&PyInt_Type == type2)) {
1863 // Different types, need to consider second value slot.
1864
1865 slot2 = (type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_lshift : NULL;
1866
1867 if (slot1 == slot2) {
1868 slot2 = NULL;
1869 }
1870 }
1871
1872 if (slot1 != NULL) {
1873 if (slot2 != NULL) {
1874 if (Nuitka_Type_IsSubtype(type2, &PyInt_Type)) {
1875 PyObject *x = slot2(operand1, operand2);
1876
1877 if (x != Py_NotImplemented) {
1878 obj_result = x;
1879 goto exit_binary_result_object;
1880 }
1881
1882 Py_DECREF_IMMORTAL(x);
1883 slot2 = NULL;
1884 }
1885 }
1886
1887 PyObject *x = slot1(operand1, operand2);
1888
1889 if (x != Py_NotImplemented) {
1890 obj_result = x;
1891 goto exit_binary_result_object;
1892 }
1893
1894 Py_DECREF_IMMORTAL(x);
1895 }
1896
1897 if (slot2 != NULL) {
1898 PyObject *x = slot2(operand1, operand2);
1899
1900 if (x != Py_NotImplemented) {
1901 obj_result = x;
1902 goto exit_binary_result_object;
1903 }
1904
1905 Py_DECREF_IMMORTAL(x);
1906 }
1907
1908#if PYTHON_VERSION < 0x300
1909 if (!1 || !NEW_STYLE_NUMBER_TYPE(type2)) {
1910 coercion c1 = PyInt_Type.tp_as_number->nb_coerce;
1911
1912 if (c1 != NULL) {
1913 PyObject *coerced1 = operand1;
1914 PyObject *coerced2 = operand2;
1915
1916 int err = c1(&coerced1, &coerced2);
1917
1918 if (unlikely(err < 0)) {
1919 goto exit_binary_exception;
1920 }
1921
1922 if (err == 0) {
1923 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
1924
1925 if (likely(mv == NULL)) {
1926 binaryfunc slot = mv->nb_lshift;
1927
1928 if (likely(slot != NULL)) {
1929 PyObject *x = slot(coerced1, coerced2);
1930
1931 Py_DECREF(coerced1);
1932 Py_DECREF(coerced2);
1933
1934 obj_result = x;
1935 goto exit_binary_result_object;
1936 }
1937 }
1938
1939 // nb_coerce took a reference.
1940 Py_DECREF(coerced1);
1941 Py_DECREF(coerced2);
1942 }
1943 }
1944 coercion c2 =
1945 (type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_coerce : NULL;
1946
1947 if (c2 != NULL) {
1948 PyObject *coerced1 = operand1;
1949 PyObject *coerced2 = operand2;
1950
1951 int err = c2(&coerced2, &coerced1);
1952
1953 if (unlikely(err < 0)) {
1954 goto exit_binary_exception;
1955 }
1956
1957 if (err == 0) {
1958 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
1959
1960 if (likely(mv == NULL)) {
1961 binaryfunc slot = mv->nb_lshift;
1962
1963 if (likely(slot != NULL)) {
1964 PyObject *x = slot(coerced1, coerced2);
1965
1966 Py_DECREF(coerced1);
1967 Py_DECREF(coerced2);
1968
1969 obj_result = x;
1970 goto exit_binary_result_object;
1971 }
1972 }
1973
1974 // nb_coerce took a reference.
1975 Py_DECREF(coerced1);
1976 Py_DECREF(coerced2);
1977 }
1978 }
1979 }
1980#endif
1981
1982 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for <<: 'int' and '%s'", type2->tp_name);
1983 goto exit_binary_exception;
1984
1985exit_binary_result_object:
1986 if (unlikely(obj_result == NULL)) {
1987 return NUITKA_BOOL_EXCEPTION;
1988 }
1989
1990 {
1991 nuitka_bool r = CHECK_IF_TRUE(obj_result) ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
1992 Py_DECREF(obj_result);
1993 return r;
1994 }
1995
1996exit_binary_exception:
1997 return NUITKA_BOOL_EXCEPTION;
1998}
1999static nuitka_bool _BINARY_OPERATION_LSHIFT_NBOOL_INT_OBJECT(PyObject *operand1, PyObject *operand2) {
2000 CHECK_OBJECT(operand1);
2001 assert(PyInt_CheckExact(operand1));
2002 CHECK_OBJECT(operand2);
2003
2004 PyTypeObject *type2 = Py_TYPE(operand2);
2005
2006 if (&PyInt_Type == type2) {
2007 nuitka_bool result;
2008
2009 // return _BINARY_OPERATION_LSHIFT_NBOOL_INT_INT(operand1, operand2);
2010
2011 // Not every code path will make use of all possible results.
2012#if defined(_MSC_VER)
2013#pragma warning(push)
2014#pragma warning(disable : 4101)
2015#endif
2016 NUITKA_MAY_BE_UNUSED bool cbool_result;
2017 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
2018 NUITKA_MAY_BE_UNUSED long clong_result;
2019 NUITKA_MAY_BE_UNUSED double cfloat_result;
2020#if defined(_MSC_VER)
2021#pragma warning(pop)
2022#endif
2023
2024 CHECK_OBJECT(operand1);
2025 assert(PyInt_CheckExact(operand1));
2026 CHECK_OBJECT(operand2);
2027 assert(PyInt_CheckExact(operand2));
2028
2029 const long a = PyInt_AS_LONG(operand1);
2030 const long b = PyInt_AS_LONG(operand2);
2031
2032 if (unlikely(b < 0)) {
2033 PyThreadState *tstate = PyThreadState_GET();
2034
2035 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ValueError, "negative shift count");
2036 goto exit_result_exception;
2037 }
2038 /* Short cut for zero shift or shifting zero. */
2039 if (a == 0 || b == 0) {
2040 goto exit_result_ok_left;
2041 } else if (b >= LONG_BIT) {
2042 PyObject *operand1_long = Nuitka_PyLong_FromLong(a);
2043 PyObject *operand2_long = Nuitka_PyLong_FromLong(b);
2044
2045 // TODO: Change this to using CLONG once we specialize that too.
2046 PyObject *r = _BINARY_OPERATION_LSHIFT_OBJECT_LONG_LONG(operand1_long, operand2_long);
2047
2048 Py_DECREF(operand1_long);
2049 Py_DECREF(operand2_long);
2050
2051 obj_result = r;
2052 goto exit_result_object;
2053 } else {
2054 long c = a << b;
2055
2056 if (a != Py_ARITHMETIC_RIGHT_SHIFT(long, c, b)) {
2057 PyObject *operand1_long = Nuitka_PyLong_FromLong(a);
2058 PyObject *operand2_long = Nuitka_PyLong_FromLong(b);
2059
2060 // TODO: Change this to using CLONG once we specialize that too.
2061 PyObject *r = _BINARY_OPERATION_LSHIFT_OBJECT_LONG_LONG(operand1_long, operand2_long);
2062
2063 Py_DECREF(operand1_long);
2064 Py_DECREF(operand2_long);
2065
2066 obj_result = r;
2067 goto exit_result_object;
2068 } else {
2069 clong_result = c;
2070 goto exit_result_ok_clong;
2071 }
2072 }
2073
2074 exit_result_ok_clong:
2075 result = clong_result != 0 ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
2076 goto exit_result_ok;
2077
2078 exit_result_ok_left:
2079 result = PyInt_AS_LONG(operand1) != 0 ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
2080 goto exit_result_ok;
2081
2082 exit_result_object:
2083 if (unlikely(obj_result == NULL)) {
2084 goto exit_result_exception;
2085 }
2086 result = CHECK_IF_TRUE(obj_result) ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
2087 Py_DECREF(obj_result);
2088 goto exit_result_ok;
2089
2090 exit_result_ok:
2091 return result;
2092
2093 exit_result_exception:
2094 return NUITKA_BOOL_EXCEPTION;
2095 }
2096
2097 return __BINARY_OPERATION_LSHIFT_NBOOL_INT_OBJECT(operand1, operand2);
2098}
2099
2100nuitka_bool BINARY_OPERATION_LSHIFT_NBOOL_INT_OBJECT(PyObject *operand1, PyObject *operand2) {
2101 return _BINARY_OPERATION_LSHIFT_NBOOL_INT_OBJECT(operand1, operand2);
2102}
2103#endif
2104
2105#if PYTHON_VERSION < 0x300
2106/* Code referring to "LONG" corresponds to Python2 'long', Python3 'int' and "INT" to Python2 'int'. */
2107static PyObject *_BINARY_OPERATION_LSHIFT_OBJECT_LONG_INT(PyObject *operand1, PyObject *operand2) {
2108 CHECK_OBJECT(operand1);
2109 assert(PyLong_CheckExact(operand1));
2110 CHECK_OBJECT(operand2);
2111 assert(PyInt_CheckExact(operand2));
2112
2113#if defined(_MSC_VER)
2114#pragma warning(push)
2115#pragma warning(disable : 4101)
2116#endif
2117 NUITKA_MAY_BE_UNUSED bool cbool_result;
2118 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
2119#if defined(_MSC_VER)
2120#pragma warning(pop)
2121#endif
2122
2123 binaryfunc slot1 = PyLong_Type.tp_as_number->nb_lshift;
2124 // Slot2 ignored on purpose, type1 takes precedence.
2125
2126 if (slot1 != NULL) {
2127 PyObject *x = slot1(operand1, operand2);
2128
2129 if (x != Py_NotImplemented) {
2130 obj_result = x;
2131 goto exit_binary_result_object;
2132 }
2133
2134 Py_DECREF_IMMORTAL(x);
2135 }
2136
2137 // Statically recognized that coercion is not possible with these types
2138
2139 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for <<: 'long' and 'int'");
2140 goto exit_binary_exception;
2141
2142exit_binary_result_object:
2143 return obj_result;
2144
2145exit_binary_exception:
2146 return NULL;
2147}
2148
2149PyObject *BINARY_OPERATION_LSHIFT_OBJECT_LONG_INT(PyObject *operand1, PyObject *operand2) {
2150 return _BINARY_OPERATION_LSHIFT_OBJECT_LONG_INT(operand1, operand2);
2151}
2152#endif
2153
2154#if PYTHON_VERSION < 0x300
2155/* Code referring to "INT" corresponds to Python2 'int' and "LONG" to Python2 'long', Python3 'int'. */
2156static PyObject *_BINARY_OPERATION_LSHIFT_OBJECT_INT_LONG(PyObject *operand1, PyObject *operand2) {
2157 CHECK_OBJECT(operand1);
2158 assert(PyInt_CheckExact(operand1));
2159 CHECK_OBJECT(operand2);
2160 assert(PyLong_CheckExact(operand2));
2161
2162#if defined(_MSC_VER)
2163#pragma warning(push)
2164#pragma warning(disable : 4101)
2165#endif
2166 NUITKA_MAY_BE_UNUSED bool cbool_result;
2167 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
2168#if defined(_MSC_VER)
2169#pragma warning(pop)
2170#endif
2171
2172 // Slot1 ignored on purpose, type2 takes precedence.
2173 binaryfunc slot2 = NULL;
2174
2175 if (!(0)) {
2176 // Different types, need to consider second value slot.
2177
2178 slot2 = PyLong_Type.tp_as_number->nb_lshift;
2179 }
2180
2181 if (slot2 != NULL) {
2182 PyObject *x = slot2(operand1, operand2);
2183
2184 if (x != Py_NotImplemented) {
2185 obj_result = x;
2186 goto exit_binary_result_object;
2187 }
2188
2189 Py_DECREF_IMMORTAL(x);
2190 }
2191
2192 // Statically recognized that coercion is not possible with these types
2193
2194 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for <<: 'int' and 'long'");
2195 goto exit_binary_exception;
2196
2197exit_binary_result_object:
2198 return obj_result;
2199
2200exit_binary_exception:
2201 return NULL;
2202}
2203
2204PyObject *BINARY_OPERATION_LSHIFT_OBJECT_INT_LONG(PyObject *operand1, PyObject *operand2) {
2205 return _BINARY_OPERATION_LSHIFT_OBJECT_INT_LONG(operand1, operand2);
2206}
2207#endif
2208
2209#if PYTHON_VERSION < 0x300
2210/* Code referring to "LONG" corresponds to Python2 'long', Python3 'int' and "INT" to Python2 'int'. */
2211static nuitka_bool _BINARY_OPERATION_LSHIFT_NBOOL_LONG_INT(PyObject *operand1, PyObject *operand2) {
2212 CHECK_OBJECT(operand1);
2213 assert(PyLong_CheckExact(operand1));
2214 CHECK_OBJECT(operand2);
2215 assert(PyInt_CheckExact(operand2));
2216
2217#if defined(_MSC_VER)
2218#pragma warning(push)
2219#pragma warning(disable : 4101)
2220#endif
2221 NUITKA_MAY_BE_UNUSED bool cbool_result;
2222 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
2223#if defined(_MSC_VER)
2224#pragma warning(pop)
2225#endif
2226
2227 binaryfunc slot1 = PyLong_Type.tp_as_number->nb_lshift;
2228 // Slot2 ignored on purpose, type1 takes precedence.
2229
2230 if (slot1 != NULL) {
2231 PyObject *x = slot1(operand1, operand2);
2232
2233 if (x != Py_NotImplemented) {
2234 obj_result = x;
2235 goto exit_binary_result_object;
2236 }
2237
2238 Py_DECREF_IMMORTAL(x);
2239 }
2240
2241 // Statically recognized that coercion is not possible with these types
2242
2243 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for <<: 'long' and 'int'");
2244 goto exit_binary_exception;
2245
2246exit_binary_result_object:
2247 if (unlikely(obj_result == NULL)) {
2248 return NUITKA_BOOL_EXCEPTION;
2249 }
2250
2251 {
2252 nuitka_bool r = CHECK_IF_TRUE(obj_result) ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
2253 Py_DECREF(obj_result);
2254 return r;
2255 }
2256
2257exit_binary_exception:
2258 return NUITKA_BOOL_EXCEPTION;
2259}
2260
2261nuitka_bool BINARY_OPERATION_LSHIFT_NBOOL_LONG_INT(PyObject *operand1, PyObject *operand2) {
2262 return _BINARY_OPERATION_LSHIFT_NBOOL_LONG_INT(operand1, operand2);
2263}
2264#endif
2265
2266#if PYTHON_VERSION < 0x300
2267/* Code referring to "INT" corresponds to Python2 'int' and "LONG" to Python2 'long', Python3 'int'. */
2268static nuitka_bool _BINARY_OPERATION_LSHIFT_NBOOL_INT_LONG(PyObject *operand1, PyObject *operand2) {
2269 CHECK_OBJECT(operand1);
2270 assert(PyInt_CheckExact(operand1));
2271 CHECK_OBJECT(operand2);
2272 assert(PyLong_CheckExact(operand2));
2273
2274#if defined(_MSC_VER)
2275#pragma warning(push)
2276#pragma warning(disable : 4101)
2277#endif
2278 NUITKA_MAY_BE_UNUSED bool cbool_result;
2279 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
2280#if defined(_MSC_VER)
2281#pragma warning(pop)
2282#endif
2283
2284 // Slot1 ignored on purpose, type2 takes precedence.
2285 binaryfunc slot2 = NULL;
2286
2287 if (!(0)) {
2288 // Different types, need to consider second value slot.
2289
2290 slot2 = PyLong_Type.tp_as_number->nb_lshift;
2291 }
2292
2293 if (slot2 != NULL) {
2294 PyObject *x = slot2(operand1, operand2);
2295
2296 if (x != Py_NotImplemented) {
2297 obj_result = x;
2298 goto exit_binary_result_object;
2299 }
2300
2301 Py_DECREF_IMMORTAL(x);
2302 }
2303
2304 // Statically recognized that coercion is not possible with these types
2305
2306 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for <<: 'int' and 'long'");
2307 goto exit_binary_exception;
2308
2309exit_binary_result_object:
2310 if (unlikely(obj_result == NULL)) {
2311 return NUITKA_BOOL_EXCEPTION;
2312 }
2313
2314 {
2315 nuitka_bool r = CHECK_IF_TRUE(obj_result) ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
2316 Py_DECREF(obj_result);
2317 return r;
2318 }
2319
2320exit_binary_exception:
2321 return NUITKA_BOOL_EXCEPTION;
2322}
2323
2324nuitka_bool BINARY_OPERATION_LSHIFT_NBOOL_INT_LONG(PyObject *operand1, PyObject *operand2) {
2325 return _BINARY_OPERATION_LSHIFT_NBOOL_INT_LONG(operand1, operand2);
2326}
2327#endif
2328
2329/* Code referring to "OBJECT" corresponds to any Python object and "OBJECT" to any Python object. */
2330static PyObject *_BINARY_OPERATION_LSHIFT_OBJECT_OBJECT_OBJECT(PyObject *operand1, PyObject *operand2) {
2331 CHECK_OBJECT(operand1);
2332 CHECK_OBJECT(operand2);
2333
2334#if PYTHON_VERSION < 0x300
2335 if (PyInt_CheckExact(operand1) && PyInt_CheckExact(operand2)) {
2336 PyObject *result;
2337
2338 // Not every code path will make use of all possible results.
2339#if defined(_MSC_VER)
2340#pragma warning(push)
2341#pragma warning(disable : 4101)
2342#endif
2343 NUITKA_MAY_BE_UNUSED bool cbool_result;
2344 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
2345 NUITKA_MAY_BE_UNUSED long clong_result;
2346 NUITKA_MAY_BE_UNUSED double cfloat_result;
2347#if defined(_MSC_VER)
2348#pragma warning(pop)
2349#endif
2350
2351 CHECK_OBJECT(operand1);
2352 assert(PyInt_CheckExact(operand1));
2353 CHECK_OBJECT(operand2);
2354 assert(PyInt_CheckExact(operand2));
2355
2356 const long a = PyInt_AS_LONG(operand1);
2357 const long b = PyInt_AS_LONG(operand2);
2358
2359 if (unlikely(b < 0)) {
2360 PyThreadState *tstate = PyThreadState_GET();
2361
2362 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ValueError, "negative shift count");
2363 goto exit_result_exception;
2364 }
2365 /* Short cut for zero shift or shifting zero. */
2366 if (a == 0 || b == 0) {
2367 goto exit_result_ok_left;
2368 } else if (b >= LONG_BIT) {
2369 PyObject *operand1_long = Nuitka_PyLong_FromLong(a);
2370 PyObject *operand2_long = Nuitka_PyLong_FromLong(b);
2371
2372 // TODO: Change this to using CLONG once we specialize that too.
2373 PyObject *r = _BINARY_OPERATION_LSHIFT_OBJECT_LONG_LONG(operand1_long, operand2_long);
2374
2375 Py_DECREF(operand1_long);
2376 Py_DECREF(operand2_long);
2377
2378 obj_result = r;
2379 goto exit_result_object;
2380 } else {
2381 long c = a << b;
2382
2383 if (a != Py_ARITHMETIC_RIGHT_SHIFT(long, c, b)) {
2384 PyObject *operand1_long = Nuitka_PyLong_FromLong(a);
2385 PyObject *operand2_long = Nuitka_PyLong_FromLong(b);
2386
2387 // TODO: Change this to using CLONG once we specialize that too.
2388 PyObject *r = _BINARY_OPERATION_LSHIFT_OBJECT_LONG_LONG(operand1_long, operand2_long);
2389
2390 Py_DECREF(operand1_long);
2391 Py_DECREF(operand2_long);
2392
2393 obj_result = r;
2394 goto exit_result_object;
2395 } else {
2396 clong_result = c;
2397 goto exit_result_ok_clong;
2398 }
2399 }
2400
2401 exit_result_ok_clong:
2402 result = Nuitka_PyInt_FromLong(clong_result);
2403 goto exit_result_ok;
2404
2405 exit_result_ok_left:
2406 result = operand1;
2407 Py_INCREF(result);
2408 goto exit_result_ok;
2409
2410 exit_result_object:
2411 if (unlikely(obj_result == NULL)) {
2412 goto exit_result_exception;
2413 }
2414 result = obj_result;
2415 goto exit_result_ok;
2416
2417 exit_result_ok:
2418 return result;
2419
2420 exit_result_exception:
2421 return NULL;
2422 }
2423#endif
2424
2425 PyTypeObject *type1 = Py_TYPE(operand1);
2426 PyTypeObject *type2 = Py_TYPE(operand2);
2427
2428#if defined(_MSC_VER)
2429#pragma warning(push)
2430#pragma warning(disable : 4101)
2431#endif
2432 NUITKA_MAY_BE_UNUSED bool cbool_result;
2433 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
2434#if defined(_MSC_VER)
2435#pragma warning(pop)
2436#endif
2437
2438 binaryfunc slot1 =
2439 (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_lshift : NULL;
2440 binaryfunc slot2 = NULL;
2441
2442 if (!(type1 == type2)) {
2443 // Different types, need to consider second value slot.
2444
2445 slot2 = (type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_lshift : NULL;
2446
2447 if (slot1 == slot2) {
2448 slot2 = NULL;
2449 }
2450 }
2451
2452 if (slot1 != NULL) {
2453 if (slot2 != NULL) {
2454 if (Nuitka_Type_IsSubtype(type2, type1)) {
2455 PyObject *x = slot2(operand1, operand2);
2456
2457 if (x != Py_NotImplemented) {
2458 obj_result = x;
2459 goto exit_binary_result_object;
2460 }
2461
2462 Py_DECREF_IMMORTAL(x);
2463 slot2 = NULL;
2464 }
2465 }
2466
2467 PyObject *x = slot1(operand1, operand2);
2468
2469 if (x != Py_NotImplemented) {
2470 obj_result = x;
2471 goto exit_binary_result_object;
2472 }
2473
2474 Py_DECREF_IMMORTAL(x);
2475 }
2476
2477 if (slot2 != NULL) {
2478 PyObject *x = slot2(operand1, operand2);
2479
2480 if (x != Py_NotImplemented) {
2481 obj_result = x;
2482 goto exit_binary_result_object;
2483 }
2484
2485 Py_DECREF_IMMORTAL(x);
2486 }
2487
2488#if PYTHON_VERSION < 0x300
2489 if (!NEW_STYLE_NUMBER_TYPE(type1) || !NEW_STYLE_NUMBER_TYPE(type2)) {
2490 coercion c1 =
2491 (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_coerce : NULL;
2492
2493 if (c1 != NULL) {
2494 PyObject *coerced1 = operand1;
2495 PyObject *coerced2 = operand2;
2496
2497 int err = c1(&coerced1, &coerced2);
2498
2499 if (unlikely(err < 0)) {
2500 goto exit_binary_exception;
2501 }
2502
2503 if (err == 0) {
2504 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
2505
2506 if (likely(mv == NULL)) {
2507 binaryfunc slot = mv->nb_lshift;
2508
2509 if (likely(slot != NULL)) {
2510 PyObject *x = slot(coerced1, coerced2);
2511
2512 Py_DECREF(coerced1);
2513 Py_DECREF(coerced2);
2514
2515 obj_result = x;
2516 goto exit_binary_result_object;
2517 }
2518 }
2519
2520 // nb_coerce took a reference.
2521 Py_DECREF(coerced1);
2522 Py_DECREF(coerced2);
2523 }
2524 }
2525 coercion c2 =
2526 (type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_coerce : NULL;
2527
2528 if (c2 != NULL) {
2529 PyObject *coerced1 = operand1;
2530 PyObject *coerced2 = operand2;
2531
2532 int err = c2(&coerced2, &coerced1);
2533
2534 if (unlikely(err < 0)) {
2535 goto exit_binary_exception;
2536 }
2537
2538 if (err == 0) {
2539 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
2540
2541 if (likely(mv == NULL)) {
2542 binaryfunc slot = mv->nb_lshift;
2543
2544 if (likely(slot != NULL)) {
2545 PyObject *x = slot(coerced1, coerced2);
2546
2547 Py_DECREF(coerced1);
2548 Py_DECREF(coerced2);
2549
2550 obj_result = x;
2551 goto exit_binary_result_object;
2552 }
2553 }
2554
2555 // nb_coerce took a reference.
2556 Py_DECREF(coerced1);
2557 Py_DECREF(coerced2);
2558 }
2559 }
2560 }
2561#endif
2562
2563 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for <<: '%s' and '%s'", type1->tp_name, type2->tp_name);
2564 goto exit_binary_exception;
2565
2566exit_binary_result_object:
2567 return obj_result;
2568
2569exit_binary_exception:
2570 return NULL;
2571}
2572
2573PyObject *BINARY_OPERATION_LSHIFT_OBJECT_OBJECT_OBJECT(PyObject *operand1, PyObject *operand2) {
2574 return _BINARY_OPERATION_LSHIFT_OBJECT_OBJECT_OBJECT(operand1, operand2);
2575}
2576
2577/* Code referring to "OBJECT" corresponds to any Python object and "OBJECT" to any Python object. */
2578static nuitka_bool _BINARY_OPERATION_LSHIFT_NBOOL_OBJECT_OBJECT(PyObject *operand1, PyObject *operand2) {
2579 CHECK_OBJECT(operand1);
2580 CHECK_OBJECT(operand2);
2581
2582#if PYTHON_VERSION < 0x300
2583 if (PyInt_CheckExact(operand1) && PyInt_CheckExact(operand2)) {
2584 nuitka_bool result;
2585
2586 // Not every code path will make use of all possible results.
2587#if defined(_MSC_VER)
2588#pragma warning(push)
2589#pragma warning(disable : 4101)
2590#endif
2591 NUITKA_MAY_BE_UNUSED bool cbool_result;
2592 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
2593 NUITKA_MAY_BE_UNUSED long clong_result;
2594 NUITKA_MAY_BE_UNUSED double cfloat_result;
2595#if defined(_MSC_VER)
2596#pragma warning(pop)
2597#endif
2598
2599 CHECK_OBJECT(operand1);
2600 assert(PyInt_CheckExact(operand1));
2601 CHECK_OBJECT(operand2);
2602 assert(PyInt_CheckExact(operand2));
2603
2604 const long a = PyInt_AS_LONG(operand1);
2605 const long b = PyInt_AS_LONG(operand2);
2606
2607 if (unlikely(b < 0)) {
2608 PyThreadState *tstate = PyThreadState_GET();
2609
2610 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ValueError, "negative shift count");
2611 goto exit_result_exception;
2612 }
2613 /* Short cut for zero shift or shifting zero. */
2614 if (a == 0 || b == 0) {
2615 goto exit_result_ok_left;
2616 } else if (b >= LONG_BIT) {
2617 PyObject *operand1_long = Nuitka_PyLong_FromLong(a);
2618 PyObject *operand2_long = Nuitka_PyLong_FromLong(b);
2619
2620 // TODO: Change this to using CLONG once we specialize that too.
2621 PyObject *r = _BINARY_OPERATION_LSHIFT_OBJECT_LONG_LONG(operand1_long, operand2_long);
2622
2623 Py_DECREF(operand1_long);
2624 Py_DECREF(operand2_long);
2625
2626 obj_result = r;
2627 goto exit_result_object;
2628 } else {
2629 long c = a << b;
2630
2631 if (a != Py_ARITHMETIC_RIGHT_SHIFT(long, c, b)) {
2632 PyObject *operand1_long = Nuitka_PyLong_FromLong(a);
2633 PyObject *operand2_long = Nuitka_PyLong_FromLong(b);
2634
2635 // TODO: Change this to using CLONG once we specialize that too.
2636 PyObject *r = _BINARY_OPERATION_LSHIFT_OBJECT_LONG_LONG(operand1_long, operand2_long);
2637
2638 Py_DECREF(operand1_long);
2639 Py_DECREF(operand2_long);
2640
2641 obj_result = r;
2642 goto exit_result_object;
2643 } else {
2644 clong_result = c;
2645 goto exit_result_ok_clong;
2646 }
2647 }
2648
2649 exit_result_ok_clong:
2650 result = clong_result != 0 ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
2651 goto exit_result_ok;
2652
2653 exit_result_ok_left:
2654 result = PyInt_AS_LONG(operand1) != 0 ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
2655 goto exit_result_ok;
2656
2657 exit_result_object:
2658 if (unlikely(obj_result == NULL)) {
2659 goto exit_result_exception;
2660 }
2661 result = CHECK_IF_TRUE(obj_result) ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
2662 Py_DECREF(obj_result);
2663 goto exit_result_ok;
2664
2665 exit_result_ok:
2666 return result;
2667
2668 exit_result_exception:
2669 return NUITKA_BOOL_EXCEPTION;
2670 }
2671#endif
2672
2673 PyTypeObject *type1 = Py_TYPE(operand1);
2674 PyTypeObject *type2 = Py_TYPE(operand2);
2675
2676#if defined(_MSC_VER)
2677#pragma warning(push)
2678#pragma warning(disable : 4101)
2679#endif
2680 NUITKA_MAY_BE_UNUSED bool cbool_result;
2681 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
2682#if defined(_MSC_VER)
2683#pragma warning(pop)
2684#endif
2685
2686 binaryfunc slot1 =
2687 (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_lshift : NULL;
2688 binaryfunc slot2 = NULL;
2689
2690 if (!(type1 == type2)) {
2691 // Different types, need to consider second value slot.
2692
2693 slot2 = (type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_lshift : NULL;
2694
2695 if (slot1 == slot2) {
2696 slot2 = NULL;
2697 }
2698 }
2699
2700 if (slot1 != NULL) {
2701 if (slot2 != NULL) {
2702 if (Nuitka_Type_IsSubtype(type2, type1)) {
2703 PyObject *x = slot2(operand1, operand2);
2704
2705 if (x != Py_NotImplemented) {
2706 obj_result = x;
2707 goto exit_binary_result_object;
2708 }
2709
2710 Py_DECREF_IMMORTAL(x);
2711 slot2 = NULL;
2712 }
2713 }
2714
2715 PyObject *x = slot1(operand1, operand2);
2716
2717 if (x != Py_NotImplemented) {
2718 obj_result = x;
2719 goto exit_binary_result_object;
2720 }
2721
2722 Py_DECREF_IMMORTAL(x);
2723 }
2724
2725 if (slot2 != NULL) {
2726 PyObject *x = slot2(operand1, operand2);
2727
2728 if (x != Py_NotImplemented) {
2729 obj_result = x;
2730 goto exit_binary_result_object;
2731 }
2732
2733 Py_DECREF_IMMORTAL(x);
2734 }
2735
2736#if PYTHON_VERSION < 0x300
2737 if (!NEW_STYLE_NUMBER_TYPE(type1) || !NEW_STYLE_NUMBER_TYPE(type2)) {
2738 coercion c1 =
2739 (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_coerce : NULL;
2740
2741 if (c1 != NULL) {
2742 PyObject *coerced1 = operand1;
2743 PyObject *coerced2 = operand2;
2744
2745 int err = c1(&coerced1, &coerced2);
2746
2747 if (unlikely(err < 0)) {
2748 goto exit_binary_exception;
2749 }
2750
2751 if (err == 0) {
2752 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
2753
2754 if (likely(mv == NULL)) {
2755 binaryfunc slot = mv->nb_lshift;
2756
2757 if (likely(slot != NULL)) {
2758 PyObject *x = slot(coerced1, coerced2);
2759
2760 Py_DECREF(coerced1);
2761 Py_DECREF(coerced2);
2762
2763 obj_result = x;
2764 goto exit_binary_result_object;
2765 }
2766 }
2767
2768 // nb_coerce took a reference.
2769 Py_DECREF(coerced1);
2770 Py_DECREF(coerced2);
2771 }
2772 }
2773 coercion c2 =
2774 (type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_coerce : NULL;
2775
2776 if (c2 != NULL) {
2777 PyObject *coerced1 = operand1;
2778 PyObject *coerced2 = operand2;
2779
2780 int err = c2(&coerced2, &coerced1);
2781
2782 if (unlikely(err < 0)) {
2783 goto exit_binary_exception;
2784 }
2785
2786 if (err == 0) {
2787 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
2788
2789 if (likely(mv == NULL)) {
2790 binaryfunc slot = mv->nb_lshift;
2791
2792 if (likely(slot != NULL)) {
2793 PyObject *x = slot(coerced1, coerced2);
2794
2795 Py_DECREF(coerced1);
2796 Py_DECREF(coerced2);
2797
2798 obj_result = x;
2799 goto exit_binary_result_object;
2800 }
2801 }
2802
2803 // nb_coerce took a reference.
2804 Py_DECREF(coerced1);
2805 Py_DECREF(coerced2);
2806 }
2807 }
2808 }
2809#endif
2810
2811 PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for <<: '%s' and '%s'", type1->tp_name, type2->tp_name);
2812 goto exit_binary_exception;
2813
2814exit_binary_result_object:
2815 if (unlikely(obj_result == NULL)) {
2816 return NUITKA_BOOL_EXCEPTION;
2817 }
2818
2819 {
2820 nuitka_bool r = CHECK_IF_TRUE(obj_result) ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
2821 Py_DECREF(obj_result);
2822 return r;
2823 }
2824
2825exit_binary_exception:
2826 return NUITKA_BOOL_EXCEPTION;
2827}
2828
2829nuitka_bool BINARY_OPERATION_LSHIFT_NBOOL_OBJECT_OBJECT(PyObject *operand1, PyObject *operand2) {
2830 return _BINARY_OPERATION_LSHIFT_NBOOL_OBJECT_OBJECT(operand1, operand2);
2831}
2832
2833// Part of "Nuitka", an optimizing Python compiler that is compatible and
2834// integrates with CPython, but also works on its own.
2835//
2836// Licensed under the Apache License, Version 2.0 (the "License");
2837// you may not use this file except in compliance with the License.
2838// You may obtain a copy of the License at
2839//
2840// http://www.apache.org/licenses/LICENSE-2.0
2841//
2842// Unless required by applicable law or agreed to in writing, software
2843// distributed under the License is distributed on an "AS IS" BASIS,
2844// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2845// See the License for the specific language governing permissions and
2846// limitations under the License.