blob: 6fc17424899af16744639832e30321b87f66c9f6 [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
149static void emit_native_set_viper_types(emit_t *emit, bool do_viper_types) {
150 emit->do_viper_types = do_viper_types;
151}
152
153static void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) {
154 emit->pass = pass;
155 emit->stack_start = 0;
156 emit->stack_size = 0;
157 emit->last_emit_was_return_value = false;
Damien13ed3a62013-10-08 09:05:10 +0100158 emit->scope = scope;
159
Damienff8ed772013-10-08 22:18:32 +0100160 if (emit->local_vtype == NULL) {
161 emit->local_vtype_alloc = scope->num_locals + 20; // XXX should be maximum over all scopes
162 emit->local_vtype = m_new(vtype_kind_t, emit->local_vtype_alloc);
163 }
164 if (emit->stack_info == NULL) {
165 emit->stack_info_alloc = scope->stack_size + 50; // XXX don't know stack size on entry, should be maximum over all scopes
166 emit->stack_info = m_new(stack_info_t, emit->stack_info_alloc);
Damien13ed3a62013-10-08 09:05:10 +0100167 }
168
169 if (emit->do_viper_types) {
Damien13ed3a62013-10-08 09:05:10 +0100170 // TODO set types of arguments based on type signature
Damienff8ed772013-10-08 22:18:32 +0100171 for (int i = 0; i < emit->local_vtype_alloc; i++) {
172 emit->local_vtype[i] = VTYPE_UNBOUND;
173 }
174 for (int i = 0; i < emit->stack_info_alloc; i++) {
175 emit->stack_info[i].kind = STACK_VALUE;
176 emit->stack_info[i].vtype = VTYPE_UNBOUND;
177 }
Damien13ed3a62013-10-08 09:05:10 +0100178 } else {
Damienff8ed772013-10-08 22:18:32 +0100179 for (int i = 0; i < emit->local_vtype_alloc; i++) {
180 emit->local_vtype[i] = VTYPE_PYOBJ;
181 }
182 for (int i = 0; i < emit->stack_info_alloc; i++) {
183 emit->stack_info[i].kind = STACK_VALUE;
184 emit->stack_info[i].vtype = VTYPE_PYOBJ;
Damien13ed3a62013-10-08 09:05:10 +0100185 }
186 }
187
Damien3ef4abb2013-10-12 16:53:13 +0100188#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100189 asm_x64_start_pass(emit->as, pass);
Damien3ef4abb2013-10-12 16:53:13 +0100190#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100191 asm_thumb_start_pass(emit->as, pass);
192#endif
193
194 // entry to function
195 int num_locals = 0;
196 if (pass > PASS_1) {
197 num_locals = scope->num_locals - REG_LOCAL_NUM;
198 if (num_locals < 0) {
199 num_locals = 0;
200 }
201 emit->stack_start = num_locals;
202 num_locals += scope->stack_size;
203 }
Damien3ef4abb2013-10-12 16:53:13 +0100204#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100205 asm_x64_entry(emit->as, num_locals);
Damien3ef4abb2013-10-12 16:53:13 +0100206#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100207 asm_thumb_entry(emit->as, num_locals);
208#endif
209
210 // initialise locals from parameters
Damien3ef4abb2013-10-12 16:53:13 +0100211#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100212 for (int i = 0; i < scope->num_params; i++) {
213 if (i == 0) {
214 asm_x64_mov_r64_to_r64(emit->as, REG_ARG_1, REG_LOCAL_1);
215 } else if (i == 1) {
216 asm_x64_mov_r64_to_local(emit->as, REG_ARG_2, i - 1);
217 } else if (i == 2) {
218 asm_x64_mov_r64_to_local(emit->as, REG_ARG_3, i - 1);
219 } else {
220 // TODO not implemented
221 assert(0);
222 }
223 }
Damien3ef4abb2013-10-12 16:53:13 +0100224#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100225 for (int i = 0; i < scope->num_params; i++) {
226 if (i == 0) {
227 asm_thumb_mov_reg_reg(emit->as, REG_LOCAL_1, REG_ARG_1);
228 } else if (i == 1) {
229 asm_thumb_mov_reg_reg(emit->as, REG_LOCAL_2, REG_ARG_2);
230 } else if (i == 2) {
231 asm_thumb_mov_reg_reg(emit->as, REG_LOCAL_3, REG_ARG_3);
232 } else if (i == 3) {
233 asm_thumb_mov_local_reg(emit->as, i - REG_LOCAL_NUM, REG_ARG_4);
234 } else {
235 // TODO not implemented
236 assert(0);
237 }
238 }
239
240 asm_thumb_mov_reg_i32(emit->as, REG_R7, (machine_uint_t)rt_fun_table);
241#endif
242}
243
244static void emit_native_end_pass(emit_t *emit) {
Damien3ef4abb2013-10-12 16:53:13 +0100245#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100246 if (!emit->last_emit_was_return_value) {
247 asm_x64_exit(emit->as);
248 }
249 asm_x64_end_pass(emit->as);
Damien3ef4abb2013-10-12 16:53:13 +0100250#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100251 if (!emit->last_emit_was_return_value) {
252 asm_thumb_exit(emit->as);
253 }
254 asm_thumb_end_pass(emit->as);
255#endif
256
257 // check stack is back to zero size
258 if (emit->stack_size != 0) {
259 printf("ERROR: stack size not back to zero; got %d\n", emit->stack_size);
260 }
261
262 if (emit->pass == PASS_3) {
Damien3ef4abb2013-10-12 16:53:13 +0100263#if N_X64
Damiend99b0522013-12-21 18:17:45 +0000264 void *f = asm_x64_get_code(emit->as);
Damien13ed3a62013-10-08 09:05:10 +0100265 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 +0100266#elif N_THUMB
Damiend99b0522013-12-21 18:17:45 +0000267 void *f = asm_thumb_get_code(emit->as);
Damien13ed3a62013-10-08 09:05:10 +0100268 rt_assign_native_code(emit->scope->unique_code_id, f, asm_thumb_get_code_size(emit->as), emit->scope->num_params);
269#endif
270 }
271}
272
273static bool emit_native_last_emit_was_return_value(emit_t *emit) {
274 return emit->last_emit_was_return_value;
275}
276
277static int emit_native_get_stack_size(emit_t *emit) {
278 return emit->stack_size;
279}
280
281static void emit_native_set_stack_size(emit_t *emit, int size) {
282 emit->stack_size = size;
283}
284
Damien George08335002014-01-18 23:24:36 +0000285static void emit_native_set_source_line(emit_t *emit, int source_line) {
286}
287
Damien13ed3a62013-10-08 09:05:10 +0100288static void adjust_stack(emit_t *emit, int stack_size_delta) {
289 emit->stack_size += stack_size_delta;
290 assert(emit->stack_size >= 0);
291 if (emit->pass > PASS_1 && emit->stack_size > emit->scope->stack_size) {
292 emit->scope->stack_size = emit->stack_size;
293 }
294}
295
Damienff8ed772013-10-08 22:18:32 +0100296/*
Damien13ed3a62013-10-08 09:05:10 +0100297static void emit_pre_raw(emit_t *emit, int stack_size_delta) {
298 adjust_stack(emit, stack_size_delta);
299 emit->last_emit_was_return_value = false;
300}
Damienff8ed772013-10-08 22:18:32 +0100301*/
Damien13ed3a62013-10-08 09:05:10 +0100302
Damienff8ed772013-10-08 22:18:32 +0100303// this must be called at start of emit functions
Damien13ed3a62013-10-08 09:05:10 +0100304static void emit_pre(emit_t *emit) {
Damienff8ed772013-10-08 22:18:32 +0100305 emit->last_emit_was_return_value = false;
306 // settle the stack
307 /*
308 if (regs_needed != 0) {
309 for (int i = 0; i < emit->stack_size; i++) {
310 switch (emit->stack_info[i].kind) {
311 case STACK_VALUE:
312 break;
313
314 case STACK_REG:
315 // TODO only push reg if in regs_needed
316 emit->stack_info[i].kind = STACK_VALUE;
317 ASM_MOV_REG_TO_LOCAL(emit->stack_info[i].u_reg, emit->stack_start + i);
318 break;
319
320 case STACK_IMM:
321 // don't think we ever need to push imms for settling
322 //ASM_MOV_IMM_TO_LOCAL(emit->last_imm, emit->stack_start + i);
323 break;
324 }
325 }
326 }
327 */
Damien13ed3a62013-10-08 09:05:10 +0100328}
329
330static vtype_kind_t peek_vtype(emit_t *emit) {
Damienff8ed772013-10-08 22:18:32 +0100331 return emit->stack_info[emit->stack_size - 1].vtype;
332}
Damien13ed3a62013-10-08 09:05:10 +0100333
Damiend2755ec2013-10-16 23:58:48 +0100334// pos=1 is TOS, pos=2 is next, etc
335// use pos=0 for no skipping
336static void need_reg_single(emit_t *emit, int reg_needed, int skip_stack_pos) {
337 skip_stack_pos = emit->stack_size - skip_stack_pos;
Damienff8ed772013-10-08 22:18:32 +0100338 for (int i = 0; i < emit->stack_size; i++) {
Damiend2755ec2013-10-16 23:58:48 +0100339 if (i != skip_stack_pos) {
340 stack_info_t *si = &emit->stack_info[i];
341 if (si->kind == STACK_REG && si->u_reg == reg_needed) {
342 si->kind = STACK_VALUE;
343 ASM_MOV_REG_TO_LOCAL(si->u_reg, emit->stack_start + i);
344 }
Damienff8ed772013-10-08 22:18:32 +0100345 }
346 }
347}
Damien13ed3a62013-10-08 09:05:10 +0100348
Damieneb19efb2013-10-10 22:06:54 +0100349static void need_reg_all(emit_t *emit) {
Damienff8ed772013-10-08 22:18:32 +0100350 for (int i = 0; i < emit->stack_size; i++) {
351 stack_info_t *si = &emit->stack_info[i];
352 if (si->kind == STACK_REG) {
353 si->kind = STACK_VALUE;
354 ASM_MOV_REG_TO_LOCAL(si->u_reg, emit->stack_start + i);
355 }
Damien13ed3a62013-10-08 09:05:10 +0100356 }
357}
358
Damiend2755ec2013-10-16 23:58:48 +0100359static void need_stack_settled(emit_t *emit) {
360 for (int i = 0; i < emit->stack_size; i++) {
361 stack_info_t *si = &emit->stack_info[i];
362 if (si->kind == STACK_REG) {
363 si->kind = STACK_VALUE;
364 ASM_MOV_REG_TO_LOCAL(si->u_reg, emit->stack_start + i);
365 }
366 }
367 for (int i = 0; i < emit->stack_size; i++) {
368 stack_info_t *si = &emit->stack_info[i];
369 if (si->kind == STACK_IMM) {
370 ASM_MOV_IMM_TO_LOCAL_USING(si->u_imm, emit->stack_start + i, REG_TEMP0);
371 }
372 }
373}
374
375// pos=1 is TOS, pos=2 is next, etc
376static void emit_access_stack(emit_t *emit, int pos, vtype_kind_t *vtype, int reg_dest) {
377 need_reg_single(emit, reg_dest, pos);
378 stack_info_t *si = &emit->stack_info[emit->stack_size - pos];
Damienff8ed772013-10-08 22:18:32 +0100379 *vtype = si->vtype;
380 switch (si->kind) {
381 case STACK_VALUE:
Damiend2755ec2013-10-16 23:58:48 +0100382 ASM_MOV_LOCAL_TO_REG(emit->stack_start + emit->stack_size - pos, reg_dest);
Damien13ed3a62013-10-08 09:05:10 +0100383 break;
384
Damienff8ed772013-10-08 22:18:32 +0100385 case STACK_REG:
386 if (si->u_reg != reg_dest) {
387 ASM_MOV_REG_TO_REG(si->u_reg, reg_dest);
Damien13ed3a62013-10-08 09:05:10 +0100388 }
389 break;
390
Damienff8ed772013-10-08 22:18:32 +0100391 case STACK_IMM:
392 ASM_MOV_IMM_TO_REG(si->u_imm, reg_dest);
Damien13ed3a62013-10-08 09:05:10 +0100393 break;
394 }
Damien13ed3a62013-10-08 09:05:10 +0100395}
396
Damiend2755ec2013-10-16 23:58:48 +0100397static void emit_pre_pop_reg(emit_t *emit, vtype_kind_t *vtype, int reg_dest) {
398 emit->last_emit_was_return_value = false;
399 emit_access_stack(emit, 1, vtype, reg_dest);
400 adjust_stack(emit, -1);
401}
402
Damien13ed3a62013-10-08 09:05:10 +0100403static void emit_pre_pop_reg_reg(emit_t *emit, vtype_kind_t *vtypea, int rega, vtype_kind_t *vtypeb, int regb) {
404 emit_pre_pop_reg(emit, vtypea, rega);
Damienff8ed772013-10-08 22:18:32 +0100405 emit_pre_pop_reg(emit, vtypeb, regb);
Damien13ed3a62013-10-08 09:05:10 +0100406}
407
408static 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) {
409 emit_pre_pop_reg(emit, vtypea, rega);
Damienff8ed772013-10-08 22:18:32 +0100410 emit_pre_pop_reg(emit, vtypeb, regb);
411 emit_pre_pop_reg(emit, vtypec, regc);
Damien13ed3a62013-10-08 09:05:10 +0100412}
413
414static void emit_post(emit_t *emit) {
415}
416
417static void emit_post_push_reg(emit_t *emit, vtype_kind_t vtype, int reg) {
Damienff8ed772013-10-08 22:18:32 +0100418 stack_info_t *si = &emit->stack_info[emit->stack_size];
419 si->vtype = vtype;
420 si->kind = STACK_REG;
421 si->u_reg = reg;
Damien13ed3a62013-10-08 09:05:10 +0100422 adjust_stack(emit, 1);
423}
424
Damienff8ed772013-10-08 22:18:32 +0100425static void emit_post_push_imm(emit_t *emit, vtype_kind_t vtype, machine_int_t imm) {
426 stack_info_t *si = &emit->stack_info[emit->stack_size];
427 si->vtype = vtype;
428 si->kind = STACK_IMM;
429 si->u_imm = imm;
430 adjust_stack(emit, 1);
431}
432
433static void emit_post_push_reg_reg(emit_t *emit, vtype_kind_t vtypea, int rega, vtype_kind_t vtypeb, int regb) {
434 emit_post_push_reg(emit, vtypea, rega);
435 emit_post_push_reg(emit, vtypeb, regb);
436}
437
Damien13ed3a62013-10-08 09:05:10 +0100438static 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 +0100439 emit_post_push_reg(emit, vtypea, rega);
440 emit_post_push_reg(emit, vtypeb, regb);
441 emit_post_push_reg(emit, vtypec, regc);
Damien13ed3a62013-10-08 09:05:10 +0100442}
443
444static 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 +0100445 emit_post_push_reg(emit, vtypea, rega);
446 emit_post_push_reg(emit, vtypeb, regb);
447 emit_post_push_reg(emit, vtypec, regc);
448 emit_post_push_reg(emit, vtyped, regd);
Damien13ed3a62013-10-08 09:05:10 +0100449}
450
451// vtype of all n_pop objects is VTYPE_PYOBJ
Damieneb19efb2013-10-10 22:06:54 +0100452// does not use any temporary registers (but may use reg_dest before loading it with stack pointer)
Damien6d4f3462013-11-16 20:44:39 +0000453// TODO this needs some thinking for viper code
Damien13ed3a62013-10-08 09:05:10 +0100454static void emit_get_stack_pointer_to_reg_for_pop(emit_t *emit, int reg_dest, int n_pop) {
Damieneb19efb2013-10-10 22:06:54 +0100455 need_reg_all(emit);
Damienff8ed772013-10-08 22:18:32 +0100456 for (int i = 0; i < n_pop; i++) {
Damieneb19efb2013-10-10 22:06:54 +0100457 stack_info_t *si = &emit->stack_info[emit->stack_size - 1 - i];
458 // must push any imm's to stack
Damien6d4f3462013-11-16 20:44:39 +0000459 // must convert them to VTYPE_PYOBJ for viper code
Damieneb19efb2013-10-10 22:06:54 +0100460 if (si->kind == STACK_IMM) {
461 si->kind = STACK_VALUE;
Damien6d4f3462013-11-16 20:44:39 +0000462 switch (si->vtype) {
463 case VTYPE_PYOBJ:
464 ASM_MOV_IMM_TO_LOCAL_USING(si->u_imm, emit->stack_start + emit->stack_size - 1 - i, reg_dest);
465 break;
466 case VTYPE_BOOL:
467 si->vtype = VTYPE_PYOBJ;
468 if (si->u_imm == 0) {
Damiend99b0522013-12-21 18:17:45 +0000469 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 +0000470 } else {
Damiend99b0522013-12-21 18:17:45 +0000471 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 +0000472 }
473 break;
474 case VTYPE_INT:
475 si->vtype = VTYPE_PYOBJ;
476 ASM_MOV_IMM_TO_LOCAL_USING((si->u_imm << 1) | 1, emit->stack_start + emit->stack_size - 1 - i, reg_dest);
477 break;
478 default:
479 // not handled
480 assert(0);
481 }
Damieneb19efb2013-10-10 22:06:54 +0100482 }
483 assert(si->kind == STACK_VALUE);
484 assert(si->vtype == VTYPE_PYOBJ);
Damienff8ed772013-10-08 22:18:32 +0100485 }
Damien13ed3a62013-10-08 09:05:10 +0100486 ASM_MOV_LOCAL_ADDR_TO_REG(emit->stack_start + emit->stack_size - 1, reg_dest);
487 adjust_stack(emit, -n_pop);
488}
489
490// vtype of all n_push objects is VTYPE_PYOBJ
491static void emit_get_stack_pointer_to_reg_for_push(emit_t *emit, int reg_dest, int n_push) {
Damieneb19efb2013-10-10 22:06:54 +0100492 need_reg_all(emit);
Damien13ed3a62013-10-08 09:05:10 +0100493 for (int i = 0; i < n_push; i++) {
Damien7f5dacf2013-10-10 11:24:39 +0100494 emit->stack_info[emit->stack_size + i].kind = STACK_VALUE;
Damienff8ed772013-10-08 22:18:32 +0100495 emit->stack_info[emit->stack_size + i].vtype = VTYPE_PYOBJ;
Damien13ed3a62013-10-08 09:05:10 +0100496 }
497 ASM_MOV_LOCAL_ADDR_TO_REG(emit->stack_start + emit->stack_size + n_push - 1, reg_dest);
498 adjust_stack(emit, n_push);
499}
500
501static void emit_call(emit_t *emit, rt_fun_kind_t fun_kind, void *fun) {
Damiend2755ec2013-10-16 23:58:48 +0100502 need_reg_all(emit);
Damien3ef4abb2013-10-12 16:53:13 +0100503#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100504 asm_x64_call_ind(emit->as, fun, REG_RAX);
Damien3ef4abb2013-10-12 16:53:13 +0100505#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100506 asm_thumb_bl_ind(emit->as, rt_fun_table[fun_kind], fun_kind, REG_R3);
507#endif
508}
509
510static 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 +0100511 need_reg_all(emit);
Damien13ed3a62013-10-08 09:05:10 +0100512 ASM_MOV_IMM_TO_REG(arg_val, arg_reg);
Damiend2755ec2013-10-16 23:58:48 +0100513#if N_X64
514 asm_x64_call_ind(emit->as, fun, REG_RAX);
515#elif N_THUMB
516 asm_thumb_bl_ind(emit->as, rt_fun_table[fun_kind], fun_kind, REG_R3);
517#endif
Damien13ed3a62013-10-08 09:05:10 +0100518}
519
520static void emit_native_load_id(emit_t *emit, qstr qstr) {
521 // check for built-ins
522 if (strcmp(qstr_str(qstr), "v_int") == 0) {
Damienff8ed772013-10-08 22:18:32 +0100523 assert(0);
Damien13ed3a62013-10-08 09:05:10 +0100524 emit_pre(emit);
525 //emit_post_push_blank(emit, VTYPE_BUILTIN_V_INT);
526
527 // not a built-in, so do usual thing
528 } else {
529 emit_common_load_id(emit, &EXPORT_FUN(method_table), emit->scope, qstr);
530 }
531}
532
533static void emit_native_store_id(emit_t *emit, qstr qstr) {
534 // TODO check for built-ins and disallow
535 emit_common_store_id(emit, &EXPORT_FUN(method_table), emit->scope, qstr);
536}
537
538static void emit_native_delete_id(emit_t *emit, qstr qstr) {
539 // TODO check for built-ins and disallow
540 emit_common_delete_id(emit, &EXPORT_FUN(method_table), emit->scope, qstr);
541}
542
543static void emit_native_label_assign(emit_t *emit, int l) {
Damien6ba13142013-11-02 20:34:54 +0000544 emit_pre(emit);
Damiend2755ec2013-10-16 23:58:48 +0100545 // need to commit stack because we can jump here from elsewhere
546 need_stack_settled(emit);
Damien3ef4abb2013-10-12 16:53:13 +0100547#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100548 asm_x64_label_assign(emit->as, l);
Damien3ef4abb2013-10-12 16:53:13 +0100549#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100550 asm_thumb_label_assign(emit->as, l);
551#endif
Damien6ba13142013-11-02 20:34:54 +0000552 emit_post(emit);
Damien13ed3a62013-10-08 09:05:10 +0100553}
554
555static void emit_native_import_name(emit_t *emit, qstr qstr) {
556 // not implemented
557 assert(0);
558}
559
560static void emit_native_import_from(emit_t *emit, qstr qstr) {
561 // not implemented
562 assert(0);
563}
564
565static void emit_native_import_star(emit_t *emit) {
566 // not implemented
567 assert(0);
568}
569
Damiend99b0522013-12-21 18:17:45 +0000570static void emit_native_load_const_tok(emit_t *emit, mp_token_kind_t tok) {
Damien13ed3a62013-10-08 09:05:10 +0100571 emit_pre(emit);
572 int vtype;
573 machine_uint_t val;
574 if (emit->do_viper_types) {
575 switch (tok) {
Damiend99b0522013-12-21 18:17:45 +0000576 case MP_TOKEN_KW_NONE: vtype = VTYPE_PTR_NONE; val = 0; break;
577 case MP_TOKEN_KW_FALSE: vtype = VTYPE_BOOL; val = 0; break;
578 case MP_TOKEN_KW_TRUE: vtype = VTYPE_BOOL; val = 1; break;
Damien13ed3a62013-10-08 09:05:10 +0100579 default: assert(0); vtype = 0; val = 0; // shouldn't happen
580 }
581 } else {
582 vtype = VTYPE_PYOBJ;
583 switch (tok) {
Damiend99b0522013-12-21 18:17:45 +0000584 case MP_TOKEN_KW_NONE: val = (machine_uint_t)mp_const_none; break;
585 case MP_TOKEN_KW_FALSE: val = (machine_uint_t)mp_const_false; break;
586 case MP_TOKEN_KW_TRUE: val = (machine_uint_t)mp_const_true; break;
Damien13ed3a62013-10-08 09:05:10 +0100587 default: assert(0); vtype = 0; val = 0; // shouldn't happen
588 }
589 }
590 emit_post_push_imm(emit, vtype, val);
591}
592
593static void emit_native_load_const_small_int(emit_t *emit, int arg) {
594 emit_pre(emit);
595 if (emit->do_viper_types) {
596 emit_post_push_imm(emit, VTYPE_INT, arg);
597 } else {
598 emit_post_push_imm(emit, VTYPE_PYOBJ, (arg << 1) | 1);
599 }
600}
601
602static void emit_native_load_const_int(emit_t *emit, qstr qstr) {
603 // not implemented
604 // load integer, check fits in 32 bits
605 assert(0);
606}
607
608static void emit_native_load_const_dec(emit_t *emit, qstr qstr) {
Damien6ba13142013-11-02 20:34:54 +0000609 // for viper, a float/complex is just a Python object
610 emit_pre(emit);
611 emit_call_with_imm_arg(emit, RT_F_LOAD_CONST_DEC, rt_load_const_dec, qstr, REG_ARG_1);
612 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
Damien13ed3a62013-10-08 09:05:10 +0100613}
614
615static void emit_native_load_const_id(emit_t *emit, qstr qstr) {
Damien7f5dacf2013-10-10 11:24:39 +0100616 emit_pre(emit);
617 if (emit->do_viper_types) {
618 assert(0);
619 } else {
620 emit_call_with_imm_arg(emit, RT_F_LOAD_CONST_STR, rt_load_const_str, qstr, REG_ARG_1); // TODO
621 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
622 }
Damien13ed3a62013-10-08 09:05:10 +0100623}
624
625static void emit_native_load_const_str(emit_t *emit, qstr qstr, bool bytes) {
626 emit_pre(emit);
627 if (emit->do_viper_types) {
628 // not implemented properly
629 // load a pointer to the asciiz string?
630 assert(0);
631 emit_post_push_imm(emit, VTYPE_PTR, (machine_uint_t)qstr_str(qstr));
632 } else {
633 emit_call_with_imm_arg(emit, RT_F_LOAD_CONST_STR, rt_load_const_str, qstr, REG_ARG_1);
634 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
635 }
636}
637
Damien13ed3a62013-10-08 09:05:10 +0100638static void emit_native_load_const_verbatim_str(emit_t *emit, const char *str) {
639 // not supported/needed for viper
640 assert(0);
641}
642
Damien13ed3a62013-10-08 09:05:10 +0100643static void emit_native_load_fast(emit_t *emit, qstr qstr, int local_num) {
644 vtype_kind_t vtype = emit->local_vtype[local_num];
645 if (vtype == VTYPE_UNBOUND) {
646 printf("ViperTypeError: local %s used before type known\n", qstr_str(qstr));
647 }
648 emit_pre(emit);
Damien3ef4abb2013-10-12 16:53:13 +0100649#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100650 if (local_num == 0) {
651 emit_post_push_reg(emit, vtype, REG_LOCAL_1);
652 } else {
Damiend2755ec2013-10-16 23:58:48 +0100653 need_reg_single(emit, REG_RAX, 0);
Damien13ed3a62013-10-08 09:05:10 +0100654 asm_x64_mov_local_to_r64(emit->as, local_num - 1, REG_RAX);
655 emit_post_push_reg(emit, vtype, REG_RAX);
656 }
Damien3ef4abb2013-10-12 16:53:13 +0100657#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100658 if (local_num == 0) {
659 emit_post_push_reg(emit, vtype, REG_LOCAL_1);
660 } else if (local_num == 1) {
661 emit_post_push_reg(emit, vtype, REG_LOCAL_2);
662 } else if (local_num == 2) {
663 emit_post_push_reg(emit, vtype, REG_LOCAL_3);
664 } else {
Damiend2755ec2013-10-16 23:58:48 +0100665 need_reg_single(emit, REG_R0, 0);
Damien13ed3a62013-10-08 09:05:10 +0100666 asm_thumb_mov_reg_local(emit->as, REG_R0, local_num - 1);
667 emit_post_push_reg(emit, vtype, REG_R0);
668 }
669#endif
670}
671
Damien9ecbcff2013-12-11 00:41:43 +0000672static void emit_native_load_deref(emit_t *emit, qstr qstr, int local_num) {
673 // not implemented
674 // in principle could support this quite easily (ldr r0, [r0, #0]) and then get closed over variables!
675 assert(0);
676}
677
678static void emit_native_load_closure(emit_t *emit, qstr qstr, int local_num) {
679 // not implemented
680 assert(0);
681}
682
Damien13ed3a62013-10-08 09:05:10 +0100683static void emit_native_load_name(emit_t *emit, qstr qstr) {
684 emit_pre(emit);
685 emit_call_with_imm_arg(emit, RT_F_LOAD_NAME, rt_load_name, qstr, REG_ARG_1);
686 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
687}
688
689static void emit_native_load_global(emit_t *emit, qstr qstr) {
690 emit_pre(emit);
691 emit_call_with_imm_arg(emit, RT_F_LOAD_GLOBAL, rt_load_global, qstr, REG_ARG_1);
692 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
693}
694
Damien13ed3a62013-10-08 09:05:10 +0100695static void emit_native_load_attr(emit_t *emit, qstr qstr) {
696 // depends on type of subject:
697 // - integer, function, pointer to integers: error
698 // - pointer to structure: get member, quite easy
699 // - Python object: call rt_load_attr, and needs to be typed to convert result
700 vtype_kind_t vtype_base;
701 emit_pre_pop_reg(emit, &vtype_base, REG_ARG_1); // arg1 = base
702 assert(vtype_base == VTYPE_PYOBJ);
703 emit_call_with_imm_arg(emit, RT_F_LOAD_ATTR, rt_load_attr, qstr, REG_ARG_2); // arg2 = attribute name
704 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
705}
706
707static void emit_native_load_method(emit_t *emit, qstr qstr) {
708 vtype_kind_t vtype_base;
709 emit_pre_pop_reg(emit, &vtype_base, REG_ARG_1); // arg1 = base
710 assert(vtype_base == VTYPE_PYOBJ);
711 emit_get_stack_pointer_to_reg_for_push(emit, REG_ARG_3, 2); // arg3 = dest ptr
712 emit_call_with_imm_arg(emit, RT_F_LOAD_METHOD, rt_load_method, qstr, REG_ARG_2); // arg2 = method name
713}
714
715static void emit_native_load_build_class(emit_t *emit) {
Damien7f5dacf2013-10-10 11:24:39 +0100716 emit_pre(emit);
717 emit_call(emit, RT_F_LOAD_BUILD_CLASS, rt_load_build_class);
718 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
Damien13ed3a62013-10-08 09:05:10 +0100719}
720
721static void emit_native_store_fast(emit_t *emit, qstr qstr, int local_num) {
722 vtype_kind_t vtype;
Damien3ef4abb2013-10-12 16:53:13 +0100723#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100724 if (local_num == 0) {
725 emit_pre_pop_reg(emit, &vtype, REG_LOCAL_1);
726 } else {
727 emit_pre_pop_reg(emit, &vtype, REG_RAX);
728 asm_x64_mov_r64_to_local(emit->as, REG_RAX, local_num - 1);
729 }
Damien3ef4abb2013-10-12 16:53:13 +0100730#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100731 if (local_num == 0) {
732 emit_pre_pop_reg(emit, &vtype, REG_LOCAL_1);
733 } else if (local_num == 1) {
734 emit_pre_pop_reg(emit, &vtype, REG_LOCAL_2);
735 } else if (local_num == 2) {
736 emit_pre_pop_reg(emit, &vtype, REG_LOCAL_3);
737 } else {
738 emit_pre_pop_reg(emit, &vtype, REG_R0);
739 asm_thumb_mov_local_reg(emit->as, local_num - 1, REG_R0);
740 }
741#endif
742
743 emit_post(emit);
744
745 // check types
746 if (emit->local_vtype[local_num] == VTYPE_UNBOUND) {
747 // first time this local is assigned, so give it a type of the object stored in it
748 emit->local_vtype[local_num] = vtype;
749 } else if (emit->local_vtype[local_num] != vtype) {
750 // type of local is not the same as object stored in it
751 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);
752 }
753}
754
Damien9ecbcff2013-12-11 00:41:43 +0000755static void emit_native_store_deref(emit_t *emit, qstr qstr, int local_num) {
756 // not implemented
757 assert(0);
758}
759
Damien13ed3a62013-10-08 09:05:10 +0100760static void emit_native_store_name(emit_t *emit, qstr qstr) {
761 // rt_store_name, but needs conversion of object (maybe have rt_viper_store_name(obj, type))
762 vtype_kind_t vtype;
763 emit_pre_pop_reg(emit, &vtype, REG_ARG_2);
764 assert(vtype == VTYPE_PYOBJ);
765 emit_call_with_imm_arg(emit, RT_F_STORE_NAME, rt_store_name, qstr, REG_ARG_1); // arg1 = name
766 emit_post(emit);
767}
768
769static void emit_native_store_global(emit_t *emit, qstr qstr) {
770 // not implemented
771 assert(0);
772}
773
Damien13ed3a62013-10-08 09:05:10 +0100774static void emit_native_store_attr(emit_t *emit, qstr qstr) {
Damien7f5dacf2013-10-10 11:24:39 +0100775 vtype_kind_t vtype_base, vtype_val;
776 emit_pre_pop_reg_reg(emit, &vtype_base, REG_ARG_1, &vtype_val, REG_ARG_3); // arg1 = base, arg3 = value
777 assert(vtype_base == VTYPE_PYOBJ);
778 assert(vtype_val == VTYPE_PYOBJ);
779 emit_call_with_imm_arg(emit, RT_F_STORE_ATTR, rt_store_attr, qstr, REG_ARG_2); // arg2 = attribute name
780 emit_post(emit);
Damien13ed3a62013-10-08 09:05:10 +0100781}
782
Damien13ed3a62013-10-08 09:05:10 +0100783static void emit_native_store_subscr(emit_t *emit) {
784 // depends on type of subject:
785 // - integer, function, pointer to structure: error
786 // - pointer to integers: store as per array
787 // - Python object: call runtime with converted object or type info
788 vtype_kind_t vtype_index, vtype_base, vtype_value;
789 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
790 assert(vtype_index == VTYPE_PYOBJ);
791 assert(vtype_base == VTYPE_PYOBJ);
792 assert(vtype_value == VTYPE_PYOBJ);
793 emit_call(emit, RT_F_STORE_SUBSCR, rt_store_subscr);
794}
795
Damiena3977762013-10-09 23:10:10 +0100796static void emit_native_store_locals(emit_t *emit) {
797 // not needed
798 vtype_kind_t vtype;
799 emit_pre_pop_reg(emit, &vtype, REG_TEMP0);
800 emit_post(emit);
801}
802
Damien13ed3a62013-10-08 09:05:10 +0100803static void emit_native_delete_fast(emit_t *emit, qstr qstr, int local_num) {
804 // not implemented
805 // could support for Python types, just set to None (so GC can reclaim it)
806 assert(0);
807}
808
Damien9ecbcff2013-12-11 00:41:43 +0000809static void emit_native_delete_deref(emit_t *emit, qstr qstr, int local_num) {
810 // not supported
811 assert(0);
812}
813
Damien13ed3a62013-10-08 09:05:10 +0100814static void emit_native_delete_name(emit_t *emit, qstr qstr) {
815 // not implemented
816 // use rt_delete_name
817 assert(0);
818}
819
820static void emit_native_delete_global(emit_t *emit, qstr qstr) {
821 // not implemented
822 // use rt_delete_global
823 assert(0);
824}
825
Damien13ed3a62013-10-08 09:05:10 +0100826static void emit_native_delete_attr(emit_t *emit, qstr qstr) {
827 // not supported
828 assert(0);
829}
830
831static void emit_native_delete_subscr(emit_t *emit) {
832 // not supported
833 assert(0);
834}
835
836static void emit_native_dup_top(emit_t *emit) {
837 vtype_kind_t vtype;
838 emit_pre_pop_reg(emit, &vtype, REG_TEMP0);
839 emit_post_push_reg_reg(emit, vtype, REG_TEMP0, vtype, REG_TEMP0);
840}
841
842static void emit_native_dup_top_two(emit_t *emit) {
843 vtype_kind_t vtype0, vtype1;
844 emit_pre_pop_reg_reg(emit, &vtype0, REG_TEMP0, &vtype1, REG_TEMP1);
845 emit_post_push_reg_reg_reg_reg(emit, vtype1, REG_TEMP1, vtype0, REG_TEMP0, vtype1, REG_TEMP1, vtype0, REG_TEMP0);
846}
847
848static void emit_native_pop_top(emit_t *emit) {
849 vtype_kind_t vtype;
850 emit_pre_pop_reg(emit, &vtype, REG_TEMP0);
851 emit_post(emit);
852}
853
854static void emit_native_rot_two(emit_t *emit) {
Damienff8ed772013-10-08 22:18:32 +0100855 vtype_kind_t vtype0, vtype1;
856 emit_pre_pop_reg_reg(emit, &vtype0, REG_TEMP0, &vtype1, REG_TEMP1);
857 emit_post_push_reg_reg(emit, vtype0, REG_TEMP0, vtype1, REG_TEMP1);
Damien13ed3a62013-10-08 09:05:10 +0100858}
859
860static void emit_native_rot_three(emit_t *emit) {
861 vtype_kind_t vtype0, vtype1, vtype2;
862 emit_pre_pop_reg_reg_reg(emit, &vtype0, REG_TEMP0, &vtype1, REG_TEMP1, &vtype2, REG_TEMP2);
863 emit_post_push_reg_reg_reg(emit, vtype0, REG_TEMP0, vtype2, REG_TEMP2, vtype1, REG_TEMP1);
864}
865
866static void emit_native_jump(emit_t *emit, int label) {
867 emit_pre(emit);
Damien3ef4abb2013-10-12 16:53:13 +0100868#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100869 asm_x64_jmp_label(emit->as, label);
Damien3ef4abb2013-10-12 16:53:13 +0100870#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +0100871 asm_thumb_b_label(emit->as, label);
872#endif
873 emit_post(emit);
874}
875
Damien1a6633a2013-11-03 13:58:19 +0000876static void emit_native_pop_jump_pre_helper(emit_t *emit, int label) {
Damien13ed3a62013-10-08 09:05:10 +0100877 vtype_kind_t vtype = peek_vtype(emit);
878 if (vtype == VTYPE_BOOL) {
879 emit_pre_pop_reg(emit, &vtype, REG_RET);
880 } else if (vtype == VTYPE_PYOBJ) {
881 emit_pre_pop_reg(emit, &vtype, REG_ARG_1);
882 emit_call(emit, RT_F_IS_TRUE, rt_is_true);
883 } else {
884 printf("ViperTypeError: expecting a bool or pyobj, got %d\n", vtype);
885 assert(0);
886 }
Damien1a6633a2013-11-03 13:58:19 +0000887}
888
889static void emit_native_pop_jump_if_false(emit_t *emit, int label) {
890 emit_native_pop_jump_pre_helper(emit, label);
Damien3ef4abb2013-10-12 16:53:13 +0100891#if N_X64
Damien13ed3a62013-10-08 09:05:10 +0100892 asm_x64_test_r8_with_r8(emit->as, REG_RET, REG_RET);
893 asm_x64_jcc_label(emit->as, JCC_JZ, label);
Damien3ef4abb2013-10-12 16:53:13 +0100894#elif N_THUMB
Damien1a6633a2013-11-03 13:58:19 +0000895 asm_thumb_cmp_rlo_i8(emit->as, REG_RET, 0);
896 asm_thumb_bcc_label(emit->as, THUMB_CC_EQ, label);
Damien13ed3a62013-10-08 09:05:10 +0100897#endif
898 emit_post(emit);
899}
900
901static void emit_native_pop_jump_if_true(emit_t *emit, int label) {
Damien1a6633a2013-11-03 13:58:19 +0000902 emit_native_pop_jump_pre_helper(emit, label);
903#if N_X64
904 asm_x64_test_r8_with_r8(emit->as, REG_RET, REG_RET);
905 asm_x64_jcc_label(emit->as, JCC_JNZ, label);
906#elif N_THUMB
907 asm_thumb_cmp_rlo_i8(emit->as, REG_RET, 0);
908 asm_thumb_bcc_label(emit->as, THUMB_CC_NE, label);
909#endif
910 emit_post(emit);
Damien13ed3a62013-10-08 09:05:10 +0100911}
Damien1a6633a2013-11-03 13:58:19 +0000912
Damien13ed3a62013-10-08 09:05:10 +0100913static void emit_native_jump_if_true_or_pop(emit_t *emit, int label) {
914 assert(0);
915}
916static void emit_native_jump_if_false_or_pop(emit_t *emit, int label) {
917 assert(0);
918}
919
920static void emit_native_setup_loop(emit_t *emit, int label) {
921 emit_pre(emit);
922 emit_post(emit);
923}
924
925static void emit_native_break_loop(emit_t *emit, int label) {
Damien6ba13142013-11-02 20:34:54 +0000926 emit_native_jump(emit, label); // TODO properly
Damien13ed3a62013-10-08 09:05:10 +0100927}
928static void emit_native_continue_loop(emit_t *emit, int label) {
929 assert(0);
930}
931static void emit_native_setup_with(emit_t *emit, int label) {
932 // not supported, or could be with runtime call
933 assert(0);
934}
935static void emit_native_with_cleanup(emit_t *emit) {
936 assert(0);
937}
938static void emit_native_setup_except(emit_t *emit, int label) {
939 assert(0);
940}
941static void emit_native_setup_finally(emit_t *emit, int label) {
942 assert(0);
943}
944static void emit_native_end_finally(emit_t *emit) {
945 assert(0);
946}
Damiend2755ec2013-10-16 23:58:48 +0100947
Damien13ed3a62013-10-08 09:05:10 +0100948static void emit_native_get_iter(emit_t *emit) {
949 // perhaps the difficult one, as we want to rewrite for loops using native code
950 // in cases where we iterate over a Python object, can we use normal runtime calls?
Damiend2755ec2013-10-16 23:58:48 +0100951
952 vtype_kind_t vtype;
953 emit_pre_pop_reg(emit, &vtype, REG_ARG_1);
954 assert(vtype == VTYPE_PYOBJ);
955 emit_call(emit, RT_F_GETITER, rt_getiter);
956 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
Damien13ed3a62013-10-08 09:05:10 +0100957}
Damiend2755ec2013-10-16 23:58:48 +0100958
959static void emit_native_for_iter(emit_t *emit, int label) {
960 emit_pre(emit);
961 vtype_kind_t vtype;
962 emit_access_stack(emit, 1, &vtype, REG_ARG_1);
963 assert(vtype == VTYPE_PYOBJ);
964 emit_call(emit, RT_F_ITERNEXT, rt_iternext);
Damiend99b0522013-12-21 18:17:45 +0000965 ASM_MOV_IMM_TO_REG((machine_uint_t)mp_const_stop_iteration, REG_TEMP1);
Damiend2755ec2013-10-16 23:58:48 +0100966#if N_X64
967 asm_x64_cmp_r64_with_r64(emit->as, REG_RET, REG_TEMP1);
968 asm_x64_jcc_label(emit->as, JCC_JE, label);
969#elif N_THUMB
Damiend2755ec2013-10-16 23:58:48 +0100970 asm_thumb_cmp_reg_reg(emit->as, REG_RET, REG_TEMP1);
Damien9b9e9962013-11-03 14:25:43 +0000971 asm_thumb_bcc_label(emit->as, THUMB_CC_EQ, label);
Damiend2755ec2013-10-16 23:58:48 +0100972#endif
973 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
974}
975
Damien13ed3a62013-10-08 09:05:10 +0100976static void emit_native_for_iter_end(emit_t *emit) {
Damiend2755ec2013-10-16 23:58:48 +0100977 // adjust stack counter (we get here from for_iter ending, which popped the value for us)
978 emit_pre(emit);
979 adjust_stack(emit, -1);
980 emit_post(emit);
Damien13ed3a62013-10-08 09:05:10 +0100981}
982
983static void emit_native_pop_block(emit_t *emit) {
984 emit_pre(emit);
985 emit_post(emit);
986}
987
988static void emit_native_pop_except(emit_t *emit) {
989 assert(0);
990}
991
992static void emit_native_unary_op(emit_t *emit, rt_unary_op_t op) {
993 vtype_kind_t vtype;
994 emit_pre_pop_reg(emit, &vtype, REG_ARG_2);
995 assert(vtype == VTYPE_PYOBJ);
996 emit_call_with_imm_arg(emit, RT_F_UNARY_OP, rt_unary_op, op, REG_ARG_1);
997 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
998}
999
1000static void emit_native_binary_op(emit_t *emit, rt_binary_op_t op) {
1001 vtype_kind_t vtype_lhs, vtype_rhs;
1002 emit_pre_pop_reg_reg(emit, &vtype_rhs, REG_ARG_3, &vtype_lhs, REG_ARG_2);
1003 if (vtype_lhs == VTYPE_INT && vtype_rhs == VTYPE_INT) {
Damien Georgebc1d3692014-01-11 09:47:06 +00001004 if (op == RT_BINARY_OP_ADD || op == RT_BINARY_OP_INPLACE_ADD) {
Damien3ef4abb2013-10-12 16:53:13 +01001005#if N_X64
Damien Georgebc1d3692014-01-11 09:47:06 +00001006 asm_x64_add_r64_to_r64(emit->as, REG_ARG_3, REG_ARG_2);
Damien3ef4abb2013-10-12 16:53:13 +01001007#elif N_THUMB
Damien Georgebc1d3692014-01-11 09:47:06 +00001008 asm_thumb_add_reg_reg_reg(emit->as, REG_ARG_2, REG_ARG_2, REG_ARG_3);
Damien13ed3a62013-10-08 09:05:10 +01001009#endif
Damien Georgebc1d3692014-01-11 09:47:06 +00001010 emit_post_push_reg(emit, VTYPE_INT, REG_ARG_2);
1011 } else if (op == RT_COMPARE_OP_LESS) {
1012#if N_X64
1013 asm_x64_xor_r64_to_r64(emit->as, REG_RET, REG_RET);
1014 asm_x64_cmp_r64_with_r64(emit->as, REG_ARG_3, REG_ARG_2);
1015 asm_x64_setcc_r8(emit->as, JCC_JL, REG_RET);
1016#elif N_THUMB
1017 asm_thumb_cmp_reg_reg(emit->as, REG_ARG_2, REG_ARG_3);
1018 asm_thumb_ite_ge(emit->as);
1019 asm_thumb_movs_rlo_i8(emit->as, REG_RET, 0); // if r0 >= r1
1020 asm_thumb_movs_rlo_i8(emit->as, REG_RET, 1); // if r0 < r1
1021#endif
1022 emit_post_push_reg(emit, VTYPE_BOOL, REG_RET);
1023 } else {
1024 // TODO other ops not yet implemented
1025 assert(0);
1026 }
Damien13ed3a62013-10-08 09:05:10 +01001027 } else if (vtype_lhs == VTYPE_PYOBJ && vtype_rhs == VTYPE_PYOBJ) {
1028 emit_call_with_imm_arg(emit, RT_F_BINARY_OP, rt_binary_op, op, REG_ARG_1);
1029 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
1030 } else {
1031 printf("ViperTypeError: can't do binary op between types %d and %d\n", vtype_lhs, vtype_rhs);
1032 assert(0);
1033 }
1034}
1035
Damien13ed3a62013-10-08 09:05:10 +01001036static void emit_native_build_tuple(emit_t *emit, int n_args) {
Damiend2755ec2013-10-16 23:58:48 +01001037 // for viper: call runtime, with types of args
1038 // if wrapped in byte_array, or something, allocates memory and fills it
1039 emit_pre(emit);
1040 emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, n_args); // pointer to items in reverse order
1041 emit_call_with_imm_arg(emit, RT_F_BUILD_TUPLE, rt_build_tuple, n_args, REG_ARG_1);
1042 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new tuple
Damien13ed3a62013-10-08 09:05:10 +01001043}
1044
1045static void emit_native_build_list(emit_t *emit, int n_args) {
1046 emit_pre(emit);
1047 emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, n_args); // pointer to items in reverse order
1048 emit_call_with_imm_arg(emit, RT_F_BUILD_LIST, rt_build_list, n_args, REG_ARG_1);
1049 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new list
1050}
1051
1052static void emit_native_list_append(emit_t *emit, int list_index) {
Damiend2755ec2013-10-16 23:58:48 +01001053 // only used in list comprehension
1054 vtype_kind_t vtype_list, vtype_item;
1055 emit_pre_pop_reg(emit, &vtype_item, REG_ARG_2);
1056 emit_access_stack(emit, list_index, &vtype_list, REG_ARG_1);
1057 assert(vtype_list == VTYPE_PYOBJ);
1058 assert(vtype_item == VTYPE_PYOBJ);
1059 emit_call(emit, RT_F_LIST_APPEND, rt_list_append);
1060 emit_post(emit);
Damien13ed3a62013-10-08 09:05:10 +01001061}
1062
1063static void emit_native_build_map(emit_t *emit, int n_args) {
1064 emit_pre(emit);
1065 emit_call_with_imm_arg(emit, RT_F_BUILD_MAP, rt_build_map, n_args, REG_ARG_1);
1066 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new map
1067}
1068
1069static void emit_native_store_map(emit_t *emit) {
1070 vtype_kind_t vtype_key, vtype_value, vtype_map;
1071 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
1072 assert(vtype_key == VTYPE_PYOBJ);
1073 assert(vtype_value == VTYPE_PYOBJ);
1074 assert(vtype_map == VTYPE_PYOBJ);
1075 emit_call(emit, RT_F_STORE_MAP, rt_store_map);
1076 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // map
1077}
1078
1079static void emit_native_map_add(emit_t *emit, int map_index) {
Damiend2755ec2013-10-16 23:58:48 +01001080 // only used in list comprehension
1081 vtype_kind_t vtype_map, vtype_key, vtype_value;
1082 emit_pre_pop_reg_reg(emit, &vtype_key, REG_ARG_2, &vtype_value, REG_ARG_3);
1083 emit_access_stack(emit, map_index, &vtype_map, REG_ARG_1);
1084 assert(vtype_map == VTYPE_PYOBJ);
1085 assert(vtype_key == VTYPE_PYOBJ);
1086 assert(vtype_value == VTYPE_PYOBJ);
1087 emit_call(emit, RT_F_STORE_MAP, rt_store_map);
1088 emit_post(emit);
Damien13ed3a62013-10-08 09:05:10 +01001089}
1090
1091static void emit_native_build_set(emit_t *emit, int n_args) {
1092 emit_pre(emit);
1093 emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, n_args); // pointer to items in reverse order
1094 emit_call_with_imm_arg(emit, RT_F_BUILD_SET, rt_build_set, n_args, REG_ARG_1);
1095 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new set
1096}
1097
1098static void emit_native_set_add(emit_t *emit, int set_index) {
Damiend2755ec2013-10-16 23:58:48 +01001099 // only used in set comprehension
1100 vtype_kind_t vtype_set, vtype_item;
1101 emit_pre_pop_reg(emit, &vtype_item, REG_ARG_2);
1102 emit_access_stack(emit, set_index, &vtype_set, REG_ARG_1);
1103 assert(vtype_set == VTYPE_PYOBJ);
1104 assert(vtype_item == VTYPE_PYOBJ);
1105 emit_call(emit, RT_F_STORE_SET, rt_store_set);
1106 emit_post(emit);
Damien13ed3a62013-10-08 09:05:10 +01001107}
Damiend2755ec2013-10-16 23:58:48 +01001108
Damien13ed3a62013-10-08 09:05:10 +01001109static void emit_native_build_slice(emit_t *emit, int n_args) {
1110 assert(0);
1111}
1112static void emit_native_unpack_sequence(emit_t *emit, int n_args) {
1113 // call runtime, needs type decl
1114 assert(0);
1115}
1116static void emit_native_unpack_ex(emit_t *emit, int n_left, int n_right) {
1117 assert(0);
1118}
1119
1120static void emit_native_make_function(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) {
1121 // call runtime, with type info for args, or don't support dict/default params, or only support Python objects for them
1122 assert(n_default_params == 0 && n_dict_params == 0);
1123 emit_pre(emit);
1124 emit_call_with_imm_arg(emit, RT_F_MAKE_FUNCTION_FROM_ID, rt_make_function_from_id, scope->unique_code_id, REG_ARG_1);
1125 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
1126}
1127
1128static void emit_native_make_closure(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) {
1129 assert(0);
1130}
1131
1132static void emit_native_call_function(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) {
1133 // call special viper runtime routine with type info for args, and wanted type info for return
1134 assert(n_keyword == 0 && !have_star_arg && !have_dbl_star_arg);
Damieneb19efb2013-10-10 22:06:54 +01001135 /*
Damien13ed3a62013-10-08 09:05:10 +01001136 if (n_positional == 0) {
1137 vtype_kind_t vtype_fun;
1138 emit_pre_pop_reg(emit, &vtype_fun, REG_ARG_1); // the function
1139 assert(vtype_fun == VTYPE_PYOBJ);
1140 emit_call(emit, RT_F_CALL_FUNCTION_0, rt_call_function_0);
1141 } else if (n_positional == 1) {
1142 vtype_kind_t vtype_fun, vtype_arg1;
1143 emit_pre_pop_reg_reg(emit, &vtype_arg1, REG_ARG_2, &vtype_fun, REG_ARG_1); // the single argument, the function
1144 assert(vtype_fun == VTYPE_PYOBJ);
1145 assert(vtype_arg1 == VTYPE_PYOBJ);
1146 emit_call(emit, RT_F_CALL_FUNCTION_1, rt_call_function_1);
1147 } else if (n_positional == 2) {
1148 vtype_kind_t vtype_fun, vtype_arg1, vtype_arg2;
1149 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
1150 assert(vtype_fun == VTYPE_PYOBJ);
1151 assert(vtype_arg1 == VTYPE_PYOBJ);
1152 assert(vtype_arg2 == VTYPE_PYOBJ);
1153 emit_call(emit, RT_F_CALL_FUNCTION_2, rt_call_function_2);
1154 } else {
Damieneb19efb2013-10-10 22:06:54 +01001155 */
1156 emit_pre(emit);
1157 if (n_positional != 0) {
1158 emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_3, n_positional); // pointer to args in reverse order
1159 }
1160 vtype_kind_t vtype_fun;
1161 emit_pre_pop_reg(emit, &vtype_fun, REG_ARG_1); // the function
1162 assert(vtype_fun == VTYPE_PYOBJ);
Damien George20006db2014-01-18 14:10:48 +00001163 // XXX rt_call_function_n now merged with rt_call_function_n_kw
1164 //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 +01001165 //}
Damien13ed3a62013-10-08 09:05:10 +01001166 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
1167}
1168
1169static void emit_native_call_method(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) {
1170 assert(n_keyword == 0 && !have_star_arg && !have_dbl_star_arg);
Damieneb19efb2013-10-10 22:06:54 +01001171 /*
Damien13ed3a62013-10-08 09:05:10 +01001172 if (n_positional == 0) {
1173 vtype_kind_t vtype_meth, vtype_self;
1174 emit_pre_pop_reg_reg(emit, &vtype_self, REG_ARG_2, &vtype_meth, REG_ARG_1); // the self object (or NULL), the method
1175 assert(vtype_meth == VTYPE_PYOBJ);
1176 assert(vtype_self == VTYPE_PYOBJ);
1177 emit_call(emit, RT_F_CALL_METHOD_1, rt_call_method_1);
1178 } else if (n_positional == 1) {
1179 vtype_kind_t vtype_meth, vtype_self, vtype_arg1;
1180 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
1181 assert(vtype_meth == VTYPE_PYOBJ);
1182 assert(vtype_self == VTYPE_PYOBJ);
1183 assert(vtype_arg1 == VTYPE_PYOBJ);
1184 emit_call(emit, RT_F_CALL_METHOD_2, rt_call_method_2);
1185 } else {
Damieneb19efb2013-10-10 22:06:54 +01001186 */
Damien7f5dacf2013-10-10 11:24:39 +01001187 emit_pre(emit);
1188 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 +00001189 // XXX rt_call_method_n now merged with rt_call_method_n_kw
1190 //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 +01001191 //}
Damien13ed3a62013-10-08 09:05:10 +01001192 emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
1193}
1194
1195static void emit_native_return_value(emit_t *emit) {
1196 // easy. since we don't know who we return to, just return the raw value.
1197 // runtime needs then to know our type signature, but I think that's possible.
1198 vtype_kind_t vtype;
1199 emit_pre_pop_reg(emit, &vtype, REG_RET);
1200 if (emit->do_viper_types) {
1201 assert(vtype == VTYPE_PTR_NONE);
1202 } else {
1203 assert(vtype == VTYPE_PYOBJ);
1204 }
1205 emit->last_emit_was_return_value = true;
Damien3ef4abb2013-10-12 16:53:13 +01001206#if N_X64
Damien13ed3a62013-10-08 09:05:10 +01001207 //asm_x64_call_ind(emit->as, 0, REG_RAX); to seg fault for debugging with gdb
1208 asm_x64_exit(emit->as);
Damien3ef4abb2013-10-12 16:53:13 +01001209#elif N_THUMB
Damien13ed3a62013-10-08 09:05:10 +01001210 //asm_thumb_call_ind(emit->as, 0, REG_R0); to seg fault for debugging with gdb
1211 asm_thumb_exit(emit->as);
1212#endif
1213}
1214
1215static void emit_native_raise_varargs(emit_t *emit, int n_args) {
1216 // call runtime
1217 assert(0);
1218}
1219static void emit_native_yield_value(emit_t *emit) {
1220 // not supported (for now)
1221 assert(0);
1222}
1223static void emit_native_yield_from(emit_t *emit) {
1224 // not supported (for now)
1225 assert(0);
1226}
1227
1228const emit_method_table_t EXPORT_FUN(method_table) = {
1229 emit_native_set_viper_types,
1230 emit_native_start_pass,
1231 emit_native_end_pass,
1232 emit_native_last_emit_was_return_value,
1233 emit_native_get_stack_size,
1234 emit_native_set_stack_size,
Damien George08335002014-01-18 23:24:36 +00001235 emit_native_set_source_line,
Damien13ed3a62013-10-08 09:05:10 +01001236
1237 emit_native_load_id,
1238 emit_native_store_id,
1239 emit_native_delete_id,
1240
1241 emit_native_label_assign,
1242 emit_native_import_name,
1243 emit_native_import_from,
1244 emit_native_import_star,
1245 emit_native_load_const_tok,
1246 emit_native_load_const_small_int,
1247 emit_native_load_const_int,
1248 emit_native_load_const_dec,
1249 emit_native_load_const_id,
1250 emit_native_load_const_str,
Damien13ed3a62013-10-08 09:05:10 +01001251 emit_native_load_const_verbatim_str,
Damien13ed3a62013-10-08 09:05:10 +01001252 emit_native_load_fast,
Damien13ed3a62013-10-08 09:05:10 +01001253 emit_native_load_deref,
1254 emit_native_load_closure,
Damien9ecbcff2013-12-11 00:41:43 +00001255 emit_native_load_name,
1256 emit_native_load_global,
Damien13ed3a62013-10-08 09:05:10 +01001257 emit_native_load_attr,
1258 emit_native_load_method,
1259 emit_native_load_build_class,
1260 emit_native_store_fast,
Damien9ecbcff2013-12-11 00:41:43 +00001261 emit_native_store_deref,
Damien13ed3a62013-10-08 09:05:10 +01001262 emit_native_store_name,
1263 emit_native_store_global,
Damien13ed3a62013-10-08 09:05:10 +01001264 emit_native_store_attr,
Damien13ed3a62013-10-08 09:05:10 +01001265 emit_native_store_subscr,
Damiena3977762013-10-09 23:10:10 +01001266 emit_native_store_locals,
Damien13ed3a62013-10-08 09:05:10 +01001267 emit_native_delete_fast,
Damien9ecbcff2013-12-11 00:41:43 +00001268 emit_native_delete_deref,
Damien13ed3a62013-10-08 09:05:10 +01001269 emit_native_delete_name,
1270 emit_native_delete_global,
Damien13ed3a62013-10-08 09:05:10 +01001271 emit_native_delete_attr,
1272 emit_native_delete_subscr,
1273 emit_native_dup_top,
1274 emit_native_dup_top_two,
1275 emit_native_pop_top,
1276 emit_native_rot_two,
1277 emit_native_rot_three,
1278 emit_native_jump,
1279 emit_native_pop_jump_if_true,
1280 emit_native_pop_jump_if_false,
1281 emit_native_jump_if_true_or_pop,
1282 emit_native_jump_if_false_or_pop,
1283 emit_native_setup_loop,
1284 emit_native_break_loop,
1285 emit_native_continue_loop,
1286 emit_native_setup_with,
1287 emit_native_with_cleanup,
1288 emit_native_setup_except,
1289 emit_native_setup_finally,
1290 emit_native_end_finally,
1291 emit_native_get_iter,
1292 emit_native_for_iter,
1293 emit_native_for_iter_end,
1294 emit_native_pop_block,
1295 emit_native_pop_except,
1296 emit_native_unary_op,
1297 emit_native_binary_op,
Damien13ed3a62013-10-08 09:05:10 +01001298 emit_native_build_tuple,
1299 emit_native_build_list,
1300 emit_native_list_append,
1301 emit_native_build_map,
1302 emit_native_store_map,
1303 emit_native_map_add,
1304 emit_native_build_set,
1305 emit_native_set_add,
1306 emit_native_build_slice,
1307 emit_native_unpack_sequence,
1308 emit_native_unpack_ex,
1309 emit_native_make_function,
1310 emit_native_make_closure,
1311 emit_native_call_function,
1312 emit_native_call_method,
1313 emit_native_return_value,
1314 emit_native_raise_varargs,
1315 emit_native_yield_value,
1316 emit_native_yield_from,
1317};
1318
Damien Georgee67ed5d2014-01-04 13:55:24 +00001319#endif // (MICROPY_EMIT_X64 && N_X64) || (MICROPY_EMIT_THUMB && N_THUMB)