Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1 | // 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" |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 27 | #include "mpconfig.h" |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 28 | #include "lexer.h" |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 29 | #include "parse.h" |
| 30 | #include "scope.h" |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 31 | #include "runtime0.h" |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 32 | #include "emit.h" |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 33 | #include "obj.h" |
| 34 | #include "runtime.h" |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 35 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 36 | // wrapper around everything in this file |
Damien George | e67ed5d | 2014-01-04 13:55:24 +0000 | [diff] [blame] | 37 | #if (MICROPY_EMIT_X64 && N_X64) || (MICROPY_EMIT_THUMB && N_THUMB) |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 38 | |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 39 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 40 | |
| 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)) |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 55 | #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) |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 56 | #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 | |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 60 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 61 | |
| 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)) |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 78 | #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) |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 79 | #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 | |
| 85 | typedef enum { |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 86 | STACK_VALUE, |
| 87 | STACK_REG, |
| 88 | STACK_IMM, |
| 89 | } stack_info_kind_t; |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 90 | |
| 91 | typedef 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 | |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 101 | typedef 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 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 110 | struct _emit_t { |
| 111 | int pass; |
| 112 | |
| 113 | bool do_viper_types; |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 114 | |
| 115 | int local_vtype_alloc; |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 116 | vtype_kind_t *local_vtype; |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 117 | |
| 118 | int stack_info_alloc; |
| 119 | stack_info_t *stack_info; |
| 120 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 121 | int stack_start; |
| 122 | int stack_size; |
| 123 | |
| 124 | bool last_emit_was_return_value; |
| 125 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 126 | scope_t *scope; |
| 127 | |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 128 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 129 | asm_x64_t *as; |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 130 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 131 | asm_thumb_t *as; |
| 132 | #endif |
| 133 | }; |
| 134 | |
| 135 | emit_t *EXPORT_FUN(new)(uint max_num_labels) { |
| 136 | emit_t *emit = m_new(emit_t, 1); |
| 137 | emit->do_viper_types = false; |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 138 | emit->local_vtype = NULL; |
| 139 | emit->stack_info = NULL; |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 140 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 141 | emit->as = asm_x64_new(max_num_labels); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 142 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 143 | emit->as = asm_thumb_new(max_num_labels); |
| 144 | #endif |
| 145 | return emit; |
| 146 | } |
| 147 | |
| 148 | static void emit_native_set_viper_types(emit_t *emit, bool do_viper_types) { |
| 149 | emit->do_viper_types = do_viper_types; |
| 150 | } |
| 151 | |
| 152 | static 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; |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 157 | emit->scope = scope; |
| 158 | |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 159 | 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); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | if (emit->do_viper_types) { |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 169 | // TODO set types of arguments based on type signature |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 170 | 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 | } |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 177 | } else { |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 178 | 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; |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 184 | } |
| 185 | } |
| 186 | |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 187 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 188 | asm_x64_start_pass(emit->as, pass); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 189 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 190 | 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 | } |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 203 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 204 | asm_x64_entry(emit->as, num_locals); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 205 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 206 | asm_thumb_entry(emit->as, num_locals); |
| 207 | #endif |
| 208 | |
| 209 | // initialise locals from parameters |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 210 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 211 | 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 | } |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 223 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 224 | 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 | |
| 243 | static void emit_native_end_pass(emit_t *emit) { |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 244 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 245 | if (!emit->last_emit_was_return_value) { |
| 246 | asm_x64_exit(emit->as); |
| 247 | } |
| 248 | asm_x64_end_pass(emit->as); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 249 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 250 | 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) { |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 262 | #if N_X64 |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 263 | void *f = asm_x64_get_code(emit->as); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 264 | rt_assign_native_code(emit->scope->unique_code_id, f, asm_x64_get_code_size(emit->as), emit->scope->num_params); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 265 | #elif N_THUMB |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 266 | void *f = asm_thumb_get_code(emit->as); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 267 | 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 | |
| 272 | static bool emit_native_last_emit_was_return_value(emit_t *emit) { |
| 273 | return emit->last_emit_was_return_value; |
| 274 | } |
| 275 | |
| 276 | static int emit_native_get_stack_size(emit_t *emit) { |
| 277 | return emit->stack_size; |
| 278 | } |
| 279 | |
| 280 | static void emit_native_set_stack_size(emit_t *emit, int size) { |
| 281 | emit->stack_size = size; |
| 282 | } |
| 283 | |
| 284 | static 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 | |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 292 | /* |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 293 | static 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 | } |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 297 | */ |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 298 | |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 299 | // this must be called at start of emit functions |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 300 | static void emit_pre(emit_t *emit) { |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 301 | 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 | */ |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | static vtype_kind_t peek_vtype(emit_t *emit) { |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 327 | return emit->stack_info[emit->stack_size - 1].vtype; |
| 328 | } |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 329 | |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 330 | // pos=1 is TOS, pos=2 is next, etc |
| 331 | // use pos=0 for no skipping |
| 332 | static void need_reg_single(emit_t *emit, int reg_needed, int skip_stack_pos) { |
| 333 | skip_stack_pos = emit->stack_size - skip_stack_pos; |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 334 | for (int i = 0; i < emit->stack_size; i++) { |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 335 | 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 | } |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | } |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 344 | |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 345 | static void need_reg_all(emit_t *emit) { |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 346 | 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 | } |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 352 | } |
| 353 | } |
| 354 | |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 355 | static 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 |
| 372 | static 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]; |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 375 | *vtype = si->vtype; |
| 376 | switch (si->kind) { |
| 377 | case STACK_VALUE: |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 378 | ASM_MOV_LOCAL_TO_REG(emit->stack_start + emit->stack_size - pos, reg_dest); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 379 | break; |
| 380 | |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 381 | case STACK_REG: |
| 382 | if (si->u_reg != reg_dest) { |
| 383 | ASM_MOV_REG_TO_REG(si->u_reg, reg_dest); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 384 | } |
| 385 | break; |
| 386 | |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 387 | case STACK_IMM: |
| 388 | ASM_MOV_IMM_TO_REG(si->u_imm, reg_dest); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 389 | break; |
| 390 | } |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 391 | } |
| 392 | |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 393 | static 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 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 399 | static 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); |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 401 | emit_pre_pop_reg(emit, vtypeb, regb); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | static 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); |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 406 | emit_pre_pop_reg(emit, vtypeb, regb); |
| 407 | emit_pre_pop_reg(emit, vtypec, regc); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | static void emit_post(emit_t *emit) { |
| 411 | } |
| 412 | |
| 413 | static void emit_post_push_reg(emit_t *emit, vtype_kind_t vtype, int reg) { |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 414 | stack_info_t *si = &emit->stack_info[emit->stack_size]; |
| 415 | si->vtype = vtype; |
| 416 | si->kind = STACK_REG; |
| 417 | si->u_reg = reg; |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 418 | adjust_stack(emit, 1); |
| 419 | } |
| 420 | |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 421 | static 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 | |
| 429 | static 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 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 434 | static 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) { |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 435 | emit_post_push_reg(emit, vtypea, rega); |
| 436 | emit_post_push_reg(emit, vtypeb, regb); |
| 437 | emit_post_push_reg(emit, vtypec, regc); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | static 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) { |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 441 | 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); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | // vtype of all n_pop objects is VTYPE_PYOBJ |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 448 | // does not use any temporary registers (but may use reg_dest before loading it with stack pointer) |
Damien | 6d4f346 | 2013-11-16 20:44:39 +0000 | [diff] [blame] | 449 | // TODO this needs some thinking for viper code |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 450 | static void emit_get_stack_pointer_to_reg_for_pop(emit_t *emit, int reg_dest, int n_pop) { |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 451 | need_reg_all(emit); |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 452 | for (int i = 0; i < n_pop; i++) { |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 453 | stack_info_t *si = &emit->stack_info[emit->stack_size - 1 - i]; |
| 454 | // must push any imm's to stack |
Damien | 6d4f346 | 2013-11-16 20:44:39 +0000 | [diff] [blame] | 455 | // must convert them to VTYPE_PYOBJ for viper code |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 456 | if (si->kind == STACK_IMM) { |
| 457 | si->kind = STACK_VALUE; |
Damien | 6d4f346 | 2013-11-16 20:44:39 +0000 | [diff] [blame] | 458 | 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) { |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 465 | ASM_MOV_IMM_TO_LOCAL_USING((machine_uint_t)mp_const_false, emit->stack_start + emit->stack_size - 1 - i, reg_dest); |
Damien | 6d4f346 | 2013-11-16 20:44:39 +0000 | [diff] [blame] | 466 | } else { |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 467 | ASM_MOV_IMM_TO_LOCAL_USING((machine_uint_t)mp_const_true, emit->stack_start + emit->stack_size - 1 - i, reg_dest); |
Damien | 6d4f346 | 2013-11-16 20:44:39 +0000 | [diff] [blame] | 468 | } |
| 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 | } |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 478 | } |
| 479 | assert(si->kind == STACK_VALUE); |
| 480 | assert(si->vtype == VTYPE_PYOBJ); |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 481 | } |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 482 | 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 |
| 487 | static void emit_get_stack_pointer_to_reg_for_push(emit_t *emit, int reg_dest, int n_push) { |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 488 | need_reg_all(emit); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 489 | for (int i = 0; i < n_push; i++) { |
Damien | 7f5dacf | 2013-10-10 11:24:39 +0100 | [diff] [blame] | 490 | emit->stack_info[emit->stack_size + i].kind = STACK_VALUE; |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 491 | emit->stack_info[emit->stack_size + i].vtype = VTYPE_PYOBJ; |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 492 | } |
| 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 | |
| 497 | static void emit_call(emit_t *emit, rt_fun_kind_t fun_kind, void *fun) { |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 498 | need_reg_all(emit); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 499 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 500 | asm_x64_call_ind(emit->as, fun, REG_RAX); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 501 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 502 | asm_thumb_bl_ind(emit->as, rt_fun_table[fun_kind], fun_kind, REG_R3); |
| 503 | #endif |
| 504 | } |
| 505 | |
| 506 | static 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) { |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 507 | need_reg_all(emit); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 508 | ASM_MOV_IMM_TO_REG(arg_val, arg_reg); |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 509 | #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 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | static void emit_native_load_id(emit_t *emit, qstr qstr) { |
| 517 | // check for built-ins |
| 518 | if (strcmp(qstr_str(qstr), "v_int") == 0) { |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 519 | assert(0); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 520 | 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 | |
| 529 | static 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 | |
| 534 | static 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 | |
| 539 | static void emit_native_label_assign(emit_t *emit, int l) { |
Damien | 6ba1314 | 2013-11-02 20:34:54 +0000 | [diff] [blame] | 540 | emit_pre(emit); |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 541 | // need to commit stack because we can jump here from elsewhere |
| 542 | need_stack_settled(emit); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 543 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 544 | asm_x64_label_assign(emit->as, l); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 545 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 546 | asm_thumb_label_assign(emit->as, l); |
| 547 | #endif |
Damien | 6ba1314 | 2013-11-02 20:34:54 +0000 | [diff] [blame] | 548 | emit_post(emit); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | static void emit_native_import_name(emit_t *emit, qstr qstr) { |
| 552 | // not implemented |
| 553 | assert(0); |
| 554 | } |
| 555 | |
| 556 | static void emit_native_import_from(emit_t *emit, qstr qstr) { |
| 557 | // not implemented |
| 558 | assert(0); |
| 559 | } |
| 560 | |
| 561 | static void emit_native_import_star(emit_t *emit) { |
| 562 | // not implemented |
| 563 | assert(0); |
| 564 | } |
| 565 | |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 566 | static void emit_native_load_const_tok(emit_t *emit, mp_token_kind_t tok) { |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 567 | emit_pre(emit); |
| 568 | int vtype; |
| 569 | machine_uint_t val; |
| 570 | if (emit->do_viper_types) { |
| 571 | switch (tok) { |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 572 | 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; |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 575 | default: assert(0); vtype = 0; val = 0; // shouldn't happen |
| 576 | } |
| 577 | } else { |
| 578 | vtype = VTYPE_PYOBJ; |
| 579 | switch (tok) { |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 580 | 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; |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 583 | default: assert(0); vtype = 0; val = 0; // shouldn't happen |
| 584 | } |
| 585 | } |
| 586 | emit_post_push_imm(emit, vtype, val); |
| 587 | } |
| 588 | |
| 589 | static 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 | |
| 598 | static 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 | |
| 604 | static void emit_native_load_const_dec(emit_t *emit, qstr qstr) { |
Damien | 6ba1314 | 2013-11-02 20:34:54 +0000 | [diff] [blame] | 605 | // 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); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | static void emit_native_load_const_id(emit_t *emit, qstr qstr) { |
Damien | 7f5dacf | 2013-10-10 11:24:39 +0100 | [diff] [blame] | 612 | 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 | } |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | static 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 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 634 | static void emit_native_load_const_verbatim_str(emit_t *emit, const char *str) { |
| 635 | // not supported/needed for viper |
| 636 | assert(0); |
| 637 | } |
| 638 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 639 | static 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); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 645 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 646 | if (local_num == 0) { |
| 647 | emit_post_push_reg(emit, vtype, REG_LOCAL_1); |
| 648 | } else { |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 649 | need_reg_single(emit, REG_RAX, 0); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 650 | asm_x64_mov_local_to_r64(emit->as, local_num - 1, REG_RAX); |
| 651 | emit_post_push_reg(emit, vtype, REG_RAX); |
| 652 | } |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 653 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 654 | 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 { |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 661 | need_reg_single(emit, REG_R0, 0); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 662 | 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 | |
Damien | 9ecbcff | 2013-12-11 00:41:43 +0000 | [diff] [blame] | 668 | static 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 | |
| 674 | static void emit_native_load_closure(emit_t *emit, qstr qstr, int local_num) { |
| 675 | // not implemented |
| 676 | assert(0); |
| 677 | } |
| 678 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 679 | static 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 | |
| 685 | static 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 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 691 | static 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 | |
| 703 | static 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 | |
| 711 | static void emit_native_load_build_class(emit_t *emit) { |
Damien | 7f5dacf | 2013-10-10 11:24:39 +0100 | [diff] [blame] | 712 | 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); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | static void emit_native_store_fast(emit_t *emit, qstr qstr, int local_num) { |
| 718 | vtype_kind_t vtype; |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 719 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 720 | 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 | } |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 726 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 727 | 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 | |
Damien | 9ecbcff | 2013-12-11 00:41:43 +0000 | [diff] [blame] | 751 | static void emit_native_store_deref(emit_t *emit, qstr qstr, int local_num) { |
| 752 | // not implemented |
| 753 | assert(0); |
| 754 | } |
| 755 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 756 | static 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 | |
| 765 | static void emit_native_store_global(emit_t *emit, qstr qstr) { |
| 766 | // not implemented |
| 767 | assert(0); |
| 768 | } |
| 769 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 770 | static void emit_native_store_attr(emit_t *emit, qstr qstr) { |
Damien | 7f5dacf | 2013-10-10 11:24:39 +0100 | [diff] [blame] | 771 | 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); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 777 | } |
| 778 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 779 | static 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 | |
Damien | a397776 | 2013-10-09 23:10:10 +0100 | [diff] [blame] | 792 | static 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 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 799 | static 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 | |
Damien | 9ecbcff | 2013-12-11 00:41:43 +0000 | [diff] [blame] | 805 | static void emit_native_delete_deref(emit_t *emit, qstr qstr, int local_num) { |
| 806 | // not supported |
| 807 | assert(0); |
| 808 | } |
| 809 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 810 | static void emit_native_delete_name(emit_t *emit, qstr qstr) { |
| 811 | // not implemented |
| 812 | // use rt_delete_name |
| 813 | assert(0); |
| 814 | } |
| 815 | |
| 816 | static void emit_native_delete_global(emit_t *emit, qstr qstr) { |
| 817 | // not implemented |
| 818 | // use rt_delete_global |
| 819 | assert(0); |
| 820 | } |
| 821 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 822 | static void emit_native_delete_attr(emit_t *emit, qstr qstr) { |
| 823 | // not supported |
| 824 | assert(0); |
| 825 | } |
| 826 | |
| 827 | static void emit_native_delete_subscr(emit_t *emit) { |
| 828 | // not supported |
| 829 | assert(0); |
| 830 | } |
| 831 | |
| 832 | static 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 | |
| 838 | static 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 | |
| 844 | static 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 | |
| 850 | static void emit_native_rot_two(emit_t *emit) { |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 851 | 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); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | static 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 | |
| 862 | static void emit_native_jump(emit_t *emit, int label) { |
| 863 | emit_pre(emit); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 864 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 865 | asm_x64_jmp_label(emit->as, label); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 866 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 867 | asm_thumb_b_label(emit->as, label); |
| 868 | #endif |
| 869 | emit_post(emit); |
| 870 | } |
| 871 | |
Damien | 1a6633a | 2013-11-03 13:58:19 +0000 | [diff] [blame] | 872 | static void emit_native_pop_jump_pre_helper(emit_t *emit, int label) { |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 873 | 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 | } |
Damien | 1a6633a | 2013-11-03 13:58:19 +0000 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | static void emit_native_pop_jump_if_false(emit_t *emit, int label) { |
| 886 | emit_native_pop_jump_pre_helper(emit, label); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 887 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 888 | asm_x64_test_r8_with_r8(emit->as, REG_RET, REG_RET); |
| 889 | asm_x64_jcc_label(emit->as, JCC_JZ, label); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 890 | #elif N_THUMB |
Damien | 1a6633a | 2013-11-03 13:58:19 +0000 | [diff] [blame] | 891 | asm_thumb_cmp_rlo_i8(emit->as, REG_RET, 0); |
| 892 | asm_thumb_bcc_label(emit->as, THUMB_CC_EQ, label); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 893 | #endif |
| 894 | emit_post(emit); |
| 895 | } |
| 896 | |
| 897 | static void emit_native_pop_jump_if_true(emit_t *emit, int label) { |
Damien | 1a6633a | 2013-11-03 13:58:19 +0000 | [diff] [blame] | 898 | 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); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 907 | } |
Damien | 1a6633a | 2013-11-03 13:58:19 +0000 | [diff] [blame] | 908 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 909 | static void emit_native_jump_if_true_or_pop(emit_t *emit, int label) { |
| 910 | assert(0); |
| 911 | } |
| 912 | static void emit_native_jump_if_false_or_pop(emit_t *emit, int label) { |
| 913 | assert(0); |
| 914 | } |
| 915 | |
| 916 | static void emit_native_setup_loop(emit_t *emit, int label) { |
| 917 | emit_pre(emit); |
| 918 | emit_post(emit); |
| 919 | } |
| 920 | |
| 921 | static void emit_native_break_loop(emit_t *emit, int label) { |
Damien | 6ba1314 | 2013-11-02 20:34:54 +0000 | [diff] [blame] | 922 | emit_native_jump(emit, label); // TODO properly |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 923 | } |
| 924 | static void emit_native_continue_loop(emit_t *emit, int label) { |
| 925 | assert(0); |
| 926 | } |
| 927 | static void emit_native_setup_with(emit_t *emit, int label) { |
| 928 | // not supported, or could be with runtime call |
| 929 | assert(0); |
| 930 | } |
| 931 | static void emit_native_with_cleanup(emit_t *emit) { |
| 932 | assert(0); |
| 933 | } |
| 934 | static void emit_native_setup_except(emit_t *emit, int label) { |
| 935 | assert(0); |
| 936 | } |
| 937 | static void emit_native_setup_finally(emit_t *emit, int label) { |
| 938 | assert(0); |
| 939 | } |
| 940 | static void emit_native_end_finally(emit_t *emit) { |
| 941 | assert(0); |
| 942 | } |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 943 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 944 | static 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? |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 947 | |
| 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); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 953 | } |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 954 | |
| 955 | static 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); |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 961 | ASM_MOV_IMM_TO_REG((machine_uint_t)mp_const_stop_iteration, REG_TEMP1); |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 962 | #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 |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 966 | asm_thumb_cmp_reg_reg(emit->as, REG_RET, REG_TEMP1); |
Damien | 9b9e996 | 2013-11-03 14:25:43 +0000 | [diff] [blame] | 967 | asm_thumb_bcc_label(emit->as, THUMB_CC_EQ, label); |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 968 | #endif |
| 969 | emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); |
| 970 | } |
| 971 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 972 | static void emit_native_for_iter_end(emit_t *emit) { |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 973 | // 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); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | static void emit_native_pop_block(emit_t *emit) { |
| 980 | emit_pre(emit); |
| 981 | emit_post(emit); |
| 982 | } |
| 983 | |
| 984 | static void emit_native_pop_except(emit_t *emit) { |
| 985 | assert(0); |
| 986 | } |
| 987 | |
| 988 | static 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 | |
| 996 | static 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 George | bc1d369 | 2014-01-11 09:47:06 +0000 | [diff] [blame] | 1000 | if (op == RT_BINARY_OP_ADD || op == RT_BINARY_OP_INPLACE_ADD) { |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 1001 | #if N_X64 |
Damien George | bc1d369 | 2014-01-11 09:47:06 +0000 | [diff] [blame] | 1002 | asm_x64_add_r64_to_r64(emit->as, REG_ARG_3, REG_ARG_2); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 1003 | #elif N_THUMB |
Damien George | bc1d369 | 2014-01-11 09:47:06 +0000 | [diff] [blame] | 1004 | asm_thumb_add_reg_reg_reg(emit->as, REG_ARG_2, REG_ARG_2, REG_ARG_3); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1005 | #endif |
Damien George | bc1d369 | 2014-01-11 09:47:06 +0000 | [diff] [blame] | 1006 | 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 | } |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1023 | } 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 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1032 | static void emit_native_build_tuple(emit_t *emit, int n_args) { |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 1033 | // 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 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | static 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 | |
| 1048 | static void emit_native_list_append(emit_t *emit, int list_index) { |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 1049 | // 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); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | static 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 | |
| 1065 | static 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 | |
| 1075 | static void emit_native_map_add(emit_t *emit, int map_index) { |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 1076 | // 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); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | static 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 | |
| 1094 | static void emit_native_set_add(emit_t *emit, int set_index) { |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 1095 | // 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); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1103 | } |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 1104 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1105 | static void emit_native_build_slice(emit_t *emit, int n_args) { |
| 1106 | assert(0); |
| 1107 | } |
| 1108 | static void emit_native_unpack_sequence(emit_t *emit, int n_args) { |
| 1109 | // call runtime, needs type decl |
| 1110 | assert(0); |
| 1111 | } |
| 1112 | static void emit_native_unpack_ex(emit_t *emit, int n_left, int n_right) { |
| 1113 | assert(0); |
| 1114 | } |
| 1115 | |
| 1116 | static 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 | |
| 1124 | static void emit_native_make_closure(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) { |
| 1125 | assert(0); |
| 1126 | } |
| 1127 | |
| 1128 | static 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); |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 1131 | /* |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1132 | 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 { |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 1151 | */ |
| 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 George | 20006db | 2014-01-18 14:10:48 +0000 | [diff] [blame^] | 1159 | // 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); |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 1161 | //} |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1162 | emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); |
| 1163 | } |
| 1164 | |
| 1165 | static 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); |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 1167 | /* |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1168 | 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 { |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 1182 | */ |
Damien | 7f5dacf | 2013-10-10 11:24:39 +0100 | [diff] [blame] | 1183 | 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 George | 20006db | 2014-01-18 14:10:48 +0000 | [diff] [blame^] | 1185 | // 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); |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 1187 | //} |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1188 | emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); |
| 1189 | } |
| 1190 | |
| 1191 | static 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; |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 1202 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1203 | //asm_x64_call_ind(emit->as, 0, REG_RAX); to seg fault for debugging with gdb |
| 1204 | asm_x64_exit(emit->as); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 1205 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1206 | //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 | |
| 1211 | static void emit_native_raise_varargs(emit_t *emit, int n_args) { |
| 1212 | // call runtime |
| 1213 | assert(0); |
| 1214 | } |
| 1215 | static void emit_native_yield_value(emit_t *emit) { |
| 1216 | // not supported (for now) |
| 1217 | assert(0); |
| 1218 | } |
| 1219 | static void emit_native_yield_from(emit_t *emit) { |
| 1220 | // not supported (for now) |
| 1221 | assert(0); |
| 1222 | } |
| 1223 | |
| 1224 | const 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, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1246 | emit_native_load_const_verbatim_str, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1247 | emit_native_load_fast, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1248 | emit_native_load_deref, |
| 1249 | emit_native_load_closure, |
Damien | 9ecbcff | 2013-12-11 00:41:43 +0000 | [diff] [blame] | 1250 | emit_native_load_name, |
| 1251 | emit_native_load_global, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1252 | emit_native_load_attr, |
| 1253 | emit_native_load_method, |
| 1254 | emit_native_load_build_class, |
| 1255 | emit_native_store_fast, |
Damien | 9ecbcff | 2013-12-11 00:41:43 +0000 | [diff] [blame] | 1256 | emit_native_store_deref, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1257 | emit_native_store_name, |
| 1258 | emit_native_store_global, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1259 | emit_native_store_attr, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1260 | emit_native_store_subscr, |
Damien | a397776 | 2013-10-09 23:10:10 +0100 | [diff] [blame] | 1261 | emit_native_store_locals, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1262 | emit_native_delete_fast, |
Damien | 9ecbcff | 2013-12-11 00:41:43 +0000 | [diff] [blame] | 1263 | emit_native_delete_deref, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1264 | emit_native_delete_name, |
| 1265 | emit_native_delete_global, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1266 | 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, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1293 | 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 George | e67ed5d | 2014-01-04 13:55:24 +0000 | [diff] [blame] | 1314 | #endif // (MICROPY_EMIT_X64 && N_X64) || (MICROPY_EMIT_THUMB && N_THUMB) |