Nuitka
The Python compiler
Loading...
Searching...
No Matches
HelpersComparisonDualLe.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 HelperOperationComparisonDual.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 "<=" (LE) comparisons */
11
12static PyObject *COMPARE_LE_OBJECT_CLONG_CLONG(long operand1, long operand2) {
13
14 const long a = operand1;
15 const long b = operand2;
16
17 bool r = a <= b;
18
19 // Convert to target type.
20 PyObject *result = BOOL_FROM(r);
21 Py_INCREF_IMMORTAL(result);
22 return result;
23}
24/* Code referring to "NILONG" corresponds to Nuitka int/long/C long value and "NILONG" to Nuitka int/long/C long value.
25 */
26PyObject *RICH_COMPARE_LE_OBJECT_NILONG_NILONG(nuitka_ilong *operand1, nuitka_ilong *operand2) {
27 CHECK_NILONG_OBJECT(operand1);
28 CHECK_NILONG_OBJECT(operand2);
29
30 bool left_c_usable = IS_NILONG_C_VALUE_VALID(operand1);
31 bool right_c_usable = IS_NILONG_C_VALUE_VALID(operand2);
32
33 if (left_c_usable && right_c_usable) {
34 return COMPARE_LE_OBJECT_CLONG_CLONG(operand1->c_value, operand2->c_value);
35 } else if (!left_c_usable && !right_c_usable) {
36 return RICH_COMPARE_LE_OBJECT_LONG_LONG(operand1->python_value, operand2->python_value);
37 } else {
38 bool r;
39 if (left_c_usable) {
40 r = COMPARE_GE_CBOOL_LONG_CLONG(operand2->python_value, operand1->c_value);
41 r = !r;
42 } else {
43 r = COMPARE_LE_CBOOL_LONG_CLONG(operand1->python_value, operand2->c_value);
44 }
45
46 // Convert to target type.
47 PyObject *result = BOOL_FROM(r);
48 Py_INCREF_IMMORTAL(result);
49 return result;
50 }
51}
52
53static bool COMPARE_LE_CBOOL_CLONG_CLONG(long operand1, long operand2) {
54
55 const long a = operand1;
56 const long b = operand2;
57
58 bool r = a <= b;
59
60 // Convert to target type.
61 bool result = r;
62
63 return result;
64}
65/* Code referring to "NILONG" corresponds to Nuitka int/long/C long value and "NILONG" to Nuitka int/long/C long value.
66 */
67bool RICH_COMPARE_LE_CBOOL_NILONG_NILONG(nuitka_ilong *operand1, nuitka_ilong *operand2) {
68 CHECK_NILONG_OBJECT(operand1);
69 CHECK_NILONG_OBJECT(operand2);
70
71 bool left_c_usable = IS_NILONG_C_VALUE_VALID(operand1);
72 bool right_c_usable = IS_NILONG_C_VALUE_VALID(operand2);
73
74 if (left_c_usable && right_c_usable) {
75 return COMPARE_LE_CBOOL_CLONG_CLONG(operand1->c_value, operand2->c_value);
76 } else if (!left_c_usable && !right_c_usable) {
77 return RICH_COMPARE_LE_CBOOL_LONG_LONG(operand1->python_value, operand2->python_value);
78 } else {
79 bool r;
80 if (left_c_usable) {
81 r = COMPARE_GE_CBOOL_LONG_CLONG(operand2->python_value, operand1->c_value);
82 r = !r;
83 } else {
84 r = COMPARE_LE_CBOOL_LONG_CLONG(operand1->python_value, operand2->c_value);
85 }
86
87 // Convert to target type.
88 bool result = r;
89
90 return result;
91 }
92}
93
94/* Code referring to "NILONG" corresponds to Nuitka int/long/C long value and "CLONG" to C platform long value. */
95PyObject *RICH_COMPARE_LE_OBJECT_NILONG_CLONG(nuitka_ilong *operand1, long operand2) {
96 CHECK_NILONG_OBJECT(operand1);
97
98 bool left_c_usable = IS_NILONG_C_VALUE_VALID(operand1);
99 bool right_c_usable = true;
100
101 if (left_c_usable && right_c_usable) {
102 return COMPARE_LE_OBJECT_CLONG_CLONG(operand1->c_value, operand2);
103 } else if (!left_c_usable && !right_c_usable) {
104 ENFORCE_NILONG_OBJECT_VALUE(operand1);
105
106 return COMPARE_LE_OBJECT_LONG_CLONG(operand1->python_value, operand2);
107 } else {
108 return COMPARE_LE_OBJECT_LONG_CLONG(operand1->python_value, operand2);
109 }
110}
111
112/* Code referring to "NILONG" corresponds to Nuitka int/long/C long value and "CLONG" to C platform long value. */
113bool RICH_COMPARE_LE_CBOOL_NILONG_CLONG(nuitka_ilong *operand1, long operand2) {
114 CHECK_NILONG_OBJECT(operand1);
115
116 bool left_c_usable = IS_NILONG_C_VALUE_VALID(operand1);
117 bool right_c_usable = true;
118
119 if (left_c_usable && right_c_usable) {
120 return COMPARE_LE_CBOOL_CLONG_CLONG(operand1->c_value, operand2);
121 } else if (!left_c_usable && !right_c_usable) {
122 ENFORCE_NILONG_OBJECT_VALUE(operand1);
123
124 return COMPARE_LE_CBOOL_LONG_CLONG(operand1->python_value, operand2);
125 } else {
126 return COMPARE_LE_CBOOL_LONG_CLONG(operand1->python_value, operand2);
127 }
128}
129
130/* Code referring to "NILONG" corresponds to Nuitka int/long/C long value and "DIGIT" to C platform digit value for long
131 * Python objects. */
132PyObject *RICH_COMPARE_LE_OBJECT_NILONG_DIGIT(nuitka_ilong *operand1, long operand2) {
133 CHECK_NILONG_OBJECT(operand1);
134 assert(Py_ABS(operand2) < (1 << PyLong_SHIFT));
135
136 bool left_c_usable = IS_NILONG_C_VALUE_VALID(operand1);
137 bool right_c_usable = true;
138
139 if (left_c_usable && right_c_usable) {
140 return COMPARE_LE_OBJECT_CLONG_CLONG(operand1->c_value, operand2);
141 } else if (!left_c_usable && !right_c_usable) {
142 ENFORCE_NILONG_OBJECT_VALUE(operand1);
143
144 return COMPARE_LE_OBJECT_LONG_DIGIT(operand1->python_value, operand2);
145 } else {
146 return COMPARE_LE_OBJECT_LONG_DIGIT(operand1->python_value, operand2);
147 }
148}
149
150/* Code referring to "NILONG" corresponds to Nuitka int/long/C long value and "DIGIT" to C platform digit value for long
151 * Python objects. */
152bool RICH_COMPARE_LE_CBOOL_NILONG_DIGIT(nuitka_ilong *operand1, long operand2) {
153 CHECK_NILONG_OBJECT(operand1);
154 assert(Py_ABS(operand2) < (1 << PyLong_SHIFT));
155
156 bool left_c_usable = IS_NILONG_C_VALUE_VALID(operand1);
157 bool right_c_usable = true;
158
159 if (left_c_usable && right_c_usable) {
160 return COMPARE_LE_CBOOL_CLONG_CLONG(operand1->c_value, operand2);
161 } else if (!left_c_usable && !right_c_usable) {
162 ENFORCE_NILONG_OBJECT_VALUE(operand1);
163
164 return COMPARE_LE_CBOOL_LONG_DIGIT(operand1->python_value, operand2);
165 } else {
166 return COMPARE_LE_CBOOL_LONG_DIGIT(operand1->python_value, operand2);
167 }
168}
169
170// Part of "Nuitka", an optimizing Python compiler that is compatible and
171// integrates with CPython, but also works on its own.
172//
173// Licensed under the Apache License, Version 2.0 (the "License");
174// you may not use this file except in compliance with the License.
175// You may obtain a copy of the License at
176//
177// http://www.apache.org/licenses/LICENSE-2.0
178//
179// Unless required by applicable law or agreed to in writing, software
180// distributed under the License is distributed on an "AS IS" BASIS,
181// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
182// See the License for the specific language governing permissions and
183// limitations under the License.
Definition ints.h:27