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
|
|
|
|
|
|
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 = []
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
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)
|
2014-04-10 00:55:56 -03:00
|
|
|
|
|
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
|
|
|
|
|
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)
|
2022-05-19 13:49:29 -03:00
|
|
|
|
|
2021-12-14 12:48:15 -04:00
|
|
|
|
def_op('PREP_RERAISE_STAR', 88)
|
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-04-15 16:19:24 -03:00
|
|
|
|
jrel_op('JUMP_IF_FALSE_OR_POP', 111) # Number of words to skip
|
|
|
|
|
jrel_op('JUMP_IF_TRUE_OR_POP', 112) # ""
|
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)
|
2022-05-06 11:18:09 -03:00
|
|
|
|
def_op('BINARY_OP', 122)
|
2021-12-15 06:30:09 -04:00
|
|
|
|
jrel_op('SEND', 123) # Number of bytes 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)
|
2016-06-12 11:36:24 -03:00
|
|
|
|
def_op('MAKE_FUNCTION', 132) # Flags
|
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_CLOSURE', 136)
|
2003-02-27 17:27:52 -04:00
|
|
|
|
hasfree.append(136)
|
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)
|
2003-02-27 17:27:52 -04:00
|
|
|
|
|
2016-09-09 14:17:08 -03:00
|
|
|
|
def_op('CALL_FUNCTION_EX', 142) # Flags
|
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
|
|
|
|
def_op('LOAD_CLASSDEREF', 148)
|
|
|
|
|
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
|
|
|
|
|
2015-11-03 13:45:05 -04:00
|
|
|
|
def_op('FORMAT_VALUE', 155)
|
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)
|
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
|
|
|
|
|
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)
|
2022-04-11 06:40:24 -03:00
|
|
|
|
|
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'])
|
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", "^="),
|
|
|
|
|
]
|
|
|
|
|
|
2022-03-21 08:11:17 -03:00
|
|
|
|
_specializations = {
|
|
|
|
|
"BINARY_OP": [
|
|
|
|
|
"BINARY_OP_ADD_FLOAT",
|
|
|
|
|
"BINARY_OP_ADD_INT",
|
|
|
|
|
"BINARY_OP_ADD_UNICODE",
|
|
|
|
|
"BINARY_OP_INPLACE_ADD_UNICODE",
|
|
|
|
|
"BINARY_OP_MULTIPLY_FLOAT",
|
|
|
|
|
"BINARY_OP_MULTIPLY_INT",
|
|
|
|
|
"BINARY_OP_SUBTRACT_FLOAT",
|
|
|
|
|
"BINARY_OP_SUBTRACT_INT",
|
|
|
|
|
],
|
|
|
|
|
"BINARY_SUBSCR": [
|
|
|
|
|
"BINARY_SUBSCR_DICT",
|
|
|
|
|
"BINARY_SUBSCR_GETITEM",
|
|
|
|
|
"BINARY_SUBSCR_LIST_INT",
|
|
|
|
|
"BINARY_SUBSCR_TUPLE_INT",
|
|
|
|
|
],
|
|
|
|
|
"CALL": [
|
|
|
|
|
"CALL_PY_EXACT_ARGS",
|
|
|
|
|
"CALL_PY_WITH_DEFAULTS",
|
2022-05-19 07:05:26 -03:00
|
|
|
|
"CALL_BOUND_METHOD_EXACT_ARGS",
|
|
|
|
|
"CALL_BUILTIN_CLASS",
|
|
|
|
|
"CALL_BUILTIN_FAST_WITH_KEYWORDS",
|
|
|
|
|
"CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS",
|
|
|
|
|
"CALL_NO_KW_BUILTIN_FAST",
|
|
|
|
|
"CALL_NO_KW_BUILTIN_O",
|
|
|
|
|
"CALL_NO_KW_ISINSTANCE",
|
|
|
|
|
"CALL_NO_KW_LEN",
|
|
|
|
|
"CALL_NO_KW_LIST_APPEND",
|
|
|
|
|
"CALL_NO_KW_METHOD_DESCRIPTOR_FAST",
|
|
|
|
|
"CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS",
|
|
|
|
|
"CALL_NO_KW_METHOD_DESCRIPTOR_O",
|
|
|
|
|
"CALL_NO_KW_STR_1",
|
|
|
|
|
"CALL_NO_KW_TUPLE_1",
|
|
|
|
|
"CALL_NO_KW_TYPE_1",
|
2022-03-21 08:11:17 -03:00
|
|
|
|
],
|
|
|
|
|
"COMPARE_OP": [
|
|
|
|
|
"COMPARE_OP_FLOAT_JUMP",
|
|
|
|
|
"COMPARE_OP_INT_JUMP",
|
|
|
|
|
"COMPARE_OP_STR_JUMP",
|
|
|
|
|
],
|
2022-06-21 07:19:26 -03:00
|
|
|
|
"FOR_ITER": [
|
|
|
|
|
"FOR_ITER_LIST",
|
2022-12-09 06:27:01 -04:00
|
|
|
|
"FOR_ITER_TUPLE",
|
2022-06-21 07:19:26 -03:00
|
|
|
|
"FOR_ITER_RANGE",
|
2022-11-07 10:49:51 -04:00
|
|
|
|
"FOR_ITER_GEN",
|
2022-06-21 07:19:26 -03:00
|
|
|
|
],
|
2022-03-21 08:11:17 -03:00
|
|
|
|
"LOAD_ATTR": [
|
2022-06-14 07:36:22 -03:00
|
|
|
|
# These potentially push [NULL, bound method] onto the stack.
|
|
|
|
|
"LOAD_ATTR_CLASS",
|
2022-08-17 08:37:07 -03:00
|
|
|
|
"LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN",
|
2022-03-21 08:11:17 -03:00
|
|
|
|
"LOAD_ATTR_INSTANCE_VALUE",
|
|
|
|
|
"LOAD_ATTR_MODULE",
|
2022-06-17 12:13:17 -03:00
|
|
|
|
"LOAD_ATTR_PROPERTY",
|
2022-03-21 08:11:17 -03:00
|
|
|
|
"LOAD_ATTR_SLOT",
|
|
|
|
|
"LOAD_ATTR_WITH_HINT",
|
2022-06-14 07:36:22 -03:00
|
|
|
|
# These will always push [unbound method, self] onto the stack.
|
|
|
|
|
"LOAD_ATTR_METHOD_LAZY_DICT",
|
|
|
|
|
"LOAD_ATTR_METHOD_NO_DICT",
|
|
|
|
|
"LOAD_ATTR_METHOD_WITH_VALUES",
|
2022-03-21 08:11:17 -03:00
|
|
|
|
],
|
|
|
|
|
"LOAD_CONST": [
|
|
|
|
|
"LOAD_CONST__LOAD_FAST",
|
|
|
|
|
],
|
|
|
|
|
"LOAD_FAST": [
|
|
|
|
|
"LOAD_FAST__LOAD_CONST",
|
|
|
|
|
"LOAD_FAST__LOAD_FAST",
|
|
|
|
|
],
|
|
|
|
|
"LOAD_GLOBAL": [
|
|
|
|
|
"LOAD_GLOBAL_BUILTIN",
|
|
|
|
|
"LOAD_GLOBAL_MODULE",
|
|
|
|
|
],
|
|
|
|
|
"STORE_ATTR": [
|
|
|
|
|
"STORE_ATTR_INSTANCE_VALUE",
|
|
|
|
|
"STORE_ATTR_SLOT",
|
|
|
|
|
"STORE_ATTR_WITH_HINT",
|
|
|
|
|
],
|
|
|
|
|
"STORE_FAST": [
|
|
|
|
|
"STORE_FAST__LOAD_FAST",
|
|
|
|
|
"STORE_FAST__STORE_FAST",
|
|
|
|
|
],
|
|
|
|
|
"STORE_SUBSCR": [
|
|
|
|
|
"STORE_SUBSCR_DICT",
|
|
|
|
|
"STORE_SUBSCR_LIST_INT",
|
|
|
|
|
],
|
|
|
|
|
"UNPACK_SEQUENCE": [
|
|
|
|
|
"UNPACK_SEQUENCE_LIST",
|
|
|
|
|
"UNPACK_SEQUENCE_TUPLE",
|
|
|
|
|
"UNPACK_SEQUENCE_TWO_TUPLE",
|
|
|
|
|
],
|
|
|
|
|
}
|
2021-06-10 04:46:01 -03:00
|
|
|
|
_specialized_instructions = [
|
2022-03-21 08:11:17 -03:00
|
|
|
|
opcode for family in _specializations.values() for opcode in family
|
2021-06-10 04:46:01 -03:00
|
|
|
|
]
|
2021-07-29 13:26:53 -03:00
|
|
|
|
_specialization_stats = [
|
2021-12-17 10:48:01 -04:00
|
|
|
|
"success",
|
|
|
|
|
"failure",
|
2021-07-29 13:26:53 -03:00
|
|
|
|
"hit",
|
|
|
|
|
"deferred",
|
|
|
|
|
"miss",
|
|
|
|
|
"deopt",
|
|
|
|
|
]
|
2022-05-06 11:18:09 -03:00
|
|
|
|
|
|
|
|
|
_cache_format = {
|
|
|
|
|
"LOAD_GLOBAL": {
|
|
|
|
|
"counter": 1,
|
|
|
|
|
"index": 1,
|
|
|
|
|
"module_keys_version": 2,
|
|
|
|
|
"builtin_keys_version": 1,
|
|
|
|
|
},
|
|
|
|
|
"BINARY_OP": {
|
|
|
|
|
"counter": 1,
|
|
|
|
|
},
|
|
|
|
|
"UNPACK_SEQUENCE": {
|
|
|
|
|
"counter": 1,
|
|
|
|
|
},
|
|
|
|
|
"COMPARE_OP": {
|
|
|
|
|
"counter": 1,
|
|
|
|
|
"mask": 1,
|
|
|
|
|
},
|
|
|
|
|
"BINARY_SUBSCR": {
|
|
|
|
|
"counter": 1,
|
|
|
|
|
"type_version": 2,
|
|
|
|
|
"func_version": 1,
|
|
|
|
|
},
|
2022-06-21 07:19:26 -03:00
|
|
|
|
"FOR_ITER": {
|
|
|
|
|
"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,
|
|
|
|
|
"min_args": 1,
|
|
|
|
|
},
|
|
|
|
|
"STORE_SUBSCR": {
|
|
|
|
|
"counter": 1,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_inline_cache_entries = [
|
|
|
|
|
sum(_cache_format.get(opname[opcode], {}).values()) for opcode in range(256)
|
|
|
|
|
]
|