| 
									
										
										
										
											2003-02-27 21:27:52 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | """
 | 
					
						
							|  |  |  |  | opcode module - potentially shared between dis and other modules which | 
					
						
							|  |  |  |  | operate on bytecodes (e.g. peephole optimizers). | 
					
						
							|  |  |  |  | """
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-01 15:33:35 +01:00
										 |  |  |  | __all__ = ["cmp_op", "hasarg", "hasconst", "hasname", "hasjrel", "hasjabs", | 
					
						
							|  |  |  |  |            "haslocal", "hascompare", "hasfree", "hasexc", "opname", "opmap", | 
					
						
							|  |  |  |  |            "HAVE_ARGUMENT", "EXTENDED_ARG"] | 
					
						
							| 
									
										
										
										
											2003-02-27 21:27:52 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-23 14:49:22 -08: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 10:12:45 +00:00
										 |  |  |  | cmp_op = ('<', '<=', '==', '!=', '>', '>=') | 
					
						
							| 
									
										
										
										
											2003-02-27 21:27:52 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-01 15:33:35 +01:00
										 |  |  |  | hasarg = [] | 
					
						
							| 
									
										
										
										
											2003-02-27 21:27:52 +00:00
										 |  |  |  | hasconst = [] | 
					
						
							|  |  |  |  | hasname = [] | 
					
						
							|  |  |  |  | hasjrel = [] | 
					
						
							|  |  |  |  | hasjabs = [] | 
					
						
							|  |  |  |  | haslocal = [] | 
					
						
							|  |  |  |  | hascompare = [] | 
					
						
							|  |  |  |  | hasfree = [] | 
					
						
							| 
									
										
										
										
											2022-07-01 15:33:35 +01: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 21:27:52 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | opmap = {} | 
					
						
							| 
									
										
										
										
											2022-07-01 15:33:35 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | ## pseudo opcodes (used in the compiler) mapped to the values | 
					
						
							|  |  |  |  | ## they can become in the actual code. | 
					
						
							|  |  |  |  | _pseudo_ops = {} | 
					
						
							| 
									
										
										
										
											2003-02-27 21:27:52 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-06 07:18:09 -07:00
										 |  |  |  | def def_op(name, op): | 
					
						
							| 
									
										
										
										
											2003-02-27 21:27:52 +00:00
										 |  |  |  |     opmap[name] = op | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-06 07:18:09 -07:00
										 |  |  |  | def name_op(name, op): | 
					
						
							|  |  |  |  |     def_op(name, op) | 
					
						
							| 
									
										
										
										
											2003-02-27 21:27:52 +00:00
										 |  |  |  |     hasname.append(op) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-06 07:18:09 -07:00
										 |  |  |  | def jrel_op(name, op): | 
					
						
							|  |  |  |  |     def_op(name, op) | 
					
						
							| 
									
										
										
										
											2003-02-27 21:27:52 +00:00
										 |  |  |  |     hasjrel.append(op) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-06 07:18:09 -07:00
										 |  |  |  | def jabs_op(name, op): | 
					
						
							|  |  |  |  |     def_op(name, op) | 
					
						
							| 
									
										
										
										
											2003-02-27 21:27:52 +00:00
										 |  |  |  |     hasjabs.append(op) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-01 15:33:35 +01: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 21:27:52 +00:00
										 |  |  |  | # Instruction opcodes for compiled code | 
					
						
							| 
									
										
										
										
											2006-02-27 22:32:47 +00:00
										 |  |  |  | # Blank lines correspond to available opcodes | 
					
						
							| 
									
										
										
										
											2003-02-27 21:27:52 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-07 11:45:00 -08:00
										 |  |  |  | def_op('CACHE', 0) | 
					
						
							| 
									
										
										
										
											2003-02-27 21:27:52 +00:00
										 |  |  |  | def_op('POP_TOP', 1) | 
					
						
							| 
									
										
										
										
											2022-02-18 17:19:08 +00:00
										 |  |  |  | def_op('PUSH_NULL', 2) | 
					
						
							| 
									
										
										
										
											2022-11-10 04:34:57 -08:00
										 |  |  |  | def_op('INTERPRETER_EXIT', 3) | 
					
						
							| 
									
										
										
										
											2003-02-27 21:27:52 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-27 03:55:03 -07:00
										 |  |  |  | def_op('END_FOR', 4) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-06-21 16:31:15 +00:00
										 |  |  |  | def_op('NOP', 9) | 
					
						
							| 
									
										
										
										
											2003-02-27 21:27:52 +00:00
										 |  |  |  | def_op('UNARY_POSITIVE', 10) | 
					
						
							|  |  |  |  | def_op('UNARY_NEGATIVE', 11) | 
					
						
							|  |  |  |  | def_op('UNARY_NOT', 12) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | def_op('UNARY_INVERT', 15) | 
					
						
							| 
									
										
										
										
											2014-04-09 23:55:56 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-06 07:18:09 -07:00
										 |  |  |  | def_op('BINARY_SUBSCR', 25) | 
					
						
							| 
									
										
										
										
											2022-06-27 12:24:23 +01:00
										 |  |  |  | def_op('BINARY_SLICE', 26) | 
					
						
							|  |  |  |  | def_op('STORE_SLICE', 27) | 
					
						
							| 
									
										
										
										
											2021-11-10 22:56:22 -08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-26 14:51:55 -08:00
										 |  |  |  | def_op('GET_LEN', 30) | 
					
						
							|  |  |  |  | def_op('MATCH_MAPPING', 31) | 
					
						
							|  |  |  |  | def_op('MATCH_SEQUENCE', 32) | 
					
						
							|  |  |  |  | def_op('MATCH_KEYS', 33) | 
					
						
							| 
									
										
										
										
											2021-10-27 02:45:35 -07:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-07 15:19:19 +01:00
										 |  |  |  | def_op('PUSH_EXC_INFO', 35) | 
					
						
							| 
									
										
										
										
											2022-04-01 13:59:38 +01:00
										 |  |  |  | def_op('CHECK_EXC_MATCH', 36) | 
					
						
							| 
									
										
										
										
											2022-04-05 12:06:22 +01:00
										 |  |  |  | def_op('CHECK_EG_MATCH', 37) | 
					
						
							| 
									
										
										
										
											2021-05-07 15:19:19 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-21 09:11:43 +00:00
										 |  |  |  | def_op('WITH_EXCEPT_START', 49) | 
					
						
							| 
									
										
										
										
											2015-05-11 22:57:16 -04:00
										 |  |  |  | def_op('GET_AITER', 50) | 
					
						
							|  |  |  |  | def_op('GET_ANEXT', 51) | 
					
						
							|  |  |  |  | def_op('BEFORE_ASYNC_WITH', 52) | 
					
						
							| 
									
										
										
										
											2021-05-07 15:19:19 +01:00
										 |  |  |  | def_op('BEFORE_WITH', 53) | 
					
						
							| 
									
										
										
										
											2018-03-23 14:34:35 +02:00
										 |  |  |  | def_op('END_ASYNC_FOR', 54) | 
					
						
							| 
									
										
										
										
											2022-08-19 12:33:44 -07:00
										 |  |  |  | def_op('CLEANUP_THROW', 55) | 
					
						
							| 
									
										
										
										
											2006-03-17 08:59:09 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-06 07:18:09 -07:00
										 |  |  |  | def_op('STORE_SUBSCR', 60) | 
					
						
							| 
									
										
										
										
											2003-02-27 21:27:52 +00:00
										 |  |  |  | def_op('DELETE_SUBSCR', 61) | 
					
						
							| 
									
										
										
										
											2021-11-10 22:56:22 -08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-03 04:38:51 -07:00
										 |  |  |  | def_op('STOPITERATION_ERROR', 63) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-02-27 21:27:52 +00: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 12:19:30 -04:00
										 |  |  |  | def_op('GET_YIELD_FROM_ITER', 69) | 
					
						
							| 
									
										
										
										
											2003-02-27 21:27:52 +00:00
										 |  |  |  | def_op('PRINT_EXPR', 70) | 
					
						
							| 
									
										
										
										
											2007-03-18 15:41:51 +00:00
										 |  |  |  | def_op('LOAD_BUILD_CLASS', 71) | 
					
						
							| 
									
										
										
										
											2021-12-15 10:30:09 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-25 03:44:09 -06:00
										 |  |  |  | def_op('LOAD_ASSERTION_ERROR', 74) | 
					
						
							| 
									
										
										
										
											2022-01-20 11:46:39 +00:00
										 |  |  |  | def_op('RETURN_GENERATOR', 75) | 
					
						
							| 
									
										
										
										
											2019-11-21 09:11:43 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-23 09:25:17 +00:00
										 |  |  |  | def_op('LIST_TO_TUPLE', 82) | 
					
						
							| 
									
										
										
										
											2003-02-27 21:27:52 +00:00
										 |  |  |  | def_op('RETURN_VALUE', 83) | 
					
						
							|  |  |  |  | def_op('IMPORT_STAR', 84) | 
					
						
							| 
									
										
										
										
											2016-09-08 20:50:03 -07:00
										 |  |  |  | def_op('SETUP_ANNOTATIONS', 85) | 
					
						
							| 
									
										
										
										
											2022-05-19 17:49:29 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-24 11:08:53 +00:00
										 |  |  |  | def_op('ASYNC_GEN_WRAP', 87) | 
					
						
							| 
									
										
										
										
											2021-12-14 16:48:15 +00:00
										 |  |  |  | def_op('PREP_RERAISE_STAR', 88) | 
					
						
							| 
									
										
										
										
											2008-06-11 15:59:43 +00:00
										 |  |  |  | def_op('POP_EXCEPT', 89) | 
					
						
							| 
									
										
										
										
											2003-02-27 21:27:52 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-01 15:33:35 +01:00
										 |  |  |  | HAVE_ARGUMENT = 90             # real opcodes from here have an argument: | 
					
						
							| 
									
										
										
										
											2003-02-27 21:27:52 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | name_op('STORE_NAME', 90)       # Index in name list | 
					
						
							|  |  |  |  | name_op('DELETE_NAME', 91)      # "" | 
					
						
							| 
									
										
										
										
											2022-05-06 07:18:09 -07:00
										 |  |  |  | def_op('UNPACK_SEQUENCE', 92)   # Number of tuple items | 
					
						
							| 
									
										
										
										
											2003-02-27 21:27:52 +00:00
										 |  |  |  | jrel_op('FOR_ITER', 93) | 
					
						
							| 
									
										
										
										
											2008-03-18 20:13:50 +00:00
										 |  |  |  | def_op('UNPACK_EX', 94) | 
					
						
							| 
									
										
										
										
											2022-05-06 07:18:09 -07:00
										 |  |  |  | name_op('STORE_ATTR', 95)       # Index in name list | 
					
						
							| 
									
										
										
										
											2003-02-27 21:27:52 +00:00
										 |  |  |  | name_op('DELETE_ATTR', 96)      # "" | 
					
						
							|  |  |  |  | name_op('STORE_GLOBAL', 97)     # "" | 
					
						
							|  |  |  |  | name_op('DELETE_GLOBAL', 98)    # "" | 
					
						
							| 
									
										
										
										
											2022-01-26 12:47:45 -08:00
										 |  |  |  | def_op('SWAP', 99) | 
					
						
							| 
									
										
										
										
											2003-02-27 21:27:52 +00: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 15:27:34 +00:00
										 |  |  |  | def_op('BUILD_SET', 104)        # Number of set items | 
					
						
							| 
									
										
										
										
											2018-02-03 18:36:10 -06:00
										 |  |  |  | def_op('BUILD_MAP', 105)        # Number of dict entries | 
					
						
							| 
									
										
										
										
											2022-05-06 07:18:09 -07:00
										 |  |  |  | name_op('LOAD_ATTR', 106)       # Index in name list | 
					
						
							|  |  |  |  | def_op('COMPARE_OP', 107)       # Comparison operator | 
					
						
							| 
									
										
										
										
											2006-08-28 15:27:34 +00: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 14:14:15 +01:00
										 |  |  |  | jrel_op('JUMP_FORWARD', 110)    # Number of words to skip | 
					
						
							| 
									
										
										
										
											2022-04-15 20:19:24 +01: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 21:36:47 +01:00
										 |  |  |  | jrel_op('POP_JUMP_IF_FALSE', 114) | 
					
						
							|  |  |  |  | jrel_op('POP_JUMP_IF_TRUE', 115) | 
					
						
							| 
									
										
										
										
											2022-05-06 07:18:09 -07:00
										 |  |  |  | name_op('LOAD_GLOBAL', 116)     # Index in name list | 
					
						
							| 
									
										
										
										
											2020-01-14 10:12:45 +00:00
										 |  |  |  | def_op('IS_OP', 117) | 
					
						
							|  |  |  |  | def_op('CONTAINS_OP', 118) | 
					
						
							| 
									
										
										
										
											2020-12-17 13:55:28 +00:00
										 |  |  |  | def_op('RERAISE', 119) | 
					
						
							| 
									
										
										
										
											2021-10-27 02:45:35 -07:00
										 |  |  |  | def_op('COPY', 120) | 
					
						
							| 
									
										
										
										
											2022-05-06 07:18:09 -07:00
										 |  |  |  | def_op('BINARY_OP', 122) | 
					
						
							| 
									
										
										
										
											2021-12-15 10:30:09 +00:00
										 |  |  |  | jrel_op('SEND', 123) # Number of bytes to skip | 
					
						
							| 
									
										
										
										
											2022-05-31 16:32:30 -04:00
										 |  |  |  | def_op('LOAD_FAST', 124)        # Local variable number, no null check | 
					
						
							| 
									
										
										
										
											2003-02-27 21:27:52 +00: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 16:32:30 -04:00
										 |  |  |  | def_op('LOAD_FAST_CHECK', 127)  # Local variable number | 
					
						
							|  |  |  |  | haslocal.append(127) | 
					
						
							| 
									
										
										
										
											2022-09-01 21:36:47 +01:00
										 |  |  |  | jrel_op('POP_JUMP_IF_NOT_NONE', 128) | 
					
						
							|  |  |  |  | jrel_op('POP_JUMP_IF_NONE', 129) | 
					
						
							| 
									
										
										
										
											2003-02-27 21:27:52 +00:00
										 |  |  |  | def_op('RAISE_VARARGS', 130)    # Number of raise arguments (1, 2, or 3) | 
					
						
							| 
									
										
										
										
											2022-03-04 04:41:17 -08:00
										 |  |  |  | def_op('GET_AWAITABLE', 131) | 
					
						
							| 
									
										
										
										
											2016-06-12 17:36:24 +03:00
										 |  |  |  | def_op('MAKE_FUNCTION', 132)    # Flags | 
					
						
							| 
									
										
										
										
											2003-02-27 21:27:52 +00:00
										 |  |  |  | def_op('BUILD_SLICE', 133)      # Number of items | 
					
						
							| 
									
										
										
										
											2022-04-05 12:49:08 +01:00
										 |  |  |  | jrel_op('JUMP_BACKWARD_NO_INTERRUPT', 134) # Number of words to skip (backwards) | 
					
						
							| 
									
										
										
										
											2021-06-08 16:01:34 -06:00
										 |  |  |  | def_op('MAKE_CELL', 135) | 
					
						
							| 
									
										
										
										
											2003-02-27 21:27:52 +00:00
										 |  |  |  | hasfree.append(135) | 
					
						
							| 
									
										
										
										
											2021-06-08 16:01:34 -06:00
										 |  |  |  | def_op('LOAD_CLOSURE', 136) | 
					
						
							| 
									
										
										
										
											2003-02-27 21:27:52 +00:00
										 |  |  |  | hasfree.append(136) | 
					
						
							| 
									
										
										
										
											2021-06-08 16:01:34 -06:00
										 |  |  |  | def_op('LOAD_DEREF', 137) | 
					
						
							| 
									
										
										
										
											2003-02-27 21:27:52 +00:00
										 |  |  |  | hasfree.append(137) | 
					
						
							| 
									
										
										
										
											2021-06-08 16:01:34 -06:00
										 |  |  |  | def_op('STORE_DEREF', 138) | 
					
						
							| 
									
										
										
										
											2010-09-10 21:39:53 +00:00
										 |  |  |  | hasfree.append(138) | 
					
						
							| 
									
										
										
										
											2021-06-08 16:01:34 -06:00
										 |  |  |  | def_op('DELETE_DEREF', 139) | 
					
						
							|  |  |  |  | hasfree.append(139) | 
					
						
							| 
									
										
										
										
											2022-03-31 14:14:15 +01:00
										 |  |  |  | jrel_op('JUMP_BACKWARD', 140)    # Number of words to skip (backwards) | 
					
						
							| 
									
										
										
										
											2003-02-27 21:27:52 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-09 10:17:08 -07:00
										 |  |  |  | def_op('CALL_FUNCTION_EX', 142)  # Flags | 
					
						
							| 
									
										
										
										
											2021-05-07 15:19:19 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-26 14:51:55 -08:00
										 |  |  |  | def_op('EXTENDED_ARG', 144) | 
					
						
							|  |  |  |  | EXTENDED_ARG = 144 | 
					
						
							| 
									
										
										
										
											2008-12-18 11:06:25 +00:00
										 |  |  |  | def_op('LIST_APPEND', 145) | 
					
						
							|  |  |  |  | def_op('SET_ADD', 146) | 
					
						
							|  |  |  |  | def_op('MAP_ADD', 147) | 
					
						
							| 
									
										
										
										
											2013-04-30 09:41:40 -04:00
										 |  |  |  | def_op('LOAD_CLASSDEREF', 148) | 
					
						
							|  |  |  |  | hasfree.append(148) | 
					
						
							| 
									
										
										
										
											2021-11-23 09:53:24 +00:00
										 |  |  |  | def_op('COPY_FREE_VARS', 149) | 
					
						
							| 
									
										
										
										
											2022-05-19 17:49:29 +01:00
										 |  |  |  | def_op('YIELD_VALUE', 150) | 
					
						
							| 
									
										
										
										
											2022-06-14 11:09:30 +01:00
										 |  |  |  | def_op('RESUME', 151)   # This must be kept in sync with deepfreeze.py | 
					
						
							| 
									
										
										
										
											2021-02-26 14:51:55 -08:00
										 |  |  |  | def_op('MATCH_CLASS', 152) | 
					
						
							| 
									
										
										
										
											2008-12-18 11:06:25 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-03 12:45:05 -05:00
										 |  |  |  | def_op('FORMAT_VALUE', 155) | 
					
						
							| 
									
										
										
										
											2016-06-12 00:39:41 +03:00
										 |  |  |  | def_op('BUILD_CONST_KEY_MAP', 156) | 
					
						
							| 
									
										
										
										
											2016-09-06 22:07:53 +03:00
										 |  |  |  | def_op('BUILD_STRING', 157) | 
					
						
							| 
									
										
										
										
											2015-11-03 12:45:05 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-23 09:25:17 +00:00
										 |  |  |  | def_op('LIST_EXTEND', 162) | 
					
						
							|  |  |  |  | def_op('SET_UPDATE', 163) | 
					
						
							| 
									
										
										
										
											2020-01-27 09:57:45 +00:00
										 |  |  |  | def_op('DICT_MERGE', 164) | 
					
						
							|  |  |  |  | def_op('DICT_UPDATE', 165) | 
					
						
							| 
									
										
										
										
											2022-01-28 12:42:30 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-06 07:18:09 -07:00
										 |  |  |  | def_op('CALL', 171) | 
					
						
							| 
									
										
										
										
											2022-01-28 12:42:30 +00:00
										 |  |  |  | def_op('KW_NAMES', 172) | 
					
						
							|  |  |  |  | hasconst.append(172) | 
					
						
							| 
									
										
										
										
											2020-01-23 09:25:17 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-11 10:40:24 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-01 15:33:35 +01: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 21:36:47 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | pseudo_op('LOAD_METHOD', 262, ['LOAD_ATTR']) | 
					
						
							| 
									
										
										
										
											2022-07-01 15:33:35 +01: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 12:56:29 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-10 08:46:01 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-10 22:56:22 -08: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 04:11:17 -07: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 11:05:26 +01: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 04:11:17 -07:00
										 |  |  |  |     ], | 
					
						
							|  |  |  |  |     "COMPARE_OP": [ | 
					
						
							|  |  |  |  |         "COMPARE_OP_FLOAT_JUMP", | 
					
						
							|  |  |  |  |         "COMPARE_OP_INT_JUMP", | 
					
						
							|  |  |  |  |         "COMPARE_OP_STR_JUMP", | 
					
						
							|  |  |  |  |     ], | 
					
						
							| 
									
										
										
										
											2022-06-21 06:19:26 -04:00
										 |  |  |  |     "FOR_ITER": [ | 
					
						
							|  |  |  |  |         "FOR_ITER_LIST", | 
					
						
							|  |  |  |  |         "FOR_ITER_RANGE", | 
					
						
							| 
									
										
										
										
											2022-11-07 06:49:51 -08:00
										 |  |  |  |         "FOR_ITER_GEN", | 
					
						
							| 
									
										
										
										
											2022-06-21 06:19:26 -04:00
										 |  |  |  |     ], | 
					
						
							| 
									
										
										
										
											2022-03-21 04:11:17 -07:00
										 |  |  |  |     "LOAD_ATTR": [ | 
					
						
							| 
									
										
										
										
											2022-06-14 18:36:22 +08:00
										 |  |  |  |         # These potentially push [NULL, bound method] onto the stack. | 
					
						
							|  |  |  |  |         "LOAD_ATTR_CLASS", | 
					
						
							| 
									
										
										
										
											2022-08-17 19:37:07 +08:00
										 |  |  |  |         "LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN", | 
					
						
							| 
									
										
										
										
											2022-03-21 04:11:17 -07:00
										 |  |  |  |         "LOAD_ATTR_INSTANCE_VALUE", | 
					
						
							|  |  |  |  |         "LOAD_ATTR_MODULE", | 
					
						
							| 
									
										
										
										
											2022-06-17 23:13:17 +08:00
										 |  |  |  |         "LOAD_ATTR_PROPERTY", | 
					
						
							| 
									
										
										
										
											2022-03-21 04:11:17 -07:00
										 |  |  |  |         "LOAD_ATTR_SLOT", | 
					
						
							|  |  |  |  |         "LOAD_ATTR_WITH_HINT", | 
					
						
							| 
									
										
										
										
											2022-06-14 18:36:22 +08: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_DICT", | 
					
						
							|  |  |  |  |         "LOAD_ATTR_METHOD_WITH_VALUES", | 
					
						
							| 
									
										
										
										
											2022-03-21 04:11:17 -07: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 08:46:01 +01:00
										 |  |  |  | _specialized_instructions = [ | 
					
						
							| 
									
										
										
										
											2022-03-21 04:11:17 -07:00
										 |  |  |  |     opcode for family in _specializations.values() for opcode in family | 
					
						
							| 
									
										
										
										
											2021-06-10 08:46:01 +01:00
										 |  |  |  | ] | 
					
						
							| 
									
										
										
										
											2021-07-29 17:26:53 +01:00
										 |  |  |  | _specialization_stats = [ | 
					
						
							| 
									
										
										
										
											2021-12-17 14:48:01 +00:00
										 |  |  |  |     "success", | 
					
						
							|  |  |  |  |     "failure", | 
					
						
							| 
									
										
										
										
											2021-07-29 17:26:53 +01:00
										 |  |  |  |     "hit", | 
					
						
							|  |  |  |  |     "deferred", | 
					
						
							|  |  |  |  |     "miss", | 
					
						
							|  |  |  |  |     "deopt", | 
					
						
							|  |  |  |  | ] | 
					
						
							| 
									
										
										
										
											2022-05-06 07:18:09 -07: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 06:19:26 -04:00
										 |  |  |  |     "FOR_ITER": { | 
					
						
							|  |  |  |  |         "counter": 1, | 
					
						
							|  |  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2022-05-06 07:18:09 -07:00
										 |  |  |  |     "LOAD_ATTR": { | 
					
						
							|  |  |  |  |         "counter": 1, | 
					
						
							|  |  |  |  |         "version": 2, | 
					
						
							| 
									
										
										
										
											2022-06-14 18:36:22 +08:00
										 |  |  |  |         "keys_version": 2, | 
					
						
							|  |  |  |  |         "descr": 4, | 
					
						
							| 
									
										
										
										
											2022-05-06 07:18:09 -07: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) | 
					
						
							|  |  |  |  | ] |