summaryrefslogtreecommitdiffstats
path: root/Python/bytecodes.c
diff options
context:
space:
mode:
authorLysandros Nikolaou <lisandrosnik@gmail.com>2025-04-30 09:46:41 (GMT)
committerGitHub <noreply@github.com>2025-04-30 09:46:41 (GMT)
commit60202609a2c2d0971aadfa4729ba30b50e89c6ea (patch)
treed821f3f8f277de56e5d8da457d492f1288cb2bb9 /Python/bytecodes.c
parent5ea9010e8910cb97555c3aef4ed95cca93a74aab (diff)
downloadcpython-60202609a2c2d0971aadfa4729ba30b50e89c6ea.zip
cpython-60202609a2c2d0971aadfa4729ba30b50e89c6ea.tar.gz
cpython-60202609a2c2d0971aadfa4729ba30b50e89c6ea.tar.bz2
gh-132661: Implement PEP 750 (#132662)
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Co-authored-by: Wingy <git@wingysam.xyz> Co-authored-by: Koudai Aono <koxudaxi@gmail.com> Co-authored-by: Dave Peck <davepeck@gmail.com> Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu> Co-authored-by: Paul Everitt <pauleveritt@me.com> Co-authored-by: sobolevn <mail@sobolevn.me>
Diffstat (limited to 'Python/bytecodes.c')
-rw-r--r--Python/bytecodes.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index 7ae687f..b30fa08 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -16,6 +16,7 @@
#include "pycore_emscripten_signal.h" // _Py_CHECK_EMSCRIPTEN_SIGNALS
#include "pycore_function.h"
#include "pycore_instruments.h"
+#include "pycore_interpolation.h" // _PyInterpolation_Build()
#include "pycore_intrinsics.h"
#include "pycore_long.h" // _PyLong_GetZero()
#include "pycore_moduleobject.h" // PyModuleObject
@@ -30,6 +31,7 @@
#include "pycore_setobject.h" // _PySet_NextEntry()
#include "pycore_sliceobject.h" // _PyBuildSlice_ConsumeRefs
#include "pycore_stackref.h"
+#include "pycore_template.h" // _PyTemplate_Build()
#include "pycore_tuple.h" // _PyTuple_ITEMS()
#include "pycore_typeobject.h" // _PySuper_Lookup()
@@ -1903,6 +1905,40 @@ dummy_func(
str = PyStackRef_FromPyObjectSteal(str_o);
}
+ inst(BUILD_INTERPOLATION, (value, str, format[oparg & 1] -- interpolation)) {
+ PyObject *value_o = PyStackRef_AsPyObjectBorrow(value);
+ PyObject *str_o = PyStackRef_AsPyObjectBorrow(str);
+ int conversion = oparg >> 2;
+ PyObject *format_o;
+ if (oparg & 1) {
+ format_o = PyStackRef_AsPyObjectBorrow(format[0]);
+ }
+ else {
+ format_o = &_Py_STR(empty);
+ }
+ PyObject *interpolation_o = _PyInterpolation_Build(value_o, str_o, conversion, format_o);
+ if (oparg & 1) {
+ PyStackRef_CLOSE(format[0]);
+ }
+ else {
+ DEAD(format);
+ }
+ PyStackRef_CLOSE(str);
+ PyStackRef_CLOSE(value);
+ ERROR_IF(interpolation_o == NULL);
+ interpolation = PyStackRef_FromPyObjectSteal(interpolation_o);
+ }
+
+ inst(BUILD_TEMPLATE, (strings, interpolations -- template)) {
+ PyObject *strings_o = PyStackRef_AsPyObjectBorrow(strings);
+ PyObject *interpolations_o = PyStackRef_AsPyObjectBorrow(interpolations);
+ PyObject *template_o = _PyTemplate_Build(strings_o, interpolations_o);
+ PyStackRef_CLOSE(interpolations);
+ PyStackRef_CLOSE(strings);
+ ERROR_IF(template_o == NULL);
+ template = PyStackRef_FromPyObjectSteal(template_o);
+ }
+
inst(BUILD_TUPLE, (values[oparg] -- tup)) {
PyObject *tup_o = _PyTuple_FromStackRefStealOnSuccess(values, oparg);
if (tup_o == NULL) {