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

Function _unpack_opargs

Lib/dis.py:934–963  ·  view source on GitHub ↗
(code)

Source from the content-addressed store, hash-verified

932_INT_OVERFLOW = 2 ** (_INT_BITS - 1)
933
934def _unpack_opargs(code):
935 extended_arg = 0
936 extended_args_offset = 0 # Number of EXTENDED_ARG instructions preceding the current instruction
937 caches = 0
938 for i in range(0, len(code), 2):
939 # Skip inline CACHE entries:
940 if caches:
941 caches -= 1
942 continue
943 op = code[i]
944 deop = _deoptop(op)
945 caches = _get_cache_size(_all_opname[deop])
946 if deop in hasarg:
947 arg = code[i+1] | extended_arg
948 extended_arg = (arg << 8) if deop == EXTENDED_ARG else 0
949 # The oparg is stored as a signed integer
950 # If the value exceeds its upper limit, it will overflow and wrap
951 # to a negative integer
952 if extended_arg >= _INT_OVERFLOW:
953 extended_arg -= 2 * _INT_OVERFLOW
954 else:
955 arg = None
956 extended_arg = 0
957 if deop == EXTENDED_ARG:
958 extended_args_offset += 1
959 yield (i, i, op, arg)
960 else:
961 start_offset = i - extended_args_offset*2
962 yield (i, start_offset, op, arg)
963 extended_args_offset = 0
964
965def findlabels(code):
966 """Detect all offsets in a byte code which are jump targets.

Callers 4

_get_instructions_bytesFunction · 0.85
findlabelsFunction · 0.85
_find_importsFunction · 0.85
_find_store_namesFunction · 0.85

Calls 3

lenFunction · 0.85
_deoptopFunction · 0.85
_get_cache_sizeFunction · 0.85

Tested by

no test coverage detected