blob: fc02f4c580dd553daf3a890119523d65dc3df865 [file] [log] [blame]
Damien George04b91472014-05-03 23:27:38 +01001/*
2 * This file is part of the Micro Python project, http://micropython.org/
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (c) 2013, 2014 Damien P. George
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 */
26
Damienf03001f2013-11-17 13:19:33 +000027#include <stdio.h>
Damienf03001f2013-11-17 13:19:33 +000028#include <assert.h>
29
Damiend99b0522013-12-21 18:17:45 +000030#include "mpconfig.h"
Paul Sokolovskyf54bcbf2014-05-02 17:47:01 +030031#include "misc.h"
Damien George55baff42014-01-21 21:40:13 +000032#include "qstr.h"
Damiend99b0522013-12-21 18:17:45 +000033#include "bc0.h"
Damienf03001f2013-11-17 13:19:33 +000034
Damien Georgecbd2f742014-01-19 11:48:48 +000035#if MICROPY_DEBUG_PRINTERS
Damien Georged3ebe482014-01-07 15:20:33 +000036
Paul Sokolovsky1d30b112014-02-21 02:31:05 +020037#define DECODE_UINT { \
38 unum = 0; \
39 do { \
40 unum = (unum << 7) + (*ip & 0x7f); \
41 } while ((*ip++ & 0x80) != 0); \
42}
Damienf03001f2013-11-17 13:19:33 +000043#define DECODE_ULABEL do { unum = (ip[0] | (ip[1] << 8)); ip += 2; } while (0)
44#define DECODE_SLABEL do { unum = (ip[0] | (ip[1] << 8)) - 0x8000; ip += 2; } while (0)
Paul Sokolovsky1d30b112014-02-21 02:31:05 +020045#define DECODE_QSTR { \
46 qstr = 0; \
47 do { \
48 qstr = (qstr << 7) + (*ip & 0x7f); \
49 } while ((*ip++ & 0x80) != 0); \
50}
Damien George3d484d92014-04-13 11:22:44 +010051#define DECODE_PTR do { \
52 ip = (byte*)(((machine_uint_t)ip + sizeof(machine_uint_t) - 1) & (~(sizeof(machine_uint_t) - 1))); /* align ip */ \
53 unum = *(machine_uint_t*)ip; \
54 ip += sizeof(machine_uint_t); \
55} while (0)
Damienf03001f2013-11-17 13:19:33 +000056
Damien George3417bc22014-05-10 10:36:38 +010057void mp_bytecode_print2(const byte *ip, int len);
Paul Sokolovskyc5e32c62014-04-23 03:40:24 +030058
Damien George3417bc22014-05-10 10:36:38 +010059void mp_bytecode_print(const byte *ip, int len) {
Damienf03001f2013-11-17 13:19:33 +000060 const byte *ip_start = ip;
Damien George6baf76e2013-12-30 22:32:17 +000061
Damien George08335002014-01-18 23:24:36 +000062 // get code info size
63 machine_uint_t code_info_size = ip[0] | (ip[1] << 8) | (ip[2] << 16) | (ip[3] << 24);
Damien George73496fb2014-04-13 14:51:56 +010064 const byte *code_info = ip;
Damien George08335002014-01-18 23:24:36 +000065 ip += code_info_size;
66
Damien George440f0412014-03-28 18:38:20 +000067 // bytecode prelude: state size and exception stack size; 16 bit uints
68 {
69 uint n_state = ip[0] | (ip[1] << 8);
70 uint n_exc_stack = ip[2] | (ip[3] << 8);
71 ip += 4;
72 printf("(N_STATE %u)\n", n_state);
73 printf("(N_EXC_STACK %u)\n", n_exc_stack);
74 }
75
76 // bytecode prelude: initialise closed over variables
Damien George6baf76e2013-12-30 22:32:17 +000077 {
78 uint n_local = *ip++;
79 printf("(NUM_LOCAL %u)\n", n_local);
80 for (; n_local > 0; n_local--) {
81 uint local_num = *ip++;
82 printf("(INIT_CELL %u)\n", local_num);
83 }
84 len -= ip - ip_start;
85 ip_start = ip;
86 }
87
Damien George73496fb2014-04-13 14:51:56 +010088 // print out line number info
89 {
90 qstr source_file = code_info[4] | (code_info[5] << 8) | (code_info[6] << 16) | (code_info[7] << 24);
91 qstr block_name = code_info[8] | (code_info[9] << 8) | (code_info[10] << 16) | (code_info[11] << 24);
Paul Sokolovsky41870682014-05-04 22:39:40 +030092 printf("File %s, block '%s'\n", qstr_str(source_file), qstr_str(block_name));
Damien George73496fb2014-04-13 14:51:56 +010093 machine_int_t bc = (code_info + code_info_size) - ip;
94 machine_uint_t source_line = 1;
95 printf(" bc=" INT_FMT " line=" UINT_FMT "\n", bc, source_line);
96 for (const byte* ci = code_info + 12; *ci; ci++) {
97 bc += *ci & 31;
98 source_line += *ci >> 5;
99 printf(" bc=" INT_FMT " line=" UINT_FMT "\n", bc, source_line);
100 }
101 }
Damien George3417bc22014-05-10 10:36:38 +0100102 mp_bytecode_print2(ip, len - 0);
Paul Sokolovskyc5e32c62014-04-23 03:40:24 +0300103}
Damien George73496fb2014-04-13 14:51:56 +0100104
Damien George3417bc22014-05-10 10:36:38 +0100105void mp_bytecode_print2(const byte *ip, int len) {
Paul Sokolovskyc5e32c62014-04-23 03:40:24 +0300106 const byte *ip_start = ip;
Damienf03001f2013-11-17 13:19:33 +0000107 machine_uint_t unum;
108 qstr qstr;
109 while (ip - ip_start < len) {
110 printf("%02u ", (uint)(ip - ip_start));
111 int op = *ip++;
112 switch (op) {
Damiend99b0522013-12-21 18:17:45 +0000113 case MP_BC_LOAD_CONST_FALSE:
Damienf03001f2013-11-17 13:19:33 +0000114 printf("LOAD_CONST_FALSE");
115 break;
116
Damiend99b0522013-12-21 18:17:45 +0000117 case MP_BC_LOAD_CONST_NONE:
Damienf03001f2013-11-17 13:19:33 +0000118 printf("LOAD_CONST_NONE");
119 break;
120
Damiend99b0522013-12-21 18:17:45 +0000121 case MP_BC_LOAD_CONST_TRUE:
Damienf03001f2013-11-17 13:19:33 +0000122 printf("LOAD_CONST_TRUE");
123 break;
124
Damien Georgee9906ac2014-01-04 18:44:46 +0000125 case MP_BC_LOAD_CONST_ELLIPSIS:
126 printf("LOAD_CONST_ELLIPSIS");
127 break;
128
Paul Sokolovsky047cd402014-02-19 15:47:59 +0200129 case MP_BC_LOAD_CONST_SMALL_INT: {
Damien George0379b552014-02-22 17:34:09 +0000130 machine_int_t num = 0;
Paul Sokolovsky047cd402014-02-19 15:47:59 +0200131 if ((ip[0] & 0x40) != 0) {
132 // Number is negative
133 num--;
134 }
135 do {
136 num = (num << 7) | (*ip & 0x7f);
137 } while ((*ip++ & 0x80) != 0);
Damien George0379b552014-02-22 17:34:09 +0000138 printf("LOAD_CONST_SMALL_INT " INT_FMT, num);
Damienf03001f2013-11-17 13:19:33 +0000139 break;
Paul Sokolovsky047cd402014-02-19 15:47:59 +0200140 }
Damienf03001f2013-11-17 13:19:33 +0000141
Paul Sokolovsky4b919d02014-01-10 04:16:50 +0200142 case MP_BC_LOAD_CONST_INT:
143 DECODE_QSTR;
144 printf("LOAD_CONST_INT %s", qstr_str(qstr));
145 break;
146
Damiend99b0522013-12-21 18:17:45 +0000147 case MP_BC_LOAD_CONST_DEC:
Damienf03001f2013-11-17 13:19:33 +0000148 DECODE_QSTR;
Damien George08d07552014-01-29 18:58:52 +0000149 printf("LOAD_CONST_DEC %s", qstr_str(qstr));
Damienf03001f2013-11-17 13:19:33 +0000150 break;
151
Paul Sokolovskyb9b1c002014-04-12 00:34:57 +0300152 case MP_BC_LOAD_CONST_BYTES:
153 DECODE_QSTR;
154 printf("LOAD_CONST_BYTES %s", qstr_str(qstr));
155 break;
156
Damiend99b0522013-12-21 18:17:45 +0000157 case MP_BC_LOAD_CONST_STRING:
Damienf03001f2013-11-17 13:19:33 +0000158 DECODE_QSTR;
Paul Sokolovskyfaf84492014-04-12 16:18:40 +0300159 printf("LOAD_CONST_STRING '%s'", qstr_str(qstr));
Damienf03001f2013-11-17 13:19:33 +0000160 break;
Damienf03001f2013-11-17 13:19:33 +0000161
Paul Sokolovsky00a9d132014-04-12 00:32:38 +0300162 case MP_BC_LOAD_NULL:
163 printf("LOAD_NULL");
164 break;
165
Damiend99b0522013-12-21 18:17:45 +0000166 case MP_BC_LOAD_FAST_0:
Damienf03001f2013-11-17 13:19:33 +0000167 printf("LOAD_FAST_0");
168 break;
169
Damiend99b0522013-12-21 18:17:45 +0000170 case MP_BC_LOAD_FAST_1:
Damienf03001f2013-11-17 13:19:33 +0000171 printf("LOAD_FAST_1");
172 break;
173
Damiend99b0522013-12-21 18:17:45 +0000174 case MP_BC_LOAD_FAST_2:
Damienf03001f2013-11-17 13:19:33 +0000175 printf("LOAD_FAST_2");
176 break;
177
Damiend99b0522013-12-21 18:17:45 +0000178 case MP_BC_LOAD_FAST_N:
Damienf03001f2013-11-17 13:19:33 +0000179 DECODE_UINT;
Paul Sokolovskye85c3892013-12-30 03:38:32 +0200180 printf("LOAD_FAST_N " UINT_FMT, unum);
Damienf03001f2013-11-17 13:19:33 +0000181 break;
Damienf03001f2013-11-17 13:19:33 +0000182
Damien George6baf76e2013-12-30 22:32:17 +0000183 case MP_BC_LOAD_DEREF:
184 DECODE_UINT;
185 printf("LOAD_DEREF " UINT_FMT, unum);
186 break;
187
Damiend99b0522013-12-21 18:17:45 +0000188 case MP_BC_LOAD_NAME:
Damienf03001f2013-11-17 13:19:33 +0000189 DECODE_QSTR;
190 printf("LOAD_NAME %s", qstr_str(qstr));
191 break;
192
Damiend99b0522013-12-21 18:17:45 +0000193 case MP_BC_LOAD_GLOBAL:
Damienf03001f2013-11-17 13:19:33 +0000194 DECODE_QSTR;
195 printf("LOAD_GLOBAL %s", qstr_str(qstr));
196 break;
197
Damiend99b0522013-12-21 18:17:45 +0000198 case MP_BC_LOAD_ATTR:
Damienf03001f2013-11-17 13:19:33 +0000199 DECODE_QSTR;
Damienc1075dd2013-11-25 23:39:36 +0000200 printf("LOAD_ATTR %s", qstr_str(qstr));
Damienf03001f2013-11-17 13:19:33 +0000201 break;
Damienf03001f2013-11-17 13:19:33 +0000202
Damiend99b0522013-12-21 18:17:45 +0000203 case MP_BC_LOAD_METHOD:
Damienf03001f2013-11-17 13:19:33 +0000204 DECODE_QSTR;
205 printf("LOAD_METHOD %s", qstr_str(qstr));
206 break;
207
Damiend99b0522013-12-21 18:17:45 +0000208 case MP_BC_LOAD_BUILD_CLASS:
Damienc1075dd2013-11-25 23:39:36 +0000209 printf("LOAD_BUILD_CLASS");
Damienf03001f2013-11-17 13:19:33 +0000210 break;
Damienf03001f2013-11-17 13:19:33 +0000211
Damien George729f7b42014-04-17 22:10:53 +0100212 case MP_BC_LOAD_SUBSCR:
213 printf("LOAD_SUBSCR");
214 break;
215
Damiend99b0522013-12-21 18:17:45 +0000216 case MP_BC_STORE_FAST_0:
Damienf03001f2013-11-17 13:19:33 +0000217 printf("STORE_FAST_0");
218 break;
219
Damiend99b0522013-12-21 18:17:45 +0000220 case MP_BC_STORE_FAST_1:
Damienf03001f2013-11-17 13:19:33 +0000221 printf("STORE_FAST_1");
222 break;
223
Damiend99b0522013-12-21 18:17:45 +0000224 case MP_BC_STORE_FAST_2:
Damienf03001f2013-11-17 13:19:33 +0000225 printf("STORE_FAST_2");
226 break;
227
Damiend99b0522013-12-21 18:17:45 +0000228 case MP_BC_STORE_FAST_N:
Damienf03001f2013-11-17 13:19:33 +0000229 DECODE_UINT;
Paul Sokolovskye85c3892013-12-30 03:38:32 +0200230 printf("STORE_FAST_N " UINT_FMT, unum);
Damienf03001f2013-11-17 13:19:33 +0000231 break;
Damienf03001f2013-11-17 13:19:33 +0000232
Damien George6baf76e2013-12-30 22:32:17 +0000233 case MP_BC_STORE_DEREF:
234 DECODE_UINT;
235 printf("STORE_DEREF " UINT_FMT, unum);
236 break;
237
Damiend99b0522013-12-21 18:17:45 +0000238 case MP_BC_STORE_NAME:
Damienf03001f2013-11-17 13:19:33 +0000239 DECODE_QSTR;
240 printf("STORE_NAME %s", qstr_str(qstr));
241 break;
242
Damiend99b0522013-12-21 18:17:45 +0000243 case MP_BC_STORE_GLOBAL:
Damienf03001f2013-11-17 13:19:33 +0000244 DECODE_QSTR;
Damien George66028ab2014-01-03 14:03:48 +0000245 printf("STORE_GLOBAL %s", qstr_str(qstr));
Damienf03001f2013-11-17 13:19:33 +0000246 break;
247
Damiend99b0522013-12-21 18:17:45 +0000248 case MP_BC_STORE_ATTR:
Damienf03001f2013-11-17 13:19:33 +0000249 DECODE_QSTR;
Damienc1075dd2013-11-25 23:39:36 +0000250 printf("STORE_ATTR %s", qstr_str(qstr));
Damienf03001f2013-11-17 13:19:33 +0000251 break;
252
Damiend99b0522013-12-21 18:17:45 +0000253 case MP_BC_STORE_SUBSCR:
Damienff099f32013-11-26 15:14:50 +0000254 printf("STORE_SUBSCR");
Damienf03001f2013-11-17 13:19:33 +0000255 break;
256
Damien George2bf7c092014-04-09 15:26:46 +0100257 case MP_BC_DELETE_FAST:
258 DECODE_UINT;
259 printf("DELETE_FAST " UINT_FMT, unum);
260 break;
261
262 case MP_BC_DELETE_DEREF:
263 DECODE_UINT;
264 printf("DELETE_DEREF " UINT_FMT, unum);
265 break;
266
Damien Georgeddaf6c12014-02-06 20:31:32 +0000267 case MP_BC_DELETE_NAME:
268 DECODE_QSTR;
269 printf("DELETE_NAME %s", qstr_str(qstr));
270 break;
271
Damiend99b0522013-12-21 18:17:45 +0000272 case MP_BC_DUP_TOP:
Damien8f9e2ee2013-12-29 16:54:59 +0000273 printf("DUP_TOP");
Damienf03001f2013-11-17 13:19:33 +0000274 break;
275
Damiend99b0522013-12-21 18:17:45 +0000276 case MP_BC_DUP_TOP_TWO:
Damienff099f32013-11-26 15:14:50 +0000277 printf("DUP_TOP_TWO");
Damienf03001f2013-11-17 13:19:33 +0000278 break;
Damienf03001f2013-11-17 13:19:33 +0000279
Damiend99b0522013-12-21 18:17:45 +0000280 case MP_BC_POP_TOP:
Damienf03001f2013-11-17 13:19:33 +0000281 printf("POP_TOP");
282 break;
283
Damiend99b0522013-12-21 18:17:45 +0000284 case MP_BC_ROT_TWO:
Paul Sokolovsky4b919d02014-01-10 04:16:50 +0200285 printf("ROT_TWO");
Damienf03001f2013-11-17 13:19:33 +0000286 break;
287
Damiend99b0522013-12-21 18:17:45 +0000288 case MP_BC_ROT_THREE:
Damienff099f32013-11-26 15:14:50 +0000289 printf("ROT_THREE");
Damienf03001f2013-11-17 13:19:33 +0000290 break;
Damienf03001f2013-11-17 13:19:33 +0000291
Damiend99b0522013-12-21 18:17:45 +0000292 case MP_BC_JUMP:
Damienf03001f2013-11-17 13:19:33 +0000293 DECODE_SLABEL;
Paul Sokolovskye85c3892013-12-30 03:38:32 +0200294 printf("JUMP " UINT_FMT, ip + unum - ip_start);
Damienf03001f2013-11-17 13:19:33 +0000295 break;
296
Damiend99b0522013-12-21 18:17:45 +0000297 case MP_BC_POP_JUMP_IF_TRUE:
Damienf03001f2013-11-17 13:19:33 +0000298 DECODE_SLABEL;
Paul Sokolovskye85c3892013-12-30 03:38:32 +0200299 printf("POP_JUMP_IF_TRUE " UINT_FMT, ip + unum - ip_start);
Damienf03001f2013-11-17 13:19:33 +0000300 break;
301
Damiend99b0522013-12-21 18:17:45 +0000302 case MP_BC_POP_JUMP_IF_FALSE:
Damienf03001f2013-11-17 13:19:33 +0000303 DECODE_SLABEL;
Paul Sokolovskye85c3892013-12-30 03:38:32 +0200304 printf("POP_JUMP_IF_FALSE " UINT_FMT, ip + unum - ip_start);
Damienf03001f2013-11-17 13:19:33 +0000305 break;
306
Damiend99b0522013-12-21 18:17:45 +0000307 case MP_BC_JUMP_IF_TRUE_OR_POP:
Damienf03001f2013-11-17 13:19:33 +0000308 DECODE_SLABEL;
Damien Georgee02b2d42014-01-19 01:14:37 +0000309 printf("JUMP_IF_TRUE_OR_POP " UINT_FMT, ip + unum - ip_start);
Damienf03001f2013-11-17 13:19:33 +0000310 break;
311
Damiend99b0522013-12-21 18:17:45 +0000312 case MP_BC_JUMP_IF_FALSE_OR_POP:
Damienf03001f2013-11-17 13:19:33 +0000313 DECODE_SLABEL;
Damien Georgee02b2d42014-01-19 01:14:37 +0000314 printf("JUMP_IF_FALSE_OR_POP " UINT_FMT, ip + unum - ip_start);
Damienf03001f2013-11-17 13:19:33 +0000315 break;
316
Paul Sokolovsky182c31a2014-03-27 12:29:34 +0200317 case MP_BC_SETUP_WITH:
318 DECODE_ULABEL; // loop-like labels are always forward
319 printf("SETUP_WITH " UINT_FMT, ip + unum - ip_start);
320 break;
321
322 case MP_BC_WITH_CLEANUP:
323 printf("WITH_CLEANUP");
324 break;
325
Damien Georgecbddb272014-02-01 20:08:18 +0000326 case MP_BC_UNWIND_JUMP:
327 DECODE_SLABEL;
328 printf("UNWIND_JUMP " UINT_FMT " %d", ip + unum - ip_start, *ip);
329 ip += 1;
Paul Sokolovsky7ee8e462014-01-31 19:33:31 +0200330 break;
331
Damiend99b0522013-12-21 18:17:45 +0000332 case MP_BC_SETUP_EXCEPT:
Damienf03001f2013-11-17 13:19:33 +0000333 DECODE_ULABEL; // except labels are always forward
Paul Sokolovskye85c3892013-12-30 03:38:32 +0200334 printf("SETUP_EXCEPT " UINT_FMT, ip + unum - ip_start);
Damienf03001f2013-11-17 13:19:33 +0000335 break;
336
Paul Sokolovsky7ee8e462014-01-31 19:33:31 +0200337 case MP_BC_SETUP_FINALLY:
338 DECODE_ULABEL; // except labels are always forward
339 printf("SETUP_FINALLY " UINT_FMT, ip + unum - ip_start);
340 break;
341
Damiend99b0522013-12-21 18:17:45 +0000342 case MP_BC_END_FINALLY:
Damienf03001f2013-11-17 13:19:33 +0000343 // if TOS is an exception, reraises the exception (3 values on TOS)
344 // if TOS is an integer, does something else
345 // if TOS is None, just pops it and continues
346 // else error
Damien8f9e2ee2013-12-29 16:54:59 +0000347 printf("END_FINALLY");
Damienf03001f2013-11-17 13:19:33 +0000348 break;
349
Damiend99b0522013-12-21 18:17:45 +0000350 case MP_BC_GET_ITER:
Damienff099f32013-11-26 15:14:50 +0000351 printf("GET_ITER");
Damienf03001f2013-11-17 13:19:33 +0000352 break;
353
Damiend99b0522013-12-21 18:17:45 +0000354 case MP_BC_FOR_ITER:
Damienf03001f2013-11-17 13:19:33 +0000355 DECODE_ULABEL; // the jump offset if iteration finishes; for labels are always forward
Paul Sokolovskye85c3892013-12-30 03:38:32 +0200356 printf("FOR_ITER " UINT_FMT, ip + unum - ip_start);
Damienf03001f2013-11-17 13:19:33 +0000357 break;
358
Damiend99b0522013-12-21 18:17:45 +0000359 case MP_BC_POP_BLOCK:
Damienf03001f2013-11-17 13:19:33 +0000360 // pops block and restores the stack
Damien8f9e2ee2013-12-29 16:54:59 +0000361 printf("POP_BLOCK");
Damienf03001f2013-11-17 13:19:33 +0000362 break;
363
Damiend99b0522013-12-21 18:17:45 +0000364 case MP_BC_POP_EXCEPT:
Damienf03001f2013-11-17 13:19:33 +0000365 // pops block, checks it's an exception block, and restores the stack, saving the 3 exception values to local threadstate
Damien8f9e2ee2013-12-29 16:54:59 +0000366 printf("POP_EXCEPT");
Damienf03001f2013-11-17 13:19:33 +0000367 break;
368
Damien George9aa2a522014-02-01 23:04:09 +0000369 case MP_BC_NOT:
370 printf("NOT");
371 break;
372
Damiend99b0522013-12-21 18:17:45 +0000373 case MP_BC_UNARY_OP:
Damienf03001f2013-11-17 13:19:33 +0000374 unum = *ip++;
Damien George9aa2a522014-02-01 23:04:09 +0000375 printf("UNARY_OP " UINT_FMT, unum);
Damienf03001f2013-11-17 13:19:33 +0000376 break;
Damienf03001f2013-11-17 13:19:33 +0000377
Damiend99b0522013-12-21 18:17:45 +0000378 case MP_BC_BINARY_OP:
Damienf03001f2013-11-17 13:19:33 +0000379 unum = *ip++;
Paul Sokolovskye85c3892013-12-30 03:38:32 +0200380 printf("BINARY_OP " UINT_FMT, unum);
Damienf03001f2013-11-17 13:19:33 +0000381 break;
382
Damiend99b0522013-12-21 18:17:45 +0000383 case MP_BC_BUILD_TUPLE:
Damienf03001f2013-11-17 13:19:33 +0000384 DECODE_UINT;
Paul Sokolovskye85c3892013-12-30 03:38:32 +0200385 printf("BUILD_TUPLE " UINT_FMT, unum);
Damienf03001f2013-11-17 13:19:33 +0000386 break;
387
Damiend99b0522013-12-21 18:17:45 +0000388 case MP_BC_BUILD_LIST:
Damienf03001f2013-11-17 13:19:33 +0000389 DECODE_UINT;
Paul Sokolovskye85c3892013-12-30 03:38:32 +0200390 printf("BUILD_LIST " UINT_FMT, unum);
Damienf03001f2013-11-17 13:19:33 +0000391 break;
392
Damiend99b0522013-12-21 18:17:45 +0000393 case MP_BC_LIST_APPEND:
Damienf03001f2013-11-17 13:19:33 +0000394 DECODE_UINT;
Damien George27bf5b82014-01-02 18:15:33 +0000395 printf("LIST_APPEND " UINT_FMT, unum);
Damienf03001f2013-11-17 13:19:33 +0000396 break;
397
Damiend99b0522013-12-21 18:17:45 +0000398 case MP_BC_BUILD_MAP:
Damienf03001f2013-11-17 13:19:33 +0000399 DECODE_UINT;
Paul Sokolovskye85c3892013-12-30 03:38:32 +0200400 printf("BUILD_MAP " UINT_FMT, unum);
Damienf03001f2013-11-17 13:19:33 +0000401 break;
402
Damiend99b0522013-12-21 18:17:45 +0000403 case MP_BC_STORE_MAP:
Damien George20006db2014-01-18 14:10:48 +0000404 printf("STORE_MAP");
Damienf03001f2013-11-17 13:19:33 +0000405 break;
406
Damiend99b0522013-12-21 18:17:45 +0000407 case MP_BC_MAP_ADD:
Damienf03001f2013-11-17 13:19:33 +0000408 DECODE_UINT;
Paul Sokolovsky0f570cf2014-05-11 19:25:01 +0300409 printf("MAP_ADD " UINT_FMT, unum);
Damienf03001f2013-11-17 13:19:33 +0000410 break;
411
Damiend99b0522013-12-21 18:17:45 +0000412 case MP_BC_BUILD_SET:
Damienf03001f2013-11-17 13:19:33 +0000413 DECODE_UINT;
Damien George212c2962013-12-30 12:52:32 +0000414 printf("BUILD_SET " UINT_FMT, unum);
Damienf03001f2013-11-17 13:19:33 +0000415 break;
416
Damiend99b0522013-12-21 18:17:45 +0000417 case MP_BC_SET_ADD:
Damienf03001f2013-11-17 13:19:33 +0000418 DECODE_UINT;
Damien George212c2962013-12-30 12:52:32 +0000419 printf("SET_ADD " UINT_FMT, unum);
Damienf03001f2013-11-17 13:19:33 +0000420 break;
Damienf03001f2013-11-17 13:19:33 +0000421
Damien Georgefb510b32014-06-01 13:32:54 +0100422#if MICROPY_PY_BUILTINS_SLICE
Damien George20006db2014-01-18 14:10:48 +0000423 case MP_BC_BUILD_SLICE:
424 DECODE_UINT;
425 printf("BUILD_SLICE " UINT_FMT, unum);
426 break;
427#endif
428
Damiend99b0522013-12-21 18:17:45 +0000429 case MP_BC_UNPACK_SEQUENCE:
Damienff099f32013-11-26 15:14:50 +0000430 DECODE_UINT;
Paul Sokolovskye85c3892013-12-30 03:38:32 +0200431 printf("UNPACK_SEQUENCE " UINT_FMT, unum);
Damienff099f32013-11-26 15:14:50 +0000432 break;
433
Damiend99b0522013-12-21 18:17:45 +0000434 case MP_BC_MAKE_FUNCTION:
Damien George3d484d92014-04-13 11:22:44 +0100435 DECODE_PTR;
Paul Sokolovskye85c3892013-12-30 03:38:32 +0200436 printf("MAKE_FUNCTION " UINT_FMT, unum);
Damienf03001f2013-11-17 13:19:33 +0000437 break;
438
Paul Sokolovsky90750022014-02-01 15:05:04 +0200439 case MP_BC_MAKE_FUNCTION_DEFARGS:
Damien George3d484d92014-04-13 11:22:44 +0100440 DECODE_PTR;
Paul Sokolovsky90750022014-02-01 15:05:04 +0200441 printf("MAKE_FUNCTION_DEFARGS " UINT_FMT, unum);
442 break;
443
Paul Sokolovsky4c6b3752014-04-23 03:22:10 +0300444 case MP_BC_MAKE_CLOSURE: {
Damien George3d484d92014-04-13 11:22:44 +0100445 DECODE_PTR;
Paul Sokolovsky4c6b3752014-04-23 03:22:10 +0300446 machine_uint_t n_closed_over = *ip++;
447 printf("MAKE_CLOSURE " UINT_FMT " " UINT_FMT, unum, n_closed_over);
Damien George6baf76e2013-12-30 22:32:17 +0000448 break;
Paul Sokolovsky4c6b3752014-04-23 03:22:10 +0300449 }
Damien George6baf76e2013-12-30 22:32:17 +0000450
Paul Sokolovsky4c6b3752014-04-23 03:22:10 +0300451 case MP_BC_MAKE_CLOSURE_DEFARGS: {
Damien George3d484d92014-04-13 11:22:44 +0100452 DECODE_PTR;
Paul Sokolovsky4c6b3752014-04-23 03:22:10 +0300453 machine_uint_t n_closed_over = *ip++;
454 printf("MAKE_CLOSURE_DEFARGS " UINT_FMT " " UINT_FMT, unum, n_closed_over);
Paul Sokolovsky2447a5b2014-03-26 23:14:59 +0200455 break;
Paul Sokolovsky4c6b3752014-04-23 03:22:10 +0300456 }
Paul Sokolovsky2447a5b2014-03-26 23:14:59 +0200457
Damiend99b0522013-12-21 18:17:45 +0000458 case MP_BC_CALL_FUNCTION:
Damienf03001f2013-11-17 13:19:33 +0000459 DECODE_UINT;
Paul Sokolovskye85c3892013-12-30 03:38:32 +0200460 printf("CALL_FUNCTION n=" UINT_FMT " nkw=" UINT_FMT, unum & 0xff, (unum >> 8) & 0xff);
Damienf03001f2013-11-17 13:19:33 +0000461 break;
462
Paul Sokolovsky48bdb212014-03-30 17:39:25 +0300463 case MP_BC_CALL_FUNCTION_VAR_KW:
464 DECODE_UINT;
465 printf("CALL_FUNCTION_VAR_KW n=" UINT_FMT " nkw=" UINT_FMT, unum & 0xff, (unum >> 8) & 0xff);
466 break;
467
Damiend99b0522013-12-21 18:17:45 +0000468 case MP_BC_CALL_METHOD:
Damienf03001f2013-11-17 13:19:33 +0000469 DECODE_UINT;
Paul Sokolovskye85c3892013-12-30 03:38:32 +0200470 printf("CALL_METHOD n=" UINT_FMT " nkw=" UINT_FMT, unum & 0xff, (unum >> 8) & 0xff);
Damienf03001f2013-11-17 13:19:33 +0000471 break;
472
Paul Sokolovsky48bdb212014-03-30 17:39:25 +0300473 case MP_BC_CALL_METHOD_VAR_KW:
474 DECODE_UINT;
475 printf("CALL_METHOD_VAR_KW n=" UINT_FMT " nkw=" UINT_FMT, unum & 0xff, (unum >> 8) & 0xff);
476 break;
477
Damiend99b0522013-12-21 18:17:45 +0000478 case MP_BC_RETURN_VALUE:
Damienf03001f2013-11-17 13:19:33 +0000479 printf("RETURN_VALUE");
480 break;
481
Paul Sokolovsky4b919d02014-01-10 04:16:50 +0200482 case MP_BC_RAISE_VARARGS:
483 unum = *ip++;
484 printf("RAISE_VARARGS " UINT_FMT, unum);
485 break;
486
Damiend99b0522013-12-21 18:17:45 +0000487 case MP_BC_YIELD_VALUE:
Damien George27bf5b82014-01-02 18:15:33 +0000488 printf("YIELD_VALUE");
489 break;
Damienf03001f2013-11-17 13:19:33 +0000490
Paul Sokolovskyda8d21e2014-03-22 13:47:06 +0200491 case MP_BC_YIELD_FROM:
492 printf("YIELD_FROM");
493 break;
494
Damien George66028ab2014-01-03 14:03:48 +0000495 case MP_BC_IMPORT_NAME:
496 DECODE_QSTR;
Paul Sokolovskyfaf84492014-04-12 16:18:40 +0300497 printf("IMPORT_NAME '%s'", qstr_str(qstr));
Damien George66028ab2014-01-03 14:03:48 +0000498 break;
499
500 case MP_BC_IMPORT_FROM:
501 DECODE_QSTR;
Paul Sokolovskyfaf84492014-04-12 16:18:40 +0300502 printf("IMPORT_FROM '%s'", qstr_str(qstr));
Damien George66028ab2014-01-03 14:03:48 +0000503 break;
504
Paul Sokolovskyda1ce932014-02-14 00:22:06 +0200505 case MP_BC_IMPORT_STAR:
506 printf("IMPORT_STAR");
507 break;
508
Damienf03001f2013-11-17 13:19:33 +0000509 default:
510 printf("code %p, byte code 0x%02x not implemented\n", ip, op);
511 assert(0);
512 return;
513 }
514 printf("\n");
515 }
516}
Damien Georged3ebe482014-01-07 15:20:33 +0000517
Damien Georgecbd2f742014-01-19 11:48:48 +0000518#endif // MICROPY_DEBUG_PRINTERS