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).
|
|
|
|
|
"""
|
|
|
|
|
|
2022-07-01 11:33:35 -03:00
|
|
|
|
__all__ = ["cmp_op", "hasarg", "hasconst", "hasname", "hasjrel", "hasjabs",
|
|
|
|
|
"haslocal", "hascompare", "hasfree", "hasexc", "opname", "opmap",
|
|
|
|
|
"HAVE_ARGUMENT", "EXTENDED_ARG"]
|
2003-02-27 17:27:52 -04:00
|
|
|
|
|
2013-11-23 18:49:22 -04:00
|
|
|
|
# It's a chicken-and-egg I'm afraid:
|
|
|
|
|
# We're imported before _opcode's made.
|
|
|
|
|
# With exception unheeded
|
|
|
|
|
# (stack_effect is not needed)
|
|
|
|
|
# Both our chickens and eggs are allayed.
|
|
|
|
|
# --Larry Hastings, 2013/11/23
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
from _opcode import stack_effect
|
|
|
|
|
__all__.append('stack_effect')
|
|
|
|
|
except ImportError:
|
|
|
|
|
pass
|
|
|
|
|
|
2023-06-19 19:47:04 -03:00
|
|
|
|
# _opcode_metadata may not be ready during early stages of the build
|
|
|
|
|
try:
|
|
|
|
|
from _opcode_metadata import _specializations, _specialized_instructions
|
|
|
|
|
except ModuleNotFoundError:
|
|
|
|
|
pass
|
|
|
|
|
|
2020-01-14 06:12:45 -04:00
|
|
|
|
cmp_op = ('<', '<=', '==', '!=', '>', '>=')
|
2003-02-27 17:27:52 -04:00
|
|
|
|
|
2022-07-01 11:33:35 -03:00
|
|
|
|
hasarg = []
|
2003-02-27 17:27:52 -04:00
|
|
|
|
hasconst = []
|
|
|
|
|
hasname = []
|
|
|
|
|
hasjrel = []
|
|
|
|
|
hasjabs = []
|
|
|
|
|
haslocal = []
|
|
|
|
|
hascompare = []
|
|
|
|
|
hasfree = []
|
2022-07-01 11:33:35 -03:00
|
|
|
|
hasexc = []
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
oplists = [hasarg, hasconst, hasname, hasjrel, hasjabs,
|
|
|
|
|
haslocal, hascompare, hasfree, hasexc]
|
2003-02-27 17:27:52 -04:00
|
|
|
|
|
|
|
|
|
opmap = {}
|
2022-07-01 11:33:35 -03:00
|
|
|
|
|
|
|
|
|
## pseudo opcodes (used in the compiler) mapped to the values
|
|
|
|
|
## they can become in the actual code.
|
|
|
|
|
_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-05-06 11:18:09 -03:00
|
|
|
|
def name_op(name, op):
|
|
|
|
|
def_op(name, op)
|
2003-02-27 17:27:52 -04:00
|
|
|
|
hasname.append(op)
|
|
|
|
|
|
2022-05-06 11:18:09 -03:00
|
|
|
|
def jrel_op(name, op):
|
|
|
|
|
def_op(name, op)
|
2003-02-27 17:27:52 -04:00
|
|
|
|
hasjrel.append(op)
|
|
|
|
|
|
2022-05-06 11:18:09 -03:00
|
|
|
|
def jabs_op(name, op):
|
|
|
|
|
def_op(name, op)
|
2003-02-27 17:27:52 -04:00
|
|
|
|
hasjabs.append(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
|
|
|
|
|
# add the pseudo opcode to the lists its targets are in
|
|
|
|
|
for oplist in oplists:
|
|
|
|
|
res = [opmap[rop] in oplist for rop in real_ops]
|
|
|
|
|
if any(res):
|
|
|
|
|
assert all(res)
|
|
|
|
|
oplist.append(op)
|
|
|
|
|
|
|
|
|
|
|
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)
|
2003-02-27 17:27:52 -04:00
|
|
|
|
|
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)
|
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-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
|
|
|
|
|
|
|
|
|
name_op('STORE_NAME', 90) # Index in name list
|
|
|
|
|
name_op('DELETE_NAME', 91) # ""
|
2022-05-06 11:18:09 -03:00
|
|
|
|
def_op('UNPACK_SEQUENCE', 92) # Number of tuple items
|
2003-02-27 17:27:52 -04:00
|
|
|
|
jrel_op('FOR_ITER', 93)
|
2008-03-18 17:13:50 -03:00
|
|
|
|
def_op('UNPACK_EX', 94)
|
2022-05-06 11:18:09 -03:00
|
|
|
|
name_op('STORE_ATTR', 95) # Index in name list
|
2003-02-27 17:27:52 -04:00
|
|
|
|
name_op('DELETE_ATTR', 96) # ""
|
|
|
|
|
name_op('STORE_GLOBAL', 97) # ""
|
|
|
|
|
name_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
|
|
|
|
|
hasconst.append(100)
|
|
|
|
|
name_op('LOAD_NAME', 101) # Index in name list
|
|
|
|
|
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
|
2022-05-06 11:18:09 -03:00
|
|
|
|
name_op('LOAD_ATTR', 106) # Index in name list
|
|
|
|
|
def_op('COMPARE_OP', 107) # Comparison operator
|
2006-08-28 12:27:34 -03:00
|
|
|
|
hascompare.append(107)
|
|
|
|
|
name_op('IMPORT_NAME', 108) # Index in name list
|
|
|
|
|
name_op('IMPORT_FROM', 109) # Index in name list
|
2022-03-31 10:14:15 -03:00
|
|
|
|
jrel_op('JUMP_FORWARD', 110) # Number of words to skip
|
2022-09-01 17:36:47 -03:00
|
|
|
|
jrel_op('POP_JUMP_IF_FALSE', 114)
|
|
|
|
|
jrel_op('POP_JUMP_IF_TRUE', 115)
|
2022-05-06 11:18:09 -03:00
|
|
|
|
name_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)
|
|
|
|
|
hasconst.append(121)
|
2022-05-06 11:18:09 -03:00
|
|
|
|
def_op('BINARY_OP', 122)
|
2023-02-13 07:24:55 -04:00
|
|
|
|
jrel_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
|
|
|
|
haslocal.append(124)
|
|
|
|
|
def_op('STORE_FAST', 125) # Local variable number
|
|
|
|
|
haslocal.append(125)
|
|
|
|
|
def_op('DELETE_FAST', 126) # Local variable number
|
|
|
|
|
haslocal.append(126)
|
2022-05-31 17:32:30 -03:00
|
|
|
|
def_op('LOAD_FAST_CHECK', 127) # Local variable number
|
|
|
|
|
haslocal.append(127)
|
2022-09-01 17:36:47 -03:00
|
|
|
|
jrel_op('POP_JUMP_IF_NOT_NONE', 128)
|
|
|
|
|
jrel_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
|
2022-04-05 08:49:08 -03:00
|
|
|
|
jrel_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)
|
2003-02-27 17:27:52 -04:00
|
|
|
|
hasfree.append(135)
|
2021-06-08 19:01:34 -03:00
|
|
|
|
def_op('LOAD_DEREF', 137)
|
2003-02-27 17:27:52 -04:00
|
|
|
|
hasfree.append(137)
|
2021-06-08 19:01:34 -03:00
|
|
|
|
def_op('STORE_DEREF', 138)
|
2010-09-10 18:39:53 -03:00
|
|
|
|
hasfree.append(138)
|
2021-06-08 19:01:34 -03:00
|
|
|
|
def_op('DELETE_DEREF', 139)
|
|
|
|
|
hasfree.append(139)
|
2022-03-31 10:14:15 -03:00
|
|
|
|
jrel_op('JUMP_BACKWARD', 140) # Number of words to skip (backwards)
|
2023-04-24 19:22:14 -03:00
|
|
|
|
name_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
|
|
|
|
|
haslocal.append(143)
|
2021-05-07 11:19:19 -03:00
|
|
|
|
|
2021-02-26 18:51:55 -04:00
|
|
|
|
def_op('EXTENDED_ARG', 144)
|
|
|
|
|
EXTENDED_ARG = 144
|
2008-12-18 07:06:25 -04:00
|
|
|
|
def_op('LIST_APPEND', 145)
|
|
|
|
|
def_op('SET_ADD', 146)
|
|
|
|
|
def_op('MAP_ADD', 147)
|
2013-04-30 10:41:40 -03:00
|
|
|
|
hasfree.append(148)
|
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)
|
|
|
|
|
hasconst.append(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)
|
2022-04-11 06:40:24 -03:00
|
|
|
|
|
2023-05-16 00:36:23 -03:00
|
|
|
|
name_op('LOAD_FROM_DICT_OR_GLOBALS', 175)
|
|
|
|
|
def_op('LOAD_FROM_DICT_OR_DEREF', 176)
|
|
|
|
|
hasfree.append(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
|
|
|
|
hasarg.extend([op for op in opmap.values() if op >= HAVE_ARGUMENT])
|
|
|
|
|
|
|
|
|
|
MIN_PSEUDO_OPCODE = 256
|
|
|
|
|
|
|
|
|
|
pseudo_op('SETUP_FINALLY', 256, ['NOP'])
|
|
|
|
|
hasexc.append(256)
|
|
|
|
|
pseudo_op('SETUP_CLEANUP', 257, ['NOP'])
|
|
|
|
|
hasexc.append(257)
|
|
|
|
|
pseudo_op('SETUP_WITH', 258, ['NOP'])
|
|
|
|
|
hasexc.append(258)
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
del def_op, name_op, jrel_op, jabs_op, pseudo_op
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
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", "^="),
|
|
|
|
|
]
|
|
|
|
|
|
2023-05-02 23:00:17 -03:00
|
|
|
|
_intrinsic_1_descs = [
|
|
|
|
|
"INTRINSIC_1_INVALID",
|
|
|
|
|
"INTRINSIC_PRINT",
|
|
|
|
|
"INTRINSIC_IMPORT_STAR",
|
|
|
|
|
"INTRINSIC_STOPITERATION_ERROR",
|
|
|
|
|
"INTRINSIC_ASYNC_GEN_WRAP",
|
|
|
|
|
"INTRINSIC_UNARY_POSITIVE",
|
|
|
|
|
"INTRINSIC_LIST_TO_TUPLE",
|
2023-05-16 00:36:23 -03:00
|
|
|
|
"INTRINSIC_TYPEVAR",
|
|
|
|
|
"INTRINSIC_PARAMSPEC",
|
|
|
|
|
"INTRINSIC_TYPEVARTUPLE",
|
|
|
|
|
"INTRINSIC_SUBSCRIPT_GENERIC",
|
|
|
|
|
"INTRINSIC_TYPEALIAS",
|
2023-05-02 23:00:17 -03:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
_intrinsic_2_descs = [
|
2023-05-16 00:36:23 -03:00
|
|
|
|
"INTRINSIC_2_INVALID",
|
|
|
|
|
"INTRINSIC_PREP_RERAISE_STAR",
|
|
|
|
|
"INTRINSIC_TYPEVAR_WITH_BOUND",
|
|
|
|
|
"INTRINSIC_TYPEVAR_WITH_CONSTRAINTS",
|
|
|
|
|
"INTRINSIC_SET_FUNCTION_TYPE_PARAMS",
|
|
|
|
|
]
|
2023-05-02 23:00:17 -03:00
|
|
|
|
|
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,
|
|
|
|
|
},
|
2022-05-06 11:18:09 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_inline_cache_entries = [
|
|
|
|
|
sum(_cache_format.get(opname[opcode], {}).values()) for opcode in range(256)
|
|
|
|
|
]
|