summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2023-06-14 15:15:08 (GMT)
committerGitHub <noreply@github.com>2023-06-14 15:15:08 (GMT)
commit1d857da7f0e4858e561223f319ae5afe737d5657 (patch)
treeebfa22004b373a48769f42f002ed401248cdd3ea /Python/compile.c
parent307bceaa65c4f1a8e110cd7a9cce6e93a1b021ba (diff)
downloadcpython-1d857da7f0e4858e561223f319ae5afe737d5657.zip
cpython-1d857da7f0e4858e561223f319ae5afe737d5657.tar.gz
cpython-1d857da7f0e4858e561223f319ae5afe737d5657.tar.bz2
GH-77273: Better bytecodes for f-strings (GH-6132)
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 399a702..daeb4db 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -4985,26 +4985,26 @@ compiler_formatted_value(struct compiler *c, expr_ty e)
/* The expression to be formatted. */
VISIT(c, expr, e->v.FormattedValue.value);
- switch (conversion) {
- case 's': oparg = FVC_STR; break;
- case 'r': oparg = FVC_REPR; break;
- case 'a': oparg = FVC_ASCII; break;
- case -1: oparg = FVC_NONE; break;
- default:
- PyErr_Format(PyExc_SystemError,
+ location loc = LOC(e);
+ if (conversion != -1) {
+ switch (conversion) {
+ case 's': oparg = FVC_STR; break;
+ case 'r': oparg = FVC_REPR; break;
+ case 'a': oparg = FVC_ASCII; break;
+ default:
+ PyErr_Format(PyExc_SystemError,
"Unrecognized conversion character %d", conversion);
- return ERROR;
+ return ERROR;
+ }
+ ADDOP_I(c, loc, CONVERT_VALUE, oparg);
}
if (e->v.FormattedValue.format_spec) {
/* Evaluate the format spec, and update our opcode arg. */
VISIT(c, expr, e->v.FormattedValue.format_spec);
- oparg |= FVS_HAVE_SPEC;
+ ADDOP(c, loc, FORMAT_WITH_SPEC);
+ } else {
+ ADDOP(c, loc, FORMAT_SIMPLE);
}
-
- /* And push our opcode and oparg */
- location loc = LOC(e);
- ADDOP_I(c, loc, FORMAT_VALUE, oparg);
-
return SUCCESS;
}