blob: aea25ac36d010e9f0ee2c0c00e58a7eaedf61d2a [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"
Damien13ed3a62013-10-08 09:05:10 +010028#include "lexer.h"
Damien13ed3a62013-10-08 09:05:10 +010029#include "parse.h"
30#include "scope.h"
Damiend99b0522013-12-21 18:17:45 +000031#include "runtime0.h"
Damien13ed3a62013-10-08 09:05:10 +010032#include "emit.h"
Damiend99b0522013-12-21 18:17:45 +000033#include "obj.h"
34#include "runtime.h"
Damien13ed3a62013-10-08 09:05:10 +010035
Damien13ed3a62013-10-08 09:05:10 +010036// wrapper around everything in this file
Damien Georgee67ed5d2014-01-04 13:55:24 +000037#if (MICROPY_EMIT_X64 && N_X64) || (MICROPY_EMIT_THUMB && N_THUMB)
Damien13ed3a62013-10-08 09:05:10 +010038
Damien3ef4abb2013-10-12 16:53:13 +010039#if N_X64
Damien13ed3a62013-10-08 09:05:10 +010040
41// x64 specific stuff
42
43#include "asmx64.h"
44
45#define REG_LOCAL_1 (REG_RBX)
46#define REG_LOCAL_NUM (1)
47
48#define EXPORT_FUN(name) emit_native_x64_##name
49
50#define REG_TEMP0 (REG_RAX)
51#define REG_TEMP1 (REG_RDI)
52#define REG_TEMP2 (REG_RSI)
53#define ASM_MOV_REG_TO_LOCAL(reg, local_num) asm_x64_mov_r64_to_local(emit->as, (reg), (local_num))
54#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 +010055#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 +010056#define ASM_MOV_LOCAL_TO_REG(local_num, reg) asm_x64_mov_local_to_r64(emit->as, (local_num), (reg))
57#define ASM_MOV_REG_TO_REG(reg_src, reg_dest) asm_x64_mov_r64_to_r64(emit->as, (reg_src), (reg_dest))
58#define ASM_MOV_LOCAL_ADDR_TO_REG(local_num, reg) asm_x64_mov_local_addr_to_r64(emit->as, (local_num), (reg))
59
Damien3ef4abb2013-10-12 16:53:13 +010060#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +010061
62// thumb specific stuff
63
64#include "asmthumb.h"
65
66#define REG_LOCAL_1 (REG_R4)
67#define REG_LOCAL_2 (REG_R5)
68#define REG_LOCAL_3 (REG_R6)
69#define REG_LOCAL_NUM (3)
70
71#define EXPORT_FUN(name) emit_native_thumb_##name
72
73#define REG_TEMP0 (REG_R0)
74#define REG_TEMP1 (REG_R1)
75#define REG_TEMP2 (REG_R2)
76#define ASM_MOV_REG_TO_LOCAL(reg, local_num) asm_thumb_mov_local_reg(emit->as, (local_num), (reg))
77#define ASM_MOV_IMM_TO_REG(imm, reg) asm_thumb_mov_reg_i32_optimised(emit->as, (reg), (imm))
Damieneb19efb2013-10-10 22:06:54 +010078#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 +010079#define ASM_MOV_LOCAL_TO_REG(local_num, reg) asm_thumb_mov_reg_local(emit->as, (reg), (local_num))
80#define ASM_MOV_REG_TO_REG(reg_src, reg_dest) asm_thumb_mov_reg_reg(emit->as, (reg_dest), (reg_src))
81#define ASM_MOV_LOCAL_ADDR_TO_REG(local_num, reg) asm_thumb_mov_reg_local_addr(emit->as, (reg), (local_num))
82
83#endif
84
85typedef enum {
Damienff8ed772013-10-08 22:18:32 +010086 STACK_VALUE,
87 STACK_REG,
88 STACK_IMM,
89} stack_info_kind_t;
Damien13ed3a62013-10-08 09:05:10 +010090
91typedef enum {
92 VTYPE_UNBOUND,
93 VTYPE_PYOBJ,
94 VTYPE_BOOL,
95 VTYPE_INT,
96 VTYPE_PTR,
97 VTYPE_PTR_NONE,
98 VTYPE_BUILTIN_V_INT,
99} vtype_kind_t;
100
Damienff8ed772013-10-08 22:18:32 +0100101typedef struct _stack_info_t {
102 vtype_kind_t vtype;
103 stack_info_kind_t kind;
104 union {
105 int u_reg;
106 machine_int_t u_imm;
107 };
108} stack_info_t;
109
Damien13ed3a62013-10-08 09:05:10 +0100110struct _emit_t {
111 int pass;
112
113 bool do_viper_types;
Damienff8ed772013-10-08 22:18:32 +0100114
115 int local_vtype_alloc;
Damien13ed3a62013-10-08 09:05:10 +0100116 vtype_kind_t *local_vtype;
Damienff8ed772013-10-08 22:18:32 +0100117
118 int stack_info_alloc;
119 stack_info_t *stack_info;
120
Damien13ed3a62013-10-08 09:05:10 +0100121 int stack_start;
122 int stack_size;
123
124 bool last_emit_was_return_value;
125
Damien13ed3a62013-10-08 09:05:10 +0100126 scope_t *scope;
127
Damien3ef4abb2013-10-12 16:53:13 +0100128#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100129 asm_x64_t *as;
Damien3ef4abb2013-10-12 16:53:13 +0100130#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100131 asm_thumb_t *as;
132#endif
133};
134
135emit_t *EXPORT_FUN(new)(uint max_num_labels) {
136 emit_t *emit = m_new(emit_t, 1);
137 emit->do_viper_types = false;
Damienff8ed772013-10-08 22:18:32 +0100138 emit->local_vtype = NULL;
139 emit->stack_info = NULL;
Damien3ef4abb2013-10-12 16:53:13 +0100140#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100141 emit->as = asm_x64_new(max_num_labels);
Damien3ef4abb2013-10-12 16:53:13 +0100142#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100143 emit->as = asm_thumb_new(max_num_labels);
144#endif
145 return emit;
146}
147
148static void emit_native_set_viper_types(emit_t *emit, bool do_viper_types) {
149 emit->do_viper_types = do_viper_types;
150}
151
152static void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) {
153 emit->pass = pass;
154 emit->stack_start = 0;
155 emit->stack_size = 0;
156 emit->last_emit_was_return_value = false;
Damien13ed3a62013-10-08 09:05:10 +0100157 emit->scope = scope;
158
Damienff8ed772013-10-08 22:18:32 +0100159 if (emit->local_vtype == NULL) {
160 emit->local_vtype_alloc = scope->num_locals + 20; // XXX should be maximum over all scopes
161 emit->local_vtype = m_new(vtype_kind_t, emit->local_vtype_alloc);
162 }
163 if (emit->stack_info == NULL) {
164 emit->stack_info_alloc = scope->stack_size + 50; // XXX don't know stack size on entry, should be maximum over all scopes
165 emit->stack_info = m_new(stack_info_t, emit->stack_info_alloc);
Damien13ed3a62013-10-08 09:05:10 +0100166 }
167
168 if (emit->do_viper_types) {
Damien13ed3a62013-10-08 09:05:10 +0100169 // TODO set types of arguments based on type signature
Damienff8ed772013-10-08 22:18:32 +0100170 for (int i = 0; i < emit->local_vtype_alloc; i++) {
171 emit->local_vtype[i] = VTYPE_UNBOUND;
172 }
173 for (int i = 0; i < emit->stack_info_alloc; i++) {
174 emit->stack_info[i].kind = STACK_VALUE;
175 emit->stack_info[i].vtype = VTYPE_UNBOUND;
176 }
Damien13ed3a62013-10-08 09:05:10 +0100177 } else {
Damienff8ed772013-10-08 22:18:32 +0100178 for (int i = 0; i < emit->local_vtype_alloc; i++) {
179 emit->local_vtype[i] = VTYPE_PYOBJ;
180 }
181 for (int i = 0; i < emit->stack_info_alloc; i++) {
182 emit->stack_info[i].kind = STACK_VALUE;
183 emit->stack_info[i].vtype = VTYPE_PYOBJ;
Damien13ed3a62013-10-08 09:05:10 +0100184 }
185 }
186
Damien3ef4abb2013-10-12 16:53:13 +0100187#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100188 asm_x64_start_pass(emit->as, pass);
Damien3ef4abb2013-10-12 16:53:13 +0100189#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100190 asm_thumb_start_pass(emit->as, pass);
191#endif
192
193 // entry to function
194 int num_locals = 0;
195 if (pass > PASS_1) {
196 num_locals = scope->num_locals - REG_LOCAL_NUM;
197 if (num_locals < 0) {
198 num_locals = 0;
199 }
200 emit->stack_start = num_locals;
201 num_locals += scope->stack_size;
202 }
Damien3ef4abb2013-10-12 16:53:13 +0100203#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100204 asm_x64_entry(emit->as, num_locals);
Damien3ef4abb2013-10-12 16:53:13 +0100205#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100206 asm_thumb_entry(emit->as, num_locals);
207#endif
208
209 // initialise locals from parameters
Damien3ef4abb2013-10-12 16:53:13 +0100210#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100211 for (int i = 0; i < scope->num_params; i++) {
212 if (i == 0) {
213 asm_x64_mov_r64_to_r64(emit->as, REG_ARG_1, REG_LOCAL_1);
214 } else if (i == 1) {
215 asm_x64_mov_r64_to_local(emit->as, REG_ARG_2, i - 1);
216 } else if (i == 2) {
217 asm_x64_mov_r64_to_local(emit->as, REG_ARG_3, i - 1);
218 } else {
219 // TODO not implemented
220 assert(0);
221 }
222 }
Damien3ef4abb2013-10-12 16:53:13 +0100223#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100224 for (int i = 0; i < scope->num_params; i++) {
225 if (i == 0) {
226 asm_thumb_mov_reg_reg(emit->as, REG_LOCAL_1, REG_ARG_1);
227 } else if (i == 1) {
228 asm_thumb_mov_reg_reg(emit->as, REG_LOCAL_2, REG_ARG_2);
229 } else if (i == 2) {
230 asm_thumb_mov_reg_reg(emit->as, REG_LOCAL_3, REG_ARG_3);
231 } else if (i == 3) {
232 asm_thumb_mov_local_reg(emit->as, i - REG_LOCAL_NUM, REG_ARG_4);
233 } else {
234 // TODO not implemented
235 assert(0);
236 }
237 }
238
239 asm_thumb_mov_reg_i32(emit->as, REG_R7, (machine_uint_t)rt_fun_table);
240#endif
241}
242
243static void emit_native_end_pass(emit_t *emit) {
Damien3ef4abb2013-10-12 16:53:13 +0100244#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100245 if (!emit->last_emit_was_return_value) {
246 asm_x64_exit(emit->as);
247 }
248 asm_x64_end_pass(emit->as);
Damien3ef4abb2013-10-12 16:53:13 +0100249#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100250 if (!emit->last_emit_was_return_value) {
251 asm_thumb_exit(emit->as);
252 }
253 asm_thumb_end_pass(emit->as);
254#endif
255
256 // check stack is back to zero size
257 if (emit->stack_size != 0) {
258 printf("ERROR: stack size not back to zero; got %d\n", emit->stack_size);
259 }
260
261 if (emit->pass == PASS_3) {
Damien3ef4abb2013-10-12 16:53:13 +0100262#if N_X64
Damiend99b0522013-12-21 18:17:45 +0000263 void *f = asm_x64_get_code(emit->as);
Damien13ed3a62013-10-08 09:05:10 +0100264 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 +0100265#elif N_THUMB
Damiend99b0522013-12-21 18:17:45 +0000266 void *f = asm_thumb_get_code(emit->as);
Damien13ed3a62013-10-08 09:05:10 +0100267 rt_assign_native_code(emit->scope->unique_code_id, f, asm_thumb_get_code_size(emit->as), emit->scope->num_params);
268#endif
269 }
270}
271
272static bool emit_native_last_emit_was_return_value(emit_t *emit) {
273 return emit->last_emit_was_return_value;
274}
275
276static int emit_native_get_stack_size(emit_t *emit) {
277 return emit->stack_size;
278}
279
280static void emit_native_set_stack_size(emit_t *emit, int size) {
281 emit->stack_size = size;
282}
283
284static void adjust_stack(emit_t *emit, int stack_size_delta) {
285 emit->stack_size += stack_size_delta;
286 assert(emit->stack_size >= 0);
287 if (emit->pass > PASS_1 && emit->stack_size > emit->scope->stack_size) {
288 emit->scope->stack_size = emit->stack_size;
289 }
290}
291
Damienff8ed772013-10-08 22:18:32 +0100292/*
Damien13ed3a62013-10-08 09:05:10 +0100293static void emit_pre_raw(emit_t *emit, int stack_size_delta) {
294 adjust_stack(emit, stack_size_delta);
295 emit->last_emit_was_return_value = false;
296}
Damienff8ed772013-10-08 22:18:32 +0100297*/
Damien13ed3a62013-10-08 09:05:10 +0100298
Damienff8ed772013-10-08 22:18:32 +0100299// this must be called at start of emit functions
Damien13ed3a62013-10-08 09:05:10 +0100300static void emit_pre(emit_t *emit) {
Damienff8ed772013-10-08 22:18:32 +0100301 emit->last_emit_was_return_value = false;
302 // settle the stack
303 /*
304 if (regs_needed != 0) {
305 for (int i = 0; i < emit->stack_size; i++) {
306 switch (emit->stack_info[i].kind) {
307 case STACK_VALUE:
308 break;
309
310 case STACK_REG:
311 // TODO only push reg if in regs_needed
312 emit->stack_info[i].kind = STACK_VALUE;
313 ASM_MOV_REG_TO_LOCAL(emit->stack_info[i].u_reg, emit->stack_start + i);
314 break;
315
316 case STACK_IMM:
317 // don't think we ever need to push imms for settling
318 //ASM_MOV_IMM_TO_LOCAL(emit->last_imm, emit->stack_start + i);
319 break;
320 }
321 }
322 }
323 */
Damien13ed3a62013-10-08 09:05:10 +0100324}
325
326static vtype_kind_t peek_vtype(emit_t *emit) {
Damienff8ed772013-10-08 22:18:32 +0100327 return emit->stack_info[emit->stack_size - 1].vtype;
328}
Damien13ed3a62013-10-08 09:05:10 +0100329
Damiend2755ec2013-10-16 23:58:48 +0100330// pos=1 is TOS, pos=2 is next, etc
331// use pos=0 for no skipping
332static void need_reg_single(emit_t *emit, int reg_needed, int skip_stack_pos) {
333 skip_stack_pos = emit->stack_size - skip_stack_pos;
Damienff8ed772013-10-08 22:18:32 +0100334 for (int i = 0; i < emit->stack_size; i++) {
Damiend2755ec2013-10-16 23:58:48 +0100335 if (i != skip_stack_pos) {
336 stack_info_t *si = &emit->stack_info[i];
337 if (si->kind == STACK_REG && si->u_reg == reg_needed) {
338 si->kind = STACK_VALUE;
339 ASM_MOV_REG_TO_LOCAL(si->u_reg, emit->stack_start + i);
340 }
Damienff8ed772013-10-08 22:18:32 +0100341 }
342 }
343}
Damien13ed3a62013-10-08 09:05:10 +0100344
Damieneb19efb2013-10-10 22:06:54 +0100345static void need_reg_all(emit_t *emit) {
Damienff8ed772013-10-08 22:18:32 +0100346 for (int i = 0; i < emit->stack_size; i++) {
347 stack_info_t *si = &emit->stack_info[i];
348 if (si->kind == STACK_REG) {
349 si->kind = STACK_VALUE;
350 ASM_MOV_REG_TO_LOCAL(si->u_reg, emit->stack_start + i);
351 }
Damien13ed3a62013-10-08 09:05:10 +0100352 }
353}
354
Damiend2755ec2013-10-16 23:58:48 +0100355static void need_stack_settled(emit_t *emit) {
356 for (int i = 0; i < emit->stack_size; i++) {
357 stack_info_t *si = &emit->stack_info[i];
358 if (si->kind == STACK_REG) {
359 si->kind = STACK_VALUE;
360 ASM_MOV_REG_TO_LOCAL(si->u_reg, emit->stack_start + i);
361 }
362 }
363 for (int i = 0; i < emit->stack_size; i++) {
364 stack_info_t *si = &emit->stack_info[i];
365 if (si->kind == STACK_IMM) {
366 ASM_MOV_IMM_TO_LOCAL_USING(si->u_imm, emit->stack_start + i, REG_TEMP0);
367 }
368 }
369}
370
371// pos=1 is TOS, pos=2 is next, etc
372static void emit_access_stack(emit_t *emit, int pos, vtype_kind_t *vtype, int reg_dest) {
373 need_reg_single(emit, reg_dest, pos);
374 stack_info_t *si = &emit->stack_info[emit->stack_size - pos];
Damienff8ed772013-10-08 22:18:32 +0100375 *vtype = si->vtype;
376 switch (si->kind) {
377 case STACK_VALUE:
Damiend2755ec2013-10-16 23:58:48 +0100378 ASM_MOV_LOCAL_TO_REG(emit->stack_start + emit->stack_size - pos, reg_dest);
Damien13ed3a62013-10-08 09:05:10 +0100379 break;
380
Damienff8ed772013-10-08 22:18:32 +0100381 case STACK_REG:
382 if (si->u_reg != reg_dest) {
383 ASM_MOV_REG_TO_REG(si->u_reg, reg_dest);
Damien13ed3a62013-10-08 09:05:10 +0100384 }
385 break;
386
Damienff8ed772013-10-08 22:18:32 +0100387 case STACK_IMM:
388 ASM_MOV_IMM_TO_REG(si->u_imm, reg_dest);
Damien13ed3a62013-10-08 09:05:10 +0100389 break;
390 }
Damien13ed3a62013-10-08 09:05:10 +0100391}
392
Damiend2755ec2013-10-16 23:58:48 +0100393static void emit_pre_pop_reg(emit_t *emit, vtype_kind_t *vtype, int reg_dest) {
394 emit->last_emit_was_return_value = false;
395 emit_access_stack(emit, 1, vtype, reg_dest);
396 adjust_stack(emit, -1);
397}
398
Damien13ed3a62013-10-08 09:05:10 +0100399static void emit_pre_pop_reg_reg(emit_t *emit, vtype_kind_t *vtypea, int rega, vtype_kind_t *vtypeb, int regb) {
400 emit_pre_pop_reg(emit, vtypea, rega);
Damienff8ed772013-10-08 22:18:32 +0100401 emit_pre_pop_reg(emit, vtypeb, regb);
Damien13ed3a62013-10-08 09:05:10 +0100402}
403
404static 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) {
405 emit_pre_pop_reg(emit, vtypea, rega);
Damienff8ed772013-10-08 22:18:32 +0100406 emit_pre_pop_reg(emit, vtypeb, regb);
407 emit_pre_pop_reg(emit, vtypec, regc);
Damien13ed3a62013-10-08 09:05:10 +0100408}
409
410static void emit_post(emit_t *emit) {
411}
412
413static void emit_post_push_reg(emit_t *emit, vtype_kind_t vtype, int reg) {
Damienff8ed772013-10-08 22:18:32 +0100414 stack_info_t *si = &emit->stack_info[emit->stack_size];
415 si->vtype = vtype;
416 si->kind = STACK_REG;
417 si->u_reg = reg;
Damien13ed3a62013-10-08 09:05:10 +0100418 adjust_stack(emit, 1);
419}
420
Damienff8ed772013-10-08 22:18:32 +0100421static void emit_post_push_imm(emit_t *emit, vtype_kind_t vtype, machine_int_t imm) {
422 stack_info_t *si = &emit->stack_info[emit->stack_size];
423 si->vtype = vtype;
424 si->kind = STACK_IMM;
425 si->u_imm = imm;
426 adjust_stack(emit, 1);
427}
428
429static void emit_post_push_reg_reg(emit_t *emit, vtype_kind_t vtypea, int rega, vtype_kind_t vtypeb, int regb) {
430 emit_post_push_reg(emit, vtypea, rega);
431 emit_post_push_reg(emit, vtypeb, regb);
432}
433
Damien13ed3a62013-10-08 09:05:10 +0100434static 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 +0100435 emit_post_push_reg(emit, vtypea, rega);
436 emit_post_push_reg(emit, vtypeb, regb);
437 emit_post_push_reg(emit, vtypec, regc);
Damien13ed3a62013-10-08 09:05:10 +0100438}
439
440static 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 +0100441 emit_post_push_reg(emit, vtypea, rega);
442 emit_post_push_reg(emit, vtypeb, regb);
443 emit_post_push_reg(emit, vtypec, regc);
444 emit_post_push_reg(emit, vtyped, regd);
Damien13ed3a62013-10-08 09:05:10 +0100445}
446
447// vtype of all n_pop objects is VTYPE_PYOBJ
Damieneb19efb2013-10-10 22:06:54 +0100448// does not use any temporary registers (but may use reg_dest before loading it with stack pointer)
Damien6d4f3462013-11-16 20:44:39 +0000449// TODO this needs some thinking for viper code
Damien13ed3a62013-10-08 09:05:10 +0100450static void emit_get_stack_pointer_to_reg_for_pop(emit_t *emit, int reg_dest, int n_pop) {
Damieneb19efb2013-10-10 22:06:54 +0100451 need_reg_all(emit);
Damienff8ed772013-10-08 22:18:32 +0100452 for (int i = 0; i < n_pop; i++) {
Damieneb19efb2013-10-10 22:06:54 +0100453 stack_info_t *si = &emit->stack_info[emit->stack_size - 1 - i];
454 // must push any imm's to stack
Damien6d4f3462013-11-16 20:44:39 +0000455 // must convert them to VTYPE_PYOBJ for viper code
Damieneb19efb2013-10-10 22:06:54 +0100456 if (si->kind == STACK_IMM) {
457 si->kind = STACK_VALUE;
Damien6d4f3462013-11-16 20:44:39 +0000458 switch (si->vtype) {
459 case VTYPE_PYOBJ:
460 ASM_MOV_IMM_TO_LOCAL_USING(si->u_imm, emit->stack_start + emit->stack_size - 1 - i, reg_dest);
461 break;
462 case VTYPE_BOOL:
463 si->vtype = VTYPE_PYOBJ;
464 if (si->u_imm == 0) {
Damiend99b0522013-12-21 18:17:45 +0000465 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 +0000466 } else {
Damiend99b0522013-12-21 18:17:45 +0000467 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 +0000468 }
469 break;
470 case VTYPE_INT:
471 si->vtype = VTYPE_PYOBJ;
472 ASM_MOV_IMM_TO_LOCAL_USING((si->u_imm << 1) | 1, emit->stack_start + emit->stack_size - 1 - i, reg_dest);
473 break;
474 default:
475 // not handled
476 assert(0);
477 }
Damieneb19efb2013-10-10 22:06:54 +0100478 }
479 assert(si->kind == STACK_VALUE);
480 assert(si->vtype == VTYPE_PYOBJ);
Damienff8ed772013-10-08 22:18:32 +0100481 }
Damien13ed3a62013-10-08 09:05:10 +0100482 ASM_MOV_LOCAL_ADDR_TO_REG(emit->stack_start + emit->stack_size - 1, reg_dest);
483 adjust_stack(emit, -n_pop);
484}
485
486// vtype of all n_push objects is VTYPE_PYOBJ
487static void emit_get_stack_pointer_to_reg_for_push(emit_t *emit, int reg_dest, int n_push) {
Damieneb19efb2013-10-10 22:06:54 +0100488 need_reg_all(emit);
Damien13ed3a62013-10-08 09:05:10 +0100489 for (int i = 0; i < n_push; i++) {
Damien7f5dacf2013-10-10 11:24:39 +0100490 emit->stack_info[emit->stack_size + i].kind = STACK_VALUE;
Damienff8ed772013-10-08 22:18:32 +0100491 emit->stack_info[emit->stack_size + i].vtype = VTYPE_PYOBJ;
Damien13ed3a62013-10-08 09:05:10 +0100492 }
493 ASM_MOV_LOCAL_ADDR_TO_REG(emit->stack_start + emit->stack_size + n_push - 1, reg_dest);
494 adjust_stack(emit, n_push);
495}
496
497static void emit_call(emit_t *emit, rt_fun_kind_t fun_kind, void *fun) {
Damiend2755ec2013-10-16 23:58:48 +0100498 need_reg_all(emit);
Damien3ef4abb2013-10-12 16:53:13 +0100499#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100500 asm_x64_call_ind(emit->as, fun, REG_RAX);
Damien3ef4abb2013-10-12 16:53:13 +0100501#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100502 asm_thumb_bl_ind(emit->as, rt_fun_table[fun_kind], fun_kind, REG_R3);
503#endif
504}
505
506static 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 +0100507 need_reg_all(emit);
Damien13ed3a62013-10-08 09:05:10 +0100508 ASM_MOV_IMM_TO_REG(arg_val, arg_reg);
Damiend2755ec2013-10-16 23:58:48 +0100509#if N_X64
510 asm_x64_call_ind(emit->as, fun, REG_RAX);
511#elif N_THUMB
512 asm_thumb_bl_ind(emit->as, rt_fun_table[fun_kind], fun_kind, REG_R3);
513#endif
Damien13ed3a62013-10-08 09:05:10 +0100514}
515
516static void emit_native_load_id(emit_t *emit, qstr qstr) {
517 // check for built-ins
518 if (strcmp(qstr_str(qstr), "v_int") == 0) {
Damienff8ed772013-10-08 22:18:32 +0100519 assert(0);
Damien13ed3a62013-10-08 09:05:10 +0100520 emit_pre(emit);
521 //emit_post_push_blank(emit, VTYPE_BUILTIN_V_INT);
522
523 // not a built-in, so do usual thing
524 } else {
525 emit_common_load_id(emit, &EXPORT_FUN(method_table), emit->scope, qstr);
526 }
527}
528
529static void emit_native_store_id(emit_t *emit, qstr qstr) {
530 // TODO check for built-ins and disallow
531 emit_common_store_id(emit, &EXPORT_FUN(method_table), emit->scope, qstr);
532}
533
534static void emit_native_delete_id(emit_t *emit, qstr qstr) {
535 // TODO check for built-ins and disallow
536 emit_common_delete_id(emit, &EXPORT_FUN(method_table), emit->scope, qstr);
537}
538
539static void emit_native_label_assign(emit_t *emit, int l) {
Damien6ba13142013-11-02 20:34:54 +0000540 emit_pre(emit);
Damiend2755ec2013-10-16 23:58:48 +0100541 // need to commit stack because we can jump here from elsewhere
542 need_stack_settled(emit);
Damien3ef4abb2013-10-12 16:53:13 +0100543#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100544 asm_x64_label_assign(emit->as, l);
Damien3ef4abb2013-10-12 16:53:13 +0100545#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100546 asm_thumb_label_assign(emit->as, l);
547#endif
Damien6ba13142013-11-02 20:34:54 +0000548 emit_post(emit);
Damien13ed3a62013-10-08 09:05:10 +0100549}
550
551static void emit_native_import_name(emit_t *emit, qstr qstr) {
552 // not implemented
553 assert(0);
554}
555
556static void emit_native_import_from(emit_t *emit, qstr qstr) {
557 // not implemented
558 assert(0);
559}
560
561static void emit_native_import_star(emit_t *emit) {
562 // not implemented
563 assert(0);
564}
565
Damiend99b0522013-12-21 18:17:45 +0000566static void emit_native_load_const_tok(emit_t *emit, mp_token_kind_t tok) {
Damien13ed3a62013-10-08 09:05:10 +0100567 emit_pre(emit);
568 int vtype;
569 machine_uint_t val;
570 if (emit->do_viper_types) {
571 switch (tok) {
Damiend99b0522013-12-21 18:17:45 +0000572 case MP_TOKEN_KW_NONE: vtype = VTYPE_PTR_NONE; val = 0; break;
573 case MP_TOKEN_KW_FALSE: vtype = VTYPE_BOOL; val = 0; break;
574 case MP_TOKEN_KW_TRUE: vtype = VTYPE_BOOL; val = 1; break;
Damien13ed3a62013-10-08 09:05:10 +0100575 default: assert(0); vtype = 0; val = 0; // shouldn't happen
576 }
577 } else {
578 vtype = VTYPE_PYOBJ;
579 switch (tok) {
Damiend99b0522013-12-21 18:17:45 +0000580 case MP_TOKEN_KW_NONE: val = (machine_uint_t)mp_const_none; break;
581 case MP_TOKEN_KW_FALSE: val = (machine_uint_t)mp_const_false; break;
582 case MP_TOKEN_KW_TRUE: val = (machine_uint_t)mp_const_true; break;
Damien13ed3a62013-10-08 09:05:10 +0100583 default: assert(0); vtype = 0; val = 0; // shouldn't happen
584 }
585 }
586 emit_post_push_imm(emit, vtype, val);
587}
588
589static void emit_native_load_const_small_int(emit_t *emit, int arg) {
590 emit_pre(emit);
591 if (emit->do_viper_types) {
592 emit_post_push_imm(emit, VTYPE_INT, arg);
593 } else {
594 emit_post_push_imm(emit, VTYPE_PYOBJ, (arg << 1) | 1);
595 }
596}
597
598static void emit_native_load_const_int(emit_t *emit, qstr qstr) {
599 // not implemented
600 // load integer, check fits in 32 bits
601 assert(0);
602}
603
604static void emit_native_load_const_dec(emit_t *emit, qstr qstr) {
Damien6ba13142013-11-02 20:34:54 +0000605 // for viper, a float/complex is just a Python object
606 emit_pre(emit);
607 emit_call_with_imm_arg(emit, RT_F_LOAD_CONST_DEC, rt_load_const_dec, qstr, REG_ARG_1);
608 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
Damien13ed3a62013-10-08 09:05:10 +0100609}
610
611static void emit_native_load_const_id(emit_t *emit, qstr qstr) {
Damien7f5dacf2013-10-10 11:24:39 +0100612 emit_pre(emit);
613 if (emit->do_viper_types) {
614 assert(0);
615 } else {
616 emit_call_with_imm_arg(emit, RT_F_LOAD_CONST_STR, rt_load_const_str, qstr, REG_ARG_1); // TODO
617 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
618 }
Damien13ed3a62013-10-08 09:05:10 +0100619}
620
621static void emit_native_load_const_str(emit_t *emit, qstr qstr, bool bytes) {
622 emit_pre(emit);
623 if (emit->do_viper_types) {
624 // not implemented properly
625 // load a pointer to the asciiz string?
626 assert(0);
627 emit_post_push_imm(emit, VTYPE_PTR, (machine_uint_t)qstr_str(qstr));
628 } else {
629 emit_call_with_imm_arg(emit, RT_F_LOAD_CONST_STR, rt_load_const_str, qstr, REG_ARG_1);
630 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
631 }
632}
633
Damien13ed3a62013-10-08 09:05:10 +0100634static void emit_native_load_const_verbatim_str(emit_t *emit, const char *str) {
635 // not supported/needed for viper
636 assert(0);
637}
638
Damien13ed3a62013-10-08 09:05:10 +0100639static void emit_native_load_fast(emit_t *emit, qstr qstr, int local_num) {
640 vtype_kind_t vtype = emit->local_vtype[local_num];
641 if (vtype == VTYPE_UNBOUND) {
642 printf("ViperTypeError: local %s used before type known\n", qstr_str(qstr));
643 }
644 emit_pre(emit);
Damien3ef4abb2013-10-12 16:53:13 +0100645#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100646 if (local_num == 0) {
647 emit_post_push_reg(emit, vtype, REG_LOCAL_1);
648 } else {
Damiend2755ec2013-10-16 23:58:48 +0100649 need_reg_single(emit, REG_RAX, 0);
Damien13ed3a62013-10-08 09:05:10 +0100650 asm_x64_mov_local_to_r64(emit->as, local_num - 1, REG_RAX);
651 emit_post_push_reg(emit, vtype, REG_RAX);
652 }
Damien3ef4abb2013-10-12 16:53:13 +0100653#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100654 if (local_num == 0) {
655 emit_post_push_reg(emit, vtype, REG_LOCAL_1);
656 } else if (local_num == 1) {
657 emit_post_push_reg(emit, vtype, REG_LOCAL_2);
658 } else if (local_num == 2) {
659 emit_post_push_reg(emit, vtype, REG_LOCAL_3);
660 } else {
Damiend2755ec2013-10-16 23:58:48 +0100661 need_reg_single(emit, REG_R0, 0);
Damien13ed3a62013-10-08 09:05:10 +0100662 asm_thumb_mov_reg_local(emit->as, REG_R0, local_num - 1);
663 emit_post_push_reg(emit, vtype, REG_R0);
664 }
665#endif
666}
667
Damien9ecbcff2013-12-11 00:41:43 +0000668static void emit_native_load_deref(emit_t *emit, qstr qstr, int local_num) {
669 // not implemented
670 // in principle could support this quite easily (ldr r0, [r0, #0]) and then get closed over variables!
671 assert(0);
672}
673
674static void emit_native_load_closure(emit_t *emit, qstr qstr, int local_num) {
675 // not implemented
676 assert(0);
677}
678
Damien13ed3a62013-10-08 09:05:10 +0100679static void emit_native_load_name(emit_t *emit, qstr qstr) {
680 emit_pre(emit);
681 emit_call_with_imm_arg(emit, RT_F_LOAD_NAME, rt_load_name, qstr, REG_ARG_1);
682 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
683}
684
685static void emit_native_load_global(emit_t *emit, qstr qstr) {
686 emit_pre(emit);
687 emit_call_with_imm_arg(emit, RT_F_LOAD_GLOBAL, rt_load_global, qstr, REG_ARG_1);
688 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
689}
690
Damien13ed3a62013-10-08 09:05:10 +0100691static void emit_native_load_attr(emit_t *emit, qstr qstr) {
692 // depends on type of subject:
693 // - integer, function, pointer to integers: error
694 // - pointer to structure: get member, quite easy
695 // - Python object: call rt_load_attr, and needs to be typed to convert result
696 vtype_kind_t vtype_base;
697 emit_pre_pop_reg(emit, &vtype_base, REG_ARG_1); // arg1 = base
698 assert(vtype_base == VTYPE_PYOBJ);
699 emit_call_with_imm_arg(emit, RT_F_LOAD_ATTR, rt_load_attr, qstr, REG_ARG_2); // arg2 = attribute name
700 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
701}
702
703static void emit_native_load_method(emit_t *emit, qstr qstr) {
704 vtype_kind_t vtype_base;
705 emit_pre_pop_reg(emit, &vtype_base, REG_ARG_1); // arg1 = base
706 assert(vtype_base == VTYPE_PYOBJ);
707 emit_get_stack_pointer_to_reg_for_push(emit, REG_ARG_3, 2); // arg3 = dest ptr
708 emit_call_with_imm_arg(emit, RT_F_LOAD_METHOD, rt_load_method, qstr, REG_ARG_2); // arg2 = method name
709}
710
711static void emit_native_load_build_class(emit_t *emit) {
Damien7f5dacf2013-10-10 11:24:39 +0100712 emit_pre(emit);
713 emit_call(emit, RT_F_LOAD_BUILD_CLASS, rt_load_build_class);
714 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
Damien13ed3a62013-10-08 09:05:10 +0100715}
716
717static void emit_native_store_fast(emit_t *emit, qstr qstr, int local_num) {
718 vtype_kind_t vtype;
Damien3ef4abb2013-10-12 16:53:13 +0100719#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100720 if (local_num == 0) {
721 emit_pre_pop_reg(emit, &vtype, REG_LOCAL_1);
722 } else {
723 emit_pre_pop_reg(emit, &vtype, REG_RAX);
724 asm_x64_mov_r64_to_local(emit->as, REG_RAX, local_num - 1);
725 }
Damien3ef4abb2013-10-12 16:53:13 +0100726#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100727 if (local_num == 0) {
728 emit_pre_pop_reg(emit, &vtype, REG_LOCAL_1);
729 } else if (local_num == 1) {
730 emit_pre_pop_reg(emit, &vtype, REG_LOCAL_2);
731 } else if (local_num == 2) {
732 emit_pre_pop_reg(emit, &vtype, REG_LOCAL_3);
733 } else {
734 emit_pre_pop_reg(emit, &vtype, REG_R0);
735 asm_thumb_mov_local_reg(emit->as, local_num - 1, REG_R0);
736 }
737#endif
738
739 emit_post(emit);
740
741 // check types
742 if (emit->local_vtype[local_num] == VTYPE_UNBOUND) {
743 // first time this local is assigned, so give it a type of the object stored in it
744 emit->local_vtype[local_num] = vtype;
745 } else if (emit->local_vtype[local_num] != vtype) {
746 // type of local is not the same as object stored in it
747 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);
748 }
749}
750
Damien9ecbcff2013-12-11 00:41:43 +0000751static void emit_native_store_deref(emit_t *emit, qstr qstr, int local_num) {
752 // not implemented
753 assert(0);
754}
755
Damien13ed3a62013-10-08 09:05:10 +0100756static void emit_native_store_name(emit_t *emit, qstr qstr) {
757 // rt_store_name, but needs conversion of object (maybe have rt_viper_store_name(obj, type))
758 vtype_kind_t vtype;
759 emit_pre_pop_reg(emit, &vtype, REG_ARG_2);
760 assert(vtype == VTYPE_PYOBJ);
761 emit_call_with_imm_arg(emit, RT_F_STORE_NAME, rt_store_name, qstr, REG_ARG_1); // arg1 = name
762 emit_post(emit);
763}
764
765static void emit_native_store_global(emit_t *emit, qstr qstr) {
766 // not implemented
767 assert(0);
768}
769
Damien13ed3a62013-10-08 09:05:10 +0100770static void emit_native_store_attr(emit_t *emit, qstr qstr) {
Damien7f5dacf2013-10-10 11:24:39 +0100771 vtype_kind_t vtype_base, vtype_val;
772 emit_pre_pop_reg_reg(emit, &vtype_base, REG_ARG_1, &vtype_val, REG_ARG_3); // arg1 = base, arg3 = value
773 assert(vtype_base == VTYPE_PYOBJ);
774 assert(vtype_val == VTYPE_PYOBJ);
775 emit_call_with_imm_arg(emit, RT_F_STORE_ATTR, rt_store_attr, qstr, REG_ARG_2); // arg2 = attribute name
776 emit_post(emit);
Damien13ed3a62013-10-08 09:05:10 +0100777}
778
Damien13ed3a62013-10-08 09:05:10 +0100779static void emit_native_store_subscr(emit_t *emit) {
780 // depends on type of subject:
781 // - integer, function, pointer to structure: error
782 // - pointer to integers: store as per array
783 // - Python object: call runtime with converted object or type info
784 vtype_kind_t vtype_index, vtype_base, vtype_value;
785 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
786 assert(vtype_index == VTYPE_PYOBJ);
787 assert(vtype_base == VTYPE_PYOBJ);
788 assert(vtype_value == VTYPE_PYOBJ);
789 emit_call(emit, RT_F_STORE_SUBSCR, rt_store_subscr);
790}
791
Damiena3977762013-10-09 23:10:10 +0100792static void emit_native_store_locals(emit_t *emit) {
793 // not needed
794 vtype_kind_t vtype;
795 emit_pre_pop_reg(emit, &vtype, REG_TEMP0);
796 emit_post(emit);
797}
798
Damien13ed3a62013-10-08 09:05:10 +0100799static void emit_native_delete_fast(emit_t *emit, qstr qstr, int local_num) {
800 // not implemented
801 // could support for Python types, just set to None (so GC can reclaim it)
802 assert(0);
803}
804
Damien9ecbcff2013-12-11 00:41:43 +0000805static void emit_native_delete_deref(emit_t *emit, qstr qstr, int local_num) {
806 // not supported
807 assert(0);
808}
809
Damien13ed3a62013-10-08 09:05:10 +0100810static void emit_native_delete_name(emit_t *emit, qstr qstr) {
811 // not implemented
812 // use rt_delete_name
813 assert(0);
814}
815
816static void emit_native_delete_global(emit_t *emit, qstr qstr) {
817 // not implemented
818 // use rt_delete_global
819 assert(0);
820}
821
Damien13ed3a62013-10-08 09:05:10 +0100822static void emit_native_delete_attr(emit_t *emit, qstr qstr) {
823 // not supported
824 assert(0);
825}
826
827static void emit_native_delete_subscr(emit_t *emit) {
828 // not supported
829 assert(0);
830}
831
832static void emit_native_dup_top(emit_t *emit) {
833 vtype_kind_t vtype;
834 emit_pre_pop_reg(emit, &vtype, REG_TEMP0);
835 emit_post_push_reg_reg(emit, vtype, REG_TEMP0, vtype, REG_TEMP0);
836}
837
838static void emit_native_dup_top_two(emit_t *emit) {
839 vtype_kind_t vtype0, vtype1;
840 emit_pre_pop_reg_reg(emit, &vtype0, REG_TEMP0, &vtype1, REG_TEMP1);
841 emit_post_push_reg_reg_reg_reg(emit, vtype1, REG_TEMP1, vtype0, REG_TEMP0, vtype1, REG_TEMP1, vtype0, REG_TEMP0);
842}
843
844static void emit_native_pop_top(emit_t *emit) {
845 vtype_kind_t vtype;
846 emit_pre_pop_reg(emit, &vtype, REG_TEMP0);
847 emit_post(emit);
848}
849
850static void emit_native_rot_two(emit_t *emit) {
Damienff8ed772013-10-08 22:18:32 +0100851 vtype_kind_t vtype0, vtype1;
852 emit_pre_pop_reg_reg(emit, &vtype0, REG_TEMP0, &vtype1, REG_TEMP1);
853 emit_post_push_reg_reg(emit, vtype0, REG_TEMP0, vtype1, REG_TEMP1);
Damien13ed3a62013-10-08 09:05:10 +0100854}
855
856static void emit_native_rot_three(emit_t *emit) {
857 vtype_kind_t vtype0, vtype1, vtype2;
858 emit_pre_pop_reg_reg_reg(emit, &vtype0, REG_TEMP0, &vtype1, REG_TEMP1, &vtype2, REG_TEMP2);
859 emit_post_push_reg_reg_reg(emit, vtype0, REG_TEMP0, vtype2, REG_TEMP2, vtype1, REG_TEMP1);
860}
861
862static void emit_native_jump(emit_t *emit, int label) {
863 emit_pre(emit);
Damien3ef4abb2013-10-12 16:53:13 +0100864#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100865 asm_x64_jmp_label(emit->as, label);
Damien3ef4abb2013-10-12 16:53:13 +0100866#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100867 asm_thumb_b_label(emit->as, label);
868#endif
869 emit_post(emit);
870}
871
Damien1a6633a2013-11-03 13:58:19 +0000872static void emit_native_pop_jump_pre_helper(emit_t *emit, int label) {
Damien13ed3a62013-10-08 09:05:10 +0100873 vtype_kind_t vtype = peek_vtype(emit);
874 if (vtype == VTYPE_BOOL) {
875 emit_pre_pop_reg(emit, &vtype, REG_RET);
876 } else if (vtype == VTYPE_PYOBJ) {
877 emit_pre_pop_reg(emit, &vtype, REG_ARG_1);
878 emit_call(emit, RT_F_IS_TRUE, rt_is_true);
879 } else {
880 printf("ViperTypeError: expecting a bool or pyobj, got %d\n", vtype);
881 assert(0);
882 }
Damien1a6633a2013-11-03 13:58:19 +0000883}
884
885static void emit_native_pop_jump_if_false(emit_t *emit, int label) {
886 emit_native_pop_jump_pre_helper(emit, label);
Damien3ef4abb2013-10-12 16:53:13 +0100887#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100888 asm_x64_test_r8_with_r8(emit->as, REG_RET, REG_RET);
889 asm_x64_jcc_label(emit->as, JCC_JZ, label);
Damien3ef4abb2013-10-12 16:53:13 +0100890#elif N_THUMB
Damien1a6633a2013-11-03 13:58:19 +0000891 asm_thumb_cmp_rlo_i8(emit->as, REG_RET, 0);
892 asm_thumb_bcc_label(emit->as, THUMB_CC_EQ, label);
Damien13ed3a62013-10-08 09:05:10 +0100893#endif
894 emit_post(emit);
895}
896
897static void emit_native_pop_jump_if_true(emit_t *emit, int label) {
Damien1a6633a2013-11-03 13:58:19 +0000898 emit_native_pop_jump_pre_helper(emit, label);
899#if N_X64
900 asm_x64_test_r8_with_r8(emit->as, REG_RET, REG_RET);
901 asm_x64_jcc_label(emit->as, JCC_JNZ, label);
902#elif N_THUMB
903 asm_thumb_cmp_rlo_i8(emit->as, REG_RET, 0);
904 asm_thumb_bcc_label(emit->as, THUMB_CC_NE, label);
905#endif
906 emit_post(emit);
Damien13ed3a62013-10-08 09:05:10 +0100907}
Damien1a6633a2013-11-03 13:58:19 +0000908
Damien13ed3a62013-10-08 09:05:10 +0100909static void emit_native_jump_if_true_or_pop(emit_t *emit, int label) {
910 assert(0);
911}
912static void emit_native_jump_if_false_or_pop(emit_t *emit, int label) {
913 assert(0);
914}
915
916static void emit_native_setup_loop(emit_t *emit, int label) {
917 emit_pre(emit);
918 emit_post(emit);
919}
920
921static void emit_native_break_loop(emit_t *emit, int label) {
Damien6ba13142013-11-02 20:34:54 +0000922 emit_native_jump(emit, label); // TODO properly
Damien13ed3a62013-10-08 09:05:10 +0100923}
924static void emit_native_continue_loop(emit_t *emit, int label) {
925 assert(0);
926}
927static void emit_native_setup_with(emit_t *emit, int label) {
928 // not supported, or could be with runtime call
929 assert(0);
930}
931static void emit_native_with_cleanup(emit_t *emit) {
932 assert(0);
933}
934static void emit_native_setup_except(emit_t *emit, int label) {
935 assert(0);
936}
937static void emit_native_setup_finally(emit_t *emit, int label) {
938 assert(0);
939}
940static void emit_native_end_finally(emit_t *emit) {
941 assert(0);
942}
Damiend2755ec2013-10-16 23:58:48 +0100943
Damien13ed3a62013-10-08 09:05:10 +0100944static void emit_native_get_iter(emit_t *emit) {
945 // perhaps the difficult one, as we want to rewrite for loops using native code
946 // in cases where we iterate over a Python object, can we use normal runtime calls?
Damiend2755ec2013-10-16 23:58:48 +0100947
948 vtype_kind_t vtype;
949 emit_pre_pop_reg(emit, &vtype, REG_ARG_1);
950 assert(vtype == VTYPE_PYOBJ);
951 emit_call(emit, RT_F_GETITER, rt_getiter);
952 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
Damien13ed3a62013-10-08 09:05:10 +0100953}
Damiend2755ec2013-10-16 23:58:48 +0100954
955static void emit_native_for_iter(emit_t *emit, int label) {
956 emit_pre(emit);
957 vtype_kind_t vtype;
958 emit_access_stack(emit, 1, &vtype, REG_ARG_1);
959 assert(vtype == VTYPE_PYOBJ);
960 emit_call(emit, RT_F_ITERNEXT, rt_iternext);
Damiend99b0522013-12-21 18:17:45 +0000961 ASM_MOV_IMM_TO_REG((machine_uint_t)mp_const_stop_iteration, REG_TEMP1);
Damiend2755ec2013-10-16 23:58:48 +0100962#if N_X64
963 asm_x64_cmp_r64_with_r64(emit->as, REG_RET, REG_TEMP1);
964 asm_x64_jcc_label(emit->as, JCC_JE, label);
965#elif N_THUMB
Damiend2755ec2013-10-16 23:58:48 +0100966 asm_thumb_cmp_reg_reg(emit->as, REG_RET, REG_TEMP1);
Damien9b9e9962013-11-03 14:25:43 +0000967 asm_thumb_bcc_label(emit->as, THUMB_CC_EQ, label);
Damiend2755ec2013-10-16 23:58:48 +0100968#endif
969 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
970}
971
Damien13ed3a62013-10-08 09:05:10 +0100972static void emit_native_for_iter_end(emit_t *emit) {
Damiend2755ec2013-10-16 23:58:48 +0100973 // adjust stack counter (we get here from for_iter ending, which popped the value for us)
974 emit_pre(emit);
975 adjust_stack(emit, -1);
976 emit_post(emit);
Damien13ed3a62013-10-08 09:05:10 +0100977}
978
979static void emit_native_pop_block(emit_t *emit) {
980 emit_pre(emit);
981 emit_post(emit);
982}
983
984static void emit_native_pop_except(emit_t *emit) {
985 assert(0);
986}
987
988static void emit_native_unary_op(emit_t *emit, rt_unary_op_t op) {
989 vtype_kind_t vtype;
990 emit_pre_pop_reg(emit, &vtype, REG_ARG_2);
991 assert(vtype == VTYPE_PYOBJ);
992 emit_call_with_imm_arg(emit, RT_F_UNARY_OP, rt_unary_op, op, REG_ARG_1);
993 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
994}
995
996static void emit_native_binary_op(emit_t *emit, rt_binary_op_t op) {
997 vtype_kind_t vtype_lhs, vtype_rhs;
998 emit_pre_pop_reg_reg(emit, &vtype_rhs, REG_ARG_3, &vtype_lhs, REG_ARG_2);
999 if (vtype_lhs == VTYPE_INT && vtype_rhs == VTYPE_INT) {
Damien Georgebc1d3692014-01-11 09:47:06 +00001000 if (op == RT_BINARY_OP_ADD || op == RT_BINARY_OP_INPLACE_ADD) {
Damien3ef4abb2013-10-12 16:53:13 +01001001#if N_X64
Damien Georgebc1d3692014-01-11 09:47:06 +00001002 asm_x64_add_r64_to_r64(emit->as, REG_ARG_3, REG_ARG_2);
Damien3ef4abb2013-10-12 16:53:13 +01001003#elif N_THUMB
Damien Georgebc1d3692014-01-11 09:47:06 +00001004 asm_thumb_add_reg_reg_reg(emit->as, REG_ARG_2, REG_ARG_2, REG_ARG_3);
Damien13ed3a62013-10-08 09:05:10 +01001005#endif
Damien Georgebc1d3692014-01-11 09:47:06 +00001006 emit_post_push_reg(emit, VTYPE_INT, REG_ARG_2);
1007 } else if (op == RT_COMPARE_OP_LESS) {
1008#if N_X64
1009 asm_x64_xor_r64_to_r64(emit->as, REG_RET, REG_RET);
1010 asm_x64_cmp_r64_with_r64(emit->as, REG_ARG_3, REG_ARG_2);
1011 asm_x64_setcc_r8(emit->as, JCC_JL, REG_RET);
1012#elif N_THUMB
1013 asm_thumb_cmp_reg_reg(emit->as, REG_ARG_2, REG_ARG_3);
1014 asm_thumb_ite_ge(emit->as);
1015 asm_thumb_movs_rlo_i8(emit->as, REG_RET, 0); // if r0 >= r1
1016 asm_thumb_movs_rlo_i8(emit->as, REG_RET, 1); // if r0 < r1
1017#endif
1018 emit_post_push_reg(emit, VTYPE_BOOL, REG_RET);
1019 } else {
1020 // TODO other ops not yet implemented
1021 assert(0);
1022 }
Damien13ed3a62013-10-08 09:05:10 +01001023 } else if (vtype_lhs == VTYPE_PYOBJ && vtype_rhs == VTYPE_PYOBJ) {
1024 emit_call_with_imm_arg(emit, RT_F_BINARY_OP, rt_binary_op, op, REG_ARG_1);
1025 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
1026 } else {
1027 printf("ViperTypeError: can't do binary op between types %d and %d\n", vtype_lhs, vtype_rhs);
1028 assert(0);
1029 }
1030}
1031
Damien13ed3a62013-10-08 09:05:10 +01001032static void emit_native_build_tuple(emit_t *emit, int n_args) {
Damiend2755ec2013-10-16 23:58:48 +01001033 // for viper: call runtime, with types of args
1034 // if wrapped in byte_array, or something, allocates memory and fills it
1035 emit_pre(emit);
1036 emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, n_args); // pointer to items in reverse order
1037 emit_call_with_imm_arg(emit, RT_F_BUILD_TUPLE, rt_build_tuple, n_args, REG_ARG_1);
1038 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new tuple
Damien13ed3a62013-10-08 09:05:10 +01001039}
1040
1041static void emit_native_build_list(emit_t *emit, int n_args) {
1042 emit_pre(emit);
1043 emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, n_args); // pointer to items in reverse order
1044 emit_call_with_imm_arg(emit, RT_F_BUILD_LIST, rt_build_list, n_args, REG_ARG_1);
1045 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new list
1046}
1047
1048static void emit_native_list_append(emit_t *emit, int list_index) {
Damiend2755ec2013-10-16 23:58:48 +01001049 // only used in list comprehension
1050 vtype_kind_t vtype_list, vtype_item;
1051 emit_pre_pop_reg(emit, &vtype_item, REG_ARG_2);
1052 emit_access_stack(emit, list_index, &vtype_list, REG_ARG_1);
1053 assert(vtype_list == VTYPE_PYOBJ);
1054 assert(vtype_item == VTYPE_PYOBJ);
1055 emit_call(emit, RT_F_LIST_APPEND, rt_list_append);
1056 emit_post(emit);
Damien13ed3a62013-10-08 09:05:10 +01001057}
1058
1059static void emit_native_build_map(emit_t *emit, int n_args) {
1060 emit_pre(emit);
1061 emit_call_with_imm_arg(emit, RT_F_BUILD_MAP, rt_build_map, n_args, REG_ARG_1);
1062 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new map
1063}
1064
1065static void emit_native_store_map(emit_t *emit) {
1066 vtype_kind_t vtype_key, vtype_value, vtype_map;
1067 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
1068 assert(vtype_key == VTYPE_PYOBJ);
1069 assert(vtype_value == VTYPE_PYOBJ);
1070 assert(vtype_map == VTYPE_PYOBJ);
1071 emit_call(emit, RT_F_STORE_MAP, rt_store_map);
1072 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // map
1073}
1074
1075static void emit_native_map_add(emit_t *emit, int map_index) {
Damiend2755ec2013-10-16 23:58:48 +01001076 // only used in list comprehension
1077 vtype_kind_t vtype_map, vtype_key, vtype_value;
1078 emit_pre_pop_reg_reg(emit, &vtype_key, REG_ARG_2, &vtype_value, REG_ARG_3);
1079 emit_access_stack(emit, map_index, &vtype_map, REG_ARG_1);
1080 assert(vtype_map == VTYPE_PYOBJ);
1081 assert(vtype_key == VTYPE_PYOBJ);
1082 assert(vtype_value == VTYPE_PYOBJ);
1083 emit_call(emit, RT_F_STORE_MAP, rt_store_map);
1084 emit_post(emit);
Damien13ed3a62013-10-08 09:05:10 +01001085}
1086
1087static void emit_native_build_set(emit_t *emit, int n_args) {
1088 emit_pre(emit);
1089 emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, n_args); // pointer to items in reverse order
1090 emit_call_with_imm_arg(emit, RT_F_BUILD_SET, rt_build_set, n_args, REG_ARG_1);
1091 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new set
1092}
1093
1094static void emit_native_set_add(emit_t *emit, int set_index) {
Damiend2755ec2013-10-16 23:58:48 +01001095 // only used in set comprehension
1096 vtype_kind_t vtype_set, vtype_item;
1097 emit_pre_pop_reg(emit, &vtype_item, REG_ARG_2);
1098 emit_access_stack(emit, set_index, &vtype_set, REG_ARG_1);
1099 assert(vtype_set == VTYPE_PYOBJ);
1100 assert(vtype_item == VTYPE_PYOBJ);
1101 emit_call(emit, RT_F_STORE_SET, rt_store_set);
1102 emit_post(emit);
Damien13ed3a62013-10-08 09:05:10 +01001103}
Damiend2755ec2013-10-16 23:58:48 +01001104
Damien13ed3a62013-10-08 09:05:10 +01001105static void emit_native_build_slice(emit_t *emit, int n_args) {
1106 assert(0);
1107}
1108static void emit_native_unpack_sequence(emit_t *emit, int n_args) {
1109 // call runtime, needs type decl
1110 assert(0);
1111}
1112static void emit_native_unpack_ex(emit_t *emit, int n_left, int n_right) {
1113 assert(0);
1114}
1115
1116static void emit_native_make_function(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) {
1117 // call runtime, with type info for args, or don't support dict/default params, or only support Python objects for them
1118 assert(n_default_params == 0 && n_dict_params == 0);
1119 emit_pre(emit);
1120 emit_call_with_imm_arg(emit, RT_F_MAKE_FUNCTION_FROM_ID, rt_make_function_from_id, scope->unique_code_id, REG_ARG_1);
1121 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
1122}
1123
1124static void emit_native_make_closure(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) {
1125 assert(0);
1126}
1127
1128static void emit_native_call_function(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) {
1129 // call special viper runtime routine with type info for args, and wanted type info for return
1130 assert(n_keyword == 0 && !have_star_arg && !have_dbl_star_arg);
Damieneb19efb2013-10-10 22:06:54 +01001131 /*
Damien13ed3a62013-10-08 09:05:10 +01001132 if (n_positional == 0) {
1133 vtype_kind_t vtype_fun;
1134 emit_pre_pop_reg(emit, &vtype_fun, REG_ARG_1); // the function
1135 assert(vtype_fun == VTYPE_PYOBJ);
1136 emit_call(emit, RT_F_CALL_FUNCTION_0, rt_call_function_0);
1137 } else if (n_positional == 1) {
1138 vtype_kind_t vtype_fun, vtype_arg1;
1139 emit_pre_pop_reg_reg(emit, &vtype_arg1, REG_ARG_2, &vtype_fun, REG_ARG_1); // the single argument, the function
1140 assert(vtype_fun == VTYPE_PYOBJ);
1141 assert(vtype_arg1 == VTYPE_PYOBJ);
1142 emit_call(emit, RT_F_CALL_FUNCTION_1, rt_call_function_1);
1143 } else if (n_positional == 2) {
1144 vtype_kind_t vtype_fun, vtype_arg1, vtype_arg2;
1145 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
1146 assert(vtype_fun == VTYPE_PYOBJ);
1147 assert(vtype_arg1 == VTYPE_PYOBJ);
1148 assert(vtype_arg2 == VTYPE_PYOBJ);
1149 emit_call(emit, RT_F_CALL_FUNCTION_2, rt_call_function_2);
1150 } else {
Damieneb19efb2013-10-10 22:06:54 +01001151 */
1152 emit_pre(emit);
1153 if (n_positional != 0) {
1154 emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_3, n_positional); // pointer to args in reverse order
1155 }
1156 vtype_kind_t vtype_fun;
1157 emit_pre_pop_reg(emit, &vtype_fun, REG_ARG_1); // the function
1158 assert(vtype_fun == VTYPE_PYOBJ);
Damien George20006db2014-01-18 14:10:48 +00001159 // XXX rt_call_function_n now merged with rt_call_function_n_kw
1160 //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 +01001161 //}
Damien13ed3a62013-10-08 09:05:10 +01001162 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
1163}
1164
1165static void emit_native_call_method(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) {
1166 assert(n_keyword == 0 && !have_star_arg && !have_dbl_star_arg);
Damieneb19efb2013-10-10 22:06:54 +01001167 /*
Damien13ed3a62013-10-08 09:05:10 +01001168 if (n_positional == 0) {
1169 vtype_kind_t vtype_meth, vtype_self;
1170 emit_pre_pop_reg_reg(emit, &vtype_self, REG_ARG_2, &vtype_meth, REG_ARG_1); // the self object (or NULL), the method
1171 assert(vtype_meth == VTYPE_PYOBJ);
1172 assert(vtype_self == VTYPE_PYOBJ);
1173 emit_call(emit, RT_F_CALL_METHOD_1, rt_call_method_1);
1174 } else if (n_positional == 1) {
1175 vtype_kind_t vtype_meth, vtype_self, vtype_arg1;
1176 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
1177 assert(vtype_meth == VTYPE_PYOBJ);
1178 assert(vtype_self == VTYPE_PYOBJ);
1179 assert(vtype_arg1 == VTYPE_PYOBJ);
1180 emit_call(emit, RT_F_CALL_METHOD_2, rt_call_method_2);
1181 } else {
Damieneb19efb2013-10-10 22:06:54 +01001182 */
Damien7f5dacf2013-10-10 11:24:39 +01001183 emit_pre(emit);
1184 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 +00001185 // XXX rt_call_method_n now merged with rt_call_method_n_kw
1186 //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 +01001187 //}
Damien13ed3a62013-10-08 09:05:10 +01001188 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
1189}
1190
1191static void emit_native_return_value(emit_t *emit) {
1192 // easy. since we don't know who we return to, just return the raw value.
1193 // runtime needs then to know our type signature, but I think that's possible.
1194 vtype_kind_t vtype;
1195 emit_pre_pop_reg(emit, &vtype, REG_RET);
1196 if (emit->do_viper_types) {
1197 assert(vtype == VTYPE_PTR_NONE);
1198 } else {
1199 assert(vtype == VTYPE_PYOBJ);
1200 }
1201 emit->last_emit_was_return_value = true;
Damien3ef4abb2013-10-12 16:53:13 +01001202#if N_X64
Damien13ed3a62013-10-08 09:05:10 +01001203 //asm_x64_call_ind(emit->as, 0, REG_RAX); to seg fault for debugging with gdb
1204 asm_x64_exit(emit->as);
Damien3ef4abb2013-10-12 16:53:13 +01001205#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +01001206 //asm_thumb_call_ind(emit->as, 0, REG_R0); to seg fault for debugging with gdb
1207 asm_thumb_exit(emit->as);
1208#endif
1209}
1210
1211static void emit_native_raise_varargs(emit_t *emit, int n_args) {
1212 // call runtime
1213 assert(0);
1214}
1215static void emit_native_yield_value(emit_t *emit) {
1216 // not supported (for now)
1217 assert(0);
1218}
1219static void emit_native_yield_from(emit_t *emit) {
1220 // not supported (for now)
1221 assert(0);
1222}
1223
1224const emit_method_table_t EXPORT_FUN(method_table) = {
1225 emit_native_set_viper_types,
1226 emit_native_start_pass,
1227 emit_native_end_pass,
1228 emit_native_last_emit_was_return_value,
1229 emit_native_get_stack_size,
1230 emit_native_set_stack_size,
1231
1232 emit_native_load_id,
1233 emit_native_store_id,
1234 emit_native_delete_id,
1235
1236 emit_native_label_assign,
1237 emit_native_import_name,
1238 emit_native_import_from,
1239 emit_native_import_star,
1240 emit_native_load_const_tok,
1241 emit_native_load_const_small_int,
1242 emit_native_load_const_int,
1243 emit_native_load_const_dec,
1244 emit_native_load_const_id,
1245 emit_native_load_const_str,
Damien13ed3a62013-10-08 09:05:10 +01001246 emit_native_load_const_verbatim_str,
Damien13ed3a62013-10-08 09:05:10 +01001247 emit_native_load_fast,
Damien13ed3a62013-10-08 09:05:10 +01001248 emit_native_load_deref,
1249 emit_native_load_closure,
Damien9ecbcff2013-12-11 00:41:43 +00001250 emit_native_load_name,
1251 emit_native_load_global,
Damien13ed3a62013-10-08 09:05:10 +01001252 emit_native_load_attr,
1253 emit_native_load_method,
1254 emit_native_load_build_class,
1255 emit_native_store_fast,
Damien9ecbcff2013-12-11 00:41:43 +00001256 emit_native_store_deref,
Damien13ed3a62013-10-08 09:05:10 +01001257 emit_native_store_name,
1258 emit_native_store_global,
Damien13ed3a62013-10-08 09:05:10 +01001259 emit_native_store_attr,
Damien13ed3a62013-10-08 09:05:10 +01001260 emit_native_store_subscr,
Damiena3977762013-10-09 23:10:10 +01001261 emit_native_store_locals,
Damien13ed3a62013-10-08 09:05:10 +01001262 emit_native_delete_fast,
Damien9ecbcff2013-12-11 00:41:43 +00001263 emit_native_delete_deref,
Damien13ed3a62013-10-08 09:05:10 +01001264 emit_native_delete_name,
1265 emit_native_delete_global,
Damien13ed3a62013-10-08 09:05:10 +01001266 emit_native_delete_attr,
1267 emit_native_delete_subscr,
1268 emit_native_dup_top,
1269 emit_native_dup_top_two,
1270 emit_native_pop_top,
1271 emit_native_rot_two,
1272 emit_native_rot_three,
1273 emit_native_jump,
1274 emit_native_pop_jump_if_true,
1275 emit_native_pop_jump_if_false,
1276 emit_native_jump_if_true_or_pop,
1277 emit_native_jump_if_false_or_pop,
1278 emit_native_setup_loop,
1279 emit_native_break_loop,
1280 emit_native_continue_loop,
1281 emit_native_setup_with,
1282 emit_native_with_cleanup,
1283 emit_native_setup_except,
1284 emit_native_setup_finally,
1285 emit_native_end_finally,
1286 emit_native_get_iter,
1287 emit_native_for_iter,
1288 emit_native_for_iter_end,
1289 emit_native_pop_block,
1290 emit_native_pop_except,
1291 emit_native_unary_op,
1292 emit_native_binary_op,
Damien13ed3a62013-10-08 09:05:10 +01001293 emit_native_build_tuple,
1294 emit_native_build_list,
1295 emit_native_list_append,
1296 emit_native_build_map,
1297 emit_native_store_map,
1298 emit_native_map_add,
1299 emit_native_build_set,
1300 emit_native_set_add,
1301 emit_native_build_slice,
1302 emit_native_unpack_sequence,
1303 emit_native_unpack_ex,
1304 emit_native_make_function,
1305 emit_native_make_closure,
1306 emit_native_call_function,
1307 emit_native_call_method,
1308 emit_native_return_value,
1309 emit_native_raise_varargs,
1310 emit_native_yield_value,
1311 emit_native_yield_from,
1312};
1313
Damien Georgee67ed5d2014-01-04 13:55:24 +00001314#endif // (MICROPY_EMIT_X64 && N_X64) || (MICROPY_EMIT_THUMB && N_THUMB)