blob: 5866d474e9ca184590f61e1819734948a9545950 [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"
Damien429d7192013-10-04 19:53:11 +010012#include "scope.h"
Damiend99b0522013-12-21 18:17:45 +000013#include "runtime0.h"
Damien429d7192013-10-04 19:53:11 +010014#include "emit.h"
15
Damien Georgee67ed5d2014-01-04 13:55:24 +000016// wrapper around everything in this file
Damien3ef4abb2013-10-12 16:53:13 +010017#if MICROPY_EMIT_CPYTHON
Damien429d7192013-10-04 19:53:11 +010018
Damien415eb6f2013-10-05 12:19:06 +010019struct _emit_t {
Damien429d7192013-10-04 19:53:11 +010020 int pass;
Damien429d7192013-10-04 19:53:11 +010021 int byte_code_offset;
22 int stack_size;
23 bool last_emit_was_return_value;
24
25 scope_t *scope;
26
Damienb05d7072013-10-05 13:37:10 +010027 uint max_num_labels;
Damien429d7192013-10-04 19:53:11 +010028 int *label_offsets;
29};
30
Damien6cdd3af2013-10-05 18:08:26 +010031emit_t *emit_cpython_new(uint max_num_labels) {
32 emit_t *emit = m_new(emit_t, 1);
33 emit->max_num_labels = max_num_labels;
34 emit->label_offsets = m_new(int, max_num_labels);
35 return emit;
36}
37
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020038STATIC void emit_cpy_set_native_types(emit_t *emit, bool do_native_types) {
Damien429d7192013-10-04 19:53:11 +010039}
40
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020041STATIC void emit_cpy_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) {
Damien429d7192013-10-04 19:53:11 +010042 emit->pass = pass;
Damien429d7192013-10-04 19:53:11 +010043 emit->byte_code_offset = 0;
44 emit->stack_size = 0;
45 emit->last_emit_was_return_value = false;
46 emit->scope = scope;
Damienb05d7072013-10-05 13:37:10 +010047 if (pass == PASS_2) {
48 memset(emit->label_offsets, -1, emit->max_num_labels * sizeof(int));
Damien429d7192013-10-04 19:53:11 +010049 }
50}
51
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020052STATIC void emit_cpy_end_pass(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +010053 // check stack is back to zero size
54 if (emit->stack_size != 0) {
55 printf("ERROR: stack size not back to zero; got %d\n", emit->stack_size);
56 }
Damien429d7192013-10-04 19:53:11 +010057}
58
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020059STATIC bool emit_cpy_last_emit_was_return_value(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +010060 return emit->last_emit_was_return_value;
61}
62
Damien Georged66ae182014-04-10 17:28:54 +000063STATIC void emit_cpy_adjust_stack_size(emit_t *emit, int delta) {
64 emit->stack_size += delta;
Damien429d7192013-10-04 19:53:11 +010065}
66
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020067STATIC void emit_cpy_set_source_line(emit_t *emit, int source_line) {
Damien George08335002014-01-18 23:24:36 +000068}
69
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020070STATIC void emit_cpy_load_id(emit_t *emit, qstr qstr) {
Damien6cdd3af2013-10-05 18:08:26 +010071 emit_common_load_id(emit, &emit_cpython_method_table, emit->scope, qstr);
Damien4b03e772013-10-05 14:17:09 +010072}
73
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020074STATIC void emit_cpy_store_id(emit_t *emit, qstr qstr) {
Damien6cdd3af2013-10-05 18:08:26 +010075 emit_common_store_id(emit, &emit_cpython_method_table, emit->scope, qstr);
Damien4b03e772013-10-05 14:17:09 +010076}
77
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020078STATIC void emit_cpy_delete_id(emit_t *emit, qstr qstr) {
Damien6cdd3af2013-10-05 18:08:26 +010079 emit_common_delete_id(emit, &emit_cpython_method_table, emit->scope, qstr);
Damien4b03e772013-10-05 14:17:09 +010080}
81
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020082// TODO: module-polymorphic function (read: name clash if made global)
Damien415eb6f2013-10-05 12:19:06 +010083static void emit_pre(emit_t *emit, int stack_size_delta, int byte_code_size) {
Damien429d7192013-10-04 19:53:11 +010084 emit->stack_size += stack_size_delta;
Damienb05d7072013-10-05 13:37:10 +010085 if (emit->stack_size > emit->scope->stack_size) {
Damien429d7192013-10-04 19:53:11 +010086 emit->scope->stack_size = emit->stack_size;
87 }
88 emit->last_emit_was_return_value = false;
89 if (emit->pass == PASS_3 && byte_code_size > 0) {
90 if (emit->byte_code_offset >= 1000) {
91 printf("%d ", emit->byte_code_offset);
92 } else {
93 printf("% 4d ", emit->byte_code_offset);
94 }
95 }
96 emit->byte_code_offset += byte_code_size;
97}
98
Damien George6f355fd2014-04-10 14:11:31 +010099STATIC void emit_cpy_label_assign(emit_t *emit, uint l) {
Damien429d7192013-10-04 19:53:11 +0100100 emit_pre(emit, 0, 0);
Damienb05d7072013-10-05 13:37:10 +0100101 assert(l < emit->max_num_labels);
102 if (emit->pass == PASS_2) {
103 // assign label offset
104 assert(emit->label_offsets[l] == -1);
105 emit->label_offsets[l] = emit->byte_code_offset;
106 } else if (emit->pass == PASS_3) {
107 // ensure label offset has not changed from PASS_2 to PASS_3
108 assert(emit->label_offsets[l] == emit->byte_code_offset);
109 //printf("l%d: (at %d)\n", l, emit->byte_code_offset);
Damien429d7192013-10-04 19:53:11 +0100110 }
111}
112
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200113STATIC void emit_cpy_import_name(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100114 emit_pre(emit, -1, 3);
115 if (emit->pass == PASS_3) {
116 printf("IMPORT_NAME %s\n", qstr_str(qstr));
117 }
118}
119
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200120STATIC void emit_cpy_import_from(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100121 emit_pre(emit, 1, 3);
122 if (emit->pass == PASS_3) {
123 printf("IMPORT_FROM %s\n", qstr_str(qstr));
124 }
125}
126
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200127STATIC void emit_cpy_import_star(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100128 emit_pre(emit, -1, 1);
129 if (emit->pass == PASS_3) {
130 printf("IMPORT_STAR\n");
131 }
132}
133
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200134STATIC void emit_cpy_load_const_tok(emit_t *emit, mp_token_kind_t tok) {
Damien429d7192013-10-04 19:53:11 +0100135 emit_pre(emit, 1, 3);
136 if (emit->pass == PASS_3) {
137 printf("LOAD_CONST ");
138 switch (tok) {
Damiend99b0522013-12-21 18:17:45 +0000139 case MP_TOKEN_KW_FALSE: printf("False"); break;
140 case MP_TOKEN_KW_NONE: printf("None"); break;
141 case MP_TOKEN_KW_TRUE: printf("True"); break;
Damien429d7192013-10-04 19:53:11 +0100142 default: printf("?=%d\n", tok); return; assert(0);
143 }
144 printf("\n");
145 }
146}
147
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200148STATIC void emit_cpy_load_const_small_int(emit_t *emit, machine_int_t arg) {
Damien429d7192013-10-04 19:53:11 +0100149 emit_pre(emit, 1, 3);
150 if (emit->pass == PASS_3) {
Damien George08d07552014-01-29 18:58:52 +0000151 printf("LOAD_CONST " INT_FMT "\n", arg);
Damien429d7192013-10-04 19:53:11 +0100152 }
153}
154
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200155STATIC void emit_cpy_load_const_int(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100156 emit_pre(emit, 1, 3);
157 if (emit->pass == PASS_3) {
158 printf("LOAD_CONST %s\n", qstr_str(qstr));
159 }
160}
161
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200162STATIC void emit_cpy_load_const_dec(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100163 emit_pre(emit, 1, 3);
164 if (emit->pass == PASS_3) {
165 printf("LOAD_CONST %s\n", qstr_str(qstr));
166 }
167}
168
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200169STATIC void emit_cpy_load_const_id(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100170 emit_pre(emit, 1, 3);
171 if (emit->pass == PASS_3) {
172 printf("LOAD_CONST '%s'\n", qstr_str(qstr));
173 }
174}
175
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200176STATIC void print_quoted_str(qstr qstr, bool bytes) {
Damiena1b26932013-12-12 15:34:40 +0000177 const char *str = qstr_str(qstr);
178 int len = strlen(str);
179 bool has_single_quote = false;
180 bool has_double_quote = false;
181 for (int i = 0; i < len; i++) {
182 if (str[i] == '\'') {
183 has_single_quote = true;
184 } else if (str[i] == '"') {
185 has_double_quote = true;
186 }
187 }
188 if (bytes) {
189 printf("b");
190 }
Damien Georgeb829b5c2014-01-25 13:51:19 +0000191 int quote_char = '\'';
Damiena1b26932013-12-12 15:34:40 +0000192 if (has_single_quote && !has_double_quote) {
Damien Georgeb829b5c2014-01-25 13:51:19 +0000193 quote_char = '"';
Damiena1b26932013-12-12 15:34:40 +0000194 }
Damien Georgeb829b5c2014-01-25 13:51:19 +0000195 printf("%c", quote_char);
196 for (const char *s = str, *top = str + len; s < top; s++) {
197 if (*s == quote_char) {
198 printf("\\%c", quote_char);
199 } else if (*s == '\\') {
Damiena1b26932013-12-12 15:34:40 +0000200 printf("\\\\");
Damien Georgeb829b5c2014-01-25 13:51:19 +0000201 } else if (32 <= *s && *s <= 126) {
202 printf("%c", *s);
203 } else if (*s == '\n') {
204 printf("\\n");
205 // TODO add more escape codes here
Damiena1b26932013-12-12 15:34:40 +0000206 } else {
Damien Georgeb829b5c2014-01-25 13:51:19 +0000207 printf("\\x%02x", (*s) & 0xff);
Damiena1b26932013-12-12 15:34:40 +0000208 }
209 }
Damien Georgeb829b5c2014-01-25 13:51:19 +0000210 printf("%c", quote_char);
Damiena1b26932013-12-12 15:34:40 +0000211}
212
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200213STATIC void emit_cpy_load_const_str(emit_t *emit, qstr qstr, bool bytes) {
Damien429d7192013-10-04 19:53:11 +0100214 emit_pre(emit, 1, 3);
215 if (emit->pass == PASS_3) {
216 printf("LOAD_CONST ");
Damiena1b26932013-12-12 15:34:40 +0000217 print_quoted_str(qstr, bytes);
Damien429d7192013-10-04 19:53:11 +0100218 printf("\n");
219 }
220}
221
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200222STATIC void emit_cpy_load_const_verbatim_str(emit_t *emit, const char *str) {
Damiena1b26932013-12-12 15:34:40 +0000223 emit_pre(emit, 1, 3);
Damien429d7192013-10-04 19:53:11 +0100224 if (emit->pass == PASS_3) {
Damiena1b26932013-12-12 15:34:40 +0000225 printf("LOAD_CONST %s\n", str);
Damien429d7192013-10-04 19:53:11 +0100226 }
227}
228
Damien Georgee2835c12014-04-09 20:20:34 +0100229STATIC void emit_cpy_load_fast(emit_t *emit, qstr qstr, uint id_flags, int local_num) {
Damien6cdd3af2013-10-05 18:08:26 +0100230 emit_pre(emit, 1, 3);
231 if (emit->pass == PASS_3) {
232 printf("LOAD_FAST %d %s\n", local_num, qstr_str(qstr));
233 }
234}
235
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200236STATIC void emit_cpy_load_deref(emit_t *emit, qstr qstr, int local_num) {
Damien429d7192013-10-04 19:53:11 +0100237 emit_pre(emit, 1, 3);
238 if (emit->pass == PASS_3) {
Damien27fb45e2013-10-20 15:07:49 +0100239 printf("LOAD_DEREF %d %s\n", local_num, qstr_str(qstr));
Damien429d7192013-10-04 19:53:11 +0100240 }
241}
242
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200243STATIC void emit_cpy_load_closure(emit_t *emit, qstr qstr, int local_num) {
Damien429d7192013-10-04 19:53:11 +0100244 emit_pre(emit, 1, 3);
245 if (emit->pass == PASS_3) {
Damien27fb45e2013-10-20 15:07:49 +0100246 printf("LOAD_CLOSURE %d %s\n", local_num, qstr_str(qstr));
Damien429d7192013-10-04 19:53:11 +0100247 }
248}
249
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200250STATIC void emit_cpy_load_name(emit_t *emit, qstr qstr) {
Damien9ecbcff2013-12-11 00:41:43 +0000251 emit_pre(emit, 1, 3);
252 if (emit->pass == PASS_3) {
253 printf("LOAD_NAME %s\n", qstr_str(qstr));
254 }
255}
256
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200257STATIC void emit_cpy_load_global(emit_t *emit, qstr qstr) {
Damien9ecbcff2013-12-11 00:41:43 +0000258 emit_pre(emit, 1, 3);
259 if (emit->pass == PASS_3) {
260 printf("LOAD_GLOBAL %s\n", qstr_str(qstr));
261 }
262}
263
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200264STATIC void emit_cpy_load_attr(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100265 emit_pre(emit, 0, 3);
266 if (emit->pass == PASS_3) {
267 printf("LOAD_ATTR %s\n", qstr_str(qstr));
268 }
269}
270
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200271STATIC void emit_cpy_load_method(emit_t *emit, qstr qstr) {
Damien415eb6f2013-10-05 12:19:06 +0100272 emit_cpy_load_attr(emit, qstr);
Damien429d7192013-10-04 19:53:11 +0100273}
274
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200275STATIC void emit_cpy_load_build_class(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100276 emit_pre(emit, 1, 1);
277 if (emit->pass == PASS_3) {
278 printf("LOAD_BUILD_CLASS\n");
279 }
280}
281
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200282STATIC void emit_cpy_store_fast(emit_t *emit, qstr qstr, int local_num) {
Damien6cdd3af2013-10-05 18:08:26 +0100283 emit_pre(emit, -1, 3);
284 if (emit->pass == PASS_3) {
285 printf("STORE_FAST %d %s\n", local_num, qstr_str(qstr));
286 }
287}
288
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200289STATIC void emit_cpy_store_deref(emit_t *emit, qstr qstr, int local_num) {
Damien9ecbcff2013-12-11 00:41:43 +0000290 emit_pre(emit, -1, 3);
291 if (emit->pass == PASS_3) {
292 printf("STORE_DEREF %d %s\n", local_num, qstr_str(qstr));
293 }
294}
295
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200296STATIC void emit_cpy_store_name(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100297 emit_pre(emit, -1, 3);
298 if (emit->pass == PASS_3) {
299 printf("STORE_NAME %s\n", qstr_str(qstr));
300 }
301}
302
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200303STATIC void emit_cpy_store_global(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100304 emit_pre(emit, -1, 3);
305 if (emit->pass == PASS_3) {
306 printf("STORE_GLOBAL %s\n", qstr_str(qstr));
307 }
308}
309
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200310STATIC void emit_cpy_store_attr(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100311 emit_pre(emit, -2, 3);
312 if (emit->pass == PASS_3) {
313 printf("STORE_ATTR %s\n", qstr_str(qstr));
314 }
315}
316
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200317STATIC void emit_cpy_store_subscr(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100318 emit_pre(emit, -3, 1);
319 if (emit->pass == PASS_3) {
320 printf("STORE_SUBSCR\n");
321 }
322}
323
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200324STATIC void emit_cpy_delete_fast(emit_t *emit, qstr qstr, int local_num) {
Damien6cdd3af2013-10-05 18:08:26 +0100325 emit_pre(emit, 0, 3);
326 if (emit->pass == PASS_3) {
327 printf("DELETE_FAST %d %s\n", local_num, qstr_str(qstr));
328 }
329}
330
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200331STATIC void emit_cpy_delete_deref(emit_t *emit, qstr qstr, int local_num) {
Damien9ecbcff2013-12-11 00:41:43 +0000332 emit_pre(emit, 0, 3);
333 if (emit->pass == PASS_3) {
334 printf("DELETE_DEREF %d %s\n", local_num, qstr_str(qstr));
335 }
336}
337
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200338STATIC void emit_cpy_delete_name(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100339 emit_pre(emit, 0, 3);
340 if (emit->pass == PASS_3) {
341 printf("DELETE_NAME %s\n", qstr_str(qstr));
342 }
343}
344
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200345STATIC void emit_cpy_delete_global(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100346 emit_pre(emit, 0, 3);
347 if (emit->pass == PASS_3) {
348 printf("DELETE_GLOBAL %s\n", qstr_str(qstr));
349 }
350}
351
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200352STATIC void emit_cpy_delete_attr(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100353 emit_pre(emit, -1, 3);
354 if (emit->pass == PASS_3) {
355 printf("DELETE_ATTR %s\n", qstr_str(qstr));
356 }
357}
358
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200359STATIC void emit_cpy_delete_subscr(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100360 emit_pre(emit, -2, 1);
361 if (emit->pass == PASS_3) {
362 printf("DELETE_SUBSCR\n");
363 }
364}
365
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200366STATIC void emit_cpy_dup_top(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100367 emit_pre(emit, 1, 1);
368 if (emit->pass == PASS_3) {
369 printf("DUP_TOP\n");
370 }
371}
372
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200373STATIC void emit_cpy_dup_top_two(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100374 emit_pre(emit, 2, 1);
375 if (emit->pass == PASS_3) {
376 printf("DUP_TOP_TWO\n");
377 }
378}
379
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200380STATIC void emit_cpy_pop_top(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100381 emit_pre(emit, -1, 1);
382 if (emit->pass == PASS_3) {
383 printf("POP_TOP\n");
384 }
385}
386
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200387STATIC void emit_cpy_rot_two(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100388 emit_pre(emit, 0, 1);
389 if (emit->pass == PASS_3) {
390 printf("ROT_TWO\n");
391 }
392}
393
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200394STATIC void emit_cpy_rot_three(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100395 emit_pre(emit, 0, 1);
396 if (emit->pass == PASS_3) {
397 printf("ROT_THREE\n");
398 }
399}
400
Damien George6f355fd2014-04-10 14:11:31 +0100401STATIC void emit_cpy_jump(emit_t *emit, uint label) {
Damien429d7192013-10-04 19:53:11 +0100402 emit_pre(emit, 0, 3);
403 if (emit->pass == PASS_3) {
404 int dest = emit->label_offsets[label];
405 if (dest < emit->byte_code_offset) {
406 printf("JUMP_ABSOLUTE %d\n", emit->label_offsets[label]);
407 } else {
408 printf("JUMP_FORWARD %d\n", emit->label_offsets[label]);
409 }
410 }
411}
412
Damien George6f355fd2014-04-10 14:11:31 +0100413STATIC void emit_cpy_pop_jump_if_true(emit_t *emit, uint label) {
Damien429d7192013-10-04 19:53:11 +0100414 emit_pre(emit, -1, 3);
415 if (emit->pass == PASS_3) {
416 printf("POP_JUMP_IF_TRUE %d\n", emit->label_offsets[label]);
417 }
418}
419
Damien George6f355fd2014-04-10 14:11:31 +0100420STATIC void emit_cpy_pop_jump_if_false(emit_t *emit, uint label) {
Damien429d7192013-10-04 19:53:11 +0100421 emit_pre(emit, -1, 3);
422 if (emit->pass == PASS_3) {
423 printf("POP_JUMP_IF_FALSE %d\n", emit->label_offsets[label]);
424 }
425}
426
Damien George6f355fd2014-04-10 14:11:31 +0100427STATIC void emit_cpy_jump_if_true_or_pop(emit_t *emit, uint label) {
Damien429d7192013-10-04 19:53:11 +0100428 emit_pre(emit, -1, 3);
429 if (emit->pass == PASS_3) {
430 printf("JUMP_IF_TRUE_OR_POP %d\n", emit->label_offsets[label]);
431 }
432}
433
Damien George6f355fd2014-04-10 14:11:31 +0100434STATIC void emit_cpy_jump_if_false_or_pop(emit_t *emit, uint label) {
Damien429d7192013-10-04 19:53:11 +0100435 emit_pre(emit, -1, 3);
436 if (emit->pass == PASS_3) {
437 printf("JUMP_IF_FALSE_OR_POP %d\n", emit->label_offsets[label]);
438 }
439}
440
Damien George6f355fd2014-04-10 14:11:31 +0100441STATIC void emit_cpy_setup_loop(emit_t *emit, uint label) {
Damien429d7192013-10-04 19:53:11 +0100442 emit_pre(emit, 0, 3);
443 if (emit->pass == PASS_3) {
444 printf("SETUP_LOOP %d\n", emit->label_offsets[label]);
445 }
446}
447
Damien George6f355fd2014-04-10 14:11:31 +0100448STATIC void emit_cpy_break_loop(emit_t *emit, uint label, int except_depth) {
Damien429d7192013-10-04 19:53:11 +0100449 emit_pre(emit, 0, 1);
450 if (emit->pass == PASS_3) {
Damien Georgee24b5632014-02-01 21:56:25 +0000451 printf("BREAK_LOOP\n");
Damien429d7192013-10-04 19:53:11 +0100452 }
453}
454
Damien George6f355fd2014-04-10 14:11:31 +0100455STATIC void emit_cpy_continue_loop(emit_t *emit, uint label, int except_depth) {
Damien Georgee24b5632014-02-01 21:56:25 +0000456 if (except_depth == 0) {
457 emit_cpy_jump(emit, label);
458 } else {
459 emit_pre(emit, 0, 3);
460 if (emit->pass == PASS_3) {
461 printf("CONTINUE_LOOP %d\n", emit->label_offsets[label]);
462 }
Damien429d7192013-10-04 19:53:11 +0100463 }
464}
465
Damien George6f355fd2014-04-10 14:11:31 +0100466STATIC void emit_cpy_setup_with(emit_t *emit, uint label) {
Damien429d7192013-10-04 19:53:11 +0100467 emit_pre(emit, 7, 3);
468 if (emit->pass == PASS_3) {
469 printf("SETUP_WITH %d\n", emit->label_offsets[label]);
470 }
471}
472
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200473STATIC void emit_cpy_with_cleanup(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100474 emit_pre(emit, -7, 1);
475 if (emit->pass == PASS_3) {
476 printf("WITH_CLEANUP\n");
477 }
478}
479
Damien George6f355fd2014-04-10 14:11:31 +0100480STATIC void emit_cpy_setup_except(emit_t *emit, uint label) {
Damien George069a35e2014-04-10 17:22:19 +0000481 emit_pre(emit, 0, 3);
Damien429d7192013-10-04 19:53:11 +0100482 if (emit->pass == PASS_3) {
483 printf("SETUP_EXCEPT %d\n", emit->label_offsets[label]);
484 }
485}
486
Damien George6f355fd2014-04-10 14:11:31 +0100487STATIC void emit_cpy_setup_finally(emit_t *emit, uint label) {
Damien George069a35e2014-04-10 17:22:19 +0000488 emit_pre(emit, 0, 3);
Damien429d7192013-10-04 19:53:11 +0100489 if (emit->pass == PASS_3) {
490 printf("SETUP_FINALLY %d\n", emit->label_offsets[label]);
491 }
492}
493
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200494STATIC void emit_cpy_end_finally(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100495 emit_pre(emit, -1, 1);
496 if (emit->pass == PASS_3) {
497 printf("END_FINALLY\n");
498 }
499}
500
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200501STATIC void emit_cpy_get_iter(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100502 emit_pre(emit, 0, 1);
503 if (emit->pass == PASS_3) {
504 printf("GET_ITER\n");
505 }
506}
507
Damien George6f355fd2014-04-10 14:11:31 +0100508STATIC void emit_cpy_for_iter(emit_t *emit, uint label) {
Damien429d7192013-10-04 19:53:11 +0100509 emit_pre(emit, 1, 3);
510 if (emit->pass == PASS_3) {
511 printf("FOR_ITER %d\n", emit->label_offsets[label]);
512 }
513}
514
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200515STATIC void emit_cpy_for_iter_end(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100516 emit_pre(emit, -1, 0);
517}
518
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200519STATIC void emit_cpy_pop_block(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100520 emit_pre(emit, 0, 1);
521 if (emit->pass == PASS_3) {
522 printf("POP_BLOCK\n");
523 }
524}
525
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200526STATIC void emit_cpy_pop_except(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100527 emit_pre(emit, 0, 1);
528 if (emit->pass == PASS_3) {
529 printf("POP_EXCEPT\n");
530 }
531}
532
Damien Georged17926d2014-03-30 13:35:08 +0100533STATIC void emit_cpy_unary_op(emit_t *emit, mp_unary_op_t op) {
Damien429d7192013-10-04 19:53:11 +0100534 emit_pre(emit, 0, 1);
535 if (emit->pass == PASS_3) {
536 switch (op) {
Damien Georged17926d2014-03-30 13:35:08 +0100537 case MP_UNARY_OP_POSITIVE: printf("UNARY_POSITIVE\n"); break;
538 case MP_UNARY_OP_NEGATIVE: printf("UNARY_NEGATIVE\n"); break;
539 case MP_UNARY_OP_INVERT: printf("UNARY_INVERT\n"); break;
540 case MP_UNARY_OP_NOT: printf("UNARY_NOT\n"); break;
Damien429d7192013-10-04 19:53:11 +0100541 default: assert(0);
542 }
543 }
544}
545
Damien Georged17926d2014-03-30 13:35:08 +0100546STATIC void emit_cpy_binary_op(emit_t *emit, mp_binary_op_t op) {
547 if (op <= MP_BINARY_OP_INPLACE_POWER) {
Damien Georgebc1d3692014-01-11 09:47:06 +0000548 // CPython uses a byte code for each binary op
549 emit_pre(emit, -1, 1);
550 } else {
551 // CPython uses a byte code plus an argument for compare ops
552 emit_pre(emit, -1, 3);
553 }
Damien429d7192013-10-04 19:53:11 +0100554 if (emit->pass == PASS_3) {
555 switch (op) {
Damien Georged17926d2014-03-30 13:35:08 +0100556 case MP_BINARY_OP_SUBSCR: printf("BINARY_SUBSCR\n"); break;
557 case MP_BINARY_OP_OR: printf("BINARY_OR\n"); break;
558 case MP_BINARY_OP_XOR: printf("BINARY_XOR\n"); break;
559 case MP_BINARY_OP_AND: printf("BINARY_AND\n"); break;
560 case MP_BINARY_OP_LSHIFT: printf("BINARY_LSHIFT\n"); break;
561 case MP_BINARY_OP_RSHIFT: printf("BINARY_RSHIFT\n"); break;
562 case MP_BINARY_OP_ADD: printf("BINARY_ADD\n"); break;
563 case MP_BINARY_OP_SUBTRACT: printf("BINARY_SUBTRACT\n"); break;
564 case MP_BINARY_OP_MULTIPLY: printf("BINARY_MULTIPLY\n"); break;
565 case MP_BINARY_OP_FLOOR_DIVIDE: printf("BINARY_FLOOR_DIVIDE\n"); break;
566 case MP_BINARY_OP_TRUE_DIVIDE: printf("BINARY_TRUE_DIVIDE\n"); break;
567 case MP_BINARY_OP_MODULO: printf("BINARY_MODULO\n"); break;
568 case MP_BINARY_OP_POWER: printf("BINARY_POWER\n"); break;
569 case MP_BINARY_OP_INPLACE_OR: printf("INPLACE_OR\n"); break;
570 case MP_BINARY_OP_INPLACE_XOR: printf("INPLACE_XOR\n"); break;
571 case MP_BINARY_OP_INPLACE_AND: printf("INPLACE_AND\n"); break;
572 case MP_BINARY_OP_INPLACE_LSHIFT: printf("INPLACE_LSHIFT\n"); break;
573 case MP_BINARY_OP_INPLACE_RSHIFT: printf("INPLACE_RSHIFT\n"); break;
574 case MP_BINARY_OP_INPLACE_ADD: printf("INPLACE_ADD\n"); break;
575 case MP_BINARY_OP_INPLACE_SUBTRACT: printf("INPLACE_SUBTRACT\n"); break;
576 case MP_BINARY_OP_INPLACE_MULTIPLY: printf("INPLACE_MULTIPLY\n"); break;
577 case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE: printf("INPLACE_FLOOR_DIVIDE\n"); break;
578 case MP_BINARY_OP_INPLACE_TRUE_DIVIDE: printf("INPLACE_TRUE_DIVIDE\n"); break;
579 case MP_BINARY_OP_INPLACE_MODULO: printf("INPLACE_MODULO\n"); break;
580 case MP_BINARY_OP_INPLACE_POWER: printf("INPLACE_POWER\n"); break;
581 case MP_BINARY_OP_LESS: printf("COMPARE_OP <\n"); break;
582 case MP_BINARY_OP_MORE: printf("COMPARE_OP >\n"); break;
583 case MP_BINARY_OP_EQUAL: printf("COMPARE_OP ==\n"); break;
584 case MP_BINARY_OP_LESS_EQUAL: printf("COMPARE_OP <=\n"); break;
585 case MP_BINARY_OP_MORE_EQUAL: printf("COMPARE_OP >=\n"); break;
586 case MP_BINARY_OP_NOT_EQUAL: printf("COMPARE_OP !=\n"); break;
587 case MP_BINARY_OP_IN: printf("COMPARE_OP in\n"); break;
588 case MP_BINARY_OP_IS: printf("COMPARE_OP is\n"); break;
589 case MP_BINARY_OP_EXCEPTION_MATCH: printf("COMPARE_OP exception match\n"); break;
590 case MP_BINARY_OP_NOT_IN: printf("COMPARE_OP not in\n"); break;
591 case MP_BINARY_OP_IS_NOT: printf("COMPARE_OP is not\n"); break;
Damien429d7192013-10-04 19:53:11 +0100592 default: assert(0);
593 }
594 }
595}
596
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200597STATIC void emit_cpy_build_tuple(emit_t *emit, int n_args) {
Damien429d7192013-10-04 19:53:11 +0100598 emit_pre(emit, 1 - n_args, 3);
599 if (emit->pass == PASS_3) {
600 printf("BUILD_TUPLE %d\n", n_args);
601 }
602}
603
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200604STATIC void emit_cpy_build_list(emit_t *emit, int n_args) {
Damien429d7192013-10-04 19:53:11 +0100605 emit_pre(emit, 1 - n_args, 3);
606 if (emit->pass == PASS_3) {
607 printf("BUILD_LIST %d\n", n_args);
608 }
609}
610
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200611STATIC void emit_cpy_list_append(emit_t *emit, int list_index) {
Damien429d7192013-10-04 19:53:11 +0100612 emit_pre(emit, -1, 3);
613 if (emit->pass == PASS_3) {
614 printf("LIST_APPEND %d\n", list_index);
615 }
616}
617
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200618STATIC void emit_cpy_build_map(emit_t *emit, int n_args) {
Damien429d7192013-10-04 19:53:11 +0100619 emit_pre(emit, 1, 3);
620 if (emit->pass == PASS_3) {
621 printf("BUILD_MAP %d\n", n_args);
622 }
623}
624
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200625STATIC void emit_cpy_store_map(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100626 emit_pre(emit, -2, 1);
627 if (emit->pass == PASS_3) {
628 printf("STORE_MAP\n");
629 }
630}
631
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200632STATIC void emit_cpy_map_add(emit_t *emit, int map_index) {
Damien429d7192013-10-04 19:53:11 +0100633 emit_pre(emit, -2, 3);
634 if (emit->pass == PASS_3) {
635 printf("MAP_ADD %d\n", map_index);
636 }
637}
638
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200639STATIC void emit_cpy_build_set(emit_t *emit, int n_args) {
Damien429d7192013-10-04 19:53:11 +0100640 emit_pre(emit, 1 - n_args, 3);
641 if (emit->pass == PASS_3) {
642 printf("BUILD_SET %d\n", n_args);
643 }
644}
645
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200646STATIC void emit_cpy_set_add(emit_t *emit, int set_index) {
Damien429d7192013-10-04 19:53:11 +0100647 emit_pre(emit, -1, 3);
648 if (emit->pass == PASS_3) {
649 printf("SET_ADD %d\n", set_index);
650 }
651}
652
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200653STATIC void emit_cpy_build_slice(emit_t *emit, int n_args) {
Damien429d7192013-10-04 19:53:11 +0100654 emit_pre(emit, 1 - n_args, 3);
655 if (emit->pass == PASS_3) {
656 printf("BUILD_SLICE %d\n", n_args);
657 }
658}
659
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200660STATIC void emit_cpy_unpack_sequence(emit_t *emit, int n_args) {
Damien429d7192013-10-04 19:53:11 +0100661 emit_pre(emit, -1 + n_args, 3);
662 if (emit->pass == PASS_3) {
663 printf("UNPACK_SEQUENCE %d\n", n_args);
664 }
665}
666
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200667STATIC void emit_cpy_unpack_ex(emit_t *emit, int n_left, int n_right) {
Damien429d7192013-10-04 19:53:11 +0100668 emit_pre(emit, -1 + n_left + n_right + 1, 3);
669 if (emit->pass == PASS_3) {
670 printf("UNPACK_EX %d\n", n_left | (n_right << 8));
671 }
672}
673
Damien George922ddd62014-04-09 12:43:17 +0100674STATIC void emit_cpy_call_function(emit_t *emit, int n_positional, int n_keyword, uint star_flags) {
Damien429d7192013-10-04 19:53:11 +0100675 int s = 0;
Damien George922ddd62014-04-09 12:43:17 +0100676 if (star_flags & MP_EMIT_STAR_FLAG_SINGLE) {
Damien429d7192013-10-04 19:53:11 +0100677 s += 1;
678 }
Damien George922ddd62014-04-09 12:43:17 +0100679 if (star_flags & MP_EMIT_STAR_FLAG_DOUBLE) {
Damien429d7192013-10-04 19:53:11 +0100680 s += 1;
681 }
682 emit_pre(emit, -n_positional - 2 * n_keyword - s, 3);
683 if (emit->pass == PASS_3) {
Damien George922ddd62014-04-09 12:43:17 +0100684 if (star_flags & MP_EMIT_STAR_FLAG_SINGLE) {
685 if (star_flags & MP_EMIT_STAR_FLAG_DOUBLE) {
Damien429d7192013-10-04 19:53:11 +0100686 printf("CALL_FUNCTION_VAR_KW");
687 } else {
688 printf("CALL_FUNCTION_VAR");
689 }
690 } else {
Damien George922ddd62014-04-09 12:43:17 +0100691 if (star_flags & MP_EMIT_STAR_FLAG_DOUBLE) {
Damien429d7192013-10-04 19:53:11 +0100692 printf("CALL_FUNCTION_KW");
693 } else {
694 printf("CALL_FUNCTION");
695 }
696 }
697 printf(" %d, %d\n", n_positional, n_keyword);
698 }
699}
700
Damien George922ddd62014-04-09 12:43:17 +0100701STATIC void emit_cpy_call_method(emit_t *emit, int n_positional, int n_keyword, uint star_flags) {
702 emit_cpy_call_function(emit, n_positional, n_keyword, star_flags);
Damien429d7192013-10-04 19:53:11 +0100703}
704
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200705STATIC void emit_cpy_return_value(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100706 emit_pre(emit, -1, 1);
707 emit->last_emit_was_return_value = true;
708 if (emit->pass == PASS_3) {
709 printf("RETURN_VALUE\n");
710 }
711}
712
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200713STATIC void emit_cpy_raise_varargs(emit_t *emit, int n_args) {
Damien429d7192013-10-04 19:53:11 +0100714 emit_pre(emit, -n_args, 3);
715 if (emit->pass == PASS_3) {
716 printf("RAISE_VARARGS %d\n", n_args);
717 }
718}
719
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200720STATIC void load_cpy_const_code_and_name(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100721 emit_pre(emit, 1, 3);
722 if (emit->pass == PASS_3) {
723 printf("LOAD_CONST code %s\n", qstr_str(qstr));
724 }
725 // load qualified name
726 emit_pre(emit, 1, 3);
727 if (emit->pass == PASS_3) {
728 printf("LOAD_CONST '");
729 // code just to work out the qualname (or whatever it is)
730 {
731 int depth = 0;
732 for (scope_t *s = emit->scope; s->parent != NULL; s = s->parent) {
733 depth += 1;
734 }
735 for (int wanted_depth = depth; wanted_depth >= 0; wanted_depth--) {
736 scope_t *s = emit->scope;
737 for (int i = 0; i < wanted_depth; i++) {
738 s = s->parent;
739 }
740 if (s->kind == SCOPE_FUNCTION) {
741 printf("%s.<locals>.", qstr_str(s->simple_name));
742 } else if (s->kind == SCOPE_CLASS) {
743 printf("%s.", qstr_str(s->simple_name));
744 }
745 }
746 }
747 printf("%s'\n", qstr_str(qstr));
748 }
749}
750
Damien George30565092014-03-31 11:30:17 +0100751STATIC 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 +0100752 load_cpy_const_code_and_name(emit, scope->simple_name);
Damien George30565092014-03-31 11:30:17 +0100753 emit_pre(emit, -1 - n_pos_defaults - 2 * n_kw_defaults, 3);
Damien429d7192013-10-04 19:53:11 +0100754 if (emit->pass == PASS_3) {
Damien George30565092014-03-31 11:30:17 +0100755 printf("MAKE_FUNCTION %d\n", (n_kw_defaults << 8) | n_pos_defaults);
Damien429d7192013-10-04 19:53:11 +0100756 }
757}
758
Damien George30565092014-03-31 11:30:17 +0100759STATIC 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 +0100760 load_cpy_const_code_and_name(emit, scope->simple_name);
Damien George30565092014-03-31 11:30:17 +0100761 emit_pre(emit, -2 - n_pos_defaults - 2 * n_kw_defaults, 3);
Damien429d7192013-10-04 19:53:11 +0100762 if (emit->pass == PASS_3) {
Damien George30565092014-03-31 11:30:17 +0100763 printf("MAKE_CLOSURE %d\n", (n_kw_defaults << 8) | n_pos_defaults);
Damien429d7192013-10-04 19:53:11 +0100764 }
765}
766
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200767STATIC void emit_cpy_yield_value(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100768 emit_pre(emit, 0, 1);
769 if (emit->pass == PASS_2) {
Paul Sokolovsky5fd7bc32014-02-16 03:02:47 +0200770 emit->scope->scope_flags |= MP_SCOPE_FLAG_GENERATOR;
Damien429d7192013-10-04 19:53:11 +0100771 }
772 if (emit->pass == PASS_3) {
773 printf("YIELD_VALUE\n");
774 }
775}
776
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200777STATIC void emit_cpy_yield_from(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100778 emit_pre(emit, -1, 1);
779 if (emit->pass == PASS_2) {
Paul Sokolovsky5fd7bc32014-02-16 03:02:47 +0200780 emit->scope->scope_flags |= MP_SCOPE_FLAG_GENERATOR;
Damien429d7192013-10-04 19:53:11 +0100781 }
782 if (emit->pass == PASS_3) {
783 printf("YIELD_FROM\n");
784 }
785}
786
Damien6cdd3af2013-10-05 18:08:26 +0100787const emit_method_table_t emit_cpython_method_table = {
Damien415eb6f2013-10-05 12:19:06 +0100788 emit_cpy_set_native_types,
789 emit_cpy_start_pass,
790 emit_cpy_end_pass,
791 emit_cpy_last_emit_was_return_value,
Damien Georged66ae182014-04-10 17:28:54 +0000792 emit_cpy_adjust_stack_size,
Damien George08335002014-01-18 23:24:36 +0000793 emit_cpy_set_source_line,
Damien415eb6f2013-10-05 12:19:06 +0100794
Damien4b03e772013-10-05 14:17:09 +0100795 emit_cpy_load_id,
796 emit_cpy_store_id,
797 emit_cpy_delete_id,
798
Damien415eb6f2013-10-05 12:19:06 +0100799 emit_cpy_label_assign,
800 emit_cpy_import_name,
801 emit_cpy_import_from,
802 emit_cpy_import_star,
803 emit_cpy_load_const_tok,
804 emit_cpy_load_const_small_int,
805 emit_cpy_load_const_int,
806 emit_cpy_load_const_dec,
807 emit_cpy_load_const_id,
808 emit_cpy_load_const_str,
Damien415eb6f2013-10-05 12:19:06 +0100809 emit_cpy_load_const_verbatim_str,
Damien415eb6f2013-10-05 12:19:06 +0100810 emit_cpy_load_fast,
Damien415eb6f2013-10-05 12:19:06 +0100811 emit_cpy_load_deref,
812 emit_cpy_load_closure,
Damien9ecbcff2013-12-11 00:41:43 +0000813 emit_cpy_load_name,
814 emit_cpy_load_global,
Damien415eb6f2013-10-05 12:19:06 +0100815 emit_cpy_load_attr,
816 emit_cpy_load_method,
817 emit_cpy_load_build_class,
818 emit_cpy_store_fast,
Damien9ecbcff2013-12-11 00:41:43 +0000819 emit_cpy_store_deref,
Damien415eb6f2013-10-05 12:19:06 +0100820 emit_cpy_store_name,
821 emit_cpy_store_global,
Damien415eb6f2013-10-05 12:19:06 +0100822 emit_cpy_store_attr,
Damien415eb6f2013-10-05 12:19:06 +0100823 emit_cpy_store_subscr,
824 emit_cpy_delete_fast,
Damien9ecbcff2013-12-11 00:41:43 +0000825 emit_cpy_delete_deref,
Damien415eb6f2013-10-05 12:19:06 +0100826 emit_cpy_delete_name,
827 emit_cpy_delete_global,
Damien415eb6f2013-10-05 12:19:06 +0100828 emit_cpy_delete_attr,
829 emit_cpy_delete_subscr,
830 emit_cpy_dup_top,
831 emit_cpy_dup_top_two,
832 emit_cpy_pop_top,
833 emit_cpy_rot_two,
834 emit_cpy_rot_three,
835 emit_cpy_jump,
836 emit_cpy_pop_jump_if_true,
837 emit_cpy_pop_jump_if_false,
838 emit_cpy_jump_if_true_or_pop,
839 emit_cpy_jump_if_false_or_pop,
840 emit_cpy_setup_loop,
841 emit_cpy_break_loop,
842 emit_cpy_continue_loop,
843 emit_cpy_setup_with,
844 emit_cpy_with_cleanup,
845 emit_cpy_setup_except,
846 emit_cpy_setup_finally,
847 emit_cpy_end_finally,
848 emit_cpy_get_iter,
849 emit_cpy_for_iter,
850 emit_cpy_for_iter_end,
851 emit_cpy_pop_block,
852 emit_cpy_pop_except,
853 emit_cpy_unary_op,
854 emit_cpy_binary_op,
Damien415eb6f2013-10-05 12:19:06 +0100855 emit_cpy_build_tuple,
856 emit_cpy_build_list,
857 emit_cpy_list_append,
858 emit_cpy_build_map,
859 emit_cpy_store_map,
860 emit_cpy_map_add,
861 emit_cpy_build_set,
862 emit_cpy_set_add,
863 emit_cpy_build_slice,
864 emit_cpy_unpack_sequence,
865 emit_cpy_unpack_ex,
866 emit_cpy_make_function,
867 emit_cpy_make_closure,
868 emit_cpy_call_function,
869 emit_cpy_call_method,
870 emit_cpy_return_value,
871 emit_cpy_raise_varargs,
872 emit_cpy_yield_value,
873 emit_cpy_yield_from,
874};
875
Damien3ef4abb2013-10-12 16:53:13 +0100876#endif // MICROPY_EMIT_CPYTHON