Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,28 +411,28 @@ dummy_func(
// BINARY_OP_INPLACE_ADD_UNICODE, // See comments at that opcode.
};

op(_GUARD_BOTH_INT, (left, right -- left: &(PYLONG_TYPE), right: &(PYLONG_TYPE))) {
op(_GUARD_BOTH_INT, (left, right -- left: &PYLONG_TYPE, right: &PYLONG_TYPE)) {
DEOPT_IF(!PyLong_CheckExact(left));
DEOPT_IF(!PyLong_CheckExact(right));
}

pure op(_BINARY_OP_MULTIPLY_INT, (left, right -- res: &(PYLONG_TYPE))) {
pure op(_BINARY_OP_MULTIPLY_INT, (left, right -- res: &PYLONG_TYPE)) {
STAT_INC(BINARY_OP, hit);
res = _PyLong_Multiply((PyLongObject *)left, (PyLongObject *)right);
_Py_DECREF_SPECIALIZED(right, (destructor)PyObject_Free);
_Py_DECREF_SPECIALIZED(left, (destructor)PyObject_Free);
ERROR_IF(res == NULL, error);
}

pure op(_BINARY_OP_ADD_INT, (left, right -- res: &(PYLONG_TYPE))) {
pure op(_BINARY_OP_ADD_INT, (left, right -- res: &PYLONG_TYPE)) {
STAT_INC(BINARY_OP, hit);
res = _PyLong_Add((PyLongObject *)left, (PyLongObject *)right);
_Py_DECREF_SPECIALIZED(right, (destructor)PyObject_Free);
_Py_DECREF_SPECIALIZED(left, (destructor)PyObject_Free);
ERROR_IF(res == NULL, error);
}

pure op(_BINARY_OP_SUBTRACT_INT, (left, right -- res: &(PYLONG_TYPE))) {
pure op(_BINARY_OP_SUBTRACT_INT, (left, right -- res: &PYLONG_TYPE)) {
STAT_INC(BINARY_OP, hit);
res = _PyLong_Subtract((PyLongObject *)left, (PyLongObject *)right);
_Py_DECREF_SPECIALIZED(right, (destructor)PyObject_Free);
Expand All @@ -447,28 +447,28 @@ dummy_func(
macro(BINARY_OP_SUBTRACT_INT) =
_GUARD_BOTH_INT + unused/1 + _BINARY_OP_SUBTRACT_INT;

op(_GUARD_BOTH_FLOAT, (left, right -- left: &(PYFLOAT_TYPE), right: &(PYFLOAT_TYPE))) {
op(_GUARD_BOTH_FLOAT, (left, right -- left: &PYFLOAT_TYPE, right: &PYFLOAT_TYPE)) {
DEOPT_IF(!PyFloat_CheckExact(left));
DEOPT_IF(!PyFloat_CheckExact(right));
}

pure op(_BINARY_OP_MULTIPLY_FLOAT, (left, right -- res: &(PYFLOAT_TYPE))) {
pure op(_BINARY_OP_MULTIPLY_FLOAT, (left, right -- res: &PYFLOAT_TYPE)) {
STAT_INC(BINARY_OP, hit);
double dres =
((PyFloatObject *)left)->ob_fval *
((PyFloatObject *)right)->ob_fval;
DECREF_INPUTS_AND_REUSE_FLOAT(left, right, dres, res);
}

pure op(_BINARY_OP_ADD_FLOAT, (left, right -- res: &(PYFLOAT_TYPE))) {
pure op(_BINARY_OP_ADD_FLOAT, (left, right -- res: &PYFLOAT_TYPE)) {
STAT_INC(BINARY_OP, hit);
double dres =
((PyFloatObject *)left)->ob_fval +
((PyFloatObject *)right)->ob_fval;
DECREF_INPUTS_AND_REUSE_FLOAT(left, right, dres, res);
}

pure op(_BINARY_OP_SUBTRACT_FLOAT, (left, right -- res: &(PYFLOAT_TYPE))) {
pure op(_BINARY_OP_SUBTRACT_FLOAT, (left, right -- res: &PYFLOAT_TYPE)) {
STAT_INC(BINARY_OP, hit);
double dres =
((PyFloatObject *)left)->ob_fval -
Expand All @@ -483,12 +483,12 @@ dummy_func(
macro(BINARY_OP_SUBTRACT_FLOAT) =
_GUARD_BOTH_FLOAT + unused/1 + _BINARY_OP_SUBTRACT_FLOAT;

op(_GUARD_BOTH_UNICODE, (left, right -- left: &(PYUNICODE_TYPE), right: &(PYUNICODE_TYPE))) {
op(_GUARD_BOTH_UNICODE, (left, right -- left: &PYUNICODE_TYPE, right: &PYUNICODE_TYPE)) {
DEOPT_IF(!PyUnicode_CheckExact(left));
DEOPT_IF(!PyUnicode_CheckExact(right));
}

pure op(_BINARY_OP_ADD_UNICODE, (left, right -- res: &(PYUNICODE_TYPE))) {
pure op(_BINARY_OP_ADD_UNICODE, (left, right -- res: &PYUNICODE_TYPE)) {
STAT_INC(BINARY_OP, hit);
res = PyUnicode_Concat(left, right);
_Py_DECREF_SPECIALIZED(left, _PyUnicode_ExactDealloc);
Expand Down Expand Up @@ -2081,7 +2081,7 @@ dummy_func(
DISPATCH_INLINED(new_frame);
}

op(_GUARD_DORV_VALUES, (owner -- owner: &(GUARD_DORV_VALUES_TYPE))) {
op(_GUARD_DORV_VALUES, (owner -- owner: &GUARD_DORV_VALUES_TYPE)) {
assert(Py_TYPE(owner)->tp_flags & Py_TPFLAGS_MANAGED_DICT);
PyDictOrValues dorv = *_PyObject_DictOrValuesPointer(owner);
DEOPT_IF(!_PyDictOrValues_IsValues(dorv));
Expand Down Expand Up @@ -2721,7 +2721,7 @@ dummy_func(
DEOPT_IF(r->len <= 0);
}

op(_ITER_NEXT_RANGE, (iter -- iter, next: &(PYLONG_TYPE))) {
op(_ITER_NEXT_RANGE, (iter -- iter, next: &PYLONG_TYPE)) {
_PyRangeIterObject *r = (_PyRangeIterObject *)iter;
assert(Py_TYPE(r) == &PyRangeIter_Type);
assert(r->len > 0);
Expand Down Expand Up @@ -2879,7 +2879,7 @@ dummy_func(
exc_info->exc_value = Py_NewRef(new_exc);
}

op(_GUARD_DORV_VALUES_INST_ATTR_FROM_DICT, (owner -- owner: &(GUARD_DORV_VALUES_INST_ATTR_FROM_DICT_TYPE))) {
op(_GUARD_DORV_VALUES_INST_ATTR_FROM_DICT, (owner -- owner: &GUARD_DORV_VALUES_INST_ATTR_FROM_DICT_TYPE)) {
assert(Py_TYPE(owner)->tp_flags & Py_TPFLAGS_MANAGED_DICT);
PyDictOrValues *dorv = _PyObject_DictOrValuesPointer(owner);
DEOPT_IF(!_PyDictOrValues_IsValues(*dorv) && !_PyObject_MakeInstanceAttributesFromDict(owner, dorv));
Expand Down Expand Up @@ -3100,7 +3100,7 @@ dummy_func(

macro(CALL) = _SPECIALIZE_CALL + unused/2 + _CALL;

op(_CHECK_CALL_BOUND_METHOD_EXACT_ARGS, (callable, null, unused[oparg] -- callable: &(PYMETHOD_TYPE), null: &(NULL_TYPE), unused[oparg])) {
op(_CHECK_CALL_BOUND_METHOD_EXACT_ARGS, (callable, null, unused[oparg] -- callable: &PYMETHOD_TYPE, null: &NULL_TYPE, unused[oparg])) {
DEOPT_IF(null != NULL);
DEOPT_IF(Py_TYPE(callable) != &PyMethod_Type);
}
Expand Down
22 changes: 10 additions & 12 deletions Tools/cases_generator/interpreter_definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ The following definitions may occur:
The optional `type` in an `object` is the C type. It defaults to `PyObject *`.
The objects before the "--" are the objects on top of the stack at the start of
the instruction. Those after the "--" are the objects on top of the stack at the
end of the instruction. When prefixed by a `&`, the type rule follows the
`type_prop` rule. This indicates the stack effect is of that specific type
after the operation. In this case, the type may also contain auxillary information
end of the instruction. When prefixed by a `&`, the `type` production rule follows the
`type_prop` production rule. This indicates the stack effect is of that specific type
Comment thread
Fidget-Spinner marked this conversation as resolved.
Outdated
after the operation. In this case, the type may also consist of auxillary information
Comment thread
Fidget-Spinner marked this conversation as resolved.
Outdated
that is fetched from a previously defined operand in the instruction header, such as
a type version tag. This follows the format `type + auxillary`. For a list of the
types and what they correspond to, see [Appendix A - Types](#Appendix-A-Types).
Expand Down Expand Up @@ -174,9 +174,7 @@ list of annotations and their meanings are as follows:

* `override`. For external use by other interpreter definitions to override the current
instruction definition.
* `pure`. This instruction has no side effects visible to the Python user. It may
still have side effects on the CPython interpreter state. All other instructions without
this annotation are assumed to be not pure.
* `pure`. This instruction has no side effects.

### Special functions/macros

Expand Down Expand Up @@ -446,16 +444,16 @@ and the tables for use by disassemblers.

## Appendix A: Types

The following types correspond to the following information:
* `PYLONG_TYPE`: `&PyLong_Type`
* `PYFLOAT_TYPE`: `&PyFloat_Type`
* `PYUNICODE_TYPE`: `&PYUNICODE_TYPE`
* `NULL_TYPE`: `NULL`
The following types obeys the following predicates:
* `PYLONG_TYPE`: `Py_TYPE(val) == &PyLong_Type`
* `PYFLOAT_TYPE`: `Py_TYPE(val) == &PyFloat_Type`
* `PYUNICODE_TYPE`: `Py_TYPE(val) == &PYUNICODE_TYPE`
* `NULL_TYPE`: `val == NULL`
* `GUARD_TYPE_VERSION_TYPE`: `type->tp_version_tag == auxillary`
* `GUARD_DORV_VALUES_TYPE`: `_PyDictOrValues_IsValues(obj)`
* `GUARD_DORV_VALUES_INST_ATTR_FROM_DICT_TYPE`:
`_PyDictOrValues_IsValues(obj) || _PyObject_MakeInstanceAttributesFromDict(obj, dorv)`
* `GUARD_KEYS_VERSION_TYPE`: `owner_heap_type->ht_cached_keys->dk_version == auxillary`
* `PYMETHOD_TYPE`: `&PyMethod_Type`
* `PYMETHOD_TYPE`: `Py_TYPE(val) == &PyMethod_Type`
* `PYFUNCTION_TYPE_VERSION_TYPE`:
`PyFunction_Check(callable) && func->func_version == auxillary && code->co_argcount == oparg + (self_or_null != NULL)`
5 changes: 3 additions & 2 deletions Tools/cases_generator/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,14 @@ def stack_effect(self) -> StackEffect | None:
if self.expect(lx.TIMES):
type_text += " *"
if self.expect(lx.AND):
self.require(lx.LPAREN)
consumed_bracket = self.expect(lx.LPAREN) is not None
type_prop_text = self.require(lx.IDENTIFIER).text.strip()
aux = None
if self.expect(lx.PLUS):
aux = self.require(lx.IDENTIFIER).text.strip()
type_prop = (type_prop_text, aux)
self.require(lx.RPAREN)
if consumed_bracket:
self.require(lx.RPAREN)
cond_text = ""
if self.expect(lx.IF):
self.require(lx.LPAREN)
Expand Down