blob: 010219d12f5dff6f57e09cec268c5e60637f709d [file] [log] [blame]
xbeefe34222014-03-16 00:14:26 -07001#include <stdbool.h>
Damien429d7192013-10-04 19:53:11 +01002#include <stdint.h>
3#include <stdio.h>
4#include <string.h>
5#include <assert.h>
6
7#include "misc.h"
Damiend99b0522013-12-21 18:17:45 +00008#include "mpconfig.h"
Damien George55baff42014-01-21 21:40:13 +00009#include "qstr.h"
Damien429d7192013-10-04 19:53:11 +010010#include "lexer.h"
Damien429d7192013-10-04 19:53:11 +010011#include "parse.h"
Damien Georgedf8127a2014-04-13 11:04:33 +010012#include "obj.h"
13#include "emitglue.h"
Damien429d7192013-10-04 19:53:11 +010014#include "scope.h"
Damiend99b0522013-12-21 18:17:45 +000015#include "runtime0.h"
Damien429d7192013-10-04 19:53:11 +010016#include "emit.h"
17
Damien Georgee67ed5d2014-01-04 13:55:24 +000018// wrapper around everything in this file
Damien3ef4abb2013-10-12 16:53:13 +010019#if MICROPY_EMIT_CPYTHON
Damien429d7192013-10-04 19:53:11 +010020
Damien415eb6f2013-10-05 12:19:06 +010021struct _emit_t {
Damien429d7192013-10-04 19:53:11 +010022 int pass;
Damien429d7192013-10-04 19:53:11 +010023 int byte_code_offset;
24 int stack_size;
25 bool last_emit_was_return_value;
26
27 scope_t *scope;
28
Damienb05d7072013-10-05 13:37:10 +010029 uint max_num_labels;
Damien429d7192013-10-04 19:53:11 +010030 int *label_offsets;
31};
32
Damien6cdd3af2013-10-05 18:08:26 +010033emit_t *emit_cpython_new(uint max_num_labels) {
34 emit_t *emit = m_new(emit_t, 1);
35 emit->max_num_labels = max_num_labels;
36 emit->label_offsets = m_new(int, max_num_labels);
37 return emit;
38}
39
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020040STATIC void emit_cpy_set_native_types(emit_t *emit, bool do_native_types) {
Damien429d7192013-10-04 19:53:11 +010041}
42
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020043STATIC void emit_cpy_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) {
Damien429d7192013-10-04 19:53:11 +010044 emit->pass = pass;
Damien429d7192013-10-04 19:53:11 +010045 emit->byte_code_offset = 0;
46 emit->stack_size = 0;
47 emit->last_emit_was_return_value = false;
48 emit->scope = scope;
Damienb05d7072013-10-05 13:37:10 +010049 if (pass == PASS_2) {
50 memset(emit->label_offsets, -1, emit->max_num_labels * sizeof(int));
Damien429d7192013-10-04 19:53:11 +010051 }
52}
53
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020054STATIC void emit_cpy_end_pass(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +010055 // check stack is back to zero size
56 if (emit->stack_size != 0) {
57 printf("ERROR: stack size not back to zero; got %d\n", emit->stack_size);
58 }
Damien429d7192013-10-04 19:53:11 +010059}
60
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020061STATIC bool emit_cpy_last_emit_was_return_value(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +010062 return emit->last_emit_was_return_value;
63}
64
Damien Georged66ae182014-04-10 17:28:54 +000065STATIC void emit_cpy_adjust_stack_size(emit_t *emit, int delta) {
66 emit->stack_size += delta;
Damien429d7192013-10-04 19:53:11 +010067}
68
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020069STATIC void emit_cpy_set_source_line(emit_t *emit, int source_line) {
Damien George08335002014-01-18 23:24:36 +000070}
71
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020072STATIC void emit_cpy_load_id(emit_t *emit, qstr qstr) {
Damien6cdd3af2013-10-05 18:08:26 +010073 emit_common_load_id(emit, &emit_cpython_method_table, emit->scope, qstr);
Damien4b03e772013-10-05 14:17:09 +010074}
75
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020076STATIC void emit_cpy_store_id(emit_t *emit, qstr qstr) {
Damien6cdd3af2013-10-05 18:08:26 +010077 emit_common_store_id(emit, &emit_cpython_method_table, emit->scope, qstr);
Damien4b03e772013-10-05 14:17:09 +010078}
79
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020080STATIC void emit_cpy_delete_id(emit_t *emit, qstr qstr) {
Damien6cdd3af2013-10-05 18:08:26 +010081 emit_common_delete_id(emit, &emit_cpython_method_table, emit->scope, qstr);
Damien4b03e772013-10-05 14:17:09 +010082}
83
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020084// TODO: module-polymorphic function (read: name clash if made global)
Damien415eb6f2013-10-05 12:19:06 +010085static void emit_pre(emit_t *emit, int stack_size_delta, int byte_code_size) {
Damien429d7192013-10-04 19:53:11 +010086 emit->stack_size += stack_size_delta;
Damienb05d7072013-10-05 13:37:10 +010087 if (emit->stack_size > emit->scope->stack_size) {
Damien429d7192013-10-04 19:53:11 +010088 emit->scope->stack_size = emit->stack_size;
89 }
90 emit->last_emit_was_return_value = false;
91 if (emit->pass == PASS_3 && byte_code_size > 0) {
92 if (emit->byte_code_offset >= 1000) {
93 printf("%d ", emit->byte_code_offset);
94 } else {
95 printf("% 4d ", emit->byte_code_offset);
96 }
97 }
98 emit->byte_code_offset += byte_code_size;
99}
100
Damien George6f355fd2014-04-10 14:11:31 +0100101STATIC void emit_cpy_label_assign(emit_t *emit, uint l) {
Damien429d7192013-10-04 19:53:11 +0100102 emit_pre(emit, 0, 0);
Damienb05d7072013-10-05 13:37:10 +0100103 assert(l < emit->max_num_labels);
104 if (emit->pass == PASS_2) {
105 // assign label offset
106 assert(emit->label_offsets[l] == -1);
107 emit->label_offsets[l] = emit->byte_code_offset;
108 } else if (emit->pass == PASS_3) {
109 // ensure label offset has not changed from PASS_2 to PASS_3
110 assert(emit->label_offsets[l] == emit->byte_code_offset);
111 //printf("l%d: (at %d)\n", l, emit->byte_code_offset);
Damien429d7192013-10-04 19:53:11 +0100112 }
113}
114
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200115STATIC void emit_cpy_import_name(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100116 emit_pre(emit, -1, 3);
117 if (emit->pass == PASS_3) {
118 printf("IMPORT_NAME %s\n", qstr_str(qstr));
119 }
120}
121
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200122STATIC void emit_cpy_import_from(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100123 emit_pre(emit, 1, 3);
124 if (emit->pass == PASS_3) {
125 printf("IMPORT_FROM %s\n", qstr_str(qstr));
126 }
127}
128
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200129STATIC void emit_cpy_import_star(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100130 emit_pre(emit, -1, 1);
131 if (emit->pass == PASS_3) {
132 printf("IMPORT_STAR\n");
133 }
134}
135
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200136STATIC void emit_cpy_load_const_tok(emit_t *emit, mp_token_kind_t tok) {
Damien429d7192013-10-04 19:53:11 +0100137 emit_pre(emit, 1, 3);
138 if (emit->pass == PASS_3) {
139 printf("LOAD_CONST ");
140 switch (tok) {
Damiend99b0522013-12-21 18:17:45 +0000141 case MP_TOKEN_KW_FALSE: printf("False"); break;
142 case MP_TOKEN_KW_NONE: printf("None"); break;
143 case MP_TOKEN_KW_TRUE: printf("True"); break;
Damien429d7192013-10-04 19:53:11 +0100144 default: printf("?=%d\n", tok); return; assert(0);
145 }
146 printf("\n");
147 }
148}
149
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200150STATIC void emit_cpy_load_const_small_int(emit_t *emit, machine_int_t arg) {
Damien429d7192013-10-04 19:53:11 +0100151 emit_pre(emit, 1, 3);
152 if (emit->pass == PASS_3) {
Damien George08d07552014-01-29 18:58:52 +0000153 printf("LOAD_CONST " INT_FMT "\n", arg);
Damien429d7192013-10-04 19:53:11 +0100154 }
155}
156
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200157STATIC void emit_cpy_load_const_int(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100158 emit_pre(emit, 1, 3);
159 if (emit->pass == PASS_3) {
160 printf("LOAD_CONST %s\n", qstr_str(qstr));
161 }
162}
163
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200164STATIC void emit_cpy_load_const_dec(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100165 emit_pre(emit, 1, 3);
166 if (emit->pass == PASS_3) {
167 printf("LOAD_CONST %s\n", qstr_str(qstr));
168 }
169}
170
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200171STATIC void emit_cpy_load_const_id(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100172 emit_pre(emit, 1, 3);
173 if (emit->pass == PASS_3) {
174 printf("LOAD_CONST '%s'\n", qstr_str(qstr));
175 }
176}
177
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200178STATIC void print_quoted_str(qstr qstr, bool bytes) {
Damiena1b26932013-12-12 15:34:40 +0000179 const char *str = qstr_str(qstr);
180 int len = strlen(str);
181 bool has_single_quote = false;
182 bool has_double_quote = false;
183 for (int i = 0; i < len; i++) {
184 if (str[i] == '\'') {
185 has_single_quote = true;
186 } else if (str[i] == '"') {
187 has_double_quote = true;
188 }
189 }
190 if (bytes) {
191 printf("b");
192 }
Damien Georgeb829b5c2014-01-25 13:51:19 +0000193 int quote_char = '\'';
Damiena1b26932013-12-12 15:34:40 +0000194 if (has_single_quote && !has_double_quote) {
Damien Georgeb829b5c2014-01-25 13:51:19 +0000195 quote_char = '"';
Damiena1b26932013-12-12 15:34:40 +0000196 }
Damien Georgeb829b5c2014-01-25 13:51:19 +0000197 printf("%c", quote_char);
198 for (const char *s = str, *top = str + len; s < top; s++) {
199 if (*s == quote_char) {
200 printf("\\%c", quote_char);
201 } else if (*s == '\\') {
Damiena1b26932013-12-12 15:34:40 +0000202 printf("\\\\");
Damien Georgeb829b5c2014-01-25 13:51:19 +0000203 } else if (32 <= *s && *s <= 126) {
204 printf("%c", *s);
205 } else if (*s == '\n') {
206 printf("\\n");
207 // TODO add more escape codes here
Damiena1b26932013-12-12 15:34:40 +0000208 } else {
Damien Georgeb829b5c2014-01-25 13:51:19 +0000209 printf("\\x%02x", (*s) & 0xff);
Damiena1b26932013-12-12 15:34:40 +0000210 }
211 }
Damien Georgeb829b5c2014-01-25 13:51:19 +0000212 printf("%c", quote_char);
Damiena1b26932013-12-12 15:34:40 +0000213}
214
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200215STATIC void emit_cpy_load_const_str(emit_t *emit, qstr qstr, bool bytes) {
Damien429d7192013-10-04 19:53:11 +0100216 emit_pre(emit, 1, 3);
217 if (emit->pass == PASS_3) {
218 printf("LOAD_CONST ");
Damiena1b26932013-12-12 15:34:40 +0000219 print_quoted_str(qstr, bytes);
Damien429d7192013-10-04 19:53:11 +0100220 printf("\n");
221 }
222}
223
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200224STATIC void emit_cpy_load_const_verbatim_str(emit_t *emit, const char *str) {
Damiena1b26932013-12-12 15:34:40 +0000225 emit_pre(emit, 1, 3);
Damien429d7192013-10-04 19:53:11 +0100226 if (emit->pass == PASS_3) {
Damiena1b26932013-12-12 15:34:40 +0000227 printf("LOAD_CONST %s\n", str);
Damien429d7192013-10-04 19:53:11 +0100228 }
229}
230
Damien Georgee2835c12014-04-09 20:20:34 +0100231STATIC void emit_cpy_load_fast(emit_t *emit, qstr qstr, uint id_flags, int local_num) {
Damien6cdd3af2013-10-05 18:08:26 +0100232 emit_pre(emit, 1, 3);
233 if (emit->pass == PASS_3) {
234 printf("LOAD_FAST %d %s\n", local_num, qstr_str(qstr));
235 }
236}
237
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200238STATIC void emit_cpy_load_deref(emit_t *emit, qstr qstr, int local_num) {
Damien429d7192013-10-04 19:53:11 +0100239 emit_pre(emit, 1, 3);
240 if (emit->pass == PASS_3) {
Damien27fb45e2013-10-20 15:07:49 +0100241 printf("LOAD_DEREF %d %s\n", local_num, qstr_str(qstr));
Damien429d7192013-10-04 19:53:11 +0100242 }
243}
244
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200245STATIC void emit_cpy_load_closure(emit_t *emit, qstr qstr, int local_num) {
Damien429d7192013-10-04 19:53:11 +0100246 emit_pre(emit, 1, 3);
247 if (emit->pass == PASS_3) {
Damien27fb45e2013-10-20 15:07:49 +0100248 printf("LOAD_CLOSURE %d %s\n", local_num, qstr_str(qstr));
Damien429d7192013-10-04 19:53:11 +0100249 }
250}
251
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200252STATIC void emit_cpy_load_name(emit_t *emit, qstr qstr) {
Damien9ecbcff2013-12-11 00:41:43 +0000253 emit_pre(emit, 1, 3);
254 if (emit->pass == PASS_3) {
255 printf("LOAD_NAME %s\n", qstr_str(qstr));
256 }
257}
258
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200259STATIC void emit_cpy_load_global(emit_t *emit, qstr qstr) {
Damien9ecbcff2013-12-11 00:41:43 +0000260 emit_pre(emit, 1, 3);
261 if (emit->pass == PASS_3) {
262 printf("LOAD_GLOBAL %s\n", qstr_str(qstr));
263 }
264}
265
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200266STATIC void emit_cpy_load_attr(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100267 emit_pre(emit, 0, 3);
268 if (emit->pass == PASS_3) {
269 printf("LOAD_ATTR %s\n", qstr_str(qstr));
270 }
271}
272
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200273STATIC void emit_cpy_load_method(emit_t *emit, qstr qstr) {
Damien415eb6f2013-10-05 12:19:06 +0100274 emit_cpy_load_attr(emit, qstr);
Damien429d7192013-10-04 19:53:11 +0100275}
276
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200277STATIC void emit_cpy_load_build_class(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100278 emit_pre(emit, 1, 1);
279 if (emit->pass == PASS_3) {
280 printf("LOAD_BUILD_CLASS\n");
281 }
282}
283
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200284STATIC void emit_cpy_store_fast(emit_t *emit, qstr qstr, int local_num) {
Damien6cdd3af2013-10-05 18:08:26 +0100285 emit_pre(emit, -1, 3);
286 if (emit->pass == PASS_3) {
287 printf("STORE_FAST %d %s\n", local_num, qstr_str(qstr));
288 }
289}
290
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200291STATIC void emit_cpy_store_deref(emit_t *emit, qstr qstr, int local_num) {
Damien9ecbcff2013-12-11 00:41:43 +0000292 emit_pre(emit, -1, 3);
293 if (emit->pass == PASS_3) {
294 printf("STORE_DEREF %d %s\n", local_num, qstr_str(qstr));
295 }
296}
297
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200298STATIC void emit_cpy_store_name(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100299 emit_pre(emit, -1, 3);
300 if (emit->pass == PASS_3) {
301 printf("STORE_NAME %s\n", qstr_str(qstr));
302 }
303}
304
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200305STATIC void emit_cpy_store_global(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100306 emit_pre(emit, -1, 3);
307 if (emit->pass == PASS_3) {
308 printf("STORE_GLOBAL %s\n", qstr_str(qstr));
309 }
310}
311
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200312STATIC void emit_cpy_store_attr(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100313 emit_pre(emit, -2, 3);
314 if (emit->pass == PASS_3) {
315 printf("STORE_ATTR %s\n", qstr_str(qstr));
316 }
317}
318
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200319STATIC void emit_cpy_store_subscr(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100320 emit_pre(emit, -3, 1);
321 if (emit->pass == PASS_3) {
322 printf("STORE_SUBSCR\n");
323 }
324}
325
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200326STATIC void emit_cpy_delete_fast(emit_t *emit, qstr qstr, int local_num) {
Damien6cdd3af2013-10-05 18:08:26 +0100327 emit_pre(emit, 0, 3);
328 if (emit->pass == PASS_3) {
329 printf("DELETE_FAST %d %s\n", local_num, qstr_str(qstr));
330 }
331}
332
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200333STATIC void emit_cpy_delete_deref(emit_t *emit, qstr qstr, int local_num) {
Damien9ecbcff2013-12-11 00:41:43 +0000334 emit_pre(emit, 0, 3);
335 if (emit->pass == PASS_3) {
336 printf("DELETE_DEREF %d %s\n", local_num, qstr_str(qstr));
337 }
338}
339
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200340STATIC void emit_cpy_delete_name(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100341 emit_pre(emit, 0, 3);
342 if (emit->pass == PASS_3) {
343 printf("DELETE_NAME %s\n", qstr_str(qstr));
344 }
345}
346
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200347STATIC void emit_cpy_delete_global(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100348 emit_pre(emit, 0, 3);
349 if (emit->pass == PASS_3) {
350 printf("DELETE_GLOBAL %s\n", qstr_str(qstr));
351 }
352}
353
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200354STATIC void emit_cpy_delete_attr(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100355 emit_pre(emit, -1, 3);
356 if (emit->pass == PASS_3) {
357 printf("DELETE_ATTR %s\n", qstr_str(qstr));
358 }
359}
360
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200361STATIC void emit_cpy_delete_subscr(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100362 emit_pre(emit, -2, 1);
363 if (emit->pass == PASS_3) {
364 printf("DELETE_SUBSCR\n");
365 }
366}
367
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200368STATIC void emit_cpy_dup_top(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100369 emit_pre(emit, 1, 1);
370 if (emit->pass == PASS_3) {
371 printf("DUP_TOP\n");
372 }
373}
374
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200375STATIC void emit_cpy_dup_top_two(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100376 emit_pre(emit, 2, 1);
377 if (emit->pass == PASS_3) {
378 printf("DUP_TOP_TWO\n");
379 }
380}
381
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200382STATIC void emit_cpy_pop_top(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100383 emit_pre(emit, -1, 1);
384 if (emit->pass == PASS_3) {
385 printf("POP_TOP\n");
386 }
387}
388
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200389STATIC void emit_cpy_rot_two(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100390 emit_pre(emit, 0, 1);
391 if (emit->pass == PASS_3) {
392 printf("ROT_TWO\n");
393 }
394}
395
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200396STATIC void emit_cpy_rot_three(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100397 emit_pre(emit, 0, 1);
398 if (emit->pass == PASS_3) {
399 printf("ROT_THREE\n");
400 }
401}
402
Damien George6f355fd2014-04-10 14:11:31 +0100403STATIC void emit_cpy_jump(emit_t *emit, uint label) {
Damien429d7192013-10-04 19:53:11 +0100404 emit_pre(emit, 0, 3);
405 if (emit->pass == PASS_3) {
406 int dest = emit->label_offsets[label];
407 if (dest < emit->byte_code_offset) {
408 printf("JUMP_ABSOLUTE %d\n", emit->label_offsets[label]);
409 } else {
410 printf("JUMP_FORWARD %d\n", emit->label_offsets[label]);
411 }
412 }
413}
414
Damien George6f355fd2014-04-10 14:11:31 +0100415STATIC void emit_cpy_pop_jump_if_true(emit_t *emit, uint label) {
Damien429d7192013-10-04 19:53:11 +0100416 emit_pre(emit, -1, 3);
417 if (emit->pass == PASS_3) {
418 printf("POP_JUMP_IF_TRUE %d\n", emit->label_offsets[label]);
419 }
420}
421
Damien George6f355fd2014-04-10 14:11:31 +0100422STATIC void emit_cpy_pop_jump_if_false(emit_t *emit, uint label) {
Damien429d7192013-10-04 19:53:11 +0100423 emit_pre(emit, -1, 3);
424 if (emit->pass == PASS_3) {
425 printf("POP_JUMP_IF_FALSE %d\n", emit->label_offsets[label]);
426 }
427}
428
Damien George6f355fd2014-04-10 14:11:31 +0100429STATIC void emit_cpy_jump_if_true_or_pop(emit_t *emit, uint label) {
Damien429d7192013-10-04 19:53:11 +0100430 emit_pre(emit, -1, 3);
431 if (emit->pass == PASS_3) {
432 printf("JUMP_IF_TRUE_OR_POP %d\n", emit->label_offsets[label]);
433 }
434}
435
Damien George6f355fd2014-04-10 14:11:31 +0100436STATIC void emit_cpy_jump_if_false_or_pop(emit_t *emit, uint label) {
Damien429d7192013-10-04 19:53:11 +0100437 emit_pre(emit, -1, 3);
438 if (emit->pass == PASS_3) {
439 printf("JUMP_IF_FALSE_OR_POP %d\n", emit->label_offsets[label]);
440 }
441}
442
Damien George6f355fd2014-04-10 14:11:31 +0100443STATIC void emit_cpy_setup_loop(emit_t *emit, uint label) {
Damien429d7192013-10-04 19:53:11 +0100444 emit_pre(emit, 0, 3);
445 if (emit->pass == PASS_3) {
446 printf("SETUP_LOOP %d\n", emit->label_offsets[label]);
447 }
448}
449
Damien George6f355fd2014-04-10 14:11:31 +0100450STATIC void emit_cpy_break_loop(emit_t *emit, uint label, int except_depth) {
Damien429d7192013-10-04 19:53:11 +0100451 emit_pre(emit, 0, 1);
452 if (emit->pass == PASS_3) {
Damien Georgee24b5632014-02-01 21:56:25 +0000453 printf("BREAK_LOOP\n");
Damien429d7192013-10-04 19:53:11 +0100454 }
455}
456
Damien George6f355fd2014-04-10 14:11:31 +0100457STATIC void emit_cpy_continue_loop(emit_t *emit, uint label, int except_depth) {
Damien Georgee24b5632014-02-01 21:56:25 +0000458 if (except_depth == 0) {
459 emit_cpy_jump(emit, label);
460 } else {
461 emit_pre(emit, 0, 3);
462 if (emit->pass == PASS_3) {
463 printf("CONTINUE_LOOP %d\n", emit->label_offsets[label]);
464 }
Damien429d7192013-10-04 19:53:11 +0100465 }
466}
467
Damien George6f355fd2014-04-10 14:11:31 +0100468STATIC void emit_cpy_setup_with(emit_t *emit, uint label) {
Damien429d7192013-10-04 19:53:11 +0100469 emit_pre(emit, 7, 3);
470 if (emit->pass == PASS_3) {
471 printf("SETUP_WITH %d\n", emit->label_offsets[label]);
472 }
473}
474
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200475STATIC void emit_cpy_with_cleanup(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100476 emit_pre(emit, -7, 1);
477 if (emit->pass == PASS_3) {
478 printf("WITH_CLEANUP\n");
479 }
480}
481
Damien George6f355fd2014-04-10 14:11:31 +0100482STATIC void emit_cpy_setup_except(emit_t *emit, uint label) {
Damien George069a35e2014-04-10 17:22:19 +0000483 emit_pre(emit, 0, 3);
Damien429d7192013-10-04 19:53:11 +0100484 if (emit->pass == PASS_3) {
485 printf("SETUP_EXCEPT %d\n", emit->label_offsets[label]);
486 }
487}
488
Damien George6f355fd2014-04-10 14:11:31 +0100489STATIC void emit_cpy_setup_finally(emit_t *emit, uint label) {
Damien George069a35e2014-04-10 17:22:19 +0000490 emit_pre(emit, 0, 3);
Damien429d7192013-10-04 19:53:11 +0100491 if (emit->pass == PASS_3) {
492 printf("SETUP_FINALLY %d\n", emit->label_offsets[label]);
493 }
494}
495
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200496STATIC void emit_cpy_end_finally(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100497 emit_pre(emit, -1, 1);
498 if (emit->pass == PASS_3) {
499 printf("END_FINALLY\n");
500 }
501}
502
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200503STATIC void emit_cpy_get_iter(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100504 emit_pre(emit, 0, 1);
505 if (emit->pass == PASS_3) {
506 printf("GET_ITER\n");
507 }
508}
509
Damien George6f355fd2014-04-10 14:11:31 +0100510STATIC void emit_cpy_for_iter(emit_t *emit, uint label) {
Damien429d7192013-10-04 19:53:11 +0100511 emit_pre(emit, 1, 3);
512 if (emit->pass == PASS_3) {
513 printf("FOR_ITER %d\n", emit->label_offsets[label]);
514 }
515}
516
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200517STATIC void emit_cpy_for_iter_end(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100518 emit_pre(emit, -1, 0);
519}
520
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200521STATIC void emit_cpy_pop_block(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100522 emit_pre(emit, 0, 1);
523 if (emit->pass == PASS_3) {
524 printf("POP_BLOCK\n");
525 }
526}
527
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200528STATIC void emit_cpy_pop_except(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100529 emit_pre(emit, 0, 1);
530 if (emit->pass == PASS_3) {
531 printf("POP_EXCEPT\n");
532 }
533}
534
Damien Georged17926d2014-03-30 13:35:08 +0100535STATIC void emit_cpy_unary_op(emit_t *emit, mp_unary_op_t op) {
Damien429d7192013-10-04 19:53:11 +0100536 emit_pre(emit, 0, 1);
537 if (emit->pass == PASS_3) {
538 switch (op) {
Damien Georged17926d2014-03-30 13:35:08 +0100539 case MP_UNARY_OP_POSITIVE: printf("UNARY_POSITIVE\n"); break;
540 case MP_UNARY_OP_NEGATIVE: printf("UNARY_NEGATIVE\n"); break;
541 case MP_UNARY_OP_INVERT: printf("UNARY_INVERT\n"); break;
542 case MP_UNARY_OP_NOT: printf("UNARY_NOT\n"); break;
Damien429d7192013-10-04 19:53:11 +0100543 default: assert(0);
544 }
545 }
546}
547
Damien Georged17926d2014-03-30 13:35:08 +0100548STATIC void emit_cpy_binary_op(emit_t *emit, mp_binary_op_t op) {
549 if (op <= MP_BINARY_OP_INPLACE_POWER) {
Damien Georgebc1d3692014-01-11 09:47:06 +0000550 // CPython uses a byte code for each binary op
551 emit_pre(emit, -1, 1);
552 } else {
553 // CPython uses a byte code plus an argument for compare ops
554 emit_pre(emit, -1, 3);
555 }
Damien429d7192013-10-04 19:53:11 +0100556 if (emit->pass == PASS_3) {
557 switch (op) {
Damien Georged17926d2014-03-30 13:35:08 +0100558 case MP_BINARY_OP_SUBSCR: printf("BINARY_SUBSCR\n"); break;
559 case MP_BINARY_OP_OR: printf("BINARY_OR\n"); break;
560 case MP_BINARY_OP_XOR: printf("BINARY_XOR\n"); break;
561 case MP_BINARY_OP_AND: printf("BINARY_AND\n"); break;
562 case MP_BINARY_OP_LSHIFT: printf("BINARY_LSHIFT\n"); break;
563 case MP_BINARY_OP_RSHIFT: printf("BINARY_RSHIFT\n"); break;
564 case MP_BINARY_OP_ADD: printf("BINARY_ADD\n"); break;
565 case MP_BINARY_OP_SUBTRACT: printf("BINARY_SUBTRACT\n"); break;
566 case MP_BINARY_OP_MULTIPLY: printf("BINARY_MULTIPLY\n"); break;
567 case MP_BINARY_OP_FLOOR_DIVIDE: printf("BINARY_FLOOR_DIVIDE\n"); break;
568 case MP_BINARY_OP_TRUE_DIVIDE: printf("BINARY_TRUE_DIVIDE\n"); break;
569 case MP_BINARY_OP_MODULO: printf("BINARY_MODULO\n"); break;
570 case MP_BINARY_OP_POWER: printf("BINARY_POWER\n"); break;
571 case MP_BINARY_OP_INPLACE_OR: printf("INPLACE_OR\n"); break;
572 case MP_BINARY_OP_INPLACE_XOR: printf("INPLACE_XOR\n"); break;
573 case MP_BINARY_OP_INPLACE_AND: printf("INPLACE_AND\n"); break;
574 case MP_BINARY_OP_INPLACE_LSHIFT: printf("INPLACE_LSHIFT\n"); break;
575 case MP_BINARY_OP_INPLACE_RSHIFT: printf("INPLACE_RSHIFT\n"); break;
576 case MP_BINARY_OP_INPLACE_ADD: printf("INPLACE_ADD\n"); break;
577 case MP_BINARY_OP_INPLACE_SUBTRACT: printf("INPLACE_SUBTRACT\n"); break;
578 case MP_BINARY_OP_INPLACE_MULTIPLY: printf("INPLACE_MULTIPLY\n"); break;
579 case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE: printf("INPLACE_FLOOR_DIVIDE\n"); break;
580 case MP_BINARY_OP_INPLACE_TRUE_DIVIDE: printf("INPLACE_TRUE_DIVIDE\n"); break;
581 case MP_BINARY_OP_INPLACE_MODULO: printf("INPLACE_MODULO\n"); break;
582 case MP_BINARY_OP_INPLACE_POWER: printf("INPLACE_POWER\n"); break;
583 case MP_BINARY_OP_LESS: printf("COMPARE_OP <\n"); break;
584 case MP_BINARY_OP_MORE: printf("COMPARE_OP >\n"); break;
585 case MP_BINARY_OP_EQUAL: printf("COMPARE_OP ==\n"); break;
586 case MP_BINARY_OP_LESS_EQUAL: printf("COMPARE_OP <=\n"); break;
587 case MP_BINARY_OP_MORE_EQUAL: printf("COMPARE_OP >=\n"); break;
588 case MP_BINARY_OP_NOT_EQUAL: printf("COMPARE_OP !=\n"); break;
589 case MP_BINARY_OP_IN: printf("COMPARE_OP in\n"); break;
590 case MP_BINARY_OP_IS: printf("COMPARE_OP is\n"); break;
591 case MP_BINARY_OP_EXCEPTION_MATCH: printf("COMPARE_OP exception match\n"); break;
592 case MP_BINARY_OP_NOT_IN: printf("COMPARE_OP not in\n"); break;
593 case MP_BINARY_OP_IS_NOT: printf("COMPARE_OP is not\n"); break;
Damien429d7192013-10-04 19:53:11 +0100594 default: assert(0);
595 }
596 }
597}
598
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200599STATIC void emit_cpy_build_tuple(emit_t *emit, int n_args) {
Damien429d7192013-10-04 19:53:11 +0100600 emit_pre(emit, 1 - n_args, 3);
601 if (emit->pass == PASS_3) {
602 printf("BUILD_TUPLE %d\n", n_args);
603 }
604}
605
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200606STATIC void emit_cpy_build_list(emit_t *emit, int n_args) {
Damien429d7192013-10-04 19:53:11 +0100607 emit_pre(emit, 1 - n_args, 3);
608 if (emit->pass == PASS_3) {
609 printf("BUILD_LIST %d\n", n_args);
610 }
611}
612
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200613STATIC void emit_cpy_list_append(emit_t *emit, int list_index) {
Damien429d7192013-10-04 19:53:11 +0100614 emit_pre(emit, -1, 3);
615 if (emit->pass == PASS_3) {
616 printf("LIST_APPEND %d\n", list_index);
617 }
618}
619
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200620STATIC void emit_cpy_build_map(emit_t *emit, int n_args) {
Damien429d7192013-10-04 19:53:11 +0100621 emit_pre(emit, 1, 3);
622 if (emit->pass == PASS_3) {
623 printf("BUILD_MAP %d\n", n_args);
624 }
625}
626
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200627STATIC void emit_cpy_store_map(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100628 emit_pre(emit, -2, 1);
629 if (emit->pass == PASS_3) {
630 printf("STORE_MAP\n");
631 }
632}
633
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200634STATIC void emit_cpy_map_add(emit_t *emit, int map_index) {
Damien429d7192013-10-04 19:53:11 +0100635 emit_pre(emit, -2, 3);
636 if (emit->pass == PASS_3) {
637 printf("MAP_ADD %d\n", map_index);
638 }
639}
640
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200641STATIC void emit_cpy_build_set(emit_t *emit, int n_args) {
Damien429d7192013-10-04 19:53:11 +0100642 emit_pre(emit, 1 - n_args, 3);
643 if (emit->pass == PASS_3) {
644 printf("BUILD_SET %d\n", n_args);
645 }
646}
647
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200648STATIC void emit_cpy_set_add(emit_t *emit, int set_index) {
Damien429d7192013-10-04 19:53:11 +0100649 emit_pre(emit, -1, 3);
650 if (emit->pass == PASS_3) {
651 printf("SET_ADD %d\n", set_index);
652 }
653}
654
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200655STATIC void emit_cpy_build_slice(emit_t *emit, int n_args) {
Damien429d7192013-10-04 19:53:11 +0100656 emit_pre(emit, 1 - n_args, 3);
657 if (emit->pass == PASS_3) {
658 printf("BUILD_SLICE %d\n", n_args);
659 }
660}
661
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200662STATIC void emit_cpy_unpack_sequence(emit_t *emit, int n_args) {
Damien429d7192013-10-04 19:53:11 +0100663 emit_pre(emit, -1 + n_args, 3);
664 if (emit->pass == PASS_3) {
665 printf("UNPACK_SEQUENCE %d\n", n_args);
666 }
667}
668
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200669STATIC void emit_cpy_unpack_ex(emit_t *emit, int n_left, int n_right) {
Damien429d7192013-10-04 19:53:11 +0100670 emit_pre(emit, -1 + n_left + n_right + 1, 3);
671 if (emit->pass == PASS_3) {
672 printf("UNPACK_EX %d\n", n_left | (n_right << 8));
673 }
674}
675
Damien George922ddd62014-04-09 12:43:17 +0100676STATIC void emit_cpy_call_function(emit_t *emit, int n_positional, int n_keyword, uint star_flags) {
Damien429d7192013-10-04 19:53:11 +0100677 int s = 0;
Damien George922ddd62014-04-09 12:43:17 +0100678 if (star_flags & MP_EMIT_STAR_FLAG_SINGLE) {
Damien429d7192013-10-04 19:53:11 +0100679 s += 1;
680 }
Damien George922ddd62014-04-09 12:43:17 +0100681 if (star_flags & MP_EMIT_STAR_FLAG_DOUBLE) {
Damien429d7192013-10-04 19:53:11 +0100682 s += 1;
683 }
684 emit_pre(emit, -n_positional - 2 * n_keyword - s, 3);
685 if (emit->pass == PASS_3) {
Damien George922ddd62014-04-09 12:43:17 +0100686 if (star_flags & MP_EMIT_STAR_FLAG_SINGLE) {
687 if (star_flags & MP_EMIT_STAR_FLAG_DOUBLE) {
Damien429d7192013-10-04 19:53:11 +0100688 printf("CALL_FUNCTION_VAR_KW");
689 } else {
690 printf("CALL_FUNCTION_VAR");
691 }
692 } else {
Damien George922ddd62014-04-09 12:43:17 +0100693 if (star_flags & MP_EMIT_STAR_FLAG_DOUBLE) {
Damien429d7192013-10-04 19:53:11 +0100694 printf("CALL_FUNCTION_KW");
695 } else {
696 printf("CALL_FUNCTION");
697 }
698 }
699 printf(" %d, %d\n", n_positional, n_keyword);
700 }
701}
702
Damien George922ddd62014-04-09 12:43:17 +0100703STATIC void emit_cpy_call_method(emit_t *emit, int n_positional, int n_keyword, uint star_flags) {
704 emit_cpy_call_function(emit, n_positional, n_keyword, star_flags);
Damien429d7192013-10-04 19:53:11 +0100705}
706
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200707STATIC void emit_cpy_return_value(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100708 emit_pre(emit, -1, 1);
709 emit->last_emit_was_return_value = true;
710 if (emit->pass == PASS_3) {
711 printf("RETURN_VALUE\n");
712 }
713}
714
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200715STATIC void emit_cpy_raise_varargs(emit_t *emit, int n_args) {
Damien429d7192013-10-04 19:53:11 +0100716 emit_pre(emit, -n_args, 3);
717 if (emit->pass == PASS_3) {
718 printf("RAISE_VARARGS %d\n", n_args);
719 }
720}
721
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200722STATIC void load_cpy_const_code_and_name(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100723 emit_pre(emit, 1, 3);
724 if (emit->pass == PASS_3) {
725 printf("LOAD_CONST code %s\n", qstr_str(qstr));
726 }
727 // load qualified name
728 emit_pre(emit, 1, 3);
729 if (emit->pass == PASS_3) {
730 printf("LOAD_CONST '");
731 // code just to work out the qualname (or whatever it is)
732 {
733 int depth = 0;
734 for (scope_t *s = emit->scope; s->parent != NULL; s = s->parent) {
735 depth += 1;
736 }
737 for (int wanted_depth = depth; wanted_depth >= 0; wanted_depth--) {
738 scope_t *s = emit->scope;
739 for (int i = 0; i < wanted_depth; i++) {
740 s = s->parent;
741 }
742 if (s->kind == SCOPE_FUNCTION) {
743 printf("%s.<locals>.", qstr_str(s->simple_name));
744 } else if (s->kind == SCOPE_CLASS) {
745 printf("%s.", qstr_str(s->simple_name));
746 }
747 }
748 }
749 printf("%s'\n", qstr_str(qstr));
750 }
751}
752
Damien George30565092014-03-31 11:30:17 +0100753STATIC void emit_cpy_make_function(emit_t *emit, scope_t *scope, uint n_pos_defaults, uint n_kw_defaults) {
Damien415eb6f2013-10-05 12:19:06 +0100754 load_cpy_const_code_and_name(emit, scope->simple_name);
Damien George30565092014-03-31 11:30:17 +0100755 emit_pre(emit, -1 - n_pos_defaults - 2 * n_kw_defaults, 3);
Damien429d7192013-10-04 19:53:11 +0100756 if (emit->pass == PASS_3) {
Damien George30565092014-03-31 11:30:17 +0100757 printf("MAKE_FUNCTION %d\n", (n_kw_defaults << 8) | n_pos_defaults);
Damien429d7192013-10-04 19:53:11 +0100758 }
759}
760
Damien George30565092014-03-31 11:30:17 +0100761STATIC void emit_cpy_make_closure(emit_t *emit, scope_t *scope, uint n_pos_defaults, uint n_kw_defaults) {
Damien415eb6f2013-10-05 12:19:06 +0100762 load_cpy_const_code_and_name(emit, scope->simple_name);
Damien George30565092014-03-31 11:30:17 +0100763 emit_pre(emit, -2 - n_pos_defaults - 2 * n_kw_defaults, 3);
Damien429d7192013-10-04 19:53:11 +0100764 if (emit->pass == PASS_3) {
Damien George30565092014-03-31 11:30:17 +0100765 printf("MAKE_CLOSURE %d\n", (n_kw_defaults << 8) | n_pos_defaults);
Damien429d7192013-10-04 19:53:11 +0100766 }
767}
768
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200769STATIC void emit_cpy_yield_value(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100770 emit_pre(emit, 0, 1);
771 if (emit->pass == PASS_2) {
Paul Sokolovsky5fd7bc32014-02-16 03:02:47 +0200772 emit->scope->scope_flags |= MP_SCOPE_FLAG_GENERATOR;
Damien429d7192013-10-04 19:53:11 +0100773 }
774 if (emit->pass == PASS_3) {
775 printf("YIELD_VALUE\n");
776 }
777}
778
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200779STATIC void emit_cpy_yield_from(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100780 emit_pre(emit, -1, 1);
781 if (emit->pass == PASS_2) {
Paul Sokolovsky5fd7bc32014-02-16 03:02:47 +0200782 emit->scope->scope_flags |= MP_SCOPE_FLAG_GENERATOR;
Damien429d7192013-10-04 19:53:11 +0100783 }
784 if (emit->pass == PASS_3) {
785 printf("YIELD_FROM\n");
786 }
787}
788
Damien6cdd3af2013-10-05 18:08:26 +0100789const emit_method_table_t emit_cpython_method_table = {
Damien415eb6f2013-10-05 12:19:06 +0100790 emit_cpy_set_native_types,
791 emit_cpy_start_pass,
792 emit_cpy_end_pass,
793 emit_cpy_last_emit_was_return_value,
Damien Georged66ae182014-04-10 17:28:54 +0000794 emit_cpy_adjust_stack_size,
Damien George08335002014-01-18 23:24:36 +0000795 emit_cpy_set_source_line,
Damien415eb6f2013-10-05 12:19:06 +0100796
Damien4b03e772013-10-05 14:17:09 +0100797 emit_cpy_load_id,
798 emit_cpy_store_id,
799 emit_cpy_delete_id,
800
Damien415eb6f2013-10-05 12:19:06 +0100801 emit_cpy_label_assign,
802 emit_cpy_import_name,
803 emit_cpy_import_from,
804 emit_cpy_import_star,
805 emit_cpy_load_const_tok,
806 emit_cpy_load_const_small_int,
807 emit_cpy_load_const_int,
808 emit_cpy_load_const_dec,
809 emit_cpy_load_const_id,
810 emit_cpy_load_const_str,
Damien415eb6f2013-10-05 12:19:06 +0100811 emit_cpy_load_const_verbatim_str,
Damien415eb6f2013-10-05 12:19:06 +0100812 emit_cpy_load_fast,
Damien415eb6f2013-10-05 12:19:06 +0100813 emit_cpy_load_deref,
814 emit_cpy_load_closure,
Damien9ecbcff2013-12-11 00:41:43 +0000815 emit_cpy_load_name,
816 emit_cpy_load_global,
Damien415eb6f2013-10-05 12:19:06 +0100817 emit_cpy_load_attr,
818 emit_cpy_load_method,
819 emit_cpy_load_build_class,
820 emit_cpy_store_fast,
Damien9ecbcff2013-12-11 00:41:43 +0000821 emit_cpy_store_deref,
Damien415eb6f2013-10-05 12:19:06 +0100822 emit_cpy_store_name,
823 emit_cpy_store_global,
Damien415eb6f2013-10-05 12:19:06 +0100824 emit_cpy_store_attr,
Damien415eb6f2013-10-05 12:19:06 +0100825 emit_cpy_store_subscr,
826 emit_cpy_delete_fast,
Damien9ecbcff2013-12-11 00:41:43 +0000827 emit_cpy_delete_deref,
Damien415eb6f2013-10-05 12:19:06 +0100828 emit_cpy_delete_name,
829 emit_cpy_delete_global,
Damien415eb6f2013-10-05 12:19:06 +0100830 emit_cpy_delete_attr,
831 emit_cpy_delete_subscr,
832 emit_cpy_dup_top,
833 emit_cpy_dup_top_two,
834 emit_cpy_pop_top,
835 emit_cpy_rot_two,
836 emit_cpy_rot_three,
837 emit_cpy_jump,
838 emit_cpy_pop_jump_if_true,
839 emit_cpy_pop_jump_if_false,
840 emit_cpy_jump_if_true_or_pop,
841 emit_cpy_jump_if_false_or_pop,
842 emit_cpy_setup_loop,
843 emit_cpy_break_loop,
844 emit_cpy_continue_loop,
845 emit_cpy_setup_with,
846 emit_cpy_with_cleanup,
847 emit_cpy_setup_except,
848 emit_cpy_setup_finally,
849 emit_cpy_end_finally,
850 emit_cpy_get_iter,
851 emit_cpy_for_iter,
852 emit_cpy_for_iter_end,
853 emit_cpy_pop_block,
854 emit_cpy_pop_except,
855 emit_cpy_unary_op,
856 emit_cpy_binary_op,
Damien415eb6f2013-10-05 12:19:06 +0100857 emit_cpy_build_tuple,
858 emit_cpy_build_list,
859 emit_cpy_list_append,
860 emit_cpy_build_map,
861 emit_cpy_store_map,
862 emit_cpy_map_add,
863 emit_cpy_build_set,
864 emit_cpy_set_add,
865 emit_cpy_build_slice,
866 emit_cpy_unpack_sequence,
867 emit_cpy_unpack_ex,
868 emit_cpy_make_function,
869 emit_cpy_make_closure,
870 emit_cpy_call_function,
871 emit_cpy_call_method,
872 emit_cpy_return_value,
873 emit_cpy_raise_varargs,
874 emit_cpy_yield_value,
875 emit_cpy_yield_from,
876};
877
Damien3ef4abb2013-10-12 16:53:13 +0100878#endif // MICROPY_EMIT_CPYTHON