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 George | 55baff4 | 2014-01-21 21:40:13 +0000 | [diff] [blame] | 28 | #include "qstr.h" |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 29 | #include "lexer.h" |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 30 | #include "parse.h" |
| 31 | #include "scope.h" |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 32 | #include "runtime0.h" |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 33 | #include "emit.h" |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 34 | #include "obj.h" |
| 35 | #include "runtime.h" |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 36 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 37 | // wrapper around everything in this file |
Damien George | e67ed5d | 2014-01-04 13:55:24 +0000 | [diff] [blame] | 38 | #if (MICROPY_EMIT_X64 && N_X64) || (MICROPY_EMIT_THUMB && N_THUMB) |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 39 | |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 40 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 41 | |
| 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)) |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 56 | #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] | 57 | #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 | |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 61 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 62 | |
| 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)) |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 79 | #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] | 80 | #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 | |
| 86 | typedef enum { |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 87 | STACK_VALUE, |
| 88 | STACK_REG, |
| 89 | STACK_IMM, |
| 90 | } stack_info_kind_t; |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 91 | |
| 92 | typedef 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 | |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 102 | typedef 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 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 111 | struct _emit_t { |
| 112 | int pass; |
| 113 | |
| 114 | bool do_viper_types; |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 115 | |
| 116 | int local_vtype_alloc; |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 117 | vtype_kind_t *local_vtype; |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 118 | |
| 119 | int stack_info_alloc; |
| 120 | stack_info_t *stack_info; |
| 121 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 122 | int stack_start; |
| 123 | int stack_size; |
| 124 | |
| 125 | bool last_emit_was_return_value; |
| 126 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 127 | scope_t *scope; |
| 128 | |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 129 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 130 | asm_x64_t *as; |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 131 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 132 | asm_thumb_t *as; |
| 133 | #endif |
| 134 | }; |
| 135 | |
| 136 | emit_t *EXPORT_FUN(new)(uint max_num_labels) { |
| 137 | emit_t *emit = m_new(emit_t, 1); |
| 138 | emit->do_viper_types = false; |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 139 | emit->local_vtype = NULL; |
| 140 | emit->stack_info = NULL; |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 141 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 142 | emit->as = asm_x64_new(max_num_labels); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 143 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 144 | emit->as = asm_thumb_new(max_num_labels); |
| 145 | #endif |
| 146 | return emit; |
| 147 | } |
| 148 | |
| 149 | static void emit_native_set_viper_types(emit_t *emit, bool do_viper_types) { |
| 150 | emit->do_viper_types = do_viper_types; |
| 151 | } |
| 152 | |
| 153 | static 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; |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 158 | emit->scope = scope; |
| 159 | |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 160 | 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); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | if (emit->do_viper_types) { |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 170 | // TODO set types of arguments based on type signature |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 171 | 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 | } |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 178 | } else { |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 179 | 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; |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 185 | } |
| 186 | } |
| 187 | |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 188 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 189 | asm_x64_start_pass(emit->as, pass); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 190 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 191 | 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 | } |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 204 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 205 | asm_x64_entry(emit->as, num_locals); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 206 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 207 | asm_thumb_entry(emit->as, num_locals); |
| 208 | #endif |
| 209 | |
| 210 | // initialise locals from parameters |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 211 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 212 | 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 | } |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 224 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 225 | 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 | |
| 244 | static void emit_native_end_pass(emit_t *emit) { |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 245 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 246 | if (!emit->last_emit_was_return_value) { |
| 247 | asm_x64_exit(emit->as); |
| 248 | } |
| 249 | asm_x64_end_pass(emit->as); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 250 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 251 | 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) { |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 263 | #if N_X64 |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 264 | void *f = asm_x64_get_code(emit->as); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 265 | 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] | 266 | #elif N_THUMB |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 267 | void *f = asm_thumb_get_code(emit->as); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 268 | 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 | |
| 273 | static bool emit_native_last_emit_was_return_value(emit_t *emit) { |
| 274 | return emit->last_emit_was_return_value; |
| 275 | } |
| 276 | |
| 277 | static int emit_native_get_stack_size(emit_t *emit) { |
| 278 | return emit->stack_size; |
| 279 | } |
| 280 | |
| 281 | static void emit_native_set_stack_size(emit_t *emit, int size) { |
| 282 | emit->stack_size = size; |
| 283 | } |
| 284 | |
Damien George | 0833500 | 2014-01-18 23:24:36 +0000 | [diff] [blame] | 285 | static void emit_native_set_source_line(emit_t *emit, int source_line) { |
| 286 | } |
| 287 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 288 | static 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 | |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 296 | /* |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 297 | static 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 | } |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 301 | */ |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 302 | |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 303 | // this must be called at start of emit functions |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 304 | static void emit_pre(emit_t *emit) { |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 305 | 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 | */ |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | static vtype_kind_t peek_vtype(emit_t *emit) { |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 331 | return emit->stack_info[emit->stack_size - 1].vtype; |
| 332 | } |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 333 | |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 334 | // pos=1 is TOS, pos=2 is next, etc |
| 335 | // use pos=0 for no skipping |
| 336 | static void need_reg_single(emit_t *emit, int reg_needed, int skip_stack_pos) { |
| 337 | skip_stack_pos = emit->stack_size - skip_stack_pos; |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 338 | for (int i = 0; i < emit->stack_size; i++) { |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 339 | 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 | } |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 345 | } |
| 346 | } |
| 347 | } |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 348 | |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 349 | static void need_reg_all(emit_t *emit) { |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 350 | 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 | } |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 356 | } |
| 357 | } |
| 358 | |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 359 | static 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 |
| 376 | static 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]; |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 379 | *vtype = si->vtype; |
| 380 | switch (si->kind) { |
| 381 | case STACK_VALUE: |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 382 | 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] | 383 | break; |
| 384 | |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 385 | case STACK_REG: |
| 386 | if (si->u_reg != reg_dest) { |
| 387 | ASM_MOV_REG_TO_REG(si->u_reg, reg_dest); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 388 | } |
| 389 | break; |
| 390 | |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 391 | case STACK_IMM: |
| 392 | ASM_MOV_IMM_TO_REG(si->u_imm, reg_dest); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 393 | break; |
| 394 | } |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 395 | } |
| 396 | |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 397 | static 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 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 403 | static 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); |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 405 | emit_pre_pop_reg(emit, vtypeb, regb); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | 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) { |
| 409 | emit_pre_pop_reg(emit, vtypea, rega); |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 410 | emit_pre_pop_reg(emit, vtypeb, regb); |
| 411 | emit_pre_pop_reg(emit, vtypec, regc); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | static void emit_post(emit_t *emit) { |
| 415 | } |
| 416 | |
| 417 | 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] | 418 | stack_info_t *si = &emit->stack_info[emit->stack_size]; |
| 419 | si->vtype = vtype; |
| 420 | si->kind = STACK_REG; |
| 421 | si->u_reg = reg; |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 422 | adjust_stack(emit, 1); |
| 423 | } |
| 424 | |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 425 | static 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 | |
| 433 | static 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 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 438 | 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] | 439 | emit_post_push_reg(emit, vtypea, rega); |
| 440 | emit_post_push_reg(emit, vtypeb, regb); |
| 441 | emit_post_push_reg(emit, vtypec, regc); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | 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] | 445 | 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); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | // vtype of all n_pop objects is VTYPE_PYOBJ |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 452 | // 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] | 453 | // TODO this needs some thinking for viper code |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 454 | 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] | 455 | need_reg_all(emit); |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 456 | for (int i = 0; i < n_pop; i++) { |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 457 | stack_info_t *si = &emit->stack_info[emit->stack_size - 1 - i]; |
| 458 | // must push any imm's to stack |
Damien | 6d4f346 | 2013-11-16 20:44:39 +0000 | [diff] [blame] | 459 | // must convert them to VTYPE_PYOBJ for viper code |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 460 | if (si->kind == STACK_IMM) { |
| 461 | si->kind = STACK_VALUE; |
Damien | 6d4f346 | 2013-11-16 20:44:39 +0000 | [diff] [blame] | 462 | 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) { |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 469 | 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] | 470 | } else { |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 471 | 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] | 472 | } |
| 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 | } |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 482 | } |
| 483 | assert(si->kind == STACK_VALUE); |
| 484 | assert(si->vtype == VTYPE_PYOBJ); |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 485 | } |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 486 | 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 |
| 491 | 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] | 492 | need_reg_all(emit); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 493 | for (int i = 0; i < n_push; i++) { |
Damien | 7f5dacf | 2013-10-10 11:24:39 +0100 | [diff] [blame] | 494 | emit->stack_info[emit->stack_size + i].kind = STACK_VALUE; |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 495 | emit->stack_info[emit->stack_size + i].vtype = VTYPE_PYOBJ; |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 496 | } |
| 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 | |
| 501 | 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] | 502 | need_reg_all(emit); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 503 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 504 | asm_x64_call_ind(emit->as, fun, REG_RAX); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 505 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 506 | asm_thumb_bl_ind(emit->as, rt_fun_table[fun_kind], fun_kind, REG_R3); |
| 507 | #endif |
| 508 | } |
| 509 | |
| 510 | 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] | 511 | need_reg_all(emit); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 512 | ASM_MOV_IMM_TO_REG(arg_val, arg_reg); |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 513 | #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 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | static void emit_native_load_id(emit_t *emit, qstr qstr) { |
| 521 | // check for built-ins |
| 522 | if (strcmp(qstr_str(qstr), "v_int") == 0) { |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 523 | assert(0); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 524 | 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 | |
| 533 | static 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 | |
| 538 | static 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 | |
| 543 | static void emit_native_label_assign(emit_t *emit, int l) { |
Damien | 6ba1314 | 2013-11-02 20:34:54 +0000 | [diff] [blame] | 544 | emit_pre(emit); |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 545 | // need to commit stack because we can jump here from elsewhere |
| 546 | need_stack_settled(emit); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 547 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 548 | asm_x64_label_assign(emit->as, l); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 549 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 550 | asm_thumb_label_assign(emit->as, l); |
| 551 | #endif |
Damien | 6ba1314 | 2013-11-02 20:34:54 +0000 | [diff] [blame] | 552 | emit_post(emit); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | static void emit_native_import_name(emit_t *emit, qstr qstr) { |
| 556 | // not implemented |
| 557 | assert(0); |
| 558 | } |
| 559 | |
| 560 | static void emit_native_import_from(emit_t *emit, qstr qstr) { |
| 561 | // not implemented |
| 562 | assert(0); |
| 563 | } |
| 564 | |
| 565 | static void emit_native_import_star(emit_t *emit) { |
| 566 | // not implemented |
| 567 | assert(0); |
| 568 | } |
| 569 | |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 570 | 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] | 571 | emit_pre(emit); |
| 572 | int vtype; |
| 573 | machine_uint_t val; |
| 574 | if (emit->do_viper_types) { |
| 575 | switch (tok) { |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 576 | 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; |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 579 | default: assert(0); vtype = 0; val = 0; // shouldn't happen |
| 580 | } |
| 581 | } else { |
| 582 | vtype = VTYPE_PYOBJ; |
| 583 | switch (tok) { |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 584 | 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; |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 587 | default: assert(0); vtype = 0; val = 0; // shouldn't happen |
| 588 | } |
| 589 | } |
| 590 | emit_post_push_imm(emit, vtype, val); |
| 591 | } |
| 592 | |
| 593 | static 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 | |
| 602 | static 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 | |
| 608 | static void emit_native_load_const_dec(emit_t *emit, qstr qstr) { |
Damien | 6ba1314 | 2013-11-02 20:34:54 +0000 | [diff] [blame] | 609 | // 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); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | static void emit_native_load_const_id(emit_t *emit, qstr qstr) { |
Damien | 7f5dacf | 2013-10-10 11:24:39 +0100 | [diff] [blame] | 616 | 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 | } |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | static 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 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 638 | static void emit_native_load_const_verbatim_str(emit_t *emit, const char *str) { |
| 639 | // not supported/needed for viper |
| 640 | assert(0); |
| 641 | } |
| 642 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 643 | static 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); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 649 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 650 | if (local_num == 0) { |
| 651 | emit_post_push_reg(emit, vtype, REG_LOCAL_1); |
| 652 | } else { |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 653 | need_reg_single(emit, REG_RAX, 0); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 654 | asm_x64_mov_local_to_r64(emit->as, local_num - 1, REG_RAX); |
| 655 | emit_post_push_reg(emit, vtype, REG_RAX); |
| 656 | } |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 657 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 658 | 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 { |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 665 | need_reg_single(emit, REG_R0, 0); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 666 | 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 | |
Damien | 9ecbcff | 2013-12-11 00:41:43 +0000 | [diff] [blame] | 672 | static 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 | |
| 678 | static void emit_native_load_closure(emit_t *emit, qstr qstr, int local_num) { |
| 679 | // not implemented |
| 680 | assert(0); |
| 681 | } |
| 682 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 683 | static 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 | |
| 689 | static 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 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 695 | static 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 | |
| 707 | static 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 | |
| 715 | static void emit_native_load_build_class(emit_t *emit) { |
Damien | 7f5dacf | 2013-10-10 11:24:39 +0100 | [diff] [blame] | 716 | 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); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | static void emit_native_store_fast(emit_t *emit, qstr qstr, int local_num) { |
| 722 | vtype_kind_t vtype; |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 723 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 724 | 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 | } |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 730 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 731 | 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 | |
Damien | 9ecbcff | 2013-12-11 00:41:43 +0000 | [diff] [blame] | 755 | static void emit_native_store_deref(emit_t *emit, qstr qstr, int local_num) { |
| 756 | // not implemented |
| 757 | assert(0); |
| 758 | } |
| 759 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 760 | static 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 | |
| 769 | static void emit_native_store_global(emit_t *emit, qstr qstr) { |
| 770 | // not implemented |
| 771 | assert(0); |
| 772 | } |
| 773 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 774 | static void emit_native_store_attr(emit_t *emit, qstr qstr) { |
Damien | 7f5dacf | 2013-10-10 11:24:39 +0100 | [diff] [blame] | 775 | 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); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 781 | } |
| 782 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 783 | static 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 | |
Damien | a397776 | 2013-10-09 23:10:10 +0100 | [diff] [blame] | 796 | static 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 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 803 | static 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 | |
Damien | 9ecbcff | 2013-12-11 00:41:43 +0000 | [diff] [blame] | 809 | static void emit_native_delete_deref(emit_t *emit, qstr qstr, int local_num) { |
| 810 | // not supported |
| 811 | assert(0); |
| 812 | } |
| 813 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 814 | static void emit_native_delete_name(emit_t *emit, qstr qstr) { |
| 815 | // not implemented |
| 816 | // use rt_delete_name |
| 817 | assert(0); |
| 818 | } |
| 819 | |
| 820 | static void emit_native_delete_global(emit_t *emit, qstr qstr) { |
| 821 | // not implemented |
| 822 | // use rt_delete_global |
| 823 | assert(0); |
| 824 | } |
| 825 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 826 | static void emit_native_delete_attr(emit_t *emit, qstr qstr) { |
| 827 | // not supported |
| 828 | assert(0); |
| 829 | } |
| 830 | |
| 831 | static void emit_native_delete_subscr(emit_t *emit) { |
| 832 | // not supported |
| 833 | assert(0); |
| 834 | } |
| 835 | |
| 836 | static 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 | |
| 842 | static 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 | |
| 848 | static 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 | |
| 854 | static void emit_native_rot_two(emit_t *emit) { |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 855 | 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); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | static 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 | |
| 866 | static void emit_native_jump(emit_t *emit, int label) { |
| 867 | emit_pre(emit); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 868 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 869 | asm_x64_jmp_label(emit->as, label); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 870 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 871 | asm_thumb_b_label(emit->as, label); |
| 872 | #endif |
| 873 | emit_post(emit); |
| 874 | } |
| 875 | |
Damien | 1a6633a | 2013-11-03 13:58:19 +0000 | [diff] [blame] | 876 | static void emit_native_pop_jump_pre_helper(emit_t *emit, int label) { |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 877 | 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 | } |
Damien | 1a6633a | 2013-11-03 13:58:19 +0000 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | static void emit_native_pop_jump_if_false(emit_t *emit, int label) { |
| 890 | emit_native_pop_jump_pre_helper(emit, label); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 891 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 892 | asm_x64_test_r8_with_r8(emit->as, REG_RET, REG_RET); |
| 893 | asm_x64_jcc_label(emit->as, JCC_JZ, label); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 894 | #elif N_THUMB |
Damien | 1a6633a | 2013-11-03 13:58:19 +0000 | [diff] [blame] | 895 | asm_thumb_cmp_rlo_i8(emit->as, REG_RET, 0); |
| 896 | asm_thumb_bcc_label(emit->as, THUMB_CC_EQ, label); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 897 | #endif |
| 898 | emit_post(emit); |
| 899 | } |
| 900 | |
| 901 | static void emit_native_pop_jump_if_true(emit_t *emit, int label) { |
Damien | 1a6633a | 2013-11-03 13:58:19 +0000 | [diff] [blame] | 902 | 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); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 911 | } |
Damien | 1a6633a | 2013-11-03 13:58:19 +0000 | [diff] [blame] | 912 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 913 | static void emit_native_jump_if_true_or_pop(emit_t *emit, int label) { |
| 914 | assert(0); |
| 915 | } |
| 916 | static void emit_native_jump_if_false_or_pop(emit_t *emit, int label) { |
| 917 | assert(0); |
| 918 | } |
| 919 | |
| 920 | static void emit_native_setup_loop(emit_t *emit, int label) { |
| 921 | emit_pre(emit); |
| 922 | emit_post(emit); |
| 923 | } |
| 924 | |
| 925 | static void emit_native_break_loop(emit_t *emit, int label) { |
Damien | 6ba1314 | 2013-11-02 20:34:54 +0000 | [diff] [blame] | 926 | emit_native_jump(emit, label); // TODO properly |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 927 | } |
| 928 | static void emit_native_continue_loop(emit_t *emit, int label) { |
| 929 | assert(0); |
| 930 | } |
| 931 | static void emit_native_setup_with(emit_t *emit, int label) { |
| 932 | // not supported, or could be with runtime call |
| 933 | assert(0); |
| 934 | } |
| 935 | static void emit_native_with_cleanup(emit_t *emit) { |
| 936 | assert(0); |
| 937 | } |
| 938 | static void emit_native_setup_except(emit_t *emit, int label) { |
| 939 | assert(0); |
| 940 | } |
| 941 | static void emit_native_setup_finally(emit_t *emit, int label) { |
| 942 | assert(0); |
| 943 | } |
| 944 | static void emit_native_end_finally(emit_t *emit) { |
| 945 | assert(0); |
| 946 | } |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 947 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 948 | static 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? |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 951 | |
| 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); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 957 | } |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 958 | |
| 959 | static 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); |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 965 | 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] | 966 | #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 |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 970 | asm_thumb_cmp_reg_reg(emit->as, REG_RET, REG_TEMP1); |
Damien | 9b9e996 | 2013-11-03 14:25:43 +0000 | [diff] [blame] | 971 | asm_thumb_bcc_label(emit->as, THUMB_CC_EQ, label); |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 972 | #endif |
| 973 | emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); |
| 974 | } |
| 975 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 976 | static void emit_native_for_iter_end(emit_t *emit) { |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 977 | // 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); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | static void emit_native_pop_block(emit_t *emit) { |
| 984 | emit_pre(emit); |
| 985 | emit_post(emit); |
| 986 | } |
| 987 | |
| 988 | static void emit_native_pop_except(emit_t *emit) { |
| 989 | assert(0); |
| 990 | } |
| 991 | |
| 992 | static 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 | |
| 1000 | static 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 George | bc1d369 | 2014-01-11 09:47:06 +0000 | [diff] [blame] | 1004 | if (op == RT_BINARY_OP_ADD || op == RT_BINARY_OP_INPLACE_ADD) { |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 1005 | #if N_X64 |
Damien George | bc1d369 | 2014-01-11 09:47:06 +0000 | [diff] [blame] | 1006 | 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] | 1007 | #elif N_THUMB |
Damien George | bc1d369 | 2014-01-11 09:47:06 +0000 | [diff] [blame] | 1008 | 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] | 1009 | #endif |
Damien George | bc1d369 | 2014-01-11 09:47:06 +0000 | [diff] [blame] | 1010 | 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 | } |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1027 | } 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 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1036 | static void emit_native_build_tuple(emit_t *emit, int n_args) { |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 1037 | // 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 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | static 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 | |
| 1052 | static void emit_native_list_append(emit_t *emit, int list_index) { |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 1053 | // 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); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | static 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 | |
| 1069 | static 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 | |
| 1079 | static void emit_native_map_add(emit_t *emit, int map_index) { |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 1080 | // 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); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | static 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 | |
| 1098 | static void emit_native_set_add(emit_t *emit, int set_index) { |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 1099 | // 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); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1107 | } |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 1108 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1109 | static void emit_native_build_slice(emit_t *emit, int n_args) { |
| 1110 | assert(0); |
| 1111 | } |
| 1112 | static void emit_native_unpack_sequence(emit_t *emit, int n_args) { |
| 1113 | // call runtime, needs type decl |
| 1114 | assert(0); |
| 1115 | } |
| 1116 | static void emit_native_unpack_ex(emit_t *emit, int n_left, int n_right) { |
| 1117 | assert(0); |
| 1118 | } |
| 1119 | |
| 1120 | static 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 | |
| 1128 | static void emit_native_make_closure(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) { |
| 1129 | assert(0); |
| 1130 | } |
| 1131 | |
| 1132 | static 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); |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 1135 | /* |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1136 | 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 { |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 1155 | */ |
| 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 George | 20006db | 2014-01-18 14:10:48 +0000 | [diff] [blame] | 1163 | // 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); |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 1165 | //} |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1166 | emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); |
| 1167 | } |
| 1168 | |
| 1169 | static 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); |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 1171 | /* |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1172 | 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 { |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 1186 | */ |
Damien | 7f5dacf | 2013-10-10 11:24:39 +0100 | [diff] [blame] | 1187 | 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 George | 20006db | 2014-01-18 14:10:48 +0000 | [diff] [blame] | 1189 | // 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); |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 1191 | //} |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1192 | emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); |
| 1193 | } |
| 1194 | |
| 1195 | static 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; |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 1206 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1207 | //asm_x64_call_ind(emit->as, 0, REG_RAX); to seg fault for debugging with gdb |
| 1208 | asm_x64_exit(emit->as); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 1209 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1210 | //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 | |
| 1215 | static void emit_native_raise_varargs(emit_t *emit, int n_args) { |
| 1216 | // call runtime |
| 1217 | assert(0); |
| 1218 | } |
| 1219 | static void emit_native_yield_value(emit_t *emit) { |
| 1220 | // not supported (for now) |
| 1221 | assert(0); |
| 1222 | } |
| 1223 | static void emit_native_yield_from(emit_t *emit) { |
| 1224 | // not supported (for now) |
| 1225 | assert(0); |
| 1226 | } |
| 1227 | |
| 1228 | const 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 George | 0833500 | 2014-01-18 23:24:36 +0000 | [diff] [blame] | 1235 | emit_native_set_source_line, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1236 | |
| 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, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1251 | emit_native_load_const_verbatim_str, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1252 | emit_native_load_fast, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1253 | emit_native_load_deref, |
| 1254 | emit_native_load_closure, |
Damien | 9ecbcff | 2013-12-11 00:41:43 +0000 | [diff] [blame] | 1255 | emit_native_load_name, |
| 1256 | emit_native_load_global, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1257 | emit_native_load_attr, |
| 1258 | emit_native_load_method, |
| 1259 | emit_native_load_build_class, |
| 1260 | emit_native_store_fast, |
Damien | 9ecbcff | 2013-12-11 00:41:43 +0000 | [diff] [blame] | 1261 | emit_native_store_deref, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1262 | emit_native_store_name, |
| 1263 | emit_native_store_global, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1264 | emit_native_store_attr, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1265 | emit_native_store_subscr, |
Damien | a397776 | 2013-10-09 23:10:10 +0100 | [diff] [blame] | 1266 | emit_native_store_locals, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1267 | emit_native_delete_fast, |
Damien | 9ecbcff | 2013-12-11 00:41:43 +0000 | [diff] [blame] | 1268 | emit_native_delete_deref, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1269 | emit_native_delete_name, |
| 1270 | emit_native_delete_global, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1271 | 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, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1298 | 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 George | e67ed5d | 2014-01-04 13:55:24 +0000 | [diff] [blame] | 1319 | #endif // (MICROPY_EMIT_X64 && N_X64) || (MICROPY_EMIT_THUMB && N_THUMB) |