3535opmap = {}
3636opname = ['<%r>' % (op ,) for op in range (256 )]
3737
38- _inline_cache_entries = [0 ] * 256
39-
40- def def_op (name , op , entries = 0 ):
38+ def def_op (name , op ):
4139 opname [op ] = name
4240 opmap [name ] = op
43- _inline_cache_entries [op ] = entries
4441
45- def name_op (name , op , entries = 0 ):
46- def_op (name , op , entries )
42+ def name_op (name , op ):
43+ def_op (name , op )
4744 hasname .append (op )
4845
49- def jrel_op (name , op , entries = 0 ):
50- def_op (name , op , entries )
46+ def jrel_op (name , op ):
47+ def_op (name , op )
5148 hasjrel .append (op )
5249
53- def jabs_op (name , op , entries = 0 ):
54- def_op (name , op , entries )
50+ def jabs_op (name , op ):
51+ def_op (name , op )
5552 hasjabs .append (op )
5653
5754# Instruction opcodes for compiled code
@@ -68,7 +65,7 @@ def jabs_op(name, op, entries=0):
6865
6966def_op ('UNARY_INVERT' , 15 )
7067
71- def_op ('BINARY_SUBSCR' , 25 , 4 )
68+ def_op ('BINARY_SUBSCR' , 25 )
7269
7370def_op ('GET_LEN' , 30 )
7471def_op ('MATCH_MAPPING' , 31 )
@@ -86,7 +83,7 @@ def jabs_op(name, op, entries=0):
8683def_op ('BEFORE_WITH' , 53 )
8784def_op ('END_ASYNC_FOR' , 54 )
8885
89- def_op ('STORE_SUBSCR' , 60 , 1 )
86+ def_op ('STORE_SUBSCR' , 60 )
9087def_op ('DELETE_SUBSCR' , 61 )
9188
9289def_op ('GET_ITER' , 68 )
@@ -110,10 +107,10 @@ def jabs_op(name, op, entries=0):
110107
111108name_op ('STORE_NAME' , 90 ) # Index in name list
112109name_op ('DELETE_NAME' , 91 ) # ""
113- def_op ('UNPACK_SEQUENCE' , 92 , 1 ) # Number of tuple items
110+ def_op ('UNPACK_SEQUENCE' , 92 ) # Number of tuple items
114111jrel_op ('FOR_ITER' , 93 )
115112def_op ('UNPACK_EX' , 94 )
116- name_op ('STORE_ATTR' , 95 , 4 ) # Index in name list
113+ name_op ('STORE_ATTR' , 95 ) # Index in name list
117114name_op ('DELETE_ATTR' , 96 ) # ""
118115name_op ('STORE_GLOBAL' , 97 ) # ""
119116name_op ('DELETE_GLOBAL' , 98 ) # ""
@@ -125,8 +122,8 @@ def jabs_op(name, op, entries=0):
125122def_op ('BUILD_LIST' , 103 ) # Number of list items
126123def_op ('BUILD_SET' , 104 ) # Number of set items
127124def_op ('BUILD_MAP' , 105 ) # Number of dict entries
128- name_op ('LOAD_ATTR' , 106 , 4 ) # Index in name list
129- def_op ('COMPARE_OP' , 107 , 2 ) # Comparison operator
125+ name_op ('LOAD_ATTR' , 106 ) # Index in name list
126+ def_op ('COMPARE_OP' , 107 ) # Comparison operator
130127hascompare .append (107 )
131128name_op ('IMPORT_NAME' , 108 ) # Index in name list
132129name_op ('IMPORT_FROM' , 109 ) # Index in name list
@@ -135,12 +132,12 @@ def jabs_op(name, op, entries=0):
135132jrel_op ('JUMP_IF_TRUE_OR_POP' , 112 ) # ""
136133jrel_op ('POP_JUMP_FORWARD_IF_FALSE' , 114 )
137134jrel_op ('POP_JUMP_FORWARD_IF_TRUE' , 115 )
138- name_op ('LOAD_GLOBAL' , 116 , 5 ) # Index in name list
135+ name_op ('LOAD_GLOBAL' , 116 ) # Index in name list
139136def_op ('IS_OP' , 117 )
140137def_op ('CONTAINS_OP' , 118 )
141138def_op ('RERAISE' , 119 )
142139def_op ('COPY' , 120 )
143- def_op ('BINARY_OP' , 122 , 1 )
140+ def_op ('BINARY_OP' , 122 )
144141jrel_op ('SEND' , 123 ) # Number of bytes to skip
145142def_op ('LOAD_FAST' , 124 ) # Local variable number
146143haslocal .append (124 )
@@ -185,15 +182,15 @@ def jabs_op(name, op, entries=0):
185182def_op ('BUILD_CONST_KEY_MAP' , 156 )
186183def_op ('BUILD_STRING' , 157 )
187184
188- name_op ('LOAD_METHOD' , 160 , 10 )
185+ name_op ('LOAD_METHOD' , 160 )
189186
190187def_op ('LIST_EXTEND' , 162 )
191188def_op ('SET_UPDATE' , 163 )
192189def_op ('DICT_MERGE' , 164 )
193190def_op ('DICT_UPDATE' , 165 )
194- def_op ('PRECALL' , 166 , 1 )
191+ def_op ('PRECALL' , 166 )
195192
196- def_op ('CALL' , 171 , 4 )
193+ def_op ('CALL' , 171 )
197194def_op ('KW_NAMES' , 172 )
198195hasconst .append (172 )
199196
@@ -352,3 +349,59 @@ def jabs_op(name, op, entries=0):
352349 "miss" ,
353350 "deopt" ,
354351]
352+
353+ _cache_format = {
354+ "LOAD_GLOBAL" : {
355+ "counter" : 1 ,
356+ "index" : 1 ,
357+ "module_keys_version" : 2 ,
358+ "builtin_keys_version" : 1 ,
359+ },
360+ "BINARY_OP" : {
361+ "counter" : 1 ,
362+ },
363+ "UNPACK_SEQUENCE" : {
364+ "counter" : 1 ,
365+ },
366+ "COMPARE_OP" : {
367+ "counter" : 1 ,
368+ "mask" : 1 ,
369+ },
370+ "BINARY_SUBSCR" : {
371+ "counter" : 1 ,
372+ "type_version" : 2 ,
373+ "func_version" : 1 ,
374+ },
375+ "LOAD_ATTR" : {
376+ "counter" : 1 ,
377+ "version" : 2 ,
378+ "index" : 1 ,
379+ },
380+ "STORE_ATTR" : {
381+ "counter" : 1 ,
382+ "version" : 2 ,
383+ "index" : 1 ,
384+ },
385+ "LOAD_METHOD" : {
386+ "counter" : 1 ,
387+ "type_version" : 2 ,
388+ "dict_offset" : 1 ,
389+ "keys_version" : 2 ,
390+ "descr" : 4 ,
391+ },
392+ "CALL" : {
393+ "counter" : 1 ,
394+ "func_version" : 2 ,
395+ "min_args" : 1 ,
396+ },
397+ "PRECALL" : {
398+ "counter" : 1 ,
399+ },
400+ "STORE_SUBSCR" : {
401+ "counter" : 1 ,
402+ },
403+ }
404+
405+ _inline_cache_entries = [
406+ sum (_cache_format .get (opname [opcode ], {}).values ()) for opcode in range (256 )
407+ ]
0 commit comments