aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/optimizer_bytecodes.c
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2025-04-02 16:31:59 +0100
committerGitHub <noreply@github.com>2025-04-02 16:31:59 +0100
commitad053d8d6afcb6452336b42528a0530c609bfff4 (patch)
tree7281c666153e325a3bbe3d2ed7bcb361f70e834b /Python/optimizer_bytecodes.c
parent6e91d1f9aafc6e375092b8c14f6e30ebc74e4004 (diff)
downloadcpython-ad053d8d6afcb6452336b42528a0530c609bfff4.tar.gz
cpython-ad053d8d6afcb6452336b42528a0530c609bfff4.zip
GH-131498: Cases generator: Parse down to C statement level. (GH-131948)
* Parse down to statement level in the cases generator * Add handling for #if macros, treating them much like normal ifs.
Diffstat (limited to 'Python/optimizer_bytecodes.c')
-rw-r--r--Python/optimizer_bytecodes.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c
index a948cccbf85..da36704d91e 100644
--- a/Python/optimizer_bytecodes.c
+++ b/Python/optimizer_bytecodes.c
@@ -367,34 +367,39 @@ dummy_func(void) {
}
op(_TO_BOOL, (value -- res)) {
- if (!optimize_to_bool(this_instr, ctx, value, &res)) {
+ int already_bool = optimize_to_bool(this_instr, ctx, value, &res);
+ if (!already_bool) {
res = sym_new_truthiness(ctx, value, true);
}
}
op(_TO_BOOL_BOOL, (value -- res)) {
- if (!optimize_to_bool(this_instr, ctx, value, &res)) {
+ int already_bool = optimize_to_bool(this_instr, ctx, value, &res);
+ if (!already_bool) {
sym_set_type(value, &PyBool_Type);
res = sym_new_truthiness(ctx, value, true);
}
}
op(_TO_BOOL_INT, (value -- res)) {
- if (!optimize_to_bool(this_instr, ctx, value, &res)) {
+ int already_bool = optimize_to_bool(this_instr, ctx, value, &res);
+ if (!already_bool) {
sym_set_type(value, &PyLong_Type);
res = sym_new_truthiness(ctx, value, true);
}
}
op(_TO_BOOL_LIST, (value -- res)) {
- if (!optimize_to_bool(this_instr, ctx, value, &res)) {
+ int already_bool = optimize_to_bool(this_instr, ctx, value, &res);
+ if (!already_bool) {
sym_set_type(value, &PyList_Type);
res = sym_new_type(ctx, &PyBool_Type);
}
}
op(_TO_BOOL_NONE, (value -- res)) {
- if (!optimize_to_bool(this_instr, ctx, value, &res)) {
+ int already_bool = optimize_to_bool(this_instr, ctx, value, &res);
+ if (!already_bool) {
sym_set_const(value, Py_None);
res = sym_new_const(ctx, Py_False);
}
@@ -415,7 +420,8 @@ dummy_func(void) {
}
op(_TO_BOOL_STR, (value -- res)) {
- if (!optimize_to_bool(this_instr, ctx, value, &res)) {
+ int already_bool = optimize_to_bool(this_instr, ctx, value, &res);
+ if (!already_bool) {
res = sym_new_truthiness(ctx, value, true);
}
}