mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
GH-77273: Better bytecodes for f-strings (GH-6132)
This commit is contained in:
parent
307bceaa65
commit
1d857da7f0
15 changed files with 525 additions and 485 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue