Skip to content

Commit

Permalink
simplify oparg & 2 handling
Browse files Browse the repository at this point in the history
  • Loading branch information
carljm committed Apr 19, 2023
1 parent 3a3cb74 commit e4466a7
Show file tree
Hide file tree
Showing 4 changed files with 232 additions and 241 deletions.
4 changes: 2 additions & 2 deletions Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1048,8 +1048,8 @@ iterations of the loop.
The low bit of ``namei`` signals to attempt a method load, as with
:opcode:`LOAD_ATTR`.

The second-low bit of ``namei``, if set, means that this was a zero-argument
call to :func:`super`.
The second-low bit of ``namei``, if set, means that this was a two-argument
call to :func:`super` (unset means zero-argument).

.. versionadded:: 3.12

Expand Down
9 changes: 2 additions & 7 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1574,13 +1574,8 @@ dummy_func(
Py_DECREF(self);
}
} else {
PyObject *super;
if (oparg & 2) {
super = PyObject_CallNoArgs(global_super);
} else {
PyObject *stack[] = {class, self};
super = PyObject_Vectorcall(global_super, stack, 2, NULL);
}
PyObject *stack[] = {class, self};
PyObject *super = PyObject_Vectorcall(global_super, stack, oparg & 2, NULL);
DECREF_INPUTS();
ERROR_IF(super == NULL, error);
res = PyObject_GetAttr(super, name);
Expand Down
6 changes: 3 additions & 3 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1053,21 +1053,21 @@ compiler_addop_name(struct compiler_unit *u, location loc,
}
if (opcode == LOAD_SUPER_ATTR) {
arg <<= 2;
arg |= 2;
}
if (opcode == LOAD_SUPER_METHOD) {
opcode = LOAD_SUPER_ATTR;
arg <<= 2;
arg |= 1;
arg |= 3;
}
if (opcode == LOAD_ZERO_SUPER_ATTR) {
opcode = LOAD_SUPER_ATTR;
arg <<= 2;
arg |= 2;
}
if (opcode == LOAD_ZERO_SUPER_METHOD) {
opcode = LOAD_SUPER_ATTR;
arg <<= 2;
arg |= 3;
arg |= 1;
}
return codegen_addop_i(&u->u_instr_sequence, opcode, arg, loc);
}
Expand Down
Loading

0 comments on commit e4466a7

Please sign in to comment.