35
35
opmap = {}
36
36
opname = ['<%r>' % (op ,) for op in range (256 )]
37
37
38
- _inline_cache_entries = [0 ] * 256
39
-
40
- def def_op (name , op , entries = 0 ):
38
+ def def_op (name , op ):
41
39
opname [op ] = name
42
40
opmap [name ] = op
43
- _inline_cache_entries [op ] = entries
44
41
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 )
47
44
hasname .append (op )
48
45
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 )
51
48
hasjrel .append (op )
52
49
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 )
55
52
hasjabs .append (op )
56
53
57
54
# Instruction opcodes for compiled code
@@ -68,7 +65,7 @@ def jabs_op(name, op, entries=0):
68
65
69
66
def_op ('UNARY_INVERT' , 15 )
70
67
71
- def_op ('BINARY_SUBSCR' , 25 , 4 )
68
+ def_op ('BINARY_SUBSCR' , 25 )
72
69
73
70
def_op ('GET_LEN' , 30 )
74
71
def_op ('MATCH_MAPPING' , 31 )
@@ -86,7 +83,7 @@ def jabs_op(name, op, entries=0):
86
83
def_op ('BEFORE_WITH' , 53 )
87
84
def_op ('END_ASYNC_FOR' , 54 )
88
85
89
- def_op ('STORE_SUBSCR' , 60 , 1 )
86
+ def_op ('STORE_SUBSCR' , 60 )
90
87
def_op ('DELETE_SUBSCR' , 61 )
91
88
92
89
def_op ('GET_ITER' , 68 )
@@ -110,10 +107,10 @@ def jabs_op(name, op, entries=0):
110
107
111
108
name_op ('STORE_NAME' , 90 ) # Index in name list
112
109
name_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
114
111
jrel_op ('FOR_ITER' , 93 )
115
112
def_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
117
114
name_op ('DELETE_ATTR' , 96 ) # ""
118
115
name_op ('STORE_GLOBAL' , 97 ) # ""
119
116
name_op ('DELETE_GLOBAL' , 98 ) # ""
@@ -125,8 +122,8 @@ def jabs_op(name, op, entries=0):
125
122
def_op ('BUILD_LIST' , 103 ) # Number of list items
126
123
def_op ('BUILD_SET' , 104 ) # Number of set items
127
124
def_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
130
127
hascompare .append (107 )
131
128
name_op ('IMPORT_NAME' , 108 ) # Index in name list
132
129
name_op ('IMPORT_FROM' , 109 ) # Index in name list
@@ -135,12 +132,12 @@ def jabs_op(name, op, entries=0):
135
132
jrel_op ('JUMP_IF_TRUE_OR_POP' , 112 ) # ""
136
133
jrel_op ('POP_JUMP_FORWARD_IF_FALSE' , 114 )
137
134
jrel_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
139
136
def_op ('IS_OP' , 117 )
140
137
def_op ('CONTAINS_OP' , 118 )
141
138
def_op ('RERAISE' , 119 )
142
139
def_op ('COPY' , 120 )
143
- def_op ('BINARY_OP' , 122 , 1 )
140
+ def_op ('BINARY_OP' , 122 )
144
141
jrel_op ('SEND' , 123 ) # Number of bytes to skip
145
142
def_op ('LOAD_FAST' , 124 ) # Local variable number
146
143
haslocal .append (124 )
@@ -185,15 +182,15 @@ def jabs_op(name, op, entries=0):
185
182
def_op ('BUILD_CONST_KEY_MAP' , 156 )
186
183
def_op ('BUILD_STRING' , 157 )
187
184
188
- name_op ('LOAD_METHOD' , 160 , 10 )
185
+ name_op ('LOAD_METHOD' , 160 )
189
186
190
187
def_op ('LIST_EXTEND' , 162 )
191
188
def_op ('SET_UPDATE' , 163 )
192
189
def_op ('DICT_MERGE' , 164 )
193
190
def_op ('DICT_UPDATE' , 165 )
194
- def_op ('PRECALL' , 166 , 1 )
191
+ def_op ('PRECALL' , 166 )
195
192
196
- def_op ('CALL' , 171 , 4 )
193
+ def_op ('CALL' , 171 )
197
194
def_op ('KW_NAMES' , 172 )
198
195
hasconst .append (172 )
199
196
@@ -352,3 +349,59 @@ def jabs_op(name, op, entries=0):
352
349
"miss" ,
353
350
"deopt" ,
354
351
]
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