mirror of https://github.com/python/cpython
GH-106529: Define POP_JUMP_IF_NONE in terms of POP_JUMP_IF_TRUE (GH-106599)
This commit is contained in:
parent
1f2921b72c
commit
c0c041a31b
|
@ -2282,21 +2282,19 @@ dummy_func(
|
|||
JUMPBY(oparg * Py_IsTrue(cond));
|
||||
}
|
||||
|
||||
inst(POP_JUMP_IF_NOT_NONE, (value -- )) {
|
||||
if (!Py_IsNone(value)) {
|
||||
op(IS_NONE, (value -- b)) {
|
||||
if (Py_IsNone(value)) {
|
||||
b = Py_True;
|
||||
}
|
||||
else {
|
||||
b = Py_False;
|
||||
DECREF_INPUTS();
|
||||
JUMPBY(oparg);
|
||||
}
|
||||
}
|
||||
|
||||
inst(POP_JUMP_IF_NONE, (value -- )) {
|
||||
if (Py_IsNone(value)) {
|
||||
JUMPBY(oparg);
|
||||
}
|
||||
else {
|
||||
DECREF_INPUTS();
|
||||
}
|
||||
}
|
||||
macro(POP_JUMP_IF_NONE) = IS_NONE + POP_JUMP_IF_TRUE;
|
||||
|
||||
macro(POP_JUMP_IF_NOT_NONE) = IS_NONE + POP_JUMP_IF_FALSE;
|
||||
|
||||
inst(JUMP_BACKWARD_NO_INTERRUPT, (--)) {
|
||||
/* This bytecode is used in the `yield from` or `await` loop.
|
||||
|
|
|
@ -1899,16 +1899,34 @@
|
|||
break;
|
||||
}
|
||||
|
||||
case IS_NONE: {
|
||||
PyObject *value = stack_pointer[-1];
|
||||
PyObject *b;
|
||||
#line 2286 "Python/bytecodes.c"
|
||||
if (Py_IsNone(value)) {
|
||||
b = Py_True;
|
||||
}
|
||||
else {
|
||||
b = Py_False;
|
||||
#line 1912 "Python/executor_cases.c.h"
|
||||
Py_DECREF(value);
|
||||
#line 2292 "Python/bytecodes.c"
|
||||
}
|
||||
#line 1916 "Python/executor_cases.c.h"
|
||||
stack_pointer[-1] = b;
|
||||
break;
|
||||
}
|
||||
|
||||
case GET_LEN: {
|
||||
PyObject *obj = stack_pointer[-1];
|
||||
PyObject *len_o;
|
||||
#line 2311 "Python/bytecodes.c"
|
||||
#line 2309 "Python/bytecodes.c"
|
||||
// PUSH(len(TOS))
|
||||
Py_ssize_t len_i = PyObject_Length(obj);
|
||||
if (len_i < 0) goto error;
|
||||
len_o = PyLong_FromSsize_t(len_i);
|
||||
if (len_o == NULL) goto error;
|
||||
#line 1912 "Python/executor_cases.c.h"
|
||||
#line 1930 "Python/executor_cases.c.h"
|
||||
STACK_GROW(1);
|
||||
stack_pointer[-1] = len_o;
|
||||
break;
|
||||
|
@ -1919,16 +1937,16 @@
|
|||
PyObject *type = stack_pointer[-2];
|
||||
PyObject *subject = stack_pointer[-3];
|
||||
PyObject *attrs;
|
||||
#line 2319 "Python/bytecodes.c"
|
||||
#line 2317 "Python/bytecodes.c"
|
||||
// Pop TOS and TOS1. Set TOS to a tuple of attributes on success, or
|
||||
// None on failure.
|
||||
assert(PyTuple_CheckExact(names));
|
||||
attrs = match_class(tstate, subject, type, oparg, names);
|
||||
#line 1928 "Python/executor_cases.c.h"
|
||||
#line 1946 "Python/executor_cases.c.h"
|
||||
Py_DECREF(subject);
|
||||
Py_DECREF(type);
|
||||
Py_DECREF(names);
|
||||
#line 2324 "Python/bytecodes.c"
|
||||
#line 2322 "Python/bytecodes.c"
|
||||
if (attrs) {
|
||||
assert(PyTuple_CheckExact(attrs)); // Success!
|
||||
}
|
||||
|
@ -1936,7 +1954,7 @@
|
|||
if (_PyErr_Occurred(tstate)) goto pop_3_error;
|
||||
attrs = Py_None; // Failure!
|
||||
}
|
||||
#line 1940 "Python/executor_cases.c.h"
|
||||
#line 1958 "Python/executor_cases.c.h"
|
||||
STACK_SHRINK(2);
|
||||
stack_pointer[-1] = attrs;
|
||||
break;
|
||||
|
@ -1945,10 +1963,10 @@
|
|||
case MATCH_MAPPING: {
|
||||
PyObject *subject = stack_pointer[-1];
|
||||
PyObject *res;
|
||||
#line 2334 "Python/bytecodes.c"
|
||||
#line 2332 "Python/bytecodes.c"
|
||||
int match = Py_TYPE(subject)->tp_flags & Py_TPFLAGS_MAPPING;
|
||||
res = match ? Py_True : Py_False;
|
||||
#line 1952 "Python/executor_cases.c.h"
|
||||
#line 1970 "Python/executor_cases.c.h"
|
||||
STACK_GROW(1);
|
||||
stack_pointer[-1] = res;
|
||||
break;
|
||||
|
@ -1957,10 +1975,10 @@
|
|||
case MATCH_SEQUENCE: {
|
||||
PyObject *subject = stack_pointer[-1];
|
||||
PyObject *res;
|
||||
#line 2339 "Python/bytecodes.c"
|
||||
#line 2337 "Python/bytecodes.c"
|
||||
int match = Py_TYPE(subject)->tp_flags & Py_TPFLAGS_SEQUENCE;
|
||||
res = match ? Py_True : Py_False;
|
||||
#line 1964 "Python/executor_cases.c.h"
|
||||
#line 1982 "Python/executor_cases.c.h"
|
||||
STACK_GROW(1);
|
||||
stack_pointer[-1] = res;
|
||||
break;
|
||||
|
@ -1970,11 +1988,11 @@
|
|||
PyObject *keys = stack_pointer[-1];
|
||||
PyObject *subject = stack_pointer[-2];
|
||||
PyObject *values_or_none;
|
||||
#line 2344 "Python/bytecodes.c"
|
||||
#line 2342 "Python/bytecodes.c"
|
||||
// On successful match, PUSH(values). Otherwise, PUSH(None).
|
||||
values_or_none = match_keys(tstate, subject, keys);
|
||||
if (values_or_none == NULL) goto error;
|
||||
#line 1978 "Python/executor_cases.c.h"
|
||||
#line 1996 "Python/executor_cases.c.h"
|
||||
STACK_GROW(1);
|
||||
stack_pointer[-1] = values_or_none;
|
||||
break;
|
||||
|
@ -1983,14 +2001,14 @@
|
|||
case GET_ITER: {
|
||||
PyObject *iterable = stack_pointer[-1];
|
||||
PyObject *iter;
|
||||
#line 2350 "Python/bytecodes.c"
|
||||
#line 2348 "Python/bytecodes.c"
|
||||
/* before: [obj]; after [getiter(obj)] */
|
||||
iter = PyObject_GetIter(iterable);
|
||||
#line 1990 "Python/executor_cases.c.h"
|
||||
#line 2008 "Python/executor_cases.c.h"
|
||||
Py_DECREF(iterable);
|
||||
#line 2353 "Python/bytecodes.c"
|
||||
#line 2351 "Python/bytecodes.c"
|
||||
if (iter == NULL) goto pop_1_error;
|
||||
#line 1994 "Python/executor_cases.c.h"
|
||||
#line 2012 "Python/executor_cases.c.h"
|
||||
stack_pointer[-1] = iter;
|
||||
break;
|
||||
}
|
||||
|
@ -1998,7 +2016,7 @@
|
|||
case GET_YIELD_FROM_ITER: {
|
||||
PyObject *iterable = stack_pointer[-1];
|
||||
PyObject *iter;
|
||||
#line 2357 "Python/bytecodes.c"
|
||||
#line 2355 "Python/bytecodes.c"
|
||||
/* before: [obj]; after [getiter(obj)] */
|
||||
if (PyCoro_CheckExact(iterable)) {
|
||||
/* `iterable` is a coroutine */
|
||||
|
@ -2021,11 +2039,11 @@
|
|||
if (iter == NULL) {
|
||||
goto error;
|
||||
}
|
||||
#line 2025 "Python/executor_cases.c.h"
|
||||
#line 2043 "Python/executor_cases.c.h"
|
||||
Py_DECREF(iterable);
|
||||
#line 2380 "Python/bytecodes.c"
|
||||
#line 2378 "Python/bytecodes.c"
|
||||
}
|
||||
#line 2029 "Python/executor_cases.c.h"
|
||||
#line 2047 "Python/executor_cases.c.h"
|
||||
stack_pointer[-1] = iter;
|
||||
break;
|
||||
}
|
||||
|
@ -2035,7 +2053,7 @@
|
|||
PyObject *lasti = stack_pointer[-3];
|
||||
PyObject *exit_func = stack_pointer[-4];
|
||||
PyObject *res;
|
||||
#line 2612 "Python/bytecodes.c"
|
||||
#line 2610 "Python/bytecodes.c"
|
||||
/* At the top of the stack are 4 values:
|
||||
- val: TOP = exc_info()
|
||||
- unused: SECOND = previous exception
|
||||
|
@ -2056,7 +2074,7 @@
|
|||
res = PyObject_Vectorcall(exit_func, stack + 1,
|
||||
3 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
|
||||
if (res == NULL) goto error;
|
||||
#line 2060 "Python/executor_cases.c.h"
|
||||
#line 2078 "Python/executor_cases.c.h"
|
||||
STACK_GROW(1);
|
||||
stack_pointer[-1] = res;
|
||||
break;
|
||||
|
@ -2065,7 +2083,7 @@
|
|||
case PUSH_EXC_INFO: {
|
||||
PyObject *new_exc = stack_pointer[-1];
|
||||
PyObject *prev_exc;
|
||||
#line 2651 "Python/bytecodes.c"
|
||||
#line 2649 "Python/bytecodes.c"
|
||||
_PyErr_StackItem *exc_info = tstate->exc_info;
|
||||
if (exc_info->exc_value != NULL) {
|
||||
prev_exc = exc_info->exc_value;
|
||||
|
@ -2075,7 +2093,7 @@
|
|||
}
|
||||
assert(PyExceptionInstance_Check(new_exc));
|
||||
exc_info->exc_value = Py_NewRef(new_exc);
|
||||
#line 2079 "Python/executor_cases.c.h"
|
||||
#line 2097 "Python/executor_cases.c.h"
|
||||
STACK_GROW(1);
|
||||
stack_pointer[-1] = new_exc;
|
||||
stack_pointer[-2] = prev_exc;
|
||||
|
@ -2084,7 +2102,7 @@
|
|||
|
||||
case EXIT_INIT_CHECK: {
|
||||
PyObject *should_be_none = stack_pointer[-1];
|
||||
#line 3050 "Python/bytecodes.c"
|
||||
#line 3048 "Python/bytecodes.c"
|
||||
assert(STACK_LEVEL() == 2);
|
||||
if (should_be_none != Py_None) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
|
@ -2092,7 +2110,7 @@
|
|||
Py_TYPE(should_be_none)->tp_name);
|
||||
goto error;
|
||||
}
|
||||
#line 2096 "Python/executor_cases.c.h"
|
||||
#line 2114 "Python/executor_cases.c.h"
|
||||
STACK_SHRINK(1);
|
||||
break;
|
||||
}
|
||||
|
@ -2100,7 +2118,7 @@
|
|||
case MAKE_FUNCTION: {
|
||||
PyObject *codeobj = stack_pointer[-1];
|
||||
PyObject *func;
|
||||
#line 3464 "Python/bytecodes.c"
|
||||
#line 3462 "Python/bytecodes.c"
|
||||
|
||||
PyFunctionObject *func_obj = (PyFunctionObject *)
|
||||
PyFunction_New(codeobj, GLOBALS());
|
||||
|
@ -2112,7 +2130,7 @@
|
|||
|
||||
func_obj->func_version = ((PyCodeObject *)codeobj)->co_version;
|
||||
func = (PyObject *)func_obj;
|
||||
#line 2116 "Python/executor_cases.c.h"
|
||||
#line 2134 "Python/executor_cases.c.h"
|
||||
stack_pointer[-1] = func;
|
||||
break;
|
||||
}
|
||||
|
@ -2120,7 +2138,7 @@
|
|||
case SET_FUNCTION_ATTRIBUTE: {
|
||||
PyObject *func = stack_pointer[-1];
|
||||
PyObject *attr = stack_pointer[-2];
|
||||
#line 3478 "Python/bytecodes.c"
|
||||
#line 3476 "Python/bytecodes.c"
|
||||
assert(PyFunction_Check(func));
|
||||
PyFunctionObject *func_obj = (PyFunctionObject *)func;
|
||||
switch(oparg) {
|
||||
|
@ -2145,7 +2163,7 @@
|
|||
default:
|
||||
Py_UNREACHABLE();
|
||||
}
|
||||
#line 2149 "Python/executor_cases.c.h"
|
||||
#line 2167 "Python/executor_cases.c.h"
|
||||
STACK_SHRINK(1);
|
||||
stack_pointer[-1] = func;
|
||||
break;
|
||||
|
@ -2156,15 +2174,15 @@
|
|||
PyObject *stop = stack_pointer[-(1 + ((oparg == 3) ? 1 : 0))];
|
||||
PyObject *start = stack_pointer[-(2 + ((oparg == 3) ? 1 : 0))];
|
||||
PyObject *slice;
|
||||
#line 3528 "Python/bytecodes.c"
|
||||
#line 3526 "Python/bytecodes.c"
|
||||
slice = PySlice_New(start, stop, step);
|
||||
#line 2162 "Python/executor_cases.c.h"
|
||||
#line 2180 "Python/executor_cases.c.h"
|
||||
Py_DECREF(start);
|
||||
Py_DECREF(stop);
|
||||
Py_XDECREF(step);
|
||||
#line 3530 "Python/bytecodes.c"
|
||||
#line 3528 "Python/bytecodes.c"
|
||||
if (slice == NULL) { STACK_SHRINK(((oparg == 3) ? 1 : 0)); goto pop_2_error; }
|
||||
#line 2168 "Python/executor_cases.c.h"
|
||||
#line 2186 "Python/executor_cases.c.h"
|
||||
STACK_SHRINK(((oparg == 3) ? 1 : 0));
|
||||
STACK_SHRINK(1);
|
||||
stack_pointer[-1] = slice;
|
||||
|
@ -2174,14 +2192,14 @@
|
|||
case CONVERT_VALUE: {
|
||||
PyObject *value = stack_pointer[-1];
|
||||
PyObject *result;
|
||||
#line 3534 "Python/bytecodes.c"
|
||||
#line 3532 "Python/bytecodes.c"
|
||||
convertion_func_ptr conv_fn;
|
||||
assert(oparg >= FVC_STR && oparg <= FVC_ASCII);
|
||||
conv_fn = CONVERSION_FUNCTIONS[oparg];
|
||||
result = conv_fn(value);
|
||||
Py_DECREF(value);
|
||||
if (result == NULL) goto pop_1_error;
|
||||
#line 2185 "Python/executor_cases.c.h"
|
||||
#line 2203 "Python/executor_cases.c.h"
|
||||
stack_pointer[-1] = result;
|
||||
break;
|
||||
}
|
||||
|
@ -2189,7 +2207,7 @@
|
|||
case FORMAT_SIMPLE: {
|
||||
PyObject *value = stack_pointer[-1];
|
||||
PyObject *res;
|
||||
#line 3543 "Python/bytecodes.c"
|
||||
#line 3541 "Python/bytecodes.c"
|
||||
/* If value is a unicode object, then we know the result
|
||||
* of format(value) is value itself. */
|
||||
if (!PyUnicode_CheckExact(value)) {
|
||||
|
@ -2200,7 +2218,7 @@
|
|||
else {
|
||||
res = value;
|
||||
}
|
||||
#line 2204 "Python/executor_cases.c.h"
|
||||
#line 2222 "Python/executor_cases.c.h"
|
||||
stack_pointer[-1] = res;
|
||||
break;
|
||||
}
|
||||
|
@ -2209,12 +2227,12 @@
|
|||
PyObject *fmt_spec = stack_pointer[-1];
|
||||
PyObject *value = stack_pointer[-2];
|
||||
PyObject *res;
|
||||
#line 3556 "Python/bytecodes.c"
|
||||
#line 3554 "Python/bytecodes.c"
|
||||
res = PyObject_Format(value, fmt_spec);
|
||||
Py_DECREF(value);
|
||||
Py_DECREF(fmt_spec);
|
||||
if (res == NULL) goto pop_2_error;
|
||||
#line 2218 "Python/executor_cases.c.h"
|
||||
#line 2236 "Python/executor_cases.c.h"
|
||||
STACK_SHRINK(1);
|
||||
stack_pointer[-1] = res;
|
||||
break;
|
||||
|
@ -2223,10 +2241,10 @@
|
|||
case COPY: {
|
||||
PyObject *bottom = stack_pointer[-(1 + (oparg-1))];
|
||||
PyObject *top;
|
||||
#line 3563 "Python/bytecodes.c"
|
||||
#line 3561 "Python/bytecodes.c"
|
||||
assert(oparg > 0);
|
||||
top = Py_NewRef(bottom);
|
||||
#line 2230 "Python/executor_cases.c.h"
|
||||
#line 2248 "Python/executor_cases.c.h"
|
||||
STACK_GROW(1);
|
||||
stack_pointer[-1] = top;
|
||||
break;
|
||||
|
@ -2237,7 +2255,7 @@
|
|||
PyObject *rhs = stack_pointer[-1];
|
||||
PyObject *lhs = stack_pointer[-2];
|
||||
PyObject *res;
|
||||
#line 3568 "Python/bytecodes.c"
|
||||
#line 3566 "Python/bytecodes.c"
|
||||
#if ENABLE_SPECIALIZATION
|
||||
_PyBinaryOpCache *cache = (_PyBinaryOpCache *)next_instr;
|
||||
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
|
||||
|
@ -2252,12 +2270,12 @@
|
|||
assert((unsigned)oparg < Py_ARRAY_LENGTH(binary_ops));
|
||||
assert(binary_ops[oparg]);
|
||||
res = binary_ops[oparg](lhs, rhs);
|
||||
#line 2256 "Python/executor_cases.c.h"
|
||||
#line 2274 "Python/executor_cases.c.h"
|
||||
Py_DECREF(lhs);
|
||||
Py_DECREF(rhs);
|
||||
#line 3583 "Python/bytecodes.c"
|
||||
#line 3581 "Python/bytecodes.c"
|
||||
if (res == NULL) goto pop_2_error;
|
||||
#line 2261 "Python/executor_cases.c.h"
|
||||
#line 2279 "Python/executor_cases.c.h"
|
||||
STACK_SHRINK(1);
|
||||
stack_pointer[-1] = res;
|
||||
break;
|
||||
|
@ -2266,9 +2284,9 @@
|
|||
case SWAP: {
|
||||
PyObject *top = stack_pointer[-1];
|
||||
PyObject *bottom = stack_pointer[-(2 + (oparg-2))];
|
||||
#line 3588 "Python/bytecodes.c"
|
||||
#line 3586 "Python/bytecodes.c"
|
||||
assert(oparg >= 2);
|
||||
#line 2272 "Python/executor_cases.c.h"
|
||||
#line 2290 "Python/executor_cases.c.h"
|
||||
stack_pointer[-1] = bottom;
|
||||
stack_pointer[-(2 + (oparg-2))] = top;
|
||||
break;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -35,6 +35,7 @@
|
|||
#define _BINARY_OP_ADD_UNICODE 313
|
||||
#define _LOAD_LOCALS 314
|
||||
#define _LOAD_FROM_DICT_OR_GLOBALS 315
|
||||
#define IS_NONE 316
|
||||
|
||||
#ifndef NEED_OPCODE_METADATA
|
||||
extern int _PyOpcode_num_popped(int opcode, int oparg, bool jump);
|
||||
|
@ -328,10 +329,10 @@ _PyOpcode_num_popped(int opcode, int oparg, bool jump) {
|
|||
return 1;
|
||||
case POP_JUMP_IF_TRUE:
|
||||
return 1;
|
||||
case POP_JUMP_IF_NOT_NONE:
|
||||
return 1;
|
||||
case POP_JUMP_IF_NONE:
|
||||
return 1;
|
||||
case POP_JUMP_IF_NOT_NONE:
|
||||
return 1;
|
||||
case JUMP_BACKWARD_NO_INTERRUPT:
|
||||
return 0;
|
||||
case GET_LEN:
|
||||
|
@ -772,10 +773,10 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
|
|||
return 0;
|
||||
case POP_JUMP_IF_TRUE:
|
||||
return 0;
|
||||
case POP_JUMP_IF_NOT_NONE:
|
||||
return 0;
|
||||
case POP_JUMP_IF_NONE:
|
||||
return 0;
|
||||
case POP_JUMP_IF_NOT_NONE:
|
||||
return 0;
|
||||
case JUMP_BACKWARD_NO_INTERRUPT:
|
||||
return 0;
|
||||
case GET_LEN:
|
||||
|
@ -1104,8 +1105,8 @@ const struct opcode_metadata _PyOpcode_opcode_metadata[512] = {
|
|||
[ENTER_EXECUTOR] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_JUMP_FLAG },
|
||||
[POP_JUMP_IF_FALSE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_JUMP_FLAG },
|
||||
[POP_JUMP_IF_TRUE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_JUMP_FLAG },
|
||||
[POP_JUMP_IF_NOT_NONE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_JUMP_FLAG },
|
||||
[POP_JUMP_IF_NONE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_JUMP_FLAG },
|
||||
[POP_JUMP_IF_NOT_NONE] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_JUMP_FLAG },
|
||||
[JUMP_BACKWARD_NO_INTERRUPT] = { true, INSTR_FMT_IB, HAS_ARG_FLAG | HAS_JUMP_FLAG },
|
||||
[GET_LEN] = { true, INSTR_FMT_IX, 0 },
|
||||
[MATCH_CLASS] = { true, INSTR_FMT_IB, HAS_ARG_FLAG },
|
||||
|
@ -1310,6 +1311,7 @@ const char * const _PyOpcode_uop_name[512] = {
|
|||
[313] = "_BINARY_OP_ADD_UNICODE",
|
||||
[314] = "_LOAD_LOCALS",
|
||||
[315] = "_LOAD_FROM_DICT_OR_GLOBALS",
|
||||
[316] = "IS_NONE",
|
||||
};
|
||||
#endif // NEED_OPCODE_METADATA
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue