blob: 2a8b577c9809fe281378e23cba673686676b161e [file] [log] [blame]
Damien429d7192013-10-04 19:53:11 +01001#include <unistd.h>
2#include <stdlib.h>
3#include <stdint.h>
4#include <stdio.h>
5#include <string.h>
6#include <assert.h>
7
8#include "misc.h"
Damiend99b0522013-12-21 18:17:45 +00009#include "mpconfig.h"
Damien George55baff42014-01-21 21:40:13 +000010#include "qstr.h"
Damien429d7192013-10-04 19:53:11 +010011#include "lexer.h"
Damien429d7192013-10-04 19:53:11 +010012#include "parse.h"
Damien429d7192013-10-04 19:53:11 +010013#include "scope.h"
Damiend99b0522013-12-21 18:17:45 +000014#include "runtime0.h"
Damien429d7192013-10-04 19:53:11 +010015#include "emit.h"
16
Damien Georgee67ed5d2014-01-04 13:55:24 +000017// wrapper around everything in this file
Damien3ef4abb2013-10-12 16:53:13 +010018#if MICROPY_EMIT_CPYTHON
Damien429d7192013-10-04 19:53:11 +010019
Damien415eb6f2013-10-05 12:19:06 +010020struct _emit_t {
Damien429d7192013-10-04 19:53:11 +010021 int pass;
Damien429d7192013-10-04 19:53:11 +010022 int byte_code_offset;
23 int stack_size;
24 bool last_emit_was_return_value;
25
26 scope_t *scope;
27
Damienb05d7072013-10-05 13:37:10 +010028 uint max_num_labels;
Damien429d7192013-10-04 19:53:11 +010029 int *label_offsets;
30};
31
Damien6cdd3af2013-10-05 18:08:26 +010032emit_t *emit_cpython_new(uint max_num_labels) {
33 emit_t *emit = m_new(emit_t, 1);
34 emit->max_num_labels = max_num_labels;
35 emit->label_offsets = m_new(int, max_num_labels);
36 return emit;
37}
38
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020039STATIC void emit_cpy_set_native_types(emit_t *emit, bool do_native_types) {
Damien429d7192013-10-04 19:53:11 +010040}
41
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020042STATIC void emit_cpy_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) {
Damien429d7192013-10-04 19:53:11 +010043 emit->pass = pass;
Damien429d7192013-10-04 19:53:11 +010044 emit->byte_code_offset = 0;
45 emit->stack_size = 0;
46 emit->last_emit_was_return_value = false;
47 emit->scope = scope;
Damienb05d7072013-10-05 13:37:10 +010048 if (pass == PASS_2) {
49 memset(emit->label_offsets, -1, emit->max_num_labels * sizeof(int));
Damien429d7192013-10-04 19:53:11 +010050 }
51}
52
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020053STATIC void emit_cpy_end_pass(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +010054 // check stack is back to zero size
55 if (emit->stack_size != 0) {
56 printf("ERROR: stack size not back to zero; got %d\n", emit->stack_size);
57 }
Damien429d7192013-10-04 19:53:11 +010058}
59
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020060STATIC bool emit_cpy_last_emit_was_return_value(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +010061 return emit->last_emit_was_return_value;
62}
63
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020064STATIC int emit_cpy_get_stack_size(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +010065 return emit->stack_size;
66}
67
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020068STATIC void emit_cpy_set_stack_size(emit_t *emit, int size) {
Damien429d7192013-10-04 19:53:11 +010069 emit->stack_size = size;
70}
71
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020072STATIC void emit_cpy_set_source_line(emit_t *emit, int source_line) {
Damien George08335002014-01-18 23:24:36 +000073}
74
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020075STATIC void emit_cpy_load_id(emit_t *emit, qstr qstr) {
Damien6cdd3af2013-10-05 18:08:26 +010076 emit_common_load_id(emit, &emit_cpython_method_table, emit->scope, qstr);
Damien4b03e772013-10-05 14:17:09 +010077}
78
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020079STATIC void emit_cpy_store_id(emit_t *emit, qstr qstr) {
Damien6cdd3af2013-10-05 18:08:26 +010080 emit_common_store_id(emit, &emit_cpython_method_table, emit->scope, qstr);
Damien4b03e772013-10-05 14:17:09 +010081}
82
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020083STATIC void emit_cpy_delete_id(emit_t *emit, qstr qstr) {
Damien6cdd3af2013-10-05 18:08:26 +010084 emit_common_delete_id(emit, &emit_cpython_method_table, emit->scope, qstr);
Damien4b03e772013-10-05 14:17:09 +010085}
86
Paul Sokolovsky520e2f52014-02-12 18:31:30 +020087// TODO: module-polymorphic function (read: name clash if made global)
Damien415eb6f2013-10-05 12:19:06 +010088static void emit_pre(emit_t *emit, int stack_size_delta, int byte_code_size) {
Damien429d7192013-10-04 19:53:11 +010089 emit->stack_size += stack_size_delta;
Damienb05d7072013-10-05 13:37:10 +010090 if (emit->stack_size > emit->scope->stack_size) {
Damien429d7192013-10-04 19:53:11 +010091 emit->scope->stack_size = emit->stack_size;
92 }
93 emit->last_emit_was_return_value = false;
94 if (emit->pass == PASS_3 && byte_code_size > 0) {
95 if (emit->byte_code_offset >= 1000) {
96 printf("%d ", emit->byte_code_offset);
97 } else {
98 printf("% 4d ", emit->byte_code_offset);
99 }
100 }
101 emit->byte_code_offset += byte_code_size;
102}
103
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200104STATIC void emit_cpy_label_assign(emit_t *emit, int l) {
Damien429d7192013-10-04 19:53:11 +0100105 emit_pre(emit, 0, 0);
Damienb05d7072013-10-05 13:37:10 +0100106 assert(l < emit->max_num_labels);
107 if (emit->pass == PASS_2) {
108 // assign label offset
109 assert(emit->label_offsets[l] == -1);
110 emit->label_offsets[l] = emit->byte_code_offset;
111 } else if (emit->pass == PASS_3) {
112 // ensure label offset has not changed from PASS_2 to PASS_3
113 assert(emit->label_offsets[l] == emit->byte_code_offset);
114 //printf("l%d: (at %d)\n", l, emit->byte_code_offset);
Damien429d7192013-10-04 19:53:11 +0100115 }
116}
117
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200118STATIC void emit_cpy_import_name(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100119 emit_pre(emit, -1, 3);
120 if (emit->pass == PASS_3) {
121 printf("IMPORT_NAME %s\n", qstr_str(qstr));
122 }
123}
124
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200125STATIC void emit_cpy_import_from(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100126 emit_pre(emit, 1, 3);
127 if (emit->pass == PASS_3) {
128 printf("IMPORT_FROM %s\n", qstr_str(qstr));
129 }
130}
131
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200132STATIC void emit_cpy_import_star(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100133 emit_pre(emit, -1, 1);
134 if (emit->pass == PASS_3) {
135 printf("IMPORT_STAR\n");
136 }
137}
138
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200139STATIC void emit_cpy_load_const_tok(emit_t *emit, mp_token_kind_t tok) {
Damien429d7192013-10-04 19:53:11 +0100140 emit_pre(emit, 1, 3);
141 if (emit->pass == PASS_3) {
142 printf("LOAD_CONST ");
143 switch (tok) {
Damiend99b0522013-12-21 18:17:45 +0000144 case MP_TOKEN_KW_FALSE: printf("False"); break;
145 case MP_TOKEN_KW_NONE: printf("None"); break;
146 case MP_TOKEN_KW_TRUE: printf("True"); break;
Damien429d7192013-10-04 19:53:11 +0100147 default: printf("?=%d\n", tok); return; assert(0);
148 }
149 printf("\n");
150 }
151}
152
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200153STATIC void emit_cpy_load_const_small_int(emit_t *emit, machine_int_t arg) {
Damien429d7192013-10-04 19:53:11 +0100154 emit_pre(emit, 1, 3);
155 if (emit->pass == PASS_3) {
Damien George08d07552014-01-29 18:58:52 +0000156 printf("LOAD_CONST " INT_FMT "\n", arg);
Damien429d7192013-10-04 19:53:11 +0100157 }
158}
159
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200160STATIC void emit_cpy_load_const_int(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100161 emit_pre(emit, 1, 3);
162 if (emit->pass == PASS_3) {
163 printf("LOAD_CONST %s\n", qstr_str(qstr));
164 }
165}
166
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200167STATIC void emit_cpy_load_const_dec(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100168 emit_pre(emit, 1, 3);
169 if (emit->pass == PASS_3) {
170 printf("LOAD_CONST %s\n", qstr_str(qstr));
171 }
172}
173
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200174STATIC void emit_cpy_load_const_id(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100175 emit_pre(emit, 1, 3);
176 if (emit->pass == PASS_3) {
177 printf("LOAD_CONST '%s'\n", qstr_str(qstr));
178 }
179}
180
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200181STATIC void print_quoted_str(qstr qstr, bool bytes) {
Damiena1b26932013-12-12 15:34:40 +0000182 const char *str = qstr_str(qstr);
183 int len = strlen(str);
184 bool has_single_quote = false;
185 bool has_double_quote = false;
186 for (int i = 0; i < len; i++) {
187 if (str[i] == '\'') {
188 has_single_quote = true;
189 } else if (str[i] == '"') {
190 has_double_quote = true;
191 }
192 }
193 if (bytes) {
194 printf("b");
195 }
Damien Georgeb829b5c2014-01-25 13:51:19 +0000196 int quote_char = '\'';
Damiena1b26932013-12-12 15:34:40 +0000197 if (has_single_quote && !has_double_quote) {
Damien Georgeb829b5c2014-01-25 13:51:19 +0000198 quote_char = '"';
Damiena1b26932013-12-12 15:34:40 +0000199 }
Damien Georgeb829b5c2014-01-25 13:51:19 +0000200 printf("%c", quote_char);
201 for (const char *s = str, *top = str + len; s < top; s++) {
202 if (*s == quote_char) {
203 printf("\\%c", quote_char);
204 } else if (*s == '\\') {
Damiena1b26932013-12-12 15:34:40 +0000205 printf("\\\\");
Damien Georgeb829b5c2014-01-25 13:51:19 +0000206 } else if (32 <= *s && *s <= 126) {
207 printf("%c", *s);
208 } else if (*s == '\n') {
209 printf("\\n");
210 // TODO add more escape codes here
Damiena1b26932013-12-12 15:34:40 +0000211 } else {
Damien Georgeb829b5c2014-01-25 13:51:19 +0000212 printf("\\x%02x", (*s) & 0xff);
Damiena1b26932013-12-12 15:34:40 +0000213 }
214 }
Damien Georgeb829b5c2014-01-25 13:51:19 +0000215 printf("%c", quote_char);
Damiena1b26932013-12-12 15:34:40 +0000216}
217
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200218STATIC void emit_cpy_load_const_str(emit_t *emit, qstr qstr, bool bytes) {
Damien429d7192013-10-04 19:53:11 +0100219 emit_pre(emit, 1, 3);
220 if (emit->pass == PASS_3) {
221 printf("LOAD_CONST ");
Damiena1b26932013-12-12 15:34:40 +0000222 print_quoted_str(qstr, bytes);
Damien429d7192013-10-04 19:53:11 +0100223 printf("\n");
224 }
225}
226
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200227STATIC void emit_cpy_load_const_verbatim_str(emit_t *emit, const char *str) {
Damiena1b26932013-12-12 15:34:40 +0000228 emit_pre(emit, 1, 3);
Damien429d7192013-10-04 19:53:11 +0100229 if (emit->pass == PASS_3) {
Damiena1b26932013-12-12 15:34:40 +0000230 printf("LOAD_CONST %s\n", str);
Damien429d7192013-10-04 19:53:11 +0100231 }
232}
233
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200234STATIC void emit_cpy_load_fast(emit_t *emit, qstr qstr, int local_num) {
Damien6cdd3af2013-10-05 18:08:26 +0100235 emit_pre(emit, 1, 3);
236 if (emit->pass == PASS_3) {
237 printf("LOAD_FAST %d %s\n", local_num, qstr_str(qstr));
238 }
239}
240
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200241STATIC void emit_cpy_load_deref(emit_t *emit, qstr qstr, int local_num) {
Damien429d7192013-10-04 19:53:11 +0100242 emit_pre(emit, 1, 3);
243 if (emit->pass == PASS_3) {
Damien27fb45e2013-10-20 15:07:49 +0100244 printf("LOAD_DEREF %d %s\n", local_num, qstr_str(qstr));
Damien429d7192013-10-04 19:53:11 +0100245 }
246}
247
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200248STATIC void emit_cpy_load_closure(emit_t *emit, qstr qstr, int local_num) {
Damien429d7192013-10-04 19:53:11 +0100249 emit_pre(emit, 1, 3);
250 if (emit->pass == PASS_3) {
Damien27fb45e2013-10-20 15:07:49 +0100251 printf("LOAD_CLOSURE %d %s\n", local_num, qstr_str(qstr));
Damien429d7192013-10-04 19:53:11 +0100252 }
253}
254
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200255STATIC void emit_cpy_load_name(emit_t *emit, qstr qstr) {
Damien9ecbcff2013-12-11 00:41:43 +0000256 emit_pre(emit, 1, 3);
257 if (emit->pass == PASS_3) {
258 printf("LOAD_NAME %s\n", qstr_str(qstr));
259 }
260}
261
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200262STATIC void emit_cpy_load_global(emit_t *emit, qstr qstr) {
Damien9ecbcff2013-12-11 00:41:43 +0000263 emit_pre(emit, 1, 3);
264 if (emit->pass == PASS_3) {
265 printf("LOAD_GLOBAL %s\n", qstr_str(qstr));
266 }
267}
268
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200269STATIC void emit_cpy_load_attr(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100270 emit_pre(emit, 0, 3);
271 if (emit->pass == PASS_3) {
272 printf("LOAD_ATTR %s\n", qstr_str(qstr));
273 }
274}
275
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200276STATIC void emit_cpy_load_method(emit_t *emit, qstr qstr) {
Damien415eb6f2013-10-05 12:19:06 +0100277 emit_cpy_load_attr(emit, qstr);
Damien429d7192013-10-04 19:53:11 +0100278}
279
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200280STATIC void emit_cpy_load_build_class(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100281 emit_pre(emit, 1, 1);
282 if (emit->pass == PASS_3) {
283 printf("LOAD_BUILD_CLASS\n");
284 }
285}
286
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200287STATIC void emit_cpy_store_fast(emit_t *emit, qstr qstr, int local_num) {
Damien6cdd3af2013-10-05 18:08:26 +0100288 emit_pre(emit, -1, 3);
289 if (emit->pass == PASS_3) {
290 printf("STORE_FAST %d %s\n", local_num, qstr_str(qstr));
291 }
292}
293
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200294STATIC void emit_cpy_store_deref(emit_t *emit, qstr qstr, int local_num) {
Damien9ecbcff2013-12-11 00:41:43 +0000295 emit_pre(emit, -1, 3);
296 if (emit->pass == PASS_3) {
297 printf("STORE_DEREF %d %s\n", local_num, qstr_str(qstr));
298 }
299}
300
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200301STATIC void emit_cpy_store_name(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100302 emit_pre(emit, -1, 3);
303 if (emit->pass == PASS_3) {
304 printf("STORE_NAME %s\n", qstr_str(qstr));
305 }
306}
307
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200308STATIC void emit_cpy_store_global(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100309 emit_pre(emit, -1, 3);
310 if (emit->pass == PASS_3) {
311 printf("STORE_GLOBAL %s\n", qstr_str(qstr));
312 }
313}
314
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200315STATIC void emit_cpy_store_attr(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100316 emit_pre(emit, -2, 3);
317 if (emit->pass == PASS_3) {
318 printf("STORE_ATTR %s\n", qstr_str(qstr));
319 }
320}
321
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200322STATIC void emit_cpy_store_subscr(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100323 emit_pre(emit, -3, 1);
324 if (emit->pass == PASS_3) {
325 printf("STORE_SUBSCR\n");
326 }
327}
328
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200329STATIC void emit_cpy_store_locals(emit_t *emit) {
Damiena3977762013-10-09 23:10:10 +0100330 emit_pre(emit, -1, 1);
331 if (emit->pass == PASS_3) {
332 printf("STORE_LOCALS\n");
333 }
334}
335
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200336STATIC void emit_cpy_delete_fast(emit_t *emit, qstr qstr, int local_num) {
Damien6cdd3af2013-10-05 18:08:26 +0100337 emit_pre(emit, 0, 3);
338 if (emit->pass == PASS_3) {
339 printf("DELETE_FAST %d %s\n", local_num, qstr_str(qstr));
340 }
341}
342
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200343STATIC void emit_cpy_delete_deref(emit_t *emit, qstr qstr, int local_num) {
Damien9ecbcff2013-12-11 00:41:43 +0000344 emit_pre(emit, 0, 3);
345 if (emit->pass == PASS_3) {
346 printf("DELETE_DEREF %d %s\n", local_num, qstr_str(qstr));
347 }
348}
349
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200350STATIC void emit_cpy_delete_name(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100351 emit_pre(emit, 0, 3);
352 if (emit->pass == PASS_3) {
353 printf("DELETE_NAME %s\n", qstr_str(qstr));
354 }
355}
356
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200357STATIC void emit_cpy_delete_global(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100358 emit_pre(emit, 0, 3);
359 if (emit->pass == PASS_3) {
360 printf("DELETE_GLOBAL %s\n", qstr_str(qstr));
361 }
362}
363
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200364STATIC void emit_cpy_delete_attr(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100365 emit_pre(emit, -1, 3);
366 if (emit->pass == PASS_3) {
367 printf("DELETE_ATTR %s\n", qstr_str(qstr));
368 }
369}
370
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200371STATIC void emit_cpy_delete_subscr(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100372 emit_pre(emit, -2, 1);
373 if (emit->pass == PASS_3) {
374 printf("DELETE_SUBSCR\n");
375 }
376}
377
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200378STATIC void emit_cpy_dup_top(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100379 emit_pre(emit, 1, 1);
380 if (emit->pass == PASS_3) {
381 printf("DUP_TOP\n");
382 }
383}
384
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200385STATIC void emit_cpy_dup_top_two(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100386 emit_pre(emit, 2, 1);
387 if (emit->pass == PASS_3) {
388 printf("DUP_TOP_TWO\n");
389 }
390}
391
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200392STATIC void emit_cpy_pop_top(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100393 emit_pre(emit, -1, 1);
394 if (emit->pass == PASS_3) {
395 printf("POP_TOP\n");
396 }
397}
398
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200399STATIC void emit_cpy_rot_two(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100400 emit_pre(emit, 0, 1);
401 if (emit->pass == PASS_3) {
402 printf("ROT_TWO\n");
403 }
404}
405
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200406STATIC void emit_cpy_rot_three(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100407 emit_pre(emit, 0, 1);
408 if (emit->pass == PASS_3) {
409 printf("ROT_THREE\n");
410 }
411}
412
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200413STATIC void emit_cpy_jump(emit_t *emit, int label) {
Damien429d7192013-10-04 19:53:11 +0100414 emit_pre(emit, 0, 3);
415 if (emit->pass == PASS_3) {
416 int dest = emit->label_offsets[label];
417 if (dest < emit->byte_code_offset) {
418 printf("JUMP_ABSOLUTE %d\n", emit->label_offsets[label]);
419 } else {
420 printf("JUMP_FORWARD %d\n", emit->label_offsets[label]);
421 }
422 }
423}
424
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200425STATIC void emit_cpy_pop_jump_if_true(emit_t *emit, int label) {
Damien429d7192013-10-04 19:53:11 +0100426 emit_pre(emit, -1, 3);
427 if (emit->pass == PASS_3) {
428 printf("POP_JUMP_IF_TRUE %d\n", emit->label_offsets[label]);
429 }
430}
431
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200432STATIC void emit_cpy_pop_jump_if_false(emit_t *emit, int label) {
Damien429d7192013-10-04 19:53:11 +0100433 emit_pre(emit, -1, 3);
434 if (emit->pass == PASS_3) {
435 printf("POP_JUMP_IF_FALSE %d\n", emit->label_offsets[label]);
436 }
437}
438
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200439STATIC void emit_cpy_jump_if_true_or_pop(emit_t *emit, int label) {
Damien429d7192013-10-04 19:53:11 +0100440 emit_pre(emit, -1, 3);
441 if (emit->pass == PASS_3) {
442 printf("JUMP_IF_TRUE_OR_POP %d\n", emit->label_offsets[label]);
443 }
444}
445
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200446STATIC void emit_cpy_jump_if_false_or_pop(emit_t *emit, int label) {
Damien429d7192013-10-04 19:53:11 +0100447 emit_pre(emit, -1, 3);
448 if (emit->pass == PASS_3) {
449 printf("JUMP_IF_FALSE_OR_POP %d\n", emit->label_offsets[label]);
450 }
451}
452
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200453STATIC void emit_cpy_setup_loop(emit_t *emit, int label) {
Damien429d7192013-10-04 19:53:11 +0100454 emit_pre(emit, 0, 3);
455 if (emit->pass == PASS_3) {
456 printf("SETUP_LOOP %d\n", emit->label_offsets[label]);
457 }
458}
459
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200460STATIC void emit_cpy_break_loop(emit_t *emit, int label, int except_depth) {
Damien429d7192013-10-04 19:53:11 +0100461 emit_pre(emit, 0, 1);
462 if (emit->pass == PASS_3) {
Damien Georgee24b5632014-02-01 21:56:25 +0000463 printf("BREAK_LOOP\n");
Damien429d7192013-10-04 19:53:11 +0100464 }
465}
466
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200467STATIC void emit_cpy_continue_loop(emit_t *emit, int label, int except_depth) {
Damien Georgee24b5632014-02-01 21:56:25 +0000468 if (except_depth == 0) {
469 emit_cpy_jump(emit, label);
470 } else {
471 emit_pre(emit, 0, 3);
472 if (emit->pass == PASS_3) {
473 printf("CONTINUE_LOOP %d\n", emit->label_offsets[label]);
474 }
Damien429d7192013-10-04 19:53:11 +0100475 }
476}
477
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200478STATIC void emit_cpy_setup_with(emit_t *emit, int label) {
Damien429d7192013-10-04 19:53:11 +0100479 emit_pre(emit, 7, 3);
480 if (emit->pass == PASS_3) {
481 printf("SETUP_WITH %d\n", emit->label_offsets[label]);
482 }
483}
484
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200485STATIC void emit_cpy_with_cleanup(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100486 emit_pre(emit, -7, 1);
487 if (emit->pass == PASS_3) {
488 printf("WITH_CLEANUP\n");
489 }
490}
491
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200492STATIC void emit_cpy_setup_except(emit_t *emit, int label) {
Damien429d7192013-10-04 19:53:11 +0100493 emit_pre(emit, 6, 3);
494 if (emit->pass == PASS_3) {
495 printf("SETUP_EXCEPT %d\n", emit->label_offsets[label]);
496 }
497}
498
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200499STATIC void emit_cpy_setup_finally(emit_t *emit, int label) {
Damien429d7192013-10-04 19:53:11 +0100500 emit_pre(emit, 6, 3);
501 if (emit->pass == PASS_3) {
502 printf("SETUP_FINALLY %d\n", emit->label_offsets[label]);
503 }
504}
505
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200506STATIC void emit_cpy_end_finally(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100507 emit_pre(emit, -1, 1);
508 if (emit->pass == PASS_3) {
509 printf("END_FINALLY\n");
510 }
511}
512
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200513STATIC void emit_cpy_get_iter(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100514 emit_pre(emit, 0, 1);
515 if (emit->pass == PASS_3) {
516 printf("GET_ITER\n");
517 }
518}
519
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200520STATIC void emit_cpy_for_iter(emit_t *emit, int label) {
Damien429d7192013-10-04 19:53:11 +0100521 emit_pre(emit, 1, 3);
522 if (emit->pass == PASS_3) {
523 printf("FOR_ITER %d\n", emit->label_offsets[label]);
524 }
525}
526
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200527STATIC void emit_cpy_for_iter_end(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100528 emit_pre(emit, -1, 0);
529}
530
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200531STATIC void emit_cpy_pop_block(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100532 emit_pre(emit, 0, 1);
533 if (emit->pass == PASS_3) {
534 printf("POP_BLOCK\n");
535 }
536}
537
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200538STATIC void emit_cpy_pop_except(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100539 emit_pre(emit, 0, 1);
540 if (emit->pass == PASS_3) {
541 printf("POP_EXCEPT\n");
542 }
543}
544
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200545STATIC void emit_cpy_unary_op(emit_t *emit, rt_unary_op_t op) {
Damien429d7192013-10-04 19:53:11 +0100546 emit_pre(emit, 0, 1);
547 if (emit->pass == PASS_3) {
548 switch (op) {
Damien429d7192013-10-04 19:53:11 +0100549 case RT_UNARY_OP_POSITIVE: printf("UNARY_POSITIVE\n"); break;
550 case RT_UNARY_OP_NEGATIVE: printf("UNARY_NEGATIVE\n"); break;
551 case RT_UNARY_OP_INVERT: printf("UNARY_INVERT\n"); break;
Damien George9aa2a522014-02-01 23:04:09 +0000552 case RT_UNARY_OP_NOT: printf("UNARY_NOT\n"); break;
Damien429d7192013-10-04 19:53:11 +0100553 default: assert(0);
554 }
555 }
556}
557
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200558STATIC void emit_cpy_binary_op(emit_t *emit, rt_binary_op_t op) {
Damien Georgebc1d3692014-01-11 09:47:06 +0000559 if (op <= RT_BINARY_OP_INPLACE_POWER) {
560 // CPython uses a byte code for each binary op
561 emit_pre(emit, -1, 1);
562 } else {
563 // CPython uses a byte code plus an argument for compare ops
564 emit_pre(emit, -1, 3);
565 }
Damien429d7192013-10-04 19:53:11 +0100566 if (emit->pass == PASS_3) {
567 switch (op) {
568 case RT_BINARY_OP_SUBSCR: printf("BINARY_SUBSCR\n"); break;
569 case RT_BINARY_OP_OR: printf("BINARY_OR\n"); break;
570 case RT_BINARY_OP_XOR: printf("BINARY_XOR\n"); break;
571 case RT_BINARY_OP_AND: printf("BINARY_AND\n"); break;
572 case RT_BINARY_OP_LSHIFT: printf("BINARY_LSHIFT\n"); break;
573 case RT_BINARY_OP_RSHIFT: printf("BINARY_RSHIFT\n"); break;
574 case RT_BINARY_OP_ADD: printf("BINARY_ADD\n"); break;
575 case RT_BINARY_OP_SUBTRACT: printf("BINARY_SUBTRACT\n"); break;
576 case RT_BINARY_OP_MULTIPLY: printf("BINARY_MULTIPLY\n"); break;
577 case RT_BINARY_OP_FLOOR_DIVIDE: printf("BINARY_FLOOR_DIVIDE\n"); break;
578 case RT_BINARY_OP_TRUE_DIVIDE: printf("BINARY_TRUE_DIVIDE\n"); break;
579 case RT_BINARY_OP_MODULO: printf("BINARY_MODULO\n"); break;
580 case RT_BINARY_OP_POWER: printf("BINARY_POWER\n"); break;
581 case RT_BINARY_OP_INPLACE_OR: printf("INPLACE_OR\n"); break;
582 case RT_BINARY_OP_INPLACE_XOR: printf("INPLACE_XOR\n"); break;
583 case RT_BINARY_OP_INPLACE_AND: printf("INPLACE_AND\n"); break;
584 case RT_BINARY_OP_INPLACE_LSHIFT: printf("INPLACE_LSHIFT\n"); break;
585 case RT_BINARY_OP_INPLACE_RSHIFT: printf("INPLACE_RSHIFT\n"); break;
586 case RT_BINARY_OP_INPLACE_ADD: printf("INPLACE_ADD\n"); break;
587 case RT_BINARY_OP_INPLACE_SUBTRACT: printf("INPLACE_SUBTRACT\n"); break;
588 case RT_BINARY_OP_INPLACE_MULTIPLY: printf("INPLACE_MULTIPLY\n"); break;
589 case RT_BINARY_OP_INPLACE_FLOOR_DIVIDE: printf("INPLACE_FLOOR_DIVIDE\n"); break;
590 case RT_BINARY_OP_INPLACE_TRUE_DIVIDE: printf("INPLACE_TRUE_DIVIDE\n"); break;
591 case RT_BINARY_OP_INPLACE_MODULO: printf("INPLACE_MODULO\n"); break;
592 case RT_BINARY_OP_INPLACE_POWER: printf("INPLACE_POWER\n"); break;
Damien George9aa2a522014-02-01 23:04:09 +0000593 case RT_BINARY_OP_LESS: printf("COMPARE_OP <\n"); break;
594 case RT_BINARY_OP_MORE: printf("COMPARE_OP >\n"); break;
595 case RT_BINARY_OP_EQUAL: printf("COMPARE_OP ==\n"); break;
596 case RT_BINARY_OP_LESS_EQUAL: printf("COMPARE_OP <=\n"); break;
597 case RT_BINARY_OP_MORE_EQUAL: printf("COMPARE_OP >=\n"); break;
598 case RT_BINARY_OP_NOT_EQUAL: printf("COMPARE_OP !=\n"); break;
599 case RT_BINARY_OP_IN: printf("COMPARE_OP in\n"); break;
600 case RT_BINARY_OP_IS: printf("COMPARE_OP is\n"); break;
601 case RT_BINARY_OP_EXCEPTION_MATCH: printf("COMPARE_OP exception match\n"); break;
602 case RT_BINARY_OP_NOT_IN: printf("COMPARE_OP not in\n"); break;
603 case RT_BINARY_OP_IS_NOT: printf("COMPARE_OP is not\n"); break;
Damien429d7192013-10-04 19:53:11 +0100604 default: assert(0);
605 }
606 }
607}
608
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200609STATIC void emit_cpy_build_tuple(emit_t *emit, int n_args) {
Damien429d7192013-10-04 19:53:11 +0100610 emit_pre(emit, 1 - n_args, 3);
611 if (emit->pass == PASS_3) {
612 printf("BUILD_TUPLE %d\n", n_args);
613 }
614}
615
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200616STATIC void emit_cpy_build_list(emit_t *emit, int n_args) {
Damien429d7192013-10-04 19:53:11 +0100617 emit_pre(emit, 1 - n_args, 3);
618 if (emit->pass == PASS_3) {
619 printf("BUILD_LIST %d\n", n_args);
620 }
621}
622
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200623STATIC void emit_cpy_list_append(emit_t *emit, int list_index) {
Damien429d7192013-10-04 19:53:11 +0100624 emit_pre(emit, -1, 3);
625 if (emit->pass == PASS_3) {
626 printf("LIST_APPEND %d\n", list_index);
627 }
628}
629
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200630STATIC void emit_cpy_build_map(emit_t *emit, int n_args) {
Damien429d7192013-10-04 19:53:11 +0100631 emit_pre(emit, 1, 3);
632 if (emit->pass == PASS_3) {
633 printf("BUILD_MAP %d\n", n_args);
634 }
635}
636
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200637STATIC void emit_cpy_store_map(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100638 emit_pre(emit, -2, 1);
639 if (emit->pass == PASS_3) {
640 printf("STORE_MAP\n");
641 }
642}
643
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200644STATIC void emit_cpy_map_add(emit_t *emit, int map_index) {
Damien429d7192013-10-04 19:53:11 +0100645 emit_pre(emit, -2, 3);
646 if (emit->pass == PASS_3) {
647 printf("MAP_ADD %d\n", map_index);
648 }
649}
650
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200651STATIC void emit_cpy_build_set(emit_t *emit, int n_args) {
Damien429d7192013-10-04 19:53:11 +0100652 emit_pre(emit, 1 - n_args, 3);
653 if (emit->pass == PASS_3) {
654 printf("BUILD_SET %d\n", n_args);
655 }
656}
657
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200658STATIC void emit_cpy_set_add(emit_t *emit, int set_index) {
Damien429d7192013-10-04 19:53:11 +0100659 emit_pre(emit, -1, 3);
660 if (emit->pass == PASS_3) {
661 printf("SET_ADD %d\n", set_index);
662 }
663}
664
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200665STATIC void emit_cpy_build_slice(emit_t *emit, int n_args) {
Damien429d7192013-10-04 19:53:11 +0100666 emit_pre(emit, 1 - n_args, 3);
667 if (emit->pass == PASS_3) {
668 printf("BUILD_SLICE %d\n", n_args);
669 }
670}
671
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200672STATIC void emit_cpy_unpack_sequence(emit_t *emit, int n_args) {
Damien429d7192013-10-04 19:53:11 +0100673 emit_pre(emit, -1 + n_args, 3);
674 if (emit->pass == PASS_3) {
675 printf("UNPACK_SEQUENCE %d\n", n_args);
676 }
677}
678
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200679STATIC void emit_cpy_unpack_ex(emit_t *emit, int n_left, int n_right) {
Damien429d7192013-10-04 19:53:11 +0100680 emit_pre(emit, -1 + n_left + n_right + 1, 3);
681 if (emit->pass == PASS_3) {
682 printf("UNPACK_EX %d\n", n_left | (n_right << 8));
683 }
684}
685
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200686STATIC void emit_cpy_call_function(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) {
Damien429d7192013-10-04 19:53:11 +0100687 int s = 0;
688 if (have_star_arg) {
689 s += 1;
690 }
691 if (have_dbl_star_arg) {
692 s += 1;
693 }
694 emit_pre(emit, -n_positional - 2 * n_keyword - s, 3);
695 if (emit->pass == PASS_3) {
696 if (have_star_arg) {
697 if (have_dbl_star_arg) {
698 printf("CALL_FUNCTION_VAR_KW");
699 } else {
700 printf("CALL_FUNCTION_VAR");
701 }
702 } else {
703 if (have_dbl_star_arg) {
704 printf("CALL_FUNCTION_KW");
705 } else {
706 printf("CALL_FUNCTION");
707 }
708 }
709 printf(" %d, %d\n", n_positional, n_keyword);
710 }
711}
712
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200713STATIC void emit_cpy_call_method(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) {
Damien415eb6f2013-10-05 12:19:06 +0100714 emit_cpy_call_function(emit, n_positional, n_keyword, have_star_arg, have_dbl_star_arg);
Damien429d7192013-10-04 19:53:11 +0100715}
716
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200717STATIC void emit_cpy_return_value(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100718 emit_pre(emit, -1, 1);
719 emit->last_emit_was_return_value = true;
720 if (emit->pass == PASS_3) {
721 printf("RETURN_VALUE\n");
722 }
723}
724
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200725STATIC void emit_cpy_raise_varargs(emit_t *emit, int n_args) {
Damien429d7192013-10-04 19:53:11 +0100726 emit_pre(emit, -n_args, 3);
727 if (emit->pass == PASS_3) {
728 printf("RAISE_VARARGS %d\n", n_args);
729 }
730}
731
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200732STATIC void load_cpy_const_code_and_name(emit_t *emit, qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100733 emit_pre(emit, 1, 3);
734 if (emit->pass == PASS_3) {
735 printf("LOAD_CONST code %s\n", qstr_str(qstr));
736 }
737 // load qualified name
738 emit_pre(emit, 1, 3);
739 if (emit->pass == PASS_3) {
740 printf("LOAD_CONST '");
741 // code just to work out the qualname (or whatever it is)
742 {
743 int depth = 0;
744 for (scope_t *s = emit->scope; s->parent != NULL; s = s->parent) {
745 depth += 1;
746 }
747 for (int wanted_depth = depth; wanted_depth >= 0; wanted_depth--) {
748 scope_t *s = emit->scope;
749 for (int i = 0; i < wanted_depth; i++) {
750 s = s->parent;
751 }
752 if (s->kind == SCOPE_FUNCTION) {
753 printf("%s.<locals>.", qstr_str(s->simple_name));
754 } else if (s->kind == SCOPE_CLASS) {
755 printf("%s.", qstr_str(s->simple_name));
756 }
757 }
758 }
759 printf("%s'\n", qstr_str(qstr));
760 }
761}
762
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200763STATIC void emit_cpy_make_function(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) {
Damien415eb6f2013-10-05 12:19:06 +0100764 load_cpy_const_code_and_name(emit, scope->simple_name);
Damien429d7192013-10-04 19:53:11 +0100765 emit_pre(emit, -1 - n_default_params - 2 * n_dict_params, 3);
766 if (emit->pass == PASS_3) {
767 printf("MAKE_FUNCTION %d\n", (n_dict_params << 8) | n_default_params);
768 }
769}
770
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200771STATIC void emit_cpy_make_closure(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) {
Damien415eb6f2013-10-05 12:19:06 +0100772 load_cpy_const_code_and_name(emit, scope->simple_name);
Damien429d7192013-10-04 19:53:11 +0100773 emit_pre(emit, -2 - n_default_params - 2 * n_dict_params, 3);
774 if (emit->pass == PASS_3) {
775 printf("MAKE_CLOSURE %d\n", (n_dict_params << 8) | n_default_params);
776 }
777}
778
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200779STATIC void emit_cpy_yield_value(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100780 emit_pre(emit, 0, 1);
781 if (emit->pass == PASS_2) {
782 emit->scope->flags |= SCOPE_FLAG_GENERATOR;
783 }
784 if (emit->pass == PASS_3) {
785 printf("YIELD_VALUE\n");
786 }
787}
788
Paul Sokolovsky520e2f52014-02-12 18:31:30 +0200789STATIC void emit_cpy_yield_from(emit_t *emit) {
Damien429d7192013-10-04 19:53:11 +0100790 emit_pre(emit, -1, 1);
791 if (emit->pass == PASS_2) {
792 emit->scope->flags |= SCOPE_FLAG_GENERATOR;
793 }
794 if (emit->pass == PASS_3) {
795 printf("YIELD_FROM\n");
796 }
797}
798
Damien6cdd3af2013-10-05 18:08:26 +0100799const emit_method_table_t emit_cpython_method_table = {
Damien415eb6f2013-10-05 12:19:06 +0100800 emit_cpy_set_native_types,
801 emit_cpy_start_pass,
802 emit_cpy_end_pass,
803 emit_cpy_last_emit_was_return_value,
804 emit_cpy_get_stack_size,
805 emit_cpy_set_stack_size,
Damien George08335002014-01-18 23:24:36 +0000806 emit_cpy_set_source_line,
Damien415eb6f2013-10-05 12:19:06 +0100807
Damien4b03e772013-10-05 14:17:09 +0100808 emit_cpy_load_id,
809 emit_cpy_store_id,
810 emit_cpy_delete_id,
811
Damien415eb6f2013-10-05 12:19:06 +0100812 emit_cpy_label_assign,
813 emit_cpy_import_name,
814 emit_cpy_import_from,
815 emit_cpy_import_star,
816 emit_cpy_load_const_tok,
817 emit_cpy_load_const_small_int,
818 emit_cpy_load_const_int,
819 emit_cpy_load_const_dec,
820 emit_cpy_load_const_id,
821 emit_cpy_load_const_str,
Damien415eb6f2013-10-05 12:19:06 +0100822 emit_cpy_load_const_verbatim_str,
Damien415eb6f2013-10-05 12:19:06 +0100823 emit_cpy_load_fast,
Damien415eb6f2013-10-05 12:19:06 +0100824 emit_cpy_load_deref,
825 emit_cpy_load_closure,
Damien9ecbcff2013-12-11 00:41:43 +0000826 emit_cpy_load_name,
827 emit_cpy_load_global,
Damien415eb6f2013-10-05 12:19:06 +0100828 emit_cpy_load_attr,
829 emit_cpy_load_method,
830 emit_cpy_load_build_class,
831 emit_cpy_store_fast,
Damien9ecbcff2013-12-11 00:41:43 +0000832 emit_cpy_store_deref,
Damien415eb6f2013-10-05 12:19:06 +0100833 emit_cpy_store_name,
834 emit_cpy_store_global,
Damien415eb6f2013-10-05 12:19:06 +0100835 emit_cpy_store_attr,
Damien415eb6f2013-10-05 12:19:06 +0100836 emit_cpy_store_subscr,
Damiena3977762013-10-09 23:10:10 +0100837 emit_cpy_store_locals,
Damien415eb6f2013-10-05 12:19:06 +0100838 emit_cpy_delete_fast,
Damien9ecbcff2013-12-11 00:41:43 +0000839 emit_cpy_delete_deref,
Damien415eb6f2013-10-05 12:19:06 +0100840 emit_cpy_delete_name,
841 emit_cpy_delete_global,
Damien415eb6f2013-10-05 12:19:06 +0100842 emit_cpy_delete_attr,
843 emit_cpy_delete_subscr,
844 emit_cpy_dup_top,
845 emit_cpy_dup_top_two,
846 emit_cpy_pop_top,
847 emit_cpy_rot_two,
848 emit_cpy_rot_three,
849 emit_cpy_jump,
850 emit_cpy_pop_jump_if_true,
851 emit_cpy_pop_jump_if_false,
852 emit_cpy_jump_if_true_or_pop,
853 emit_cpy_jump_if_false_or_pop,
854 emit_cpy_setup_loop,
855 emit_cpy_break_loop,
856 emit_cpy_continue_loop,
857 emit_cpy_setup_with,
858 emit_cpy_with_cleanup,
859 emit_cpy_setup_except,
860 emit_cpy_setup_finally,
861 emit_cpy_end_finally,
862 emit_cpy_get_iter,
863 emit_cpy_for_iter,
864 emit_cpy_for_iter_end,
865 emit_cpy_pop_block,
866 emit_cpy_pop_except,
867 emit_cpy_unary_op,
868 emit_cpy_binary_op,
Damien415eb6f2013-10-05 12:19:06 +0100869 emit_cpy_build_tuple,
870 emit_cpy_build_list,
871 emit_cpy_list_append,
872 emit_cpy_build_map,
873 emit_cpy_store_map,
874 emit_cpy_map_add,
875 emit_cpy_build_set,
876 emit_cpy_set_add,
877 emit_cpy_build_slice,
878 emit_cpy_unpack_sequence,
879 emit_cpy_unpack_ex,
880 emit_cpy_make_function,
881 emit_cpy_make_closure,
882 emit_cpy_call_function,
883 emit_cpy_call_method,
884 emit_cpy_return_value,
885 emit_cpy_raise_varargs,
886 emit_cpy_yield_value,
887 emit_cpy_yield_from,
888};
889
Damien3ef4abb2013-10-12 16:53:13 +0100890#endif // MICROPY_EMIT_CPYTHON