2003-02-27 17:27:52 -04:00
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
opcode module - potentially shared between dis and other modules which
|
|
|
|
|
operate on bytecodes (e.g. peephole optimizers).
|
|
|
|
|
"""
|
|
|
|
|
|
2023-07-17 06:28:33 -03:00
|
|
|
|
|
2023-07-18 15:42:44 -03:00
|
|
|
|
# Note that __all__ is further extended below
|
|
|
|
|
__all__ = ["cmp_op", "opname", "opmap", "stack_effect", "hascompare",
|
|
|
|
|
"HAVE_ARGUMENT", "EXTENDED_ARG"]
|
|
|
|
|
|
|
|
|
|
import _opcode
|
2023-07-17 06:28:33 -03:00
|
|
|
|
from _opcode import stack_effect
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
# The build uses older versions of Python which do not have _opcode_metadata
|
|
|
|
|
if sys.version_info[:2] >= (3, 13):
|
2023-06-19 19:47:04 -03:00
|
|
|
|
from _opcode_metadata import _specializations, _specialized_instructions
|
|
|
|
|
|
2020-01-14 06:12:45 -04:00
|
|
|
|
cmp_op = ('<', '<=', '==', '!=', '>', '>=')
|
2003-02-27 17:27:52 -04:00
|
|
|
|
|
2023-01-19 14:14:55 -04:00
|
|
|
|
|
|
|
|
|
ENABLE_SPECIALIZATION = True
|
|
|
|
|
|
2022-07-01 11:33:35 -03:00
|
|
|
|
def is_pseudo(op):
|
|
|
|
|
return op >= MIN_PSEUDO_OPCODE and op <= MAX_PSEUDO_OPCODE
|
|
|
|
|
|
2003-02-27 17:27:52 -04:00
|
|
|
|
opmap = {}
|
2022-07-01 11:33:35 -03:00
|
|
|
|
|
2023-07-18 15:42:44 -03:00
|
|
|
|
# pseudo opcodes (used in the compiler) mapped to the values
|
|
|
|
|
# they can become in the actual code.
|
2022-07-01 11:33:35 -03:00
|
|
|
|
_pseudo_ops = {}
|
2003-02-27 17:27:52 -04:00
|
|
|
|
|
2022-05-06 11:18:09 -03:00
|
|
|
|
def def_op(name, op):
|
2003-02-27 17:27:52 -04:00
|
|
|
|
opmap[name] = op
|
|
|
|
|
|
2022-07-01 11:33:35 -03:00
|
|
|
|
def pseudo_op(name, op, real_ops):
|
|
|
|
|
def_op(name, op)
|
|
|
|
|
_pseudo_ops[name] = real_ops
|
|
|
|
|
|
|
|
|
|
|
2003-02-27 17:27:52 -04:00
|
|
|
|
# Instruction opcodes for compiled code
|
2006-02-27 18:32:47 -04:00
|
|
|
|
# Blank lines correspond to available opcodes
|
2003-02-27 17:27:52 -04:00
|
|
|
|
|
2022-03-07 15:45:00 -04:00
|
|
|
|
def_op('CACHE', 0)
|
2003-02-27 17:27:52 -04:00
|
|
|
|
def_op('POP_TOP', 1)
|
2022-02-18 13:19:08 -04:00
|
|
|
|
def_op('PUSH_NULL', 2)
|
2022-11-10 08:34:57 -04:00
|
|
|
|
def_op('INTERPRETER_EXIT', 3)
|
2022-10-27 07:55:03 -03:00
|
|
|
|
def_op('END_FOR', 4)
|
2023-04-12 08:04:55 -03:00
|
|
|
|
def_op('END_SEND', 5)
|
2023-06-29 17:49:54 -03:00
|
|
|
|
def_op('TO_BOOL', 6)
|
2022-10-27 07:55:03 -03:00
|
|
|
|
|
2004-06-21 13:31:15 -03:00
|
|
|
|
def_op('NOP', 9)
|
2023-01-06 10:47:57 -04:00
|
|
|
|
|
2003-02-27 17:27:52 -04:00
|
|
|
|
def_op('UNARY_NEGATIVE', 11)
|
|
|
|
|
def_op('UNARY_NOT', 12)
|
|
|
|
|
|
|
|
|
|
def_op('UNARY_INVERT', 15)
|
2023-06-22 05:48:19 -03:00
|
|
|
|
def_op('EXIT_INIT_CHECK', 16)
|
2014-04-10 00:55:56 -03:00
|
|
|
|
|
2023-04-12 08:04:55 -03:00
|
|
|
|
# We reserve 17 as it is the initial value for the specializing counter
|
|
|
|
|
# This helps us catch cases where we attempt to execute a cache.
|
|
|
|
|
def_op('RESERVED', 17)
|
|
|
|
|
|
2023-06-13 05:51:05 -03:00
|
|
|
|
def_op('MAKE_FUNCTION', 24)
|
2022-05-06 11:18:09 -03:00
|
|
|
|
def_op('BINARY_SUBSCR', 25)
|
2022-06-27 08:24:23 -03:00
|
|
|
|
def_op('BINARY_SLICE', 26)
|
|
|
|
|
def_op('STORE_SLICE', 27)
|
2021-11-11 02:56:22 -04:00
|
|
|
|
|
2021-02-26 18:51:55 -04:00
|
|
|
|
def_op('GET_LEN', 30)
|
|
|
|
|
def_op('MATCH_MAPPING', 31)
|
|
|
|
|
def_op('MATCH_SEQUENCE', 32)
|
|
|
|
|
def_op('MATCH_KEYS', 33)
|
2021-10-27 06:45:35 -03:00
|
|
|
|
|
2021-05-07 11:19:19 -03:00
|
|
|
|
def_op('PUSH_EXC_INFO', 35)
|
2022-04-01 09:59:38 -03:00
|
|
|
|
def_op('CHECK_EXC_MATCH', 36)
|
2022-04-05 08:06:22 -03:00
|
|
|
|
def_op('CHECK_EG_MATCH', 37)
|
2021-05-07 11:19:19 -03:00
|
|
|
|
|
2023-06-14 12:15:08 -03:00
|
|
|
|
def_op('FORMAT_SIMPLE', 40)
|
|
|
|
|
def_op('FORMAT_WITH_SPEC', 41)
|
|
|
|
|
|
2019-11-21 05:11:43 -04:00
|
|
|
|
def_op('WITH_EXCEPT_START', 49)
|
2015-05-11 23:57:16 -03:00
|
|
|
|
def_op('GET_AITER', 50)
|
|
|
|
|
def_op('GET_ANEXT', 51)
|
|
|
|
|
def_op('BEFORE_ASYNC_WITH', 52)
|
2021-05-07 11:19:19 -03:00
|
|
|
|
def_op('BEFORE_WITH', 53)
|
2018-03-23 09:34:35 -03:00
|
|
|
|
def_op('END_ASYNC_FOR', 54)
|
2022-08-19 16:33:44 -03:00
|
|
|
|
def_op('CLEANUP_THROW', 55)
|
2006-03-17 04:59:09 -04:00
|
|
|
|
|
2022-05-06 11:18:09 -03:00
|
|
|
|
def_op('STORE_SUBSCR', 60)
|
2003-02-27 17:27:52 -04:00
|
|
|
|
def_op('DELETE_SUBSCR', 61)
|
2021-11-11 02:56:22 -04:00
|
|
|
|
|
2003-02-27 17:27:52 -04:00
|
|
|
|
def_op('GET_ITER', 68)
|
Issue #24400: Introduce a distinct type for 'async def' coroutines.
Summary of changes:
1. Coroutines now have a distinct, separate from generators
type at the C level: PyGen_Type, and a new typedef PyCoroObject.
PyCoroObject shares the initial segment of struct layout with
PyGenObject, making it possible to reuse existing generators
machinery. The new type is exposed as 'types.CoroutineType'.
As a consequence of having a new type, CO_GENERATOR flag is
no longer applied to coroutines.
2. Having a separate type for coroutines made it possible to add
an __await__ method to the type. Although it is not used by the
interpreter (see details on that below), it makes coroutines
naturally (without using __instancecheck__) conform to
collections.abc.Coroutine and collections.abc.Awaitable ABCs.
[The __instancecheck__ is still used for generator-based
coroutines, as we don't want to add __await__ for generators.]
3. Add new opcode: GET_YIELD_FROM_ITER. The opcode is needed to
allow passing native coroutines to the YIELD_FROM opcode.
Before this change, 'yield from o' expression was compiled to:
(o)
GET_ITER
LOAD_CONST
YIELD_FROM
Now, we use GET_YIELD_FROM_ITER instead of GET_ITER.
The reason for adding a new opcode is that GET_ITER is used
in some contexts (such as 'for .. in' loops) where passing
a coroutine object is invalid.
4. Add two new introspection functions to the inspec module:
getcoroutinestate(c) and getcoroutinelocals(c).
5. inspect.iscoroutine(o) is updated to test if 'o' is a native
coroutine object. Before this commit it used abc.Coroutine,
and it was requested to update inspect.isgenerator(o) to use
abc.Generator; it was decided, however, that inspect functions
should really be tailored for checking for native types.
6. sys.set_coroutine_wrapper(w) API is updated to work with only
native coroutines. Since types.coroutine decorator supports
any type of callables now, it would be confusing that it does
not work for all types of coroutines.
7. Exceptions logic in generators C implementation was updated
to raise clearer messages for coroutines:
Before: TypeError("generator raised StopIteration")
After: TypeError("coroutine raised StopIteration")
2015-06-22 13:19:30 -03:00
|
|
|
|
def_op('GET_YIELD_FROM_ITER', 69)
|
2023-01-05 12:05:51 -04:00
|
|
|
|
|
2007-03-18 12:41:51 -03:00
|
|
|
|
def_op('LOAD_BUILD_CLASS', 71)
|
2021-12-15 06:30:09 -04:00
|
|
|
|
|
2019-08-25 06:44:09 -03:00
|
|
|
|
def_op('LOAD_ASSERTION_ERROR', 74)
|
2022-01-20 07:46:39 -04:00
|
|
|
|
def_op('RETURN_GENERATOR', 75)
|
2019-11-21 05:11:43 -04:00
|
|
|
|
|
2003-02-27 17:27:52 -04:00
|
|
|
|
def_op('RETURN_VALUE', 83)
|
2023-01-05 12:05:51 -04:00
|
|
|
|
|
2016-09-09 00:50:03 -03:00
|
|
|
|
def_op('SETUP_ANNOTATIONS', 85)
|
2023-06-29 17:49:54 -03:00
|
|
|
|
|
2023-05-16 00:36:23 -03:00
|
|
|
|
def_op('LOAD_LOCALS', 87)
|
2022-05-19 13:49:29 -03:00
|
|
|
|
|
2008-06-11 12:59:43 -03:00
|
|
|
|
def_op('POP_EXCEPT', 89)
|
2003-02-27 17:27:52 -04:00
|
|
|
|
|
2022-07-01 11:33:35 -03:00
|
|
|
|
HAVE_ARGUMENT = 90 # real opcodes from here have an argument:
|
2003-02-27 17:27:52 -04:00
|
|
|
|
|
2023-07-18 15:42:44 -03:00
|
|
|
|
def_op('STORE_NAME', 90) # Index in name list
|
|
|
|
|
def_op('DELETE_NAME', 91) # ""
|
2022-05-06 11:18:09 -03:00
|
|
|
|
def_op('UNPACK_SEQUENCE', 92) # Number of tuple items
|
2023-07-18 15:42:44 -03:00
|
|
|
|
def_op('FOR_ITER', 93)
|
2008-03-18 17:13:50 -03:00
|
|
|
|
def_op('UNPACK_EX', 94)
|
2023-07-18 15:42:44 -03:00
|
|
|
|
def_op('STORE_ATTR', 95) # Index in name list
|
|
|
|
|
def_op('DELETE_ATTR', 96) # ""
|
|
|
|
|
def_op('STORE_GLOBAL', 97) # ""
|
|
|
|
|
def_op('DELETE_GLOBAL', 98) # ""
|
2022-01-26 16:47:45 -04:00
|
|
|
|
def_op('SWAP', 99)
|
2003-02-27 17:27:52 -04:00
|
|
|
|
def_op('LOAD_CONST', 100) # Index in const list
|
2023-07-18 15:42:44 -03:00
|
|
|
|
def_op('LOAD_NAME', 101) # Index in name list
|
2003-02-27 17:27:52 -04:00
|
|
|
|
def_op('BUILD_TUPLE', 102) # Number of tuple items
|
|
|
|
|
def_op('BUILD_LIST', 103) # Number of list items
|
2006-08-28 12:27:34 -03:00
|
|
|
|
def_op('BUILD_SET', 104) # Number of set items
|
2018-02-03 20:36:10 -04:00
|
|
|
|
def_op('BUILD_MAP', 105) # Number of dict entries
|
2023-07-18 15:42:44 -03:00
|
|
|
|
def_op('LOAD_ATTR', 106) # Index in name list
|
2022-05-06 11:18:09 -03:00
|
|
|
|
def_op('COMPARE_OP', 107) # Comparison operator
|
2023-07-18 15:42:44 -03:00
|
|
|
|
def_op('IMPORT_NAME', 108) # Index in name list
|
|
|
|
|
def_op('IMPORT_FROM', 109) # Index in name list
|
|
|
|
|
def_op('JUMP_FORWARD', 110) # Number of words to skip
|
|
|
|
|
|
|
|
|
|
def_op('POP_JUMP_IF_FALSE', 114)
|
|
|
|
|
def_op('POP_JUMP_IF_TRUE', 115)
|
|
|
|
|
def_op('LOAD_GLOBAL', 116) # Index in name list
|
2020-01-14 06:12:45 -04:00
|
|
|
|
def_op('IS_OP', 117)
|
|
|
|
|
def_op('CONTAINS_OP', 118)
|
2020-12-17 09:55:28 -04:00
|
|
|
|
def_op('RERAISE', 119)
|
2021-10-27 06:45:35 -03:00
|
|
|
|
def_op('COPY', 120)
|
2023-02-07 18:32:21 -04:00
|
|
|
|
def_op('RETURN_CONST', 121)
|
2022-05-06 11:18:09 -03:00
|
|
|
|
def_op('BINARY_OP', 122)
|
2023-07-18 15:42:44 -03:00
|
|
|
|
def_op('SEND', 123) # Number of words to skip
|
2022-05-31 17:32:30 -03:00
|
|
|
|
def_op('LOAD_FAST', 124) # Local variable number, no null check
|
2003-02-27 17:27:52 -04:00
|
|
|
|
def_op('STORE_FAST', 125) # Local variable number
|
|
|
|
|
def_op('DELETE_FAST', 126) # Local variable number
|
2022-05-31 17:32:30 -03:00
|
|
|
|
def_op('LOAD_FAST_CHECK', 127) # Local variable number
|
2023-07-18 15:42:44 -03:00
|
|
|
|
def_op('POP_JUMP_IF_NOT_NONE', 128)
|
|
|
|
|
def_op('POP_JUMP_IF_NONE', 129)
|
2003-02-27 17:27:52 -04:00
|
|
|
|
def_op('RAISE_VARARGS', 130) # Number of raise arguments (1, 2, or 3)
|
2022-03-04 08:41:17 -04:00
|
|
|
|
def_op('GET_AWAITABLE', 131)
|
2003-02-27 17:27:52 -04:00
|
|
|
|
def_op('BUILD_SLICE', 133) # Number of items
|
2023-07-18 15:42:44 -03:00
|
|
|
|
def_op('JUMP_BACKWARD_NO_INTERRUPT', 134) # Number of words to skip (backwards)
|
2021-06-08 19:01:34 -03:00
|
|
|
|
def_op('MAKE_CELL', 135)
|
|
|
|
|
def_op('LOAD_DEREF', 137)
|
|
|
|
|
def_op('STORE_DEREF', 138)
|
|
|
|
|
def_op('DELETE_DEREF', 139)
|
2023-07-18 15:42:44 -03:00
|
|
|
|
def_op('JUMP_BACKWARD', 140) # Number of words to skip (backwards)
|
|
|
|
|
def_op('LOAD_SUPER_ATTR', 141)
|
2016-09-09 14:17:08 -03:00
|
|
|
|
def_op('CALL_FUNCTION_EX', 142) # Flags
|
2023-05-09 14:02:14 -03:00
|
|
|
|
def_op('LOAD_FAST_AND_CLEAR', 143) # Local variable number
|
2021-02-26 18:51:55 -04:00
|
|
|
|
def_op('EXTENDED_ARG', 144)
|
2023-07-18 15:42:44 -03:00
|
|
|
|
EXTENDED_ARG = opmap['EXTENDED_ARG']
|
2008-12-18 07:06:25 -04:00
|
|
|
|
def_op('LIST_APPEND', 145)
|
|
|
|
|
def_op('SET_ADD', 146)
|
|
|
|
|
def_op('MAP_ADD', 147)
|
2021-11-23 05:53:24 -04:00
|
|
|
|
def_op('COPY_FREE_VARS', 149)
|
2022-05-19 13:49:29 -03:00
|
|
|
|
def_op('YIELD_VALUE', 150)
|
2022-06-14 07:09:30 -03:00
|
|
|
|
def_op('RESUME', 151) # This must be kept in sync with deepfreeze.py
|
2021-02-26 18:51:55 -04:00
|
|
|
|
def_op('MATCH_CLASS', 152)
|
2008-12-18 07:06:25 -04:00
|
|
|
|
|
2016-06-11 18:39:41 -03:00
|
|
|
|
def_op('BUILD_CONST_KEY_MAP', 156)
|
2016-09-06 16:07:53 -03:00
|
|
|
|
def_op('BUILD_STRING', 157)
|
2023-06-14 12:15:08 -03:00
|
|
|
|
def_op('CONVERT_VALUE', 158)
|
2015-11-03 13:45:05 -04:00
|
|
|
|
|
2020-01-23 05:25:17 -04:00
|
|
|
|
def_op('LIST_EXTEND', 162)
|
|
|
|
|
def_op('SET_UPDATE', 163)
|
2020-01-27 05:57:45 -04:00
|
|
|
|
def_op('DICT_MERGE', 164)
|
|
|
|
|
def_op('DICT_UPDATE', 165)
|
2022-01-28 08:42:30 -04:00
|
|
|
|
|
2023-06-05 07:07:04 -03:00
|
|
|
|
def_op('LOAD_FAST_LOAD_FAST', 168)
|
|
|
|
|
def_op('STORE_FAST_LOAD_FAST', 169)
|
|
|
|
|
def_op('STORE_FAST_STORE_FAST', 170)
|
2022-05-06 11:18:09 -03:00
|
|
|
|
def_op('CALL', 171)
|
2022-01-28 08:42:30 -04:00
|
|
|
|
def_op('KW_NAMES', 172)
|
2023-01-05 12:05:51 -04:00
|
|
|
|
def_op('CALL_INTRINSIC_1', 173)
|
2023-02-14 07:54:13 -04:00
|
|
|
|
def_op('CALL_INTRINSIC_2', 174)
|
2023-07-18 15:42:44 -03:00
|
|
|
|
def_op('LOAD_FROM_DICT_OR_GLOBALS', 175)
|
2023-05-16 00:36:23 -03:00
|
|
|
|
def_op('LOAD_FROM_DICT_OR_DEREF', 176)
|
2023-06-13 05:51:05 -03:00
|
|
|
|
def_op('SET_FUNCTION_ATTRIBUTE', 177) # Attribute
|
2023-05-16 00:36:23 -03:00
|
|
|
|
|
2023-06-02 07:46:18 -03:00
|
|
|
|
# Optimizer hook
|
|
|
|
|
def_op('ENTER_EXECUTOR', 230)
|
|
|
|
|
|
2023-04-12 08:04:55 -03:00
|
|
|
|
# Instrumented instructions
|
2023-05-16 13:29:00 -03:00
|
|
|
|
MIN_INSTRUMENTED_OPCODE = 237
|
2023-04-12 08:04:55 -03:00
|
|
|
|
|
2023-05-16 13:29:00 -03:00
|
|
|
|
def_op('INSTRUMENTED_LOAD_SUPER_ATTR', 237)
|
2023-04-12 08:04:55 -03:00
|
|
|
|
def_op('INSTRUMENTED_POP_JUMP_IF_NONE', 238)
|
|
|
|
|
def_op('INSTRUMENTED_POP_JUMP_IF_NOT_NONE', 239)
|
|
|
|
|
def_op('INSTRUMENTED_RESUME', 240)
|
|
|
|
|
def_op('INSTRUMENTED_CALL', 241)
|
|
|
|
|
def_op('INSTRUMENTED_RETURN_VALUE', 242)
|
|
|
|
|
def_op('INSTRUMENTED_YIELD_VALUE', 243)
|
|
|
|
|
def_op('INSTRUMENTED_CALL_FUNCTION_EX', 244)
|
|
|
|
|
def_op('INSTRUMENTED_JUMP_FORWARD', 245)
|
|
|
|
|
def_op('INSTRUMENTED_JUMP_BACKWARD', 246)
|
|
|
|
|
def_op('INSTRUMENTED_RETURN_CONST', 247)
|
|
|
|
|
def_op('INSTRUMENTED_FOR_ITER', 248)
|
|
|
|
|
def_op('INSTRUMENTED_POP_JUMP_IF_FALSE', 249)
|
|
|
|
|
def_op('INSTRUMENTED_POP_JUMP_IF_TRUE', 250)
|
|
|
|
|
def_op('INSTRUMENTED_END_FOR', 251)
|
|
|
|
|
def_op('INSTRUMENTED_END_SEND', 252)
|
|
|
|
|
def_op('INSTRUMENTED_INSTRUCTION', 253)
|
|
|
|
|
def_op('INSTRUMENTED_LINE', 254)
|
|
|
|
|
# 255 is reserved
|
|
|
|
|
|
2022-07-01 11:33:35 -03:00
|
|
|
|
|
|
|
|
|
MIN_PSEUDO_OPCODE = 256
|
|
|
|
|
|
|
|
|
|
pseudo_op('SETUP_FINALLY', 256, ['NOP'])
|
|
|
|
|
pseudo_op('SETUP_CLEANUP', 257, ['NOP'])
|
|
|
|
|
pseudo_op('SETUP_WITH', 258, ['NOP'])
|
|
|
|
|
pseudo_op('POP_BLOCK', 259, ['NOP'])
|
|
|
|
|
|
|
|
|
|
pseudo_op('JUMP', 260, ['JUMP_FORWARD', 'JUMP_BACKWARD'])
|
|
|
|
|
pseudo_op('JUMP_NO_INTERRUPT', 261, ['JUMP_FORWARD', 'JUMP_BACKWARD_NO_INTERRUPT'])
|
2022-09-01 17:36:47 -03:00
|
|
|
|
|
|
|
|
|
pseudo_op('LOAD_METHOD', 262, ['LOAD_ATTR'])
|
2023-04-24 19:22:14 -03:00
|
|
|
|
pseudo_op('LOAD_SUPER_METHOD', 263, ['LOAD_SUPER_ATTR'])
|
|
|
|
|
pseudo_op('LOAD_ZERO_SUPER_METHOD', 264, ['LOAD_SUPER_ATTR'])
|
|
|
|
|
pseudo_op('LOAD_ZERO_SUPER_ATTR', 265, ['LOAD_SUPER_ATTR'])
|
2022-07-01 11:33:35 -03:00
|
|
|
|
|
2023-05-09 14:02:14 -03:00
|
|
|
|
pseudo_op('STORE_FAST_MAYBE_NULL', 266, ['STORE_FAST'])
|
2023-06-29 13:34:00 -03:00
|
|
|
|
pseudo_op('LOAD_CLOSURE', 267, ['LOAD_FAST'])
|
2023-05-09 14:02:14 -03:00
|
|
|
|
|
2022-07-01 11:33:35 -03:00
|
|
|
|
MAX_PSEUDO_OPCODE = MIN_PSEUDO_OPCODE + len(_pseudo_ops) - 1
|
|
|
|
|
|
2023-07-18 15:42:44 -03:00
|
|
|
|
del def_op, pseudo_op
|
2022-07-01 11:33:35 -03:00
|
|
|
|
|
|
|
|
|
opname = ['<%r>' % (op,) for op in range(MAX_PSEUDO_OPCODE + 1)]
|
|
|
|
|
for op, i in opmap.items():
|
|
|
|
|
opname[i] = op
|
2022-02-28 08:56:29 -04:00
|
|
|
|
|
2023-07-18 15:42:44 -03:00
|
|
|
|
# The build uses older versions of Python which do not have _opcode.has_* functions
|
|
|
|
|
if sys.version_info[:2] >= (3, 13):
|
|
|
|
|
# These lists are documented as part of the dis module's API
|
|
|
|
|
hasarg = [op for op in opmap.values() if _opcode.has_arg(op)]
|
|
|
|
|
hasconst = [op for op in opmap.values() if _opcode.has_const(op)]
|
|
|
|
|
hasname = [op for op in opmap.values() if _opcode.has_name(op)]
|
|
|
|
|
hasjump = [op for op in opmap.values() if _opcode.has_jump(op)]
|
|
|
|
|
hasjrel = hasjump # for backward compatibility
|
|
|
|
|
hasjabs = []
|
|
|
|
|
hasfree = [op for op in opmap.values() if _opcode.has_free(op)]
|
|
|
|
|
haslocal = [op for op in opmap.values() if _opcode.has_local(op)]
|
|
|
|
|
hasexc = [op for op in opmap.values() if _opcode.has_exc(op)]
|
|
|
|
|
|
|
|
|
|
__all__.extend(["hasarg", "hasconst", "hasname", "hasjump", "hasjrel",
|
|
|
|
|
"hasjabs", "hasfree", "haslocal", "hasexc"])
|
|
|
|
|
|
2023-07-20 13:46:04 -03:00
|
|
|
|
_intrinsic_1_descs = _opcode.get_intrinsic1_descs()
|
|
|
|
|
_intrinsic_2_descs = _opcode.get_intrinsic2_descs()
|
|
|
|
|
|
2023-07-18 15:42:44 -03:00
|
|
|
|
hascompare = [opmap["COMPARE_OP"]]
|
2021-06-10 04:46:01 -03:00
|
|
|
|
|
2021-11-11 02:56:22 -04:00
|
|
|
|
_nb_ops = [
|
|
|
|
|
("NB_ADD", "+"),
|
|
|
|
|
("NB_AND", "&"),
|
|
|
|
|
("NB_FLOOR_DIVIDE", "//"),
|
|
|
|
|
("NB_LSHIFT", "<<"),
|
|
|
|
|
("NB_MATRIX_MULTIPLY", "@"),
|
|
|
|
|
("NB_MULTIPLY", "*"),
|
|
|
|
|
("NB_REMAINDER", "%"),
|
|
|
|
|
("NB_OR", "|"),
|
|
|
|
|
("NB_POWER", "**"),
|
|
|
|
|
("NB_RSHIFT", ">>"),
|
|
|
|
|
("NB_SUBTRACT", "-"),
|
|
|
|
|
("NB_TRUE_DIVIDE", "/"),
|
|
|
|
|
("NB_XOR", "^"),
|
|
|
|
|
("NB_INPLACE_ADD", "+="),
|
|
|
|
|
("NB_INPLACE_AND", "&="),
|
|
|
|
|
("NB_INPLACE_FLOOR_DIVIDE", "//="),
|
|
|
|
|
("NB_INPLACE_LSHIFT", "<<="),
|
|
|
|
|
("NB_INPLACE_MATRIX_MULTIPLY", "@="),
|
|
|
|
|
("NB_INPLACE_MULTIPLY", "*="),
|
|
|
|
|
("NB_INPLACE_REMAINDER", "%="),
|
|
|
|
|
("NB_INPLACE_OR", "|="),
|
|
|
|
|
("NB_INPLACE_POWER", "**="),
|
|
|
|
|
("NB_INPLACE_RSHIFT", ">>="),
|
|
|
|
|
("NB_INPLACE_SUBTRACT", "-="),
|
|
|
|
|
("NB_INPLACE_TRUE_DIVIDE", "/="),
|
|
|
|
|
("NB_INPLACE_XOR", "^="),
|
|
|
|
|
]
|
|
|
|
|
|
2022-05-06 11:18:09 -03:00
|
|
|
|
|
|
|
|
|
_cache_format = {
|
|
|
|
|
"LOAD_GLOBAL": {
|
|
|
|
|
"counter": 1,
|
|
|
|
|
"index": 1,
|
2023-03-10 21:01:16 -04:00
|
|
|
|
"module_keys_version": 1,
|
2022-05-06 11:18:09 -03:00
|
|
|
|
"builtin_keys_version": 1,
|
|
|
|
|
},
|
|
|
|
|
"BINARY_OP": {
|
|
|
|
|
"counter": 1,
|
|
|
|
|
},
|
|
|
|
|
"UNPACK_SEQUENCE": {
|
|
|
|
|
"counter": 1,
|
|
|
|
|
},
|
|
|
|
|
"COMPARE_OP": {
|
|
|
|
|
"counter": 1,
|
|
|
|
|
},
|
|
|
|
|
"BINARY_SUBSCR": {
|
|
|
|
|
"counter": 1,
|
|
|
|
|
},
|
2022-06-21 07:19:26 -03:00
|
|
|
|
"FOR_ITER": {
|
|
|
|
|
"counter": 1,
|
|
|
|
|
},
|
2023-04-25 14:45:51 -03:00
|
|
|
|
"LOAD_SUPER_ATTR": {
|
|
|
|
|
"counter": 1,
|
|
|
|
|
},
|
2022-05-06 11:18:09 -03:00
|
|
|
|
"LOAD_ATTR": {
|
|
|
|
|
"counter": 1,
|
|
|
|
|
"version": 2,
|
2022-06-14 07:36:22 -03:00
|
|
|
|
"keys_version": 2,
|
|
|
|
|
"descr": 4,
|
2022-05-06 11:18:09 -03:00
|
|
|
|
},
|
|
|
|
|
"STORE_ATTR": {
|
|
|
|
|
"counter": 1,
|
|
|
|
|
"version": 2,
|
|
|
|
|
"index": 1,
|
|
|
|
|
},
|
|
|
|
|
"CALL": {
|
|
|
|
|
"counter": 1,
|
|
|
|
|
"func_version": 2,
|
|
|
|
|
},
|
|
|
|
|
"STORE_SUBSCR": {
|
|
|
|
|
"counter": 1,
|
|
|
|
|
},
|
2023-02-13 07:24:55 -04:00
|
|
|
|
"SEND": {
|
|
|
|
|
"counter": 1,
|
|
|
|
|
},
|
2023-06-02 07:46:18 -03:00
|
|
|
|
"JUMP_BACKWARD": {
|
|
|
|
|
"counter": 1,
|
|
|
|
|
},
|
2023-06-29 17:49:54 -03:00
|
|
|
|
"TO_BOOL": {
|
|
|
|
|
"counter": 1,
|
|
|
|
|
"version": 2,
|
|
|
|
|
},
|
2022-05-06 11:18:09 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_inline_cache_entries = [
|
|
|
|
|
sum(_cache_format.get(opname[opcode], {}).values()) for opcode in range(256)
|
|
|
|
|
]
|