GH-77273: Better bytecodes for f-strings (GH-6132)

This commit is contained in:
Mark Shannon 2023-06-14 16:15:08 +01:00 committed by GitHub
parent 307bceaa65
commit 1d857da7f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 525 additions and 485 deletions

View file

@ -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;
}