MCPcopy Index your code
hub / github.com/RustPython/RustPython / _unroll_caches_as_Instructions

Function _unroll_caches_as_Instructions

Lib/test/test_dis.py:2501–2524  ·  view source on GitHub ↗
(instrs, show_caches=False)

Source from the content-addressed store, hash-verified

2499 return output.getvalue()
2500
2501def _unroll_caches_as_Instructions(instrs, show_caches=False):
2502 # Cache entries are no longer reported by dis as fake instructions,
2503 # but some tests assume that do. We should rewrite the tests to assume
2504 # the new API, but it will be clearer to keep the tests working as
2505 # before and do that in a separate PR.
2506
2507 for instr in instrs:
2508 yield instr
2509 if not show_caches:
2510 continue
2511
2512 offset = instr.offset
2513 for name, size, data in (instr.cache_info or ()):
2514 for i in range(size):
2515 offset += 2
2516 # Only show the fancy argrepr for a CACHE instruction when it's
2517 # the first entry for a particular cache value:
2518 if i == 0:
2519 argrepr = f"{name}: {int.from_bytes(data, sys.byteorder)}"
2520 else:
2521 argrepr = ""
2522
2523 yield make_inst("CACHE", 0, None, argrepr, offset, offset,
2524 False, None, None, instr.positions)
2525
2526
2527class TestDisCLI(unittest.TestCase):

Calls 1

from_bytesMethod · 0.45

Tested by

no test coverage detected