summaryrefslogtreecommitdiffstats
path: root/Python/bytecodes.c
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2023-01-24 22:39:13 (GMT)
committerGitHub <noreply@github.com>2023-01-24 22:39:13 (GMT)
commit1a9d8c750be83e6abb65769d312361fe9742de02 (patch)
treebee01eac8527f9fd4cbcb7d4a71733c4762318ba /Python/bytecodes.c
parentf02fa64bf2d03ef7a28650c164e17a5fb5d8543d (diff)
downloadcpython-1a9d8c750be83e6abb65769d312361fe9742de02.zip
cpython-1a9d8c750be83e6abb65769d312361fe9742de02.tar.gz
cpython-1a9d8c750be83e6abb65769d312361fe9742de02.tar.bz2
gh-98831: rewrite pattern matching opcodes in the instruction definition DSL (#101287)
Diffstat (limited to 'Python/bytecodes.c')
-rw-r--r--Python/bytecodes.c50
1 files changed, 13 insertions, 37 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index ac54791..d3e242b 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -2092,61 +2092,37 @@ dummy_func(
PUSH(len_o);
}
- // stack effect: (__0, __1 -- )
- inst(MATCH_CLASS) {
+ inst(MATCH_CLASS, (subject, type, names -- attrs)) {
// Pop TOS and TOS1. Set TOS to a tuple of attributes on success, or
// None on failure.
- PyObject *names = POP();
- PyObject *type = POP();
- PyObject *subject = TOP();
assert(PyTuple_CheckExact(names));
- PyObject *attrs = match_class(tstate, subject, type, oparg, names);
- Py_DECREF(names);
- Py_DECREF(type);
+ attrs = match_class(tstate, subject, type, oparg, names);
+ DECREF_INPUTS();
if (attrs) {
- // Success!
- assert(PyTuple_CheckExact(attrs));
- SET_TOP(attrs);
- }
- else if (_PyErr_Occurred(tstate)) {
- // Error!
- goto error;
+ assert(PyTuple_CheckExact(attrs)); // Success!
}
else {
- // Failure!
- SET_TOP(Py_NewRef(Py_None));
+ ERROR_IF(_PyErr_Occurred(tstate), error); // Error!
+ attrs = Py_NewRef(Py_None); // Failure!
}
- Py_DECREF(subject);
}
- // stack effect: ( -- __0)
- inst(MATCH_MAPPING) {
- PyObject *subject = TOP();
+ inst(MATCH_MAPPING, (subject -- subject, res)) {
int match = Py_TYPE(subject)->tp_flags & Py_TPFLAGS_MAPPING;
- PyObject *res = match ? Py_True : Py_False;
- PUSH(Py_NewRef(res));
+ res = Py_NewRef(match ? Py_True : Py_False);
PREDICT(POP_JUMP_IF_FALSE);
}
- // stack effect: ( -- __0)
- inst(MATCH_SEQUENCE) {
- PyObject *subject = TOP();
+ inst(MATCH_SEQUENCE, (subject -- subject, res)) {
int match = Py_TYPE(subject)->tp_flags & Py_TPFLAGS_SEQUENCE;
- PyObject *res = match ? Py_True : Py_False;
- PUSH(Py_NewRef(res));
+ res = Py_NewRef(match ? Py_True : Py_False);
PREDICT(POP_JUMP_IF_FALSE);
}
- // stack effect: ( -- __0)
- inst(MATCH_KEYS) {
+ inst(MATCH_KEYS, (subject, keys -- subject, keys, values_or_none)) {
// On successful match, PUSH(values). Otherwise, PUSH(None).
- PyObject *keys = TOP();
- PyObject *subject = SECOND();
- PyObject *values_or_none = match_keys(tstate, subject, keys);
- if (values_or_none == NULL) {
- goto error;
- }
- PUSH(values_or_none);
+ values_or_none = match_keys(tstate, subject, keys);
+ ERROR_IF(values_or_none == NULL, error);
}
// stack effect: ( -- )