blob: ddda90659eb3334f5fadd17c6866e727de8b3889 [file] [log] [blame]
Damien13ed3a62013-10-08 09:05:10 +01001// Essentially normal Python has 1 type: Python objects
2// Viper has more than 1 type, and is just a more complicated (a superset of) Python.
3// If you declare everything in Viper as a Python object (ie omit type decls) then
4// it should in principle be exactly the same as Python native.
5// Having types means having more opcodes, like binary_op_nat_nat, binary_op_nat_obj etc.
6// In practice we won't have a VM but rather do this in asm which is actually very minimal.
7
8// Because it breaks strict Python equivalence it should be a completely separate
9// decorator. It breaks equivalence because overflow on integers wraps around.
10// It shouldn't break equivalence if you don't use the new types, but since the
11// type decls might be used in normal Python for other reasons, it's probably safest,
12// cleanest and clearest to make it a separate decorator.
13
14// Actually, it does break equivalence because integers default to native integers,
15// not Python objects.
16
17// for x in l[0:8]: can be compiled into a native loop if l has pointer type
18
19#include <unistd.h>
20#include <stdlib.h>
21#include <stdint.h>
22#include <stdio.h>
23#include <string.h>
24#include <assert.h>
25
26#include "misc.h"
Damiend99b0522013-12-21 18:17:45 +000027#include "mpconfig.h"
Damien George55baff42014-01-21 21:40:13 +000028#include "qstr.h"
Damien13ed3a62013-10-08 09:05:10 +010029#include "lexer.h"
Damien13ed3a62013-10-08 09:05:10 +010030#include "parse.h"
31#include "scope.h"
Damiend99b0522013-12-21 18:17:45 +000032#include "runtime0.h"
Damien13ed3a62013-10-08 09:05:10 +010033#include "emit.h"
Damiend99b0522013-12-21 18:17:45 +000034#include "obj.h"
35#include "runtime.h"
Damien13ed3a62013-10-08 09:05:10 +010036
Damien13ed3a62013-10-08 09:05:10 +010037// wrapper around everything in this file
Damien Georgee67ed5d2014-01-04 13:55:24 +000038#if (MICROPY_EMIT_X64 && N_X64) || (MICROPY_EMIT_THUMB && N_THUMB)
Damien13ed3a62013-10-08 09:05:10 +010039
Damien3ef4abb2013-10-12 16:53:13 +010040#if N_X64
Damien13ed3a62013-10-08 09:05:10 +010041
42// x64 specific stuff
43
44#include "asmx64.h"
45
46#define REG_LOCAL_1 (REG_RBX)
47#define REG_LOCAL_NUM (1)
48
49#define EXPORT_FUN(name) emit_native_x64_##name
50
51#define REG_TEMP0 (REG_RAX)
52#define REG_TEMP1 (REG_RDI)
53#define REG_TEMP2 (REG_RSI)
54#define ASM_MOV_REG_TO_LOCAL(reg, local_num) asm_x64_mov_r64_to_local(emit->as, (reg), (local_num))
55#define ASM_MOV_IMM_TO_REG(imm, reg) asm_x64_mov_i64_to_r64_optimised(emit->as, (imm), (reg))
Damieneb19efb2013-10-10 22:06:54 +010056#define ASM_MOV_IMM_TO_LOCAL_USING(imm, local_num, reg_temp) do { asm_x64_mov_i64_to_r64_optimised(emit->as, (imm), (reg_temp)); asm_x64_mov_r64_to_local(emit->as, (reg_temp), (local_num)); } while (false)
Damien13ed3a62013-10-08 09:05:10 +010057#define ASM_MOV_LOCAL_TO_REG(local_num, reg) asm_x64_mov_local_to_r64(emit->as, (local_num), (reg))
58#define ASM_MOV_REG_TO_REG(reg_src, reg_dest) asm_x64_mov_r64_to_r64(emit->as, (reg_src), (reg_dest))
59#define ASM_MOV_LOCAL_ADDR_TO_REG(local_num, reg) asm_x64_mov_local_addr_to_r64(emit->as, (local_num), (reg))
60
Damien3ef4abb2013-10-12 16:53:13 +010061#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +010062
63// thumb specific stuff
64
65#include "asmthumb.h"
66
67#define REG_LOCAL_1 (REG_R4)
68#define REG_LOCAL_2 (REG_R5)
69#define REG_LOCAL_3 (REG_R6)
70#define REG_LOCAL_NUM (3)
71
72#define EXPORT_FUN(name) emit_native_thumb_##name
73
74#define REG_TEMP0 (REG_R0)
75#define REG_TEMP1 (REG_R1)
76#define REG_TEMP2 (REG_R2)
77#define ASM_MOV_REG_TO_LOCAL(reg, local_num) asm_thumb_mov_local_reg(emit->as, (local_num), (reg))
78#define ASM_MOV_IMM_TO_REG(imm, reg) asm_thumb_mov_reg_i32_optimised(emit->as, (reg), (imm))
Damieneb19efb2013-10-10 22:06:54 +010079#define ASM_MOV_IMM_TO_LOCAL_USING(imm, local_num, reg_temp) do { asm_thumb_mov_reg_i32_optimised(emit->as, (reg_temp), (imm)); asm_thumb_mov_local_reg(emit->as, (local_num), (reg_temp)); } while (false)
Damien13ed3a62013-10-08 09:05:10 +010080#define ASM_MOV_LOCAL_TO_REG(local_num, reg) asm_thumb_mov_reg_local(emit->as, (reg), (local_num))
81#define ASM_MOV_REG_TO_REG(reg_src, reg_dest) asm_thumb_mov_reg_reg(emit->as, (reg_dest), (reg_src))
82#define ASM_MOV_LOCAL_ADDR_TO_REG(local_num, reg) asm_thumb_mov_reg_local_addr(emit->as, (reg), (local_num))
83
84#endif
85
86typedef enum {
Damienff8ed772013-10-08 22:18:32 +010087 STACK_VALUE,
88 STACK_REG,
89 STACK_IMM,
90} stack_info_kind_t;
Damien13ed3a62013-10-08 09:05:10 +010091
92typedef enum {
93 VTYPE_UNBOUND,
94 VTYPE_PYOBJ,
95 VTYPE_BOOL,
96 VTYPE_INT,
97 VTYPE_PTR,
98 VTYPE_PTR_NONE,
99 VTYPE_BUILTIN_V_INT,
100} vtype_kind_t;
101
Damienff8ed772013-10-08 22:18:32 +0100102typedef struct _stack_info_t {
103 vtype_kind_t vtype;
104 stack_info_kind_t kind;
105 union {
106 int u_reg;
107 machine_int_t u_imm;
108 };
109} stack_info_t;
110
Damien13ed3a62013-10-08 09:05:10 +0100111struct _emit_t {
112 int pass;
113
114 bool do_viper_types;
Damienff8ed772013-10-08 22:18:32 +0100115
116 int local_vtype_alloc;
Damien13ed3a62013-10-08 09:05:10 +0100117 vtype_kind_t *local_vtype;
Damienff8ed772013-10-08 22:18:32 +0100118
119 int stack_info_alloc;
120 stack_info_t *stack_info;
121
Damien13ed3a62013-10-08 09:05:10 +0100122 int stack_start;
123 int stack_size;
124
125 bool last_emit_was_return_value;
126
Damien13ed3a62013-10-08 09:05:10 +0100127 scope_t *scope;
128
Damien3ef4abb2013-10-12 16:53:13 +0100129#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100130 asm_x64_t *as;
Damien3ef4abb2013-10-12 16:53:13 +0100131#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100132 asm_thumb_t *as;
133#endif
134};
135
136emit_t *EXPORT_FUN(new)(uint max_num_labels) {
137 emit_t *emit = m_new(emit_t, 1);
138 emit->do_viper_types = false;
Damienff8ed772013-10-08 22:18:32 +0100139 emit->local_vtype = NULL;
140 emit->stack_info = NULL;
Damien3ef4abb2013-10-12 16:53:13 +0100141#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100142 emit->as = asm_x64_new(max_num_labels);
Damien3ef4abb2013-10-12 16:53:13 +0100143#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100144 emit->as = asm_thumb_new(max_num_labels);
145#endif
146 return emit;
147}
148
Paul Sokolovskyf46d87a2014-01-24 16:20:11 +0200149static void emit_native_free(emit_t *emit) {
150#if N_X64
151 asm_x64_free(emit->as, false);
152#elif N_THUMB
153 asm_thumb_free(emit->as, false);
154#endif
155 m_del_obj(emit_t, emit);
156}
157
Damien13ed3a62013-10-08 09:05:10 +0100158static void emit_native_set_viper_types(emit_t *emit, bool do_viper_types) {
159 emit->do_viper_types = do_viper_types;
160}
161
162static void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) {
163 emit->pass = pass;
164 emit->stack_start = 0;
165 emit->stack_size = 0;
166 emit->last_emit_was_return_value = false;
Damien13ed3a62013-10-08 09:05:10 +0100167 emit->scope = scope;
168
Damienff8ed772013-10-08 22:18:32 +0100169 if (emit->local_vtype == NULL) {
170 emit->local_vtype_alloc = scope->num_locals + 20; // XXX should be maximum over all scopes
171 emit->local_vtype = m_new(vtype_kind_t, emit->local_vtype_alloc);
172 }
173 if (emit->stack_info == NULL) {
174 emit->stack_info_alloc = scope->stack_size + 50; // XXX don't know stack size on entry, should be maximum over all scopes
175 emit->stack_info = m_new(stack_info_t, emit->stack_info_alloc);
Damien13ed3a62013-10-08 09:05:10 +0100176 }
177
178 if (emit->do_viper_types) {
Damien13ed3a62013-10-08 09:05:10 +0100179 // TODO set types of arguments based on type signature
Damienff8ed772013-10-08 22:18:32 +0100180 for (int i = 0; i < emit->local_vtype_alloc; i++) {
181 emit->local_vtype[i] = VTYPE_UNBOUND;
182 }
183 for (int i = 0; i < emit->stack_info_alloc; i++) {
184 emit->stack_info[i].kind = STACK_VALUE;
185 emit->stack_info[i].vtype = VTYPE_UNBOUND;
186 }
Damien13ed3a62013-10-08 09:05:10 +0100187 } else {
Damienff8ed772013-10-08 22:18:32 +0100188 for (int i = 0; i < emit->local_vtype_alloc; i++) {
189 emit->local_vtype[i] = VTYPE_PYOBJ;
190 }
191 for (int i = 0; i < emit->stack_info_alloc; i++) {
192 emit->stack_info[i].kind = STACK_VALUE;
193 emit->stack_info[i].vtype = VTYPE_PYOBJ;
Damien13ed3a62013-10-08 09:05:10 +0100194 }
195 }
196
Damien3ef4abb2013-10-12 16:53:13 +0100197#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100198 asm_x64_start_pass(emit->as, pass);
Damien3ef4abb2013-10-12 16:53:13 +0100199#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100200 asm_thumb_start_pass(emit->as, pass);
201#endif
202
203 // entry to function
204 int num_locals = 0;
205 if (pass > PASS_1) {
206 num_locals = scope->num_locals - REG_LOCAL_NUM;
207 if (num_locals < 0) {
208 num_locals = 0;
209 }
210 emit->stack_start = num_locals;
211 num_locals += scope->stack_size;
212 }
Damien3ef4abb2013-10-12 16:53:13 +0100213#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100214 asm_x64_entry(emit->as, num_locals);
Damien3ef4abb2013-10-12 16:53:13 +0100215#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100216 asm_thumb_entry(emit->as, num_locals);
217#endif
218
219 // initialise locals from parameters
Damien3ef4abb2013-10-12 16:53:13 +0100220#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100221 for (int i = 0; i < scope->num_params; i++) {
222 if (i == 0) {
223 asm_x64_mov_r64_to_r64(emit->as, REG_ARG_1, REG_LOCAL_1);
224 } else if (i == 1) {
225 asm_x64_mov_r64_to_local(emit->as, REG_ARG_2, i - 1);
226 } else if (i == 2) {
227 asm_x64_mov_r64_to_local(emit->as, REG_ARG_3, i - 1);
228 } else {
229 // TODO not implemented
230 assert(0);
231 }
232 }
Damien3ef4abb2013-10-12 16:53:13 +0100233#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100234 for (int i = 0; i < scope->num_params; i++) {
235 if (i == 0) {
236 asm_thumb_mov_reg_reg(emit->as, REG_LOCAL_1, REG_ARG_1);
237 } else if (i == 1) {
238 asm_thumb_mov_reg_reg(emit->as, REG_LOCAL_2, REG_ARG_2);
239 } else if (i == 2) {
240 asm_thumb_mov_reg_reg(emit->as, REG_LOCAL_3, REG_ARG_3);
241 } else if (i == 3) {
242 asm_thumb_mov_local_reg(emit->as, i - REG_LOCAL_NUM, REG_ARG_4);
243 } else {
244 // TODO not implemented
245 assert(0);
246 }
247 }
248
249 asm_thumb_mov_reg_i32(emit->as, REG_R7, (machine_uint_t)rt_fun_table);
250#endif
251}
252
253static void emit_native_end_pass(emit_t *emit) {
Damien3ef4abb2013-10-12 16:53:13 +0100254#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100255 if (!emit->last_emit_was_return_value) {
256 asm_x64_exit(emit->as);
257 }
258 asm_x64_end_pass(emit->as);
Damien3ef4abb2013-10-12 16:53:13 +0100259#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100260 if (!emit->last_emit_was_return_value) {
261 asm_thumb_exit(emit->as);
262 }
263 asm_thumb_end_pass(emit->as);
264#endif
265
266 // check stack is back to zero size
267 if (emit->stack_size != 0) {
268 printf("ERROR: stack size not back to zero; got %d\n", emit->stack_size);
269 }
270
271 if (emit->pass == PASS_3) {
Damien3ef4abb2013-10-12 16:53:13 +0100272#if N_X64
Damiend99b0522013-12-21 18:17:45 +0000273 void *f = asm_x64_get_code(emit->as);
Damien13ed3a62013-10-08 09:05:10 +0100274 rt_assign_native_code(emit->scope->unique_code_id, f, asm_x64_get_code_size(emit->as), emit->scope->num_params);
Damien3ef4abb2013-10-12 16:53:13 +0100275#elif N_THUMB
Damiend99b0522013-12-21 18:17:45 +0000276 void *f = asm_thumb_get_code(emit->as);
Damien13ed3a62013-10-08 09:05:10 +0100277 rt_assign_native_code(emit->scope->unique_code_id, f, asm_thumb_get_code_size(emit->as), emit->scope->num_params);
278#endif
279 }
280}
281
282static bool emit_native_last_emit_was_return_value(emit_t *emit) {
283 return emit->last_emit_was_return_value;
284}
285
286static int emit_native_get_stack_size(emit_t *emit) {
287 return emit->stack_size;
288}
289
290static void emit_native_set_stack_size(emit_t *emit, int size) {
291 emit->stack_size = size;
292}
293
Damien George08335002014-01-18 23:24:36 +0000294static void emit_native_set_source_line(emit_t *emit, int source_line) {
295}
296
Damien13ed3a62013-10-08 09:05:10 +0100297static void adjust_stack(emit_t *emit, int stack_size_delta) {
298 emit->stack_size += stack_size_delta;
299 assert(emit->stack_size >= 0);
300 if (emit->pass > PASS_1 && emit->stack_size > emit->scope->stack_size) {
301 emit->scope->stack_size = emit->stack_size;
302 }
303}
304
Damienff8ed772013-10-08 22:18:32 +0100305/*
Damien13ed3a62013-10-08 09:05:10 +0100306static void emit_pre_raw(emit_t *emit, int stack_size_delta) {
307 adjust_stack(emit, stack_size_delta);
308 emit->last_emit_was_return_value = false;
309}
Damienff8ed772013-10-08 22:18:32 +0100310*/
Damien13ed3a62013-10-08 09:05:10 +0100311
Damienff8ed772013-10-08 22:18:32 +0100312// this must be called at start of emit functions
Damien13ed3a62013-10-08 09:05:10 +0100313static void emit_pre(emit_t *emit) {
Damienff8ed772013-10-08 22:18:32 +0100314 emit->last_emit_was_return_value = false;
315 // settle the stack
316 /*
317 if (regs_needed != 0) {
318 for (int i = 0; i < emit->stack_size; i++) {
319 switch (emit->stack_info[i].kind) {
320 case STACK_VALUE:
321 break;
322
323 case STACK_REG:
324 // TODO only push reg if in regs_needed
325 emit->stack_info[i].kind = STACK_VALUE;
326 ASM_MOV_REG_TO_LOCAL(emit->stack_info[i].u_reg, emit->stack_start + i);
327 break;
328
329 case STACK_IMM:
330 // don't think we ever need to push imms for settling
331 //ASM_MOV_IMM_TO_LOCAL(emit->last_imm, emit->stack_start + i);
332 break;
333 }
334 }
335 }
336 */
Damien13ed3a62013-10-08 09:05:10 +0100337}
338
339static vtype_kind_t peek_vtype(emit_t *emit) {
Damienff8ed772013-10-08 22:18:32 +0100340 return emit->stack_info[emit->stack_size - 1].vtype;
341}
Damien13ed3a62013-10-08 09:05:10 +0100342
Damiend2755ec2013-10-16 23:58:48 +0100343// pos=1 is TOS, pos=2 is next, etc
344// use pos=0 for no skipping
345static void need_reg_single(emit_t *emit, int reg_needed, int skip_stack_pos) {
346 skip_stack_pos = emit->stack_size - skip_stack_pos;
Damienff8ed772013-10-08 22:18:32 +0100347 for (int i = 0; i < emit->stack_size; i++) {
Damiend2755ec2013-10-16 23:58:48 +0100348 if (i != skip_stack_pos) {
349 stack_info_t *si = &emit->stack_info[i];
350 if (si->kind == STACK_REG && si->u_reg == reg_needed) {
351 si->kind = STACK_VALUE;
352 ASM_MOV_REG_TO_LOCAL(si->u_reg, emit->stack_start + i);
353 }
Damienff8ed772013-10-08 22:18:32 +0100354 }
355 }
356}
Damien13ed3a62013-10-08 09:05:10 +0100357
Damieneb19efb2013-10-10 22:06:54 +0100358static void need_reg_all(emit_t *emit) {
Damienff8ed772013-10-08 22:18:32 +0100359 for (int i = 0; i < emit->stack_size; i++) {
360 stack_info_t *si = &emit->stack_info[i];
361 if (si->kind == STACK_REG) {
362 si->kind = STACK_VALUE;
363 ASM_MOV_REG_TO_LOCAL(si->u_reg, emit->stack_start + i);
364 }
Damien13ed3a62013-10-08 09:05:10 +0100365 }
366}
367
Damiend2755ec2013-10-16 23:58:48 +0100368static void need_stack_settled(emit_t *emit) {
369 for (int i = 0; i < emit->stack_size; i++) {
370 stack_info_t *si = &emit->stack_info[i];
371 if (si->kind == STACK_REG) {
372 si->kind = STACK_VALUE;
373 ASM_MOV_REG_TO_LOCAL(si->u_reg, emit->stack_start + i);
374 }
375 }
376 for (int i = 0; i < emit->stack_size; i++) {
377 stack_info_t *si = &emit->stack_info[i];
378 if (si->kind == STACK_IMM) {
379 ASM_MOV_IMM_TO_LOCAL_USING(si->u_imm, emit->stack_start + i, REG_TEMP0);
380 }
381 }
382}
383
384// pos=1 is TOS, pos=2 is next, etc
385static void emit_access_stack(emit_t *emit, int pos, vtype_kind_t *vtype, int reg_dest) {
386 need_reg_single(emit, reg_dest, pos);
387 stack_info_t *si = &emit->stack_info[emit->stack_size - pos];
Damienff8ed772013-10-08 22:18:32 +0100388 *vtype = si->vtype;
389 switch (si->kind) {
390 case STACK_VALUE:
Damiend2755ec2013-10-16 23:58:48 +0100391 ASM_MOV_LOCAL_TO_REG(emit->stack_start + emit->stack_size - pos, reg_dest);
Damien13ed3a62013-10-08 09:05:10 +0100392 break;
393
Damienff8ed772013-10-08 22:18:32 +0100394 case STACK_REG:
395 if (si->u_reg != reg_dest) {
396 ASM_MOV_REG_TO_REG(si->u_reg, reg_dest);
Damien13ed3a62013-10-08 09:05:10 +0100397 }
398 break;
399
Damienff8ed772013-10-08 22:18:32 +0100400 case STACK_IMM:
401 ASM_MOV_IMM_TO_REG(si->u_imm, reg_dest);
Damien13ed3a62013-10-08 09:05:10 +0100402 break;
403 }
Damien13ed3a62013-10-08 09:05:10 +0100404}
405
Damiend2755ec2013-10-16 23:58:48 +0100406static void emit_pre_pop_reg(emit_t *emit, vtype_kind_t *vtype, int reg_dest) {
407 emit->last_emit_was_return_value = false;
408 emit_access_stack(emit, 1, vtype, reg_dest);
409 adjust_stack(emit, -1);
410}
411
Damien13ed3a62013-10-08 09:05:10 +0100412static void emit_pre_pop_reg_reg(emit_t *emit, vtype_kind_t *vtypea, int rega, vtype_kind_t *vtypeb, int regb) {
413 emit_pre_pop_reg(emit, vtypea, rega);
Damienff8ed772013-10-08 22:18:32 +0100414 emit_pre_pop_reg(emit, vtypeb, regb);
Damien13ed3a62013-10-08 09:05:10 +0100415}
416
417static void emit_pre_pop_reg_reg_reg(emit_t *emit, vtype_kind_t *vtypea, int rega, vtype_kind_t *vtypeb, int regb, vtype_kind_t *vtypec, int regc) {
418 emit_pre_pop_reg(emit, vtypea, rega);
Damienff8ed772013-10-08 22:18:32 +0100419 emit_pre_pop_reg(emit, vtypeb, regb);
420 emit_pre_pop_reg(emit, vtypec, regc);
Damien13ed3a62013-10-08 09:05:10 +0100421}
422
423static void emit_post(emit_t *emit) {
424}
425
426static void emit_post_push_reg(emit_t *emit, vtype_kind_t vtype, int reg) {
Damienff8ed772013-10-08 22:18:32 +0100427 stack_info_t *si = &emit->stack_info[emit->stack_size];
428 si->vtype = vtype;
429 si->kind = STACK_REG;
430 si->u_reg = reg;
Damien13ed3a62013-10-08 09:05:10 +0100431 adjust_stack(emit, 1);
432}
433
Damienff8ed772013-10-08 22:18:32 +0100434static void emit_post_push_imm(emit_t *emit, vtype_kind_t vtype, machine_int_t imm) {
435 stack_info_t *si = &emit->stack_info[emit->stack_size];
436 si->vtype = vtype;
437 si->kind = STACK_IMM;
438 si->u_imm = imm;
439 adjust_stack(emit, 1);
440}
441
442static void emit_post_push_reg_reg(emit_t *emit, vtype_kind_t vtypea, int rega, vtype_kind_t vtypeb, int regb) {
443 emit_post_push_reg(emit, vtypea, rega);
444 emit_post_push_reg(emit, vtypeb, regb);
445}
446
Damien13ed3a62013-10-08 09:05:10 +0100447static void emit_post_push_reg_reg_reg(emit_t *emit, vtype_kind_t vtypea, int rega, vtype_kind_t vtypeb, int regb, vtype_kind_t vtypec, int regc) {
Damienff8ed772013-10-08 22:18:32 +0100448 emit_post_push_reg(emit, vtypea, rega);
449 emit_post_push_reg(emit, vtypeb, regb);
450 emit_post_push_reg(emit, vtypec, regc);
Damien13ed3a62013-10-08 09:05:10 +0100451}
452
453static void emit_post_push_reg_reg_reg_reg(emit_t *emit, vtype_kind_t vtypea, int rega, vtype_kind_t vtypeb, int regb, vtype_kind_t vtypec, int regc, vtype_kind_t vtyped, int regd) {
Damienff8ed772013-10-08 22:18:32 +0100454 emit_post_push_reg(emit, vtypea, rega);
455 emit_post_push_reg(emit, vtypeb, regb);
456 emit_post_push_reg(emit, vtypec, regc);
457 emit_post_push_reg(emit, vtyped, regd);
Damien13ed3a62013-10-08 09:05:10 +0100458}
459
460// vtype of all n_pop objects is VTYPE_PYOBJ
Damieneb19efb2013-10-10 22:06:54 +0100461// does not use any temporary registers (but may use reg_dest before loading it with stack pointer)
Damien6d4f3462013-11-16 20:44:39 +0000462// TODO this needs some thinking for viper code
Damien13ed3a62013-10-08 09:05:10 +0100463static void emit_get_stack_pointer_to_reg_for_pop(emit_t *emit, int reg_dest, int n_pop) {
Damieneb19efb2013-10-10 22:06:54 +0100464 need_reg_all(emit);
Damienff8ed772013-10-08 22:18:32 +0100465 for (int i = 0; i < n_pop; i++) {
Damieneb19efb2013-10-10 22:06:54 +0100466 stack_info_t *si = &emit->stack_info[emit->stack_size - 1 - i];
467 // must push any imm's to stack
Damien6d4f3462013-11-16 20:44:39 +0000468 // must convert them to VTYPE_PYOBJ for viper code
Damieneb19efb2013-10-10 22:06:54 +0100469 if (si->kind == STACK_IMM) {
470 si->kind = STACK_VALUE;
Damien6d4f3462013-11-16 20:44:39 +0000471 switch (si->vtype) {
472 case VTYPE_PYOBJ:
473 ASM_MOV_IMM_TO_LOCAL_USING(si->u_imm, emit->stack_start + emit->stack_size - 1 - i, reg_dest);
474 break;
475 case VTYPE_BOOL:
476 si->vtype = VTYPE_PYOBJ;
477 if (si->u_imm == 0) {
Damiend99b0522013-12-21 18:17:45 +0000478 ASM_MOV_IMM_TO_LOCAL_USING((machine_uint_t)mp_const_false, emit->stack_start + emit->stack_size - 1 - i, reg_dest);
Damien6d4f3462013-11-16 20:44:39 +0000479 } else {
Damiend99b0522013-12-21 18:17:45 +0000480 ASM_MOV_IMM_TO_LOCAL_USING((machine_uint_t)mp_const_true, emit->stack_start + emit->stack_size - 1 - i, reg_dest);
Damien6d4f3462013-11-16 20:44:39 +0000481 }
482 break;
483 case VTYPE_INT:
484 si->vtype = VTYPE_PYOBJ;
485 ASM_MOV_IMM_TO_LOCAL_USING((si->u_imm << 1) | 1, emit->stack_start + emit->stack_size - 1 - i, reg_dest);
486 break;
487 default:
488 // not handled
489 assert(0);
490 }
Damieneb19efb2013-10-10 22:06:54 +0100491 }
492 assert(si->kind == STACK_VALUE);
493 assert(si->vtype == VTYPE_PYOBJ);
Damienff8ed772013-10-08 22:18:32 +0100494 }
Damien13ed3a62013-10-08 09:05:10 +0100495 ASM_MOV_LOCAL_ADDR_TO_REG(emit->stack_start + emit->stack_size - 1, reg_dest);
496 adjust_stack(emit, -n_pop);
497}
498
499// vtype of all n_push objects is VTYPE_PYOBJ
500static void emit_get_stack_pointer_to_reg_for_push(emit_t *emit, int reg_dest, int n_push) {
Damieneb19efb2013-10-10 22:06:54 +0100501 need_reg_all(emit);
Damien13ed3a62013-10-08 09:05:10 +0100502 for (int i = 0; i < n_push; i++) {
Damien7f5dacf2013-10-10 11:24:39 +0100503 emit->stack_info[emit->stack_size + i].kind = STACK_VALUE;
Damienff8ed772013-10-08 22:18:32 +0100504 emit->stack_info[emit->stack_size + i].vtype = VTYPE_PYOBJ;
Damien13ed3a62013-10-08 09:05:10 +0100505 }
506 ASM_MOV_LOCAL_ADDR_TO_REG(emit->stack_start + emit->stack_size + n_push - 1, reg_dest);
507 adjust_stack(emit, n_push);
508}
509
510static void emit_call(emit_t *emit, rt_fun_kind_t fun_kind, void *fun) {
Damiend2755ec2013-10-16 23:58:48 +0100511 need_reg_all(emit);
Damien3ef4abb2013-10-12 16:53:13 +0100512#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100513 asm_x64_call_ind(emit->as, fun, REG_RAX);
Damien3ef4abb2013-10-12 16:53:13 +0100514#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100515 asm_thumb_bl_ind(emit->as, rt_fun_table[fun_kind], fun_kind, REG_R3);
516#endif
517}
518
519static void emit_call_with_imm_arg(emit_t *emit, rt_fun_kind_t fun_kind, void *fun, machine_int_t arg_val, int arg_reg) {
Damieneb19efb2013-10-10 22:06:54 +0100520 need_reg_all(emit);
Damien13ed3a62013-10-08 09:05:10 +0100521 ASM_MOV_IMM_TO_REG(arg_val, arg_reg);
Damiend2755ec2013-10-16 23:58:48 +0100522#if N_X64
523 asm_x64_call_ind(emit->as, fun, REG_RAX);
524#elif N_THUMB
525 asm_thumb_bl_ind(emit->as, rt_fun_table[fun_kind], fun_kind, REG_R3);
526#endif
Damien13ed3a62013-10-08 09:05:10 +0100527}
528
529static void emit_native_load_id(emit_t *emit, qstr qstr) {
530 // check for built-ins
531 if (strcmp(qstr_str(qstr), "v_int") == 0) {
Damienff8ed772013-10-08 22:18:32 +0100532 assert(0);
Damien13ed3a62013-10-08 09:05:10 +0100533 emit_pre(emit);
534 //emit_post_push_blank(emit, VTYPE_BUILTIN_V_INT);
535
536 // not a built-in, so do usual thing
537 } else {
538 emit_common_load_id(emit, &EXPORT_FUN(method_table), emit->scope, qstr);
539 }
540}
541
542static void emit_native_store_id(emit_t *emit, qstr qstr) {
543 // TODO check for built-ins and disallow
544 emit_common_store_id(emit, &EXPORT_FUN(method_table), emit->scope, qstr);
545}
546
547static void emit_native_delete_id(emit_t *emit, qstr qstr) {
548 // TODO check for built-ins and disallow
549 emit_common_delete_id(emit, &EXPORT_FUN(method_table), emit->scope, qstr);
550}
551
552static void emit_native_label_assign(emit_t *emit, int l) {
Damien6ba13142013-11-02 20:34:54 +0000553 emit_pre(emit);
Damiend2755ec2013-10-16 23:58:48 +0100554 // need to commit stack because we can jump here from elsewhere
555 need_stack_settled(emit);
Damien3ef4abb2013-10-12 16:53:13 +0100556#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100557 asm_x64_label_assign(emit->as, l);
Damien3ef4abb2013-10-12 16:53:13 +0100558#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100559 asm_thumb_label_assign(emit->as, l);
560#endif
Damien6ba13142013-11-02 20:34:54 +0000561 emit_post(emit);
Damien13ed3a62013-10-08 09:05:10 +0100562}
563
564static void emit_native_import_name(emit_t *emit, qstr qstr) {
565 // not implemented
566 assert(0);
567}
568
569static void emit_native_import_from(emit_t *emit, qstr qstr) {
570 // not implemented
571 assert(0);
572}
573
574static void emit_native_import_star(emit_t *emit) {
575 // not implemented
576 assert(0);
577}
578
Damiend99b0522013-12-21 18:17:45 +0000579static void emit_native_load_const_tok(emit_t *emit, mp_token_kind_t tok) {
Damien13ed3a62013-10-08 09:05:10 +0100580 emit_pre(emit);
581 int vtype;
582 machine_uint_t val;
583 if (emit->do_viper_types) {
584 switch (tok) {
Damiend99b0522013-12-21 18:17:45 +0000585 case MP_TOKEN_KW_NONE: vtype = VTYPE_PTR_NONE; val = 0; break;
586 case MP_TOKEN_KW_FALSE: vtype = VTYPE_BOOL; val = 0; break;
587 case MP_TOKEN_KW_TRUE: vtype = VTYPE_BOOL; val = 1; break;
Damien13ed3a62013-10-08 09:05:10 +0100588 default: assert(0); vtype = 0; val = 0; // shouldn't happen
589 }
590 } else {
591 vtype = VTYPE_PYOBJ;
592 switch (tok) {
Damiend99b0522013-12-21 18:17:45 +0000593 case MP_TOKEN_KW_NONE: val = (machine_uint_t)mp_const_none; break;
594 case MP_TOKEN_KW_FALSE: val = (machine_uint_t)mp_const_false; break;
595 case MP_TOKEN_KW_TRUE: val = (machine_uint_t)mp_const_true; break;
Damien13ed3a62013-10-08 09:05:10 +0100596 default: assert(0); vtype = 0; val = 0; // shouldn't happen
597 }
598 }
599 emit_post_push_imm(emit, vtype, val);
600}
601
602static void emit_native_load_const_small_int(emit_t *emit, int arg) {
603 emit_pre(emit);
604 if (emit->do_viper_types) {
605 emit_post_push_imm(emit, VTYPE_INT, arg);
606 } else {
607 emit_post_push_imm(emit, VTYPE_PYOBJ, (arg << 1) | 1);
608 }
609}
610
611static void emit_native_load_const_int(emit_t *emit, qstr qstr) {
612 // not implemented
613 // load integer, check fits in 32 bits
614 assert(0);
615}
616
617static void emit_native_load_const_dec(emit_t *emit, qstr qstr) {
Damien6ba13142013-11-02 20:34:54 +0000618 // for viper, a float/complex is just a Python object
619 emit_pre(emit);
620 emit_call_with_imm_arg(emit, RT_F_LOAD_CONST_DEC, rt_load_const_dec, qstr, REG_ARG_1);
621 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
Damien13ed3a62013-10-08 09:05:10 +0100622}
623
624static void emit_native_load_const_id(emit_t *emit, qstr qstr) {
Damien7f5dacf2013-10-10 11:24:39 +0100625 emit_pre(emit);
626 if (emit->do_viper_types) {
627 assert(0);
628 } else {
629 emit_call_with_imm_arg(emit, RT_F_LOAD_CONST_STR, rt_load_const_str, qstr, REG_ARG_1); // TODO
630 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
631 }
Damien13ed3a62013-10-08 09:05:10 +0100632}
633
634static void emit_native_load_const_str(emit_t *emit, qstr qstr, bool bytes) {
635 emit_pre(emit);
636 if (emit->do_viper_types) {
637 // not implemented properly
638 // load a pointer to the asciiz string?
639 assert(0);
640 emit_post_push_imm(emit, VTYPE_PTR, (machine_uint_t)qstr_str(qstr));
641 } else {
642 emit_call_with_imm_arg(emit, RT_F_LOAD_CONST_STR, rt_load_const_str, qstr, REG_ARG_1);
643 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
644 }
645}
646
Damien13ed3a62013-10-08 09:05:10 +0100647static void emit_native_load_const_verbatim_str(emit_t *emit, const char *str) {
648 // not supported/needed for viper
649 assert(0);
650}
651
Damien13ed3a62013-10-08 09:05:10 +0100652static void emit_native_load_fast(emit_t *emit, qstr qstr, int local_num) {
653 vtype_kind_t vtype = emit->local_vtype[local_num];
654 if (vtype == VTYPE_UNBOUND) {
655 printf("ViperTypeError: local %s used before type known\n", qstr_str(qstr));
656 }
657 emit_pre(emit);
Damien3ef4abb2013-10-12 16:53:13 +0100658#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100659 if (local_num == 0) {
660 emit_post_push_reg(emit, vtype, REG_LOCAL_1);
661 } else {
Damiend2755ec2013-10-16 23:58:48 +0100662 need_reg_single(emit, REG_RAX, 0);
Damien13ed3a62013-10-08 09:05:10 +0100663 asm_x64_mov_local_to_r64(emit->as, local_num - 1, REG_RAX);
664 emit_post_push_reg(emit, vtype, REG_RAX);
665 }
Damien3ef4abb2013-10-12 16:53:13 +0100666#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100667 if (local_num == 0) {
668 emit_post_push_reg(emit, vtype, REG_LOCAL_1);
669 } else if (local_num == 1) {
670 emit_post_push_reg(emit, vtype, REG_LOCAL_2);
671 } else if (local_num == 2) {
672 emit_post_push_reg(emit, vtype, REG_LOCAL_3);
673 } else {
Damiend2755ec2013-10-16 23:58:48 +0100674 need_reg_single(emit, REG_R0, 0);
Damien13ed3a62013-10-08 09:05:10 +0100675 asm_thumb_mov_reg_local(emit->as, REG_R0, local_num - 1);
676 emit_post_push_reg(emit, vtype, REG_R0);
677 }
678#endif
679}
680
Damien9ecbcff2013-12-11 00:41:43 +0000681static void emit_native_load_deref(emit_t *emit, qstr qstr, int local_num) {
682 // not implemented
683 // in principle could support this quite easily (ldr r0, [r0, #0]) and then get closed over variables!
684 assert(0);
685}
686
687static void emit_native_load_closure(emit_t *emit, qstr qstr, int local_num) {
688 // not implemented
689 assert(0);
690}
691
Damien13ed3a62013-10-08 09:05:10 +0100692static void emit_native_load_name(emit_t *emit, qstr qstr) {
693 emit_pre(emit);
694 emit_call_with_imm_arg(emit, RT_F_LOAD_NAME, rt_load_name, qstr, REG_ARG_1);
695 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
696}
697
698static void emit_native_load_global(emit_t *emit, qstr qstr) {
699 emit_pre(emit);
700 emit_call_with_imm_arg(emit, RT_F_LOAD_GLOBAL, rt_load_global, qstr, REG_ARG_1);
701 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
702}
703
Damien13ed3a62013-10-08 09:05:10 +0100704static void emit_native_load_attr(emit_t *emit, qstr qstr) {
705 // depends on type of subject:
706 // - integer, function, pointer to integers: error
707 // - pointer to structure: get member, quite easy
708 // - Python object: call rt_load_attr, and needs to be typed to convert result
709 vtype_kind_t vtype_base;
710 emit_pre_pop_reg(emit, &vtype_base, REG_ARG_1); // arg1 = base
711 assert(vtype_base == VTYPE_PYOBJ);
712 emit_call_with_imm_arg(emit, RT_F_LOAD_ATTR, rt_load_attr, qstr, REG_ARG_2); // arg2 = attribute name
713 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
714}
715
716static void emit_native_load_method(emit_t *emit, qstr qstr) {
717 vtype_kind_t vtype_base;
718 emit_pre_pop_reg(emit, &vtype_base, REG_ARG_1); // arg1 = base
719 assert(vtype_base == VTYPE_PYOBJ);
720 emit_get_stack_pointer_to_reg_for_push(emit, REG_ARG_3, 2); // arg3 = dest ptr
721 emit_call_with_imm_arg(emit, RT_F_LOAD_METHOD, rt_load_method, qstr, REG_ARG_2); // arg2 = method name
722}
723
724static void emit_native_load_build_class(emit_t *emit) {
Damien7f5dacf2013-10-10 11:24:39 +0100725 emit_pre(emit);
726 emit_call(emit, RT_F_LOAD_BUILD_CLASS, rt_load_build_class);
727 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
Damien13ed3a62013-10-08 09:05:10 +0100728}
729
730static void emit_native_store_fast(emit_t *emit, qstr qstr, int local_num) {
731 vtype_kind_t vtype;
Damien3ef4abb2013-10-12 16:53:13 +0100732#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100733 if (local_num == 0) {
734 emit_pre_pop_reg(emit, &vtype, REG_LOCAL_1);
735 } else {
736 emit_pre_pop_reg(emit, &vtype, REG_RAX);
737 asm_x64_mov_r64_to_local(emit->as, REG_RAX, local_num - 1);
738 }
Damien3ef4abb2013-10-12 16:53:13 +0100739#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100740 if (local_num == 0) {
741 emit_pre_pop_reg(emit, &vtype, REG_LOCAL_1);
742 } else if (local_num == 1) {
743 emit_pre_pop_reg(emit, &vtype, REG_LOCAL_2);
744 } else if (local_num == 2) {
745 emit_pre_pop_reg(emit, &vtype, REG_LOCAL_3);
746 } else {
747 emit_pre_pop_reg(emit, &vtype, REG_R0);
748 asm_thumb_mov_local_reg(emit->as, local_num - 1, REG_R0);
749 }
750#endif
751
752 emit_post(emit);
753
754 // check types
755 if (emit->local_vtype[local_num] == VTYPE_UNBOUND) {
756 // first time this local is assigned, so give it a type of the object stored in it
757 emit->local_vtype[local_num] = vtype;
758 } else if (emit->local_vtype[local_num] != vtype) {
759 // type of local is not the same as object stored in it
760 printf("ViperTypeError: type mismatch, local %s has type %d but source object has type %d\n", qstr_str(qstr), emit->local_vtype[local_num], vtype);
761 }
762}
763
Damien9ecbcff2013-12-11 00:41:43 +0000764static void emit_native_store_deref(emit_t *emit, qstr qstr, int local_num) {
765 // not implemented
766 assert(0);
767}
768
Damien13ed3a62013-10-08 09:05:10 +0100769static void emit_native_store_name(emit_t *emit, qstr qstr) {
770 // rt_store_name, but needs conversion of object (maybe have rt_viper_store_name(obj, type))
771 vtype_kind_t vtype;
772 emit_pre_pop_reg(emit, &vtype, REG_ARG_2);
773 assert(vtype == VTYPE_PYOBJ);
774 emit_call_with_imm_arg(emit, RT_F_STORE_NAME, rt_store_name, qstr, REG_ARG_1); // arg1 = name
775 emit_post(emit);
776}
777
778static void emit_native_store_global(emit_t *emit, qstr qstr) {
779 // not implemented
780 assert(0);
781}
782
Damien13ed3a62013-10-08 09:05:10 +0100783static void emit_native_store_attr(emit_t *emit, qstr qstr) {
Damien7f5dacf2013-10-10 11:24:39 +0100784 vtype_kind_t vtype_base, vtype_val;
785 emit_pre_pop_reg_reg(emit, &vtype_base, REG_ARG_1, &vtype_val, REG_ARG_3); // arg1 = base, arg3 = value
786 assert(vtype_base == VTYPE_PYOBJ);
787 assert(vtype_val == VTYPE_PYOBJ);
788 emit_call_with_imm_arg(emit, RT_F_STORE_ATTR, rt_store_attr, qstr, REG_ARG_2); // arg2 = attribute name
789 emit_post(emit);
Damien13ed3a62013-10-08 09:05:10 +0100790}
791
Damien13ed3a62013-10-08 09:05:10 +0100792static void emit_native_store_subscr(emit_t *emit) {
793 // depends on type of subject:
794 // - integer, function, pointer to structure: error
795 // - pointer to integers: store as per array
796 // - Python object: call runtime with converted object or type info
797 vtype_kind_t vtype_index, vtype_base, vtype_value;
798 emit_pre_pop_reg_reg_reg(emit, &vtype_index, REG_ARG_2, &vtype_base, REG_ARG_1, &vtype_value, REG_ARG_3); // index, base, value to store
799 assert(vtype_index == VTYPE_PYOBJ);
800 assert(vtype_base == VTYPE_PYOBJ);
801 assert(vtype_value == VTYPE_PYOBJ);
802 emit_call(emit, RT_F_STORE_SUBSCR, rt_store_subscr);
803}
804
Damiena3977762013-10-09 23:10:10 +0100805static void emit_native_store_locals(emit_t *emit) {
806 // not needed
807 vtype_kind_t vtype;
808 emit_pre_pop_reg(emit, &vtype, REG_TEMP0);
809 emit_post(emit);
810}
811
Damien13ed3a62013-10-08 09:05:10 +0100812static void emit_native_delete_fast(emit_t *emit, qstr qstr, int local_num) {
813 // not implemented
814 // could support for Python types, just set to None (so GC can reclaim it)
815 assert(0);
816}
817
Damien9ecbcff2013-12-11 00:41:43 +0000818static void emit_native_delete_deref(emit_t *emit, qstr qstr, int local_num) {
819 // not supported
820 assert(0);
821}
822
Damien13ed3a62013-10-08 09:05:10 +0100823static void emit_native_delete_name(emit_t *emit, qstr qstr) {
824 // not implemented
825 // use rt_delete_name
826 assert(0);
827}
828
829static void emit_native_delete_global(emit_t *emit, qstr qstr) {
830 // not implemented
831 // use rt_delete_global
832 assert(0);
833}
834
Damien13ed3a62013-10-08 09:05:10 +0100835static void emit_native_delete_attr(emit_t *emit, qstr qstr) {
836 // not supported
837 assert(0);
838}
839
840static void emit_native_delete_subscr(emit_t *emit) {
841 // not supported
842 assert(0);
843}
844
845static void emit_native_dup_top(emit_t *emit) {
846 vtype_kind_t vtype;
847 emit_pre_pop_reg(emit, &vtype, REG_TEMP0);
848 emit_post_push_reg_reg(emit, vtype, REG_TEMP0, vtype, REG_TEMP0);
849}
850
851static void emit_native_dup_top_two(emit_t *emit) {
852 vtype_kind_t vtype0, vtype1;
853 emit_pre_pop_reg_reg(emit, &vtype0, REG_TEMP0, &vtype1, REG_TEMP1);
854 emit_post_push_reg_reg_reg_reg(emit, vtype1, REG_TEMP1, vtype0, REG_TEMP0, vtype1, REG_TEMP1, vtype0, REG_TEMP0);
855}
856
857static void emit_native_pop_top(emit_t *emit) {
858 vtype_kind_t vtype;
859 emit_pre_pop_reg(emit, &vtype, REG_TEMP0);
860 emit_post(emit);
861}
862
863static void emit_native_rot_two(emit_t *emit) {
Damienff8ed772013-10-08 22:18:32 +0100864 vtype_kind_t vtype0, vtype1;
865 emit_pre_pop_reg_reg(emit, &vtype0, REG_TEMP0, &vtype1, REG_TEMP1);
866 emit_post_push_reg_reg(emit, vtype0, REG_TEMP0, vtype1, REG_TEMP1);
Damien13ed3a62013-10-08 09:05:10 +0100867}
868
869static void emit_native_rot_three(emit_t *emit) {
870 vtype_kind_t vtype0, vtype1, vtype2;
871 emit_pre_pop_reg_reg_reg(emit, &vtype0, REG_TEMP0, &vtype1, REG_TEMP1, &vtype2, REG_TEMP2);
872 emit_post_push_reg_reg_reg(emit, vtype0, REG_TEMP0, vtype2, REG_TEMP2, vtype1, REG_TEMP1);
873}
874
875static void emit_native_jump(emit_t *emit, int label) {
876 emit_pre(emit);
Damien3ef4abb2013-10-12 16:53:13 +0100877#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100878 asm_x64_jmp_label(emit->as, label);
Damien3ef4abb2013-10-12 16:53:13 +0100879#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100880 asm_thumb_b_label(emit->as, label);
881#endif
882 emit_post(emit);
883}
884
Damien1a6633a2013-11-03 13:58:19 +0000885static void emit_native_pop_jump_pre_helper(emit_t *emit, int label) {
Damien13ed3a62013-10-08 09:05:10 +0100886 vtype_kind_t vtype = peek_vtype(emit);
887 if (vtype == VTYPE_BOOL) {
888 emit_pre_pop_reg(emit, &vtype, REG_RET);
889 } else if (vtype == VTYPE_PYOBJ) {
890 emit_pre_pop_reg(emit, &vtype, REG_ARG_1);
891 emit_call(emit, RT_F_IS_TRUE, rt_is_true);
892 } else {
893 printf("ViperTypeError: expecting a bool or pyobj, got %d\n", vtype);
894 assert(0);
895 }
Damien1a6633a2013-11-03 13:58:19 +0000896}
897
898static void emit_native_pop_jump_if_false(emit_t *emit, int label) {
899 emit_native_pop_jump_pre_helper(emit, label);
Damien3ef4abb2013-10-12 16:53:13 +0100900#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100901 asm_x64_test_r8_with_r8(emit->as, REG_RET, REG_RET);
902 asm_x64_jcc_label(emit->as, JCC_JZ, label);
Damien3ef4abb2013-10-12 16:53:13 +0100903#elif N_THUMB
Damien1a6633a2013-11-03 13:58:19 +0000904 asm_thumb_cmp_rlo_i8(emit->as, REG_RET, 0);
905 asm_thumb_bcc_label(emit->as, THUMB_CC_EQ, label);
Damien13ed3a62013-10-08 09:05:10 +0100906#endif
907 emit_post(emit);
908}
909
910static void emit_native_pop_jump_if_true(emit_t *emit, int label) {
Damien1a6633a2013-11-03 13:58:19 +0000911 emit_native_pop_jump_pre_helper(emit, label);
912#if N_X64
913 asm_x64_test_r8_with_r8(emit->as, REG_RET, REG_RET);
914 asm_x64_jcc_label(emit->as, JCC_JNZ, label);
915#elif N_THUMB
916 asm_thumb_cmp_rlo_i8(emit->as, REG_RET, 0);
917 asm_thumb_bcc_label(emit->as, THUMB_CC_NE, label);
918#endif
919 emit_post(emit);
Damien13ed3a62013-10-08 09:05:10 +0100920}
Damien1a6633a2013-11-03 13:58:19 +0000921
Damien13ed3a62013-10-08 09:05:10 +0100922static void emit_native_jump_if_true_or_pop(emit_t *emit, int label) {
923 assert(0);
924}
925static void emit_native_jump_if_false_or_pop(emit_t *emit, int label) {
926 assert(0);
927}
928
929static void emit_native_setup_loop(emit_t *emit, int label) {
930 emit_pre(emit);
931 emit_post(emit);
932}
933
934static void emit_native_break_loop(emit_t *emit, int label) {
Damien6ba13142013-11-02 20:34:54 +0000935 emit_native_jump(emit, label); // TODO properly
Damien13ed3a62013-10-08 09:05:10 +0100936}
937static void emit_native_continue_loop(emit_t *emit, int label) {
938 assert(0);
939}
940static void emit_native_setup_with(emit_t *emit, int label) {
941 // not supported, or could be with runtime call
942 assert(0);
943}
944static void emit_native_with_cleanup(emit_t *emit) {
945 assert(0);
946}
947static void emit_native_setup_except(emit_t *emit, int label) {
948 assert(0);
949}
950static void emit_native_setup_finally(emit_t *emit, int label) {
951 assert(0);
952}
953static void emit_native_end_finally(emit_t *emit) {
954 assert(0);
955}
Damiend2755ec2013-10-16 23:58:48 +0100956
Damien13ed3a62013-10-08 09:05:10 +0100957static void emit_native_get_iter(emit_t *emit) {
958 // perhaps the difficult one, as we want to rewrite for loops using native code
959 // in cases where we iterate over a Python object, can we use normal runtime calls?
Damiend2755ec2013-10-16 23:58:48 +0100960
961 vtype_kind_t vtype;
962 emit_pre_pop_reg(emit, &vtype, REG_ARG_1);
963 assert(vtype == VTYPE_PYOBJ);
964 emit_call(emit, RT_F_GETITER, rt_getiter);
965 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
Damien13ed3a62013-10-08 09:05:10 +0100966}
Damiend2755ec2013-10-16 23:58:48 +0100967
968static void emit_native_for_iter(emit_t *emit, int label) {
969 emit_pre(emit);
970 vtype_kind_t vtype;
971 emit_access_stack(emit, 1, &vtype, REG_ARG_1);
972 assert(vtype == VTYPE_PYOBJ);
973 emit_call(emit, RT_F_ITERNEXT, rt_iternext);
Damiend99b0522013-12-21 18:17:45 +0000974 ASM_MOV_IMM_TO_REG((machine_uint_t)mp_const_stop_iteration, REG_TEMP1);
Damiend2755ec2013-10-16 23:58:48 +0100975#if N_X64
976 asm_x64_cmp_r64_with_r64(emit->as, REG_RET, REG_TEMP1);
977 asm_x64_jcc_label(emit->as, JCC_JE, label);
978#elif N_THUMB
Damiend2755ec2013-10-16 23:58:48 +0100979 asm_thumb_cmp_reg_reg(emit->as, REG_RET, REG_TEMP1);
Damien9b9e9962013-11-03 14:25:43 +0000980 asm_thumb_bcc_label(emit->as, THUMB_CC_EQ, label);
Damiend2755ec2013-10-16 23:58:48 +0100981#endif
982 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
983}
984
Damien13ed3a62013-10-08 09:05:10 +0100985static void emit_native_for_iter_end(emit_t *emit) {
Damiend2755ec2013-10-16 23:58:48 +0100986 // adjust stack counter (we get here from for_iter ending, which popped the value for us)
987 emit_pre(emit);
988 adjust_stack(emit, -1);
989 emit_post(emit);
Damien13ed3a62013-10-08 09:05:10 +0100990}
991
992static void emit_native_pop_block(emit_t *emit) {
993 emit_pre(emit);
994 emit_post(emit);
995}
996
997static void emit_native_pop_except(emit_t *emit) {
998 assert(0);
999}
1000
1001static void emit_native_unary_op(emit_t *emit, rt_unary_op_t op) {
1002 vtype_kind_t vtype;
1003 emit_pre_pop_reg(emit, &vtype, REG_ARG_2);
1004 assert(vtype == VTYPE_PYOBJ);
1005 emit_call_with_imm_arg(emit, RT_F_UNARY_OP, rt_unary_op, op, REG_ARG_1);
1006 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
1007}
1008
1009static void emit_native_binary_op(emit_t *emit, rt_binary_op_t op) {
1010 vtype_kind_t vtype_lhs, vtype_rhs;
1011 emit_pre_pop_reg_reg(emit, &vtype_rhs, REG_ARG_3, &vtype_lhs, REG_ARG_2);
1012 if (vtype_lhs == VTYPE_INT && vtype_rhs == VTYPE_INT) {
Damien Georgebc1d3692014-01-11 09:47:06 +00001013 if (op == RT_BINARY_OP_ADD || op == RT_BINARY_OP_INPLACE_ADD) {
Damien3ef4abb2013-10-12 16:53:13 +01001014#if N_X64
Damien Georgebc1d3692014-01-11 09:47:06 +00001015 asm_x64_add_r64_to_r64(emit->as, REG_ARG_3, REG_ARG_2);
Damien3ef4abb2013-10-12 16:53:13 +01001016#elif N_THUMB
Damien Georgebc1d3692014-01-11 09:47:06 +00001017 asm_thumb_add_reg_reg_reg(emit->as, REG_ARG_2, REG_ARG_2, REG_ARG_3);
Damien13ed3a62013-10-08 09:05:10 +01001018#endif
Damien Georgebc1d3692014-01-11 09:47:06 +00001019 emit_post_push_reg(emit, VTYPE_INT, REG_ARG_2);
1020 } else if (op == RT_COMPARE_OP_LESS) {
1021#if N_X64
1022 asm_x64_xor_r64_to_r64(emit->as, REG_RET, REG_RET);
1023 asm_x64_cmp_r64_with_r64(emit->as, REG_ARG_3, REG_ARG_2);
1024 asm_x64_setcc_r8(emit->as, JCC_JL, REG_RET);
1025#elif N_THUMB
1026 asm_thumb_cmp_reg_reg(emit->as, REG_ARG_2, REG_ARG_3);
1027 asm_thumb_ite_ge(emit->as);
1028 asm_thumb_movs_rlo_i8(emit->as, REG_RET, 0); // if r0 >= r1
1029 asm_thumb_movs_rlo_i8(emit->as, REG_RET, 1); // if r0 < r1
1030#endif
1031 emit_post_push_reg(emit, VTYPE_BOOL, REG_RET);
1032 } else {
1033 // TODO other ops not yet implemented
1034 assert(0);
1035 }
Damien13ed3a62013-10-08 09:05:10 +01001036 } else if (vtype_lhs == VTYPE_PYOBJ && vtype_rhs == VTYPE_PYOBJ) {
1037 emit_call_with_imm_arg(emit, RT_F_BINARY_OP, rt_binary_op, op, REG_ARG_1);
1038 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
1039 } else {
1040 printf("ViperTypeError: can't do binary op between types %d and %d\n", vtype_lhs, vtype_rhs);
1041 assert(0);
1042 }
1043}
1044
Damien13ed3a62013-10-08 09:05:10 +01001045static void emit_native_build_tuple(emit_t *emit, int n_args) {
Damiend2755ec2013-10-16 23:58:48 +01001046 // for viper: call runtime, with types of args
1047 // if wrapped in byte_array, or something, allocates memory and fills it
1048 emit_pre(emit);
1049 emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, n_args); // pointer to items in reverse order
1050 emit_call_with_imm_arg(emit, RT_F_BUILD_TUPLE, rt_build_tuple, n_args, REG_ARG_1);
1051 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new tuple
Damien13ed3a62013-10-08 09:05:10 +01001052}
1053
1054static void emit_native_build_list(emit_t *emit, int n_args) {
1055 emit_pre(emit);
1056 emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, n_args); // pointer to items in reverse order
1057 emit_call_with_imm_arg(emit, RT_F_BUILD_LIST, rt_build_list, n_args, REG_ARG_1);
1058 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new list
1059}
1060
1061static void emit_native_list_append(emit_t *emit, int list_index) {
Damiend2755ec2013-10-16 23:58:48 +01001062 // only used in list comprehension
1063 vtype_kind_t vtype_list, vtype_item;
1064 emit_pre_pop_reg(emit, &vtype_item, REG_ARG_2);
1065 emit_access_stack(emit, list_index, &vtype_list, REG_ARG_1);
1066 assert(vtype_list == VTYPE_PYOBJ);
1067 assert(vtype_item == VTYPE_PYOBJ);
1068 emit_call(emit, RT_F_LIST_APPEND, rt_list_append);
1069 emit_post(emit);
Damien13ed3a62013-10-08 09:05:10 +01001070}
1071
1072static void emit_native_build_map(emit_t *emit, int n_args) {
1073 emit_pre(emit);
1074 emit_call_with_imm_arg(emit, RT_F_BUILD_MAP, rt_build_map, n_args, REG_ARG_1);
1075 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new map
1076}
1077
1078static void emit_native_store_map(emit_t *emit) {
1079 vtype_kind_t vtype_key, vtype_value, vtype_map;
1080 emit_pre_pop_reg_reg_reg(emit, &vtype_key, REG_ARG_2, &vtype_value, REG_ARG_3, &vtype_map, REG_ARG_1); // key, value, map
1081 assert(vtype_key == VTYPE_PYOBJ);
1082 assert(vtype_value == VTYPE_PYOBJ);
1083 assert(vtype_map == VTYPE_PYOBJ);
1084 emit_call(emit, RT_F_STORE_MAP, rt_store_map);
1085 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // map
1086}
1087
1088static void emit_native_map_add(emit_t *emit, int map_index) {
Damiend2755ec2013-10-16 23:58:48 +01001089 // only used in list comprehension
1090 vtype_kind_t vtype_map, vtype_key, vtype_value;
1091 emit_pre_pop_reg_reg(emit, &vtype_key, REG_ARG_2, &vtype_value, REG_ARG_3);
1092 emit_access_stack(emit, map_index, &vtype_map, REG_ARG_1);
1093 assert(vtype_map == VTYPE_PYOBJ);
1094 assert(vtype_key == VTYPE_PYOBJ);
1095 assert(vtype_value == VTYPE_PYOBJ);
1096 emit_call(emit, RT_F_STORE_MAP, rt_store_map);
1097 emit_post(emit);
Damien13ed3a62013-10-08 09:05:10 +01001098}
1099
1100static void emit_native_build_set(emit_t *emit, int n_args) {
1101 emit_pre(emit);
1102 emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, n_args); // pointer to items in reverse order
1103 emit_call_with_imm_arg(emit, RT_F_BUILD_SET, rt_build_set, n_args, REG_ARG_1);
1104 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new set
1105}
1106
1107static void emit_native_set_add(emit_t *emit, int set_index) {
Damiend2755ec2013-10-16 23:58:48 +01001108 // only used in set comprehension
1109 vtype_kind_t vtype_set, vtype_item;
1110 emit_pre_pop_reg(emit, &vtype_item, REG_ARG_2);
1111 emit_access_stack(emit, set_index, &vtype_set, REG_ARG_1);
1112 assert(vtype_set == VTYPE_PYOBJ);
1113 assert(vtype_item == VTYPE_PYOBJ);
1114 emit_call(emit, RT_F_STORE_SET, rt_store_set);
1115 emit_post(emit);
Damien13ed3a62013-10-08 09:05:10 +01001116}
Damiend2755ec2013-10-16 23:58:48 +01001117
Damien13ed3a62013-10-08 09:05:10 +01001118static void emit_native_build_slice(emit_t *emit, int n_args) {
1119 assert(0);
1120}
1121static void emit_native_unpack_sequence(emit_t *emit, int n_args) {
1122 // call runtime, needs type decl
1123 assert(0);
1124}
1125static void emit_native_unpack_ex(emit_t *emit, int n_left, int n_right) {
1126 assert(0);
1127}
1128
1129static void emit_native_make_function(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) {
1130 // call runtime, with type info for args, or don't support dict/default params, or only support Python objects for them
1131 assert(n_default_params == 0 && n_dict_params == 0);
1132 emit_pre(emit);
1133 emit_call_with_imm_arg(emit, RT_F_MAKE_FUNCTION_FROM_ID, rt_make_function_from_id, scope->unique_code_id, REG_ARG_1);
1134 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
1135}
1136
1137static void emit_native_make_closure(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) {
1138 assert(0);
1139}
1140
1141static void emit_native_call_function(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) {
1142 // call special viper runtime routine with type info for args, and wanted type info for return
1143 assert(n_keyword == 0 && !have_star_arg && !have_dbl_star_arg);
Damieneb19efb2013-10-10 22:06:54 +01001144 /*
Damien13ed3a62013-10-08 09:05:10 +01001145 if (n_positional == 0) {
1146 vtype_kind_t vtype_fun;
1147 emit_pre_pop_reg(emit, &vtype_fun, REG_ARG_1); // the function
1148 assert(vtype_fun == VTYPE_PYOBJ);
1149 emit_call(emit, RT_F_CALL_FUNCTION_0, rt_call_function_0);
1150 } else if (n_positional == 1) {
1151 vtype_kind_t vtype_fun, vtype_arg1;
1152 emit_pre_pop_reg_reg(emit, &vtype_arg1, REG_ARG_2, &vtype_fun, REG_ARG_1); // the single argument, the function
1153 assert(vtype_fun == VTYPE_PYOBJ);
1154 assert(vtype_arg1 == VTYPE_PYOBJ);
1155 emit_call(emit, RT_F_CALL_FUNCTION_1, rt_call_function_1);
1156 } else if (n_positional == 2) {
1157 vtype_kind_t vtype_fun, vtype_arg1, vtype_arg2;
1158 emit_pre_pop_reg_reg_reg(emit, &vtype_arg2, REG_ARG_3, &vtype_arg1, REG_ARG_2, &vtype_fun, REG_ARG_1); // the second argument, the first argument, the function
1159 assert(vtype_fun == VTYPE_PYOBJ);
1160 assert(vtype_arg1 == VTYPE_PYOBJ);
1161 assert(vtype_arg2 == VTYPE_PYOBJ);
1162 emit_call(emit, RT_F_CALL_FUNCTION_2, rt_call_function_2);
1163 } else {
Damieneb19efb2013-10-10 22:06:54 +01001164 */
1165 emit_pre(emit);
1166 if (n_positional != 0) {
1167 emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_3, n_positional); // pointer to args in reverse order
1168 }
1169 vtype_kind_t vtype_fun;
1170 emit_pre_pop_reg(emit, &vtype_fun, REG_ARG_1); // the function
1171 assert(vtype_fun == VTYPE_PYOBJ);
Damien George20006db2014-01-18 14:10:48 +00001172 // XXX rt_call_function_n now merged with rt_call_function_n_kw
1173 //emit_call_with_imm_arg(emit, RT_F_CALL_FUNCTION_N, rt_call_function_n, n_positional, REG_ARG_2);
Damieneb19efb2013-10-10 22:06:54 +01001174 //}
Damien13ed3a62013-10-08 09:05:10 +01001175 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
1176}
1177
1178static void emit_native_call_method(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) {
1179 assert(n_keyword == 0 && !have_star_arg && !have_dbl_star_arg);
Damieneb19efb2013-10-10 22:06:54 +01001180 /*
Damien13ed3a62013-10-08 09:05:10 +01001181 if (n_positional == 0) {
1182 vtype_kind_t vtype_meth, vtype_self;
1183 emit_pre_pop_reg_reg(emit, &vtype_self, REG_ARG_2, &vtype_meth, REG_ARG_1); // the self object (or NULL), the method
1184 assert(vtype_meth == VTYPE_PYOBJ);
1185 assert(vtype_self == VTYPE_PYOBJ);
1186 emit_call(emit, RT_F_CALL_METHOD_1, rt_call_method_1);
1187 } else if (n_positional == 1) {
1188 vtype_kind_t vtype_meth, vtype_self, vtype_arg1;
1189 emit_pre_pop_reg_reg_reg(emit, &vtype_arg1, REG_ARG_3, &vtype_self, REG_ARG_2, &vtype_meth, REG_ARG_1); // the first argument, the self object (or NULL), the method
1190 assert(vtype_meth == VTYPE_PYOBJ);
1191 assert(vtype_self == VTYPE_PYOBJ);
1192 assert(vtype_arg1 == VTYPE_PYOBJ);
1193 emit_call(emit, RT_F_CALL_METHOD_2, rt_call_method_2);
1194 } else {
Damieneb19efb2013-10-10 22:06:54 +01001195 */
Damien7f5dacf2013-10-10 11:24:39 +01001196 emit_pre(emit);
1197 emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, n_positional + 2); // pointer to items in reverse order, including meth and self
Damien George20006db2014-01-18 14:10:48 +00001198 // XXX rt_call_method_n now merged with rt_call_method_n_kw
1199 //emit_call_with_imm_arg(emit, RT_F_CALL_METHOD_N, rt_call_method_n, n_positional, REG_ARG_1);
Damieneb19efb2013-10-10 22:06:54 +01001200 //}
Damien13ed3a62013-10-08 09:05:10 +01001201 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
1202}
1203
1204static void emit_native_return_value(emit_t *emit) {
1205 // easy. since we don't know who we return to, just return the raw value.
1206 // runtime needs then to know our type signature, but I think that's possible.
1207 vtype_kind_t vtype;
1208 emit_pre_pop_reg(emit, &vtype, REG_RET);
1209 if (emit->do_viper_types) {
1210 assert(vtype == VTYPE_PTR_NONE);
1211 } else {
1212 assert(vtype == VTYPE_PYOBJ);
1213 }
1214 emit->last_emit_was_return_value = true;
Damien3ef4abb2013-10-12 16:53:13 +01001215#if N_X64
Damien13ed3a62013-10-08 09:05:10 +01001216 //asm_x64_call_ind(emit->as, 0, REG_RAX); to seg fault for debugging with gdb
1217 asm_x64_exit(emit->as);
Damien3ef4abb2013-10-12 16:53:13 +01001218#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +01001219 //asm_thumb_call_ind(emit->as, 0, REG_R0); to seg fault for debugging with gdb
1220 asm_thumb_exit(emit->as);
1221#endif
1222}
1223
1224static void emit_native_raise_varargs(emit_t *emit, int n_args) {
1225 // call runtime
1226 assert(0);
1227}
1228static void emit_native_yield_value(emit_t *emit) {
1229 // not supported (for now)
1230 assert(0);
1231}
1232static void emit_native_yield_from(emit_t *emit) {
1233 // not supported (for now)
1234 assert(0);
1235}
1236
1237const emit_method_table_t EXPORT_FUN(method_table) = {
Paul Sokolovskyf46d87a2014-01-24 16:20:11 +02001238 emit_native_free,
1239
Damien13ed3a62013-10-08 09:05:10 +01001240 emit_native_set_viper_types,
1241 emit_native_start_pass,
1242 emit_native_end_pass,
1243 emit_native_last_emit_was_return_value,
1244 emit_native_get_stack_size,
1245 emit_native_set_stack_size,
Damien George08335002014-01-18 23:24:36 +00001246 emit_native_set_source_line,
Damien13ed3a62013-10-08 09:05:10 +01001247
1248 emit_native_load_id,
1249 emit_native_store_id,
1250 emit_native_delete_id,
1251
1252 emit_native_label_assign,
1253 emit_native_import_name,
1254 emit_native_import_from,
1255 emit_native_import_star,
1256 emit_native_load_const_tok,
1257 emit_native_load_const_small_int,
1258 emit_native_load_const_int,
1259 emit_native_load_const_dec,
1260 emit_native_load_const_id,
1261 emit_native_load_const_str,
Damien13ed3a62013-10-08 09:05:10 +01001262 emit_native_load_const_verbatim_str,
Damien13ed3a62013-10-08 09:05:10 +01001263 emit_native_load_fast,
Damien13ed3a62013-10-08 09:05:10 +01001264 emit_native_load_deref,
1265 emit_native_load_closure,
Damien9ecbcff2013-12-11 00:41:43 +00001266 emit_native_load_name,
1267 emit_native_load_global,
Damien13ed3a62013-10-08 09:05:10 +01001268 emit_native_load_attr,
1269 emit_native_load_method,
1270 emit_native_load_build_class,
1271 emit_native_store_fast,
Damien9ecbcff2013-12-11 00:41:43 +00001272 emit_native_store_deref,
Damien13ed3a62013-10-08 09:05:10 +01001273 emit_native_store_name,
1274 emit_native_store_global,
Damien13ed3a62013-10-08 09:05:10 +01001275 emit_native_store_attr,
Damien13ed3a62013-10-08 09:05:10 +01001276 emit_native_store_subscr,
Damiena3977762013-10-09 23:10:10 +01001277 emit_native_store_locals,
Damien13ed3a62013-10-08 09:05:10 +01001278 emit_native_delete_fast,
Damien9ecbcff2013-12-11 00:41:43 +00001279 emit_native_delete_deref,
Damien13ed3a62013-10-08 09:05:10 +01001280 emit_native_delete_name,
1281 emit_native_delete_global,
Damien13ed3a62013-10-08 09:05:10 +01001282 emit_native_delete_attr,
1283 emit_native_delete_subscr,
1284 emit_native_dup_top,
1285 emit_native_dup_top_two,
1286 emit_native_pop_top,
1287 emit_native_rot_two,
1288 emit_native_rot_three,
1289 emit_native_jump,
1290 emit_native_pop_jump_if_true,
1291 emit_native_pop_jump_if_false,
1292 emit_native_jump_if_true_or_pop,
1293 emit_native_jump_if_false_or_pop,
1294 emit_native_setup_loop,
1295 emit_native_break_loop,
1296 emit_native_continue_loop,
1297 emit_native_setup_with,
1298 emit_native_with_cleanup,
1299 emit_native_setup_except,
1300 emit_native_setup_finally,
1301 emit_native_end_finally,
1302 emit_native_get_iter,
1303 emit_native_for_iter,
1304 emit_native_for_iter_end,
1305 emit_native_pop_block,
1306 emit_native_pop_except,
1307 emit_native_unary_op,
1308 emit_native_binary_op,
Damien13ed3a62013-10-08 09:05:10 +01001309 emit_native_build_tuple,
1310 emit_native_build_list,
1311 emit_native_list_append,
1312 emit_native_build_map,
1313 emit_native_store_map,
1314 emit_native_map_add,
1315 emit_native_build_set,
1316 emit_native_set_add,
1317 emit_native_build_slice,
1318 emit_native_unpack_sequence,
1319 emit_native_unpack_ex,
1320 emit_native_make_function,
1321 emit_native_make_closure,
1322 emit_native_call_function,
1323 emit_native_call_method,
1324 emit_native_return_value,
1325 emit_native_raise_varargs,
1326 emit_native_yield_value,
1327 emit_native_yield_from,
1328};
1329
Damien Georgee67ed5d2014-01-04 13:55:24 +00001330#endif // (MICROPY_EMIT_X64 && N_X64) || (MICROPY_EMIT_THUMB && N_THUMB)