Skip to content

Commit d87946a

Browse files
committed
let generator deal with fetching descr from the cache
1 parent 0432b9a commit d87946a

File tree

6 files changed

+35
-47
lines changed

6 files changed

+35
-47
lines changed

Include/internal/pycore_opcode_metadata.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/test/test_code.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,14 +429,14 @@ def test_invalid_bytecode(self):
429429
def foo():
430430
pass
431431

432-
# assert that opcode 229 is invalid
433-
self.assertEqual(opname[229], '<229>')
432+
# assert that opcode 135 is invalid
433+
self.assertEqual(opname[135], '<135>')
434434

435-
# change first opcode to 0xeb (=229)
435+
# change first opcode to 0x87 (=135)
436436
foo.__code__ = foo.__code__.replace(
437-
co_code=b'\xe5' + foo.__code__.co_code[1:])
437+
co_code=b'\x87' + foo.__code__.co_code[1:])
438438

439-
msg = "unknown opcode 229"
439+
msg = "unknown opcode 135"
440440
with self.assertRaisesRegex(SystemError, msg):
441441
foo()
442442

Python/bytecodes.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -742,35 +742,31 @@ dummy_func(
742742
#endif
743743
}
744744

745-
op(_GUARD_BINARY_OP_EXTEND, (left, right -- left, right)) {
745+
op(_GUARD_BINARY_OP_EXTEND, (descr/4, left, right -- left, right)) {
746746
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
747747
PyObject *right_o = PyStackRef_AsPyObjectBorrow(right);
748+
_PyBinaryOpSpecializationDescr *d = (_PyBinaryOpSpecializationDescr*)descr;
748749
assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5);
749-
_PyBinaryOpCache *cache = (_PyBinaryOpCache *)(next_instr - INLINE_CACHE_ENTRIES_BINARY_OP);
750-
_PyBinaryOpSpecializationDescr *descr =
751-
(_PyBinaryOpSpecializationDescr *)read_void(cache->external_cache);
752-
assert(descr && descr->guard);
753-
int res = descr->guard(left_o, right_o);
750+
assert(d && d->guard);
751+
int res = d->guard(left_o, right_o);
754752
EXIT_IF(!res);
755753
}
756754

757-
pure op(_BINARY_OP_EXTEND, (left, right -- res)) {
755+
pure op(_BINARY_OP_EXTEND, (descr/4, left, right -- res)) {
758756
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
759757
PyObject *right_o = PyStackRef_AsPyObjectBorrow(right);
760758
assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5);
761-
_PyBinaryOpCache *cache = (_PyBinaryOpCache *)(next_instr - INLINE_CACHE_ENTRIES_BINARY_OP);
762-
_PyBinaryOpSpecializationDescr *descr =
763-
(_PyBinaryOpSpecializationDescr *)read_void(cache->external_cache);
759+
_PyBinaryOpSpecializationDescr *d = (_PyBinaryOpSpecializationDescr*)descr;
764760

765761
STAT_INC(BINARY_OP, hit);
766762

767-
PyObject *res_o = descr->action(left_o, right_o);
763+
PyObject *res_o = d->action(left_o, right_o);
768764
DECREF_INPUTS();
769765
res = PyStackRef_FromPyObjectSteal(res_o);
770766
}
771767

772768
macro(BINARY_OP_EXTEND) =
773-
_GUARD_BINARY_OP_EXTEND + unused/5 + _BINARY_OP_EXTEND;
769+
unused/1 + _GUARD_BINARY_OP_EXTEND + descr/-4 + _BINARY_OP_EXTEND;
774770

775771
macro(BINARY_OP_INPLACE_ADD_UNICODE) =
776772
_GUARD_BOTH_UNICODE + unused/5 + _BINARY_OP_INPLACE_ADD_UNICODE;

Python/executor_cases.c.h

Lines changed: 7 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 10 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tools/cases_generator/parsing.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,12 @@ def uops(self) -> list[UOp] | None:
357357
def uop(self) -> UOp | None:
358358
if tkn := self.expect(lx.IDENTIFIER):
359359
if self.expect(lx.DIVIDE):
360+
sign = 1
361+
if negate := self.expect(lx.MINUS):
362+
sign = -1
360363
if num := self.expect(lx.NUMBER):
361364
try:
362-
size = int(num.text)
365+
size = sign * int(num.text)
363366
except ValueError:
364367
raise self.make_syntax_error(
365368
f"Expected integer, got {num.text!r}"

0 commit comments

Comments
 (0)