Skip to content

Commit ff099f3

Browse files
committed
py: add more functionality to showbc.
1 parent d47f9d5 commit ff099f3

File tree

1 file changed

+25
-46
lines changed

1 file changed

+25
-46
lines changed

py/showbc.c

Lines changed: 25 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,10 @@ void py_show_byte_code(const byte *ip, int len) {
5252
printf("LOAD_CONST_ID %s", qstr_str(qstr));
5353
break;
5454

55-
/*
5655
case PYBC_LOAD_CONST_STRING:
5756
DECODE_QSTR;
58-
PUSH(rt_load_const_str(qstr));
57+
printf("LOAD_CONST_STRING %s", qstr_str(qstr));
5958
break;
60-
*/
6159

6260
case PYBC_LOAD_FAST_0:
6361
printf("LOAD_FAST_0");
@@ -71,12 +69,10 @@ void py_show_byte_code(const byte *ip, int len) {
7169
printf("LOAD_FAST_2");
7270
break;
7371

74-
/*
7572
case PYBC_LOAD_FAST_N:
7673
DECODE_UINT;
77-
PUSH(fastn[unum]);
74+
printf("LOAD_FAST_N %lu", unum);
7875
break;
79-
*/
8076

8177
case PYBC_LOAD_NAME:
8278
DECODE_QSTR;
@@ -114,12 +110,10 @@ void py_show_byte_code(const byte *ip, int len) {
114110
printf("STORE_FAST_2");
115111
break;
116112

117-
/*
118113
case PYBC_STORE_FAST_N:
119114
DECODE_UINT;
120-
fastn[unum] = POP();
115+
printf("STORE_FAST_N %lu", unum);
121116
break;
122-
*/
123117

124118
case PYBC_STORE_NAME:
125119
DECODE_QSTR;
@@ -138,23 +132,20 @@ void py_show_byte_code(const byte *ip, int len) {
138132
printf("STORE_ATTR %s", qstr_str(qstr));
139133
break;
140134

141-
/*
142135
case PYBC_STORE_SUBSCR:
143-
rt_store_subscr(sp[1], sp[0], sp[2]);
144-
sp += 3;
136+
printf("STORE_SUBSCR");
145137
break;
146138

139+
/*
147140
case PYBC_DUP_TOP:
148141
obj1 = *sp;
149142
PUSH(obj1);
150143
break;
144+
*/
151145

152146
case PYBC_DUP_TOP_TWO:
153-
sp -= 2;
154-
sp[0] = sp[2];
155-
sp[1] = sp[3];
147+
printf("DUP_TOP_TWO");
156148
break;
157-
*/
158149

159150
case PYBC_POP_TOP:
160151
printf("POP_TOP");
@@ -166,14 +157,11 @@ void py_show_byte_code(const byte *ip, int len) {
166157
sp[0] = sp[1];
167158
sp[1] = obj1;
168159
break;
160+
*/
169161

170162
case PYBC_ROT_THREE:
171-
obj1 = sp[0];
172-
sp[0] = sp[1];
173-
sp[1] = sp[2];
174-
sp[2] = obj1;
163+
printf("ROT_THREE");
175164
break;
176-
*/
177165

178166
case PYBC_JUMP:
179167
DECODE_SLABEL;
@@ -185,14 +173,12 @@ void py_show_byte_code(const byte *ip, int len) {
185173
printf("POP_JUMP_IF_TRUE %lu", ip + unum - ip_start);
186174
break;
187175

188-
/*
189176
case PYBC_POP_JUMP_IF_FALSE:
190177
DECODE_SLABEL;
191-
if (!rt_is_true(POP())) {
192-
ip += unum;
193-
}
178+
printf("POP_JUMP_IF_FALSE %lu", ip + unum - ip_start);
194179
break;
195180

181+
/*
196182
case PYBC_JUMP_IF_TRUE_OR_POP:
197183
DECODE_SLABEL;
198184
if (rt_is_true(*sp)) {
@@ -225,22 +211,18 @@ void py_show_byte_code(const byte *ip, int len) {
225211
// else error
226212
assert(0);
227213
break;
214+
*/
228215

229216
case PYBC_GET_ITER:
230-
*sp = rt_getiter(*sp);
217+
printf("GET_ITER");
231218
break;
232219

233220
case PYBC_FOR_ITER:
234221
DECODE_ULABEL; // the jump offset if iteration finishes; for labels are always forward
235-
obj1 = rt_iternext(*sp);
236-
if (obj1 == py_const_stop_iteration) {
237-
++sp; // pop the exhausted iterator
238-
ip += unum; // jump to after for-block
239-
} else {
240-
PUSH(obj1); // push the next iteration value
241-
}
222+
printf("FOR_ITER %lu", ip + unum - ip_start);
242223
break;
243224

225+
/*
244226
case PYBC_POP_BLOCK:
245227
// pops block and restores the stack
246228
assert(0);
@@ -272,21 +254,17 @@ void py_show_byte_code(const byte *ip, int len) {
272254
printf("COMPARE_OP %lu", unum);
273255
break;
274256

275-
/*
276257
case PYBC_BUILD_TUPLE:
277258
DECODE_UINT;
278-
obj1 = rt_build_tuple(unum, sp);
279-
sp += unum - 1;
280-
*sp = obj1;
259+
printf("BUILD_TUPLE %lu", unum);
281260
break;
282261

283262
case PYBC_BUILD_LIST:
284263
DECODE_UINT;
285-
obj1 = rt_build_list(unum, sp);
286-
sp += unum - 1;
287-
*sp = obj1;
264+
printf("BUILD_LIST %lu", unum);
288265
break;
289266

267+
/*
290268
case PYBC_LIST_APPEND:
291269
DECODE_UINT;
292270
// I think it's guaranteed by the compiler that sp[unum] is a list
@@ -326,23 +304,24 @@ void py_show_byte_code(const byte *ip, int len) {
326304
break;
327305
*/
328306

307+
case PYBC_UNPACK_SEQUENCE:
308+
DECODE_UINT;
309+
printf("UNPACK_SEQUENCE %lu", unum);
310+
break;
311+
329312
case PYBC_MAKE_FUNCTION:
330313
DECODE_UINT;
331314
printf("MAKE_FUNCTION %lu", unum);
332315
break;
333316

334317
case PYBC_CALL_FUNCTION:
335318
DECODE_UINT;
336-
assert((unum & 0xff00) == 0); // n_keyword
337-
unum &= 0xff; // n_positional
338-
printf("CALL_FUNCTION %lu", unum);
319+
printf("CALL_FUNCTION n=%lu nkw=%lu", unum & 0xff, (unum >> 8) & 0xff);
339320
break;
340321

341322
case PYBC_CALL_METHOD:
342323
DECODE_UINT;
343-
assert((unum & 0xff00) == 0); // n_keyword
344-
unum &= 0xff;
345-
printf("CALL_METHOD %lu", unum);
324+
printf("CALL_METHOD n=%lu nkw=%lu", unum & 0xff, (unum >> 8) & 0xff);
346325
break;
347326

348327
case PYBC_RETURN_VALUE:

0 commit comments

Comments
 (0)