GH-94163: Add BINARY_SLICE and STORE_SLICE instructions. (GH-94168)

This commit is contained in:
Mark Shannon 2022-06-27 12:24:23 +01:00 committed by GitHub
parent 33fc3b5e42
commit c0453a40fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 339 additions and 161 deletions

View file

@ -1026,6 +1026,42 @@ if 1:
for instr in dis.Bytecode(while_not_chained):
self.assertNotEqual(instr.opname, "EXTENDED_ARG")
@support.cpython_only
def test_uses_slice_instructions(self):
def check_op_count(func, op, expected):
actual = 0
for instr in dis.Bytecode(func):
if instr.opname == op:
actual += 1
self.assertEqual(actual, expected)
def load():
return x[a:b] + x [a:] + x[:b] + x[:]
def store():
x[a:b] = y
x [a:] = y
x[:b] = y
x[:] = y
def long_slice():
return x[a:b:c]
def aug():
x[a:b] += y
check_op_count(load, "BINARY_SLICE", 4)
check_op_count(load, "BUILD_SLICE", 0)
check_op_count(store, "STORE_SLICE", 4)
check_op_count(store, "BUILD_SLICE", 0)
check_op_count(long_slice, "BUILD_SLICE", 1)
check_op_count(long_slice, "BINARY_SLICE", 0)
check_op_count(aug, "BINARY_SLICE", 1)
check_op_count(aug, "STORE_SLICE", 1)
check_op_count(aug, "BUILD_SLICE", 0)
@requires_debug_ranges()
class TestSourcePositions(unittest.TestCase):
# Ensure that compiled code snippets have correct line and column numbers