diff options
author | Mark Shannon <mark@hotpy.org> | 2023-06-14 15:15:08 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-14 15:15:08 (GMT) |
commit | 1d857da7f0e4858e561223f319ae5afe737d5657 (patch) | |
tree | ebfa22004b373a48769f42f002ed401248cdd3ea /Python/compile.c | |
parent | 307bceaa65c4f1a8e110cd7a9cce6e93a1b021ba (diff) | |
download | cpython-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.c | 28 |
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; } |