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 | |
Paul Sokolovsky | f46d87a | 2014-01-24 16:20:11 +0200 | [diff] [blame^] | 149 | static void emit_native_free(emit_t *emit) { |
| 150 | #if N_X64 |
| 151 | asm_x64_free(emit->as, false); |
| 152 | #elif N_THUMB |
| 153 | asm_thumb_free(emit->as, false); |
| 154 | #endif |
| 155 | m_del_obj(emit_t, emit); |
| 156 | } |
| 157 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 158 | static void emit_native_set_viper_types(emit_t *emit, bool do_viper_types) { |
| 159 | emit->do_viper_types = do_viper_types; |
| 160 | } |
| 161 | |
| 162 | static void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) { |
| 163 | emit->pass = pass; |
| 164 | emit->stack_start = 0; |
| 165 | emit->stack_size = 0; |
| 166 | emit->last_emit_was_return_value = false; |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 167 | emit->scope = scope; |
| 168 | |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 169 | if (emit->local_vtype == NULL) { |
| 170 | emit->local_vtype_alloc = scope->num_locals + 20; // XXX should be maximum over all scopes |
| 171 | emit->local_vtype = m_new(vtype_kind_t, emit->local_vtype_alloc); |
| 172 | } |
| 173 | if (emit->stack_info == NULL) { |
| 174 | emit->stack_info_alloc = scope->stack_size + 50; // XXX don't know stack size on entry, should be maximum over all scopes |
| 175 | emit->stack_info = m_new(stack_info_t, emit->stack_info_alloc); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | if (emit->do_viper_types) { |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 179 | // TODO set types of arguments based on type signature |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 180 | for (int i = 0; i < emit->local_vtype_alloc; i++) { |
| 181 | emit->local_vtype[i] = VTYPE_UNBOUND; |
| 182 | } |
| 183 | for (int i = 0; i < emit->stack_info_alloc; i++) { |
| 184 | emit->stack_info[i].kind = STACK_VALUE; |
| 185 | emit->stack_info[i].vtype = VTYPE_UNBOUND; |
| 186 | } |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 187 | } else { |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 188 | for (int i = 0; i < emit->local_vtype_alloc; i++) { |
| 189 | emit->local_vtype[i] = VTYPE_PYOBJ; |
| 190 | } |
| 191 | for (int i = 0; i < emit->stack_info_alloc; i++) { |
| 192 | emit->stack_info[i].kind = STACK_VALUE; |
| 193 | emit->stack_info[i].vtype = VTYPE_PYOBJ; |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 197 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 198 | asm_x64_start_pass(emit->as, pass); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 199 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 200 | asm_thumb_start_pass(emit->as, pass); |
| 201 | #endif |
| 202 | |
| 203 | // entry to function |
| 204 | int num_locals = 0; |
| 205 | if (pass > PASS_1) { |
| 206 | num_locals = scope->num_locals - REG_LOCAL_NUM; |
| 207 | if (num_locals < 0) { |
| 208 | num_locals = 0; |
| 209 | } |
| 210 | emit->stack_start = num_locals; |
| 211 | num_locals += scope->stack_size; |
| 212 | } |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 213 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 214 | asm_x64_entry(emit->as, num_locals); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 215 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 216 | asm_thumb_entry(emit->as, num_locals); |
| 217 | #endif |
| 218 | |
| 219 | // initialise locals from parameters |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 220 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 221 | for (int i = 0; i < scope->num_params; i++) { |
| 222 | if (i == 0) { |
| 223 | asm_x64_mov_r64_to_r64(emit->as, REG_ARG_1, REG_LOCAL_1); |
| 224 | } else if (i == 1) { |
| 225 | asm_x64_mov_r64_to_local(emit->as, REG_ARG_2, i - 1); |
| 226 | } else if (i == 2) { |
| 227 | asm_x64_mov_r64_to_local(emit->as, REG_ARG_3, i - 1); |
| 228 | } else { |
| 229 | // TODO not implemented |
| 230 | assert(0); |
| 231 | } |
| 232 | } |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 233 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 234 | for (int i = 0; i < scope->num_params; i++) { |
| 235 | if (i == 0) { |
| 236 | asm_thumb_mov_reg_reg(emit->as, REG_LOCAL_1, REG_ARG_1); |
| 237 | } else if (i == 1) { |
| 238 | asm_thumb_mov_reg_reg(emit->as, REG_LOCAL_2, REG_ARG_2); |
| 239 | } else if (i == 2) { |
| 240 | asm_thumb_mov_reg_reg(emit->as, REG_LOCAL_3, REG_ARG_3); |
| 241 | } else if (i == 3) { |
| 242 | asm_thumb_mov_local_reg(emit->as, i - REG_LOCAL_NUM, REG_ARG_4); |
| 243 | } else { |
| 244 | // TODO not implemented |
| 245 | assert(0); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | asm_thumb_mov_reg_i32(emit->as, REG_R7, (machine_uint_t)rt_fun_table); |
| 250 | #endif |
| 251 | } |
| 252 | |
| 253 | static void emit_native_end_pass(emit_t *emit) { |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 254 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 255 | if (!emit->last_emit_was_return_value) { |
| 256 | asm_x64_exit(emit->as); |
| 257 | } |
| 258 | asm_x64_end_pass(emit->as); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 259 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 260 | if (!emit->last_emit_was_return_value) { |
| 261 | asm_thumb_exit(emit->as); |
| 262 | } |
| 263 | asm_thumb_end_pass(emit->as); |
| 264 | #endif |
| 265 | |
| 266 | // check stack is back to zero size |
| 267 | if (emit->stack_size != 0) { |
| 268 | printf("ERROR: stack size not back to zero; got %d\n", emit->stack_size); |
| 269 | } |
| 270 | |
| 271 | if (emit->pass == PASS_3) { |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 272 | #if N_X64 |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 273 | void *f = asm_x64_get_code(emit->as); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 274 | 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] | 275 | #elif N_THUMB |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 276 | void *f = asm_thumb_get_code(emit->as); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 277 | rt_assign_native_code(emit->scope->unique_code_id, f, asm_thumb_get_code_size(emit->as), emit->scope->num_params); |
| 278 | #endif |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | static bool emit_native_last_emit_was_return_value(emit_t *emit) { |
| 283 | return emit->last_emit_was_return_value; |
| 284 | } |
| 285 | |
| 286 | static int emit_native_get_stack_size(emit_t *emit) { |
| 287 | return emit->stack_size; |
| 288 | } |
| 289 | |
| 290 | static void emit_native_set_stack_size(emit_t *emit, int size) { |
| 291 | emit->stack_size = size; |
| 292 | } |
| 293 | |
Damien George | 0833500 | 2014-01-18 23:24:36 +0000 | [diff] [blame] | 294 | static void emit_native_set_source_line(emit_t *emit, int source_line) { |
| 295 | } |
| 296 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 297 | static void adjust_stack(emit_t *emit, int stack_size_delta) { |
| 298 | emit->stack_size += stack_size_delta; |
| 299 | assert(emit->stack_size >= 0); |
| 300 | if (emit->pass > PASS_1 && emit->stack_size > emit->scope->stack_size) { |
| 301 | emit->scope->stack_size = emit->stack_size; |
| 302 | } |
| 303 | } |
| 304 | |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 305 | /* |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 306 | static void emit_pre_raw(emit_t *emit, int stack_size_delta) { |
| 307 | adjust_stack(emit, stack_size_delta); |
| 308 | emit->last_emit_was_return_value = false; |
| 309 | } |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 310 | */ |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 311 | |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 312 | // this must be called at start of emit functions |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 313 | static void emit_pre(emit_t *emit) { |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 314 | emit->last_emit_was_return_value = false; |
| 315 | // settle the stack |
| 316 | /* |
| 317 | if (regs_needed != 0) { |
| 318 | for (int i = 0; i < emit->stack_size; i++) { |
| 319 | switch (emit->stack_info[i].kind) { |
| 320 | case STACK_VALUE: |
| 321 | break; |
| 322 | |
| 323 | case STACK_REG: |
| 324 | // TODO only push reg if in regs_needed |
| 325 | emit->stack_info[i].kind = STACK_VALUE; |
| 326 | ASM_MOV_REG_TO_LOCAL(emit->stack_info[i].u_reg, emit->stack_start + i); |
| 327 | break; |
| 328 | |
| 329 | case STACK_IMM: |
| 330 | // don't think we ever need to push imms for settling |
| 331 | //ASM_MOV_IMM_TO_LOCAL(emit->last_imm, emit->stack_start + i); |
| 332 | break; |
| 333 | } |
| 334 | } |
| 335 | } |
| 336 | */ |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | static vtype_kind_t peek_vtype(emit_t *emit) { |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 340 | return emit->stack_info[emit->stack_size - 1].vtype; |
| 341 | } |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 342 | |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 343 | // pos=1 is TOS, pos=2 is next, etc |
| 344 | // use pos=0 for no skipping |
| 345 | static void need_reg_single(emit_t *emit, int reg_needed, int skip_stack_pos) { |
| 346 | skip_stack_pos = emit->stack_size - skip_stack_pos; |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 347 | for (int i = 0; i < emit->stack_size; i++) { |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 348 | if (i != skip_stack_pos) { |
| 349 | stack_info_t *si = &emit->stack_info[i]; |
| 350 | if (si->kind == STACK_REG && si->u_reg == reg_needed) { |
| 351 | si->kind = STACK_VALUE; |
| 352 | ASM_MOV_REG_TO_LOCAL(si->u_reg, emit->stack_start + i); |
| 353 | } |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | } |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 357 | |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 358 | static void need_reg_all(emit_t *emit) { |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 359 | for (int i = 0; i < emit->stack_size; i++) { |
| 360 | stack_info_t *si = &emit->stack_info[i]; |
| 361 | if (si->kind == STACK_REG) { |
| 362 | si->kind = STACK_VALUE; |
| 363 | ASM_MOV_REG_TO_LOCAL(si->u_reg, emit->stack_start + i); |
| 364 | } |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 365 | } |
| 366 | } |
| 367 | |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 368 | static void need_stack_settled(emit_t *emit) { |
| 369 | for (int i = 0; i < emit->stack_size; i++) { |
| 370 | stack_info_t *si = &emit->stack_info[i]; |
| 371 | if (si->kind == STACK_REG) { |
| 372 | si->kind = STACK_VALUE; |
| 373 | ASM_MOV_REG_TO_LOCAL(si->u_reg, emit->stack_start + i); |
| 374 | } |
| 375 | } |
| 376 | for (int i = 0; i < emit->stack_size; i++) { |
| 377 | stack_info_t *si = &emit->stack_info[i]; |
| 378 | if (si->kind == STACK_IMM) { |
| 379 | ASM_MOV_IMM_TO_LOCAL_USING(si->u_imm, emit->stack_start + i, REG_TEMP0); |
| 380 | } |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | // pos=1 is TOS, pos=2 is next, etc |
| 385 | static void emit_access_stack(emit_t *emit, int pos, vtype_kind_t *vtype, int reg_dest) { |
| 386 | need_reg_single(emit, reg_dest, pos); |
| 387 | stack_info_t *si = &emit->stack_info[emit->stack_size - pos]; |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 388 | *vtype = si->vtype; |
| 389 | switch (si->kind) { |
| 390 | case STACK_VALUE: |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 391 | 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] | 392 | break; |
| 393 | |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 394 | case STACK_REG: |
| 395 | if (si->u_reg != reg_dest) { |
| 396 | ASM_MOV_REG_TO_REG(si->u_reg, reg_dest); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 397 | } |
| 398 | break; |
| 399 | |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 400 | case STACK_IMM: |
| 401 | ASM_MOV_IMM_TO_REG(si->u_imm, reg_dest); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 402 | break; |
| 403 | } |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 404 | } |
| 405 | |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 406 | static void emit_pre_pop_reg(emit_t *emit, vtype_kind_t *vtype, int reg_dest) { |
| 407 | emit->last_emit_was_return_value = false; |
| 408 | emit_access_stack(emit, 1, vtype, reg_dest); |
| 409 | adjust_stack(emit, -1); |
| 410 | } |
| 411 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 412 | static void emit_pre_pop_reg_reg(emit_t *emit, vtype_kind_t *vtypea, int rega, vtype_kind_t *vtypeb, int regb) { |
| 413 | emit_pre_pop_reg(emit, vtypea, rega); |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 414 | emit_pre_pop_reg(emit, vtypeb, regb); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | 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) { |
| 418 | emit_pre_pop_reg(emit, vtypea, rega); |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 419 | emit_pre_pop_reg(emit, vtypeb, regb); |
| 420 | emit_pre_pop_reg(emit, vtypec, regc); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | static void emit_post(emit_t *emit) { |
| 424 | } |
| 425 | |
| 426 | 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] | 427 | stack_info_t *si = &emit->stack_info[emit->stack_size]; |
| 428 | si->vtype = vtype; |
| 429 | si->kind = STACK_REG; |
| 430 | si->u_reg = reg; |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 431 | adjust_stack(emit, 1); |
| 432 | } |
| 433 | |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 434 | static void emit_post_push_imm(emit_t *emit, vtype_kind_t vtype, machine_int_t imm) { |
| 435 | stack_info_t *si = &emit->stack_info[emit->stack_size]; |
| 436 | si->vtype = vtype; |
| 437 | si->kind = STACK_IMM; |
| 438 | si->u_imm = imm; |
| 439 | adjust_stack(emit, 1); |
| 440 | } |
| 441 | |
| 442 | static void emit_post_push_reg_reg(emit_t *emit, vtype_kind_t vtypea, int rega, vtype_kind_t vtypeb, int regb) { |
| 443 | emit_post_push_reg(emit, vtypea, rega); |
| 444 | emit_post_push_reg(emit, vtypeb, regb); |
| 445 | } |
| 446 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 447 | 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] | 448 | emit_post_push_reg(emit, vtypea, rega); |
| 449 | emit_post_push_reg(emit, vtypeb, regb); |
| 450 | emit_post_push_reg(emit, vtypec, regc); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | 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] | 454 | emit_post_push_reg(emit, vtypea, rega); |
| 455 | emit_post_push_reg(emit, vtypeb, regb); |
| 456 | emit_post_push_reg(emit, vtypec, regc); |
| 457 | emit_post_push_reg(emit, vtyped, regd); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | // vtype of all n_pop objects is VTYPE_PYOBJ |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 461 | // 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] | 462 | // TODO this needs some thinking for viper code |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 463 | 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] | 464 | need_reg_all(emit); |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 465 | for (int i = 0; i < n_pop; i++) { |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 466 | stack_info_t *si = &emit->stack_info[emit->stack_size - 1 - i]; |
| 467 | // must push any imm's to stack |
Damien | 6d4f346 | 2013-11-16 20:44:39 +0000 | [diff] [blame] | 468 | // must convert them to VTYPE_PYOBJ for viper code |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 469 | if (si->kind == STACK_IMM) { |
| 470 | si->kind = STACK_VALUE; |
Damien | 6d4f346 | 2013-11-16 20:44:39 +0000 | [diff] [blame] | 471 | switch (si->vtype) { |
| 472 | case VTYPE_PYOBJ: |
| 473 | ASM_MOV_IMM_TO_LOCAL_USING(si->u_imm, emit->stack_start + emit->stack_size - 1 - i, reg_dest); |
| 474 | break; |
| 475 | case VTYPE_BOOL: |
| 476 | si->vtype = VTYPE_PYOBJ; |
| 477 | if (si->u_imm == 0) { |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 478 | 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] | 479 | } else { |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 480 | 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] | 481 | } |
| 482 | break; |
| 483 | case VTYPE_INT: |
| 484 | si->vtype = VTYPE_PYOBJ; |
| 485 | ASM_MOV_IMM_TO_LOCAL_USING((si->u_imm << 1) | 1, emit->stack_start + emit->stack_size - 1 - i, reg_dest); |
| 486 | break; |
| 487 | default: |
| 488 | // not handled |
| 489 | assert(0); |
| 490 | } |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 491 | } |
| 492 | assert(si->kind == STACK_VALUE); |
| 493 | assert(si->vtype == VTYPE_PYOBJ); |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 494 | } |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 495 | ASM_MOV_LOCAL_ADDR_TO_REG(emit->stack_start + emit->stack_size - 1, reg_dest); |
| 496 | adjust_stack(emit, -n_pop); |
| 497 | } |
| 498 | |
| 499 | // vtype of all n_push objects is VTYPE_PYOBJ |
| 500 | 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] | 501 | need_reg_all(emit); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 502 | for (int i = 0; i < n_push; i++) { |
Damien | 7f5dacf | 2013-10-10 11:24:39 +0100 | [diff] [blame] | 503 | emit->stack_info[emit->stack_size + i].kind = STACK_VALUE; |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 504 | emit->stack_info[emit->stack_size + i].vtype = VTYPE_PYOBJ; |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 505 | } |
| 506 | ASM_MOV_LOCAL_ADDR_TO_REG(emit->stack_start + emit->stack_size + n_push - 1, reg_dest); |
| 507 | adjust_stack(emit, n_push); |
| 508 | } |
| 509 | |
| 510 | 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] | 511 | need_reg_all(emit); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 512 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 513 | asm_x64_call_ind(emit->as, fun, REG_RAX); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 514 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 515 | asm_thumb_bl_ind(emit->as, rt_fun_table[fun_kind], fun_kind, REG_R3); |
| 516 | #endif |
| 517 | } |
| 518 | |
| 519 | 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] | 520 | need_reg_all(emit); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 521 | ASM_MOV_IMM_TO_REG(arg_val, arg_reg); |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 522 | #if N_X64 |
| 523 | asm_x64_call_ind(emit->as, fun, REG_RAX); |
| 524 | #elif N_THUMB |
| 525 | asm_thumb_bl_ind(emit->as, rt_fun_table[fun_kind], fun_kind, REG_R3); |
| 526 | #endif |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | static void emit_native_load_id(emit_t *emit, qstr qstr) { |
| 530 | // check for built-ins |
| 531 | if (strcmp(qstr_str(qstr), "v_int") == 0) { |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 532 | assert(0); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 533 | emit_pre(emit); |
| 534 | //emit_post_push_blank(emit, VTYPE_BUILTIN_V_INT); |
| 535 | |
| 536 | // not a built-in, so do usual thing |
| 537 | } else { |
| 538 | emit_common_load_id(emit, &EXPORT_FUN(method_table), emit->scope, qstr); |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | static void emit_native_store_id(emit_t *emit, qstr qstr) { |
| 543 | // TODO check for built-ins and disallow |
| 544 | emit_common_store_id(emit, &EXPORT_FUN(method_table), emit->scope, qstr); |
| 545 | } |
| 546 | |
| 547 | static void emit_native_delete_id(emit_t *emit, qstr qstr) { |
| 548 | // TODO check for built-ins and disallow |
| 549 | emit_common_delete_id(emit, &EXPORT_FUN(method_table), emit->scope, qstr); |
| 550 | } |
| 551 | |
| 552 | static void emit_native_label_assign(emit_t *emit, int l) { |
Damien | 6ba1314 | 2013-11-02 20:34:54 +0000 | [diff] [blame] | 553 | emit_pre(emit); |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 554 | // need to commit stack because we can jump here from elsewhere |
| 555 | need_stack_settled(emit); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 556 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 557 | asm_x64_label_assign(emit->as, l); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 558 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 559 | asm_thumb_label_assign(emit->as, l); |
| 560 | #endif |
Damien | 6ba1314 | 2013-11-02 20:34:54 +0000 | [diff] [blame] | 561 | emit_post(emit); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | static void emit_native_import_name(emit_t *emit, qstr qstr) { |
| 565 | // not implemented |
| 566 | assert(0); |
| 567 | } |
| 568 | |
| 569 | static void emit_native_import_from(emit_t *emit, qstr qstr) { |
| 570 | // not implemented |
| 571 | assert(0); |
| 572 | } |
| 573 | |
| 574 | static void emit_native_import_star(emit_t *emit) { |
| 575 | // not implemented |
| 576 | assert(0); |
| 577 | } |
| 578 | |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 579 | 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] | 580 | emit_pre(emit); |
| 581 | int vtype; |
| 582 | machine_uint_t val; |
| 583 | if (emit->do_viper_types) { |
| 584 | switch (tok) { |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 585 | case MP_TOKEN_KW_NONE: vtype = VTYPE_PTR_NONE; val = 0; break; |
| 586 | case MP_TOKEN_KW_FALSE: vtype = VTYPE_BOOL; val = 0; break; |
| 587 | case MP_TOKEN_KW_TRUE: vtype = VTYPE_BOOL; val = 1; break; |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 588 | default: assert(0); vtype = 0; val = 0; // shouldn't happen |
| 589 | } |
| 590 | } else { |
| 591 | vtype = VTYPE_PYOBJ; |
| 592 | switch (tok) { |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 593 | case MP_TOKEN_KW_NONE: val = (machine_uint_t)mp_const_none; break; |
| 594 | case MP_TOKEN_KW_FALSE: val = (machine_uint_t)mp_const_false; break; |
| 595 | case MP_TOKEN_KW_TRUE: val = (machine_uint_t)mp_const_true; break; |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 596 | default: assert(0); vtype = 0; val = 0; // shouldn't happen |
| 597 | } |
| 598 | } |
| 599 | emit_post_push_imm(emit, vtype, val); |
| 600 | } |
| 601 | |
| 602 | static void emit_native_load_const_small_int(emit_t *emit, int arg) { |
| 603 | emit_pre(emit); |
| 604 | if (emit->do_viper_types) { |
| 605 | emit_post_push_imm(emit, VTYPE_INT, arg); |
| 606 | } else { |
| 607 | emit_post_push_imm(emit, VTYPE_PYOBJ, (arg << 1) | 1); |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | static void emit_native_load_const_int(emit_t *emit, qstr qstr) { |
| 612 | // not implemented |
| 613 | // load integer, check fits in 32 bits |
| 614 | assert(0); |
| 615 | } |
| 616 | |
| 617 | static void emit_native_load_const_dec(emit_t *emit, qstr qstr) { |
Damien | 6ba1314 | 2013-11-02 20:34:54 +0000 | [diff] [blame] | 618 | // for viper, a float/complex is just a Python object |
| 619 | emit_pre(emit); |
| 620 | emit_call_with_imm_arg(emit, RT_F_LOAD_CONST_DEC, rt_load_const_dec, qstr, REG_ARG_1); |
| 621 | emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | static void emit_native_load_const_id(emit_t *emit, qstr qstr) { |
Damien | 7f5dacf | 2013-10-10 11:24:39 +0100 | [diff] [blame] | 625 | emit_pre(emit); |
| 626 | if (emit->do_viper_types) { |
| 627 | assert(0); |
| 628 | } else { |
| 629 | emit_call_with_imm_arg(emit, RT_F_LOAD_CONST_STR, rt_load_const_str, qstr, REG_ARG_1); // TODO |
| 630 | emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); |
| 631 | } |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | static void emit_native_load_const_str(emit_t *emit, qstr qstr, bool bytes) { |
| 635 | emit_pre(emit); |
| 636 | if (emit->do_viper_types) { |
| 637 | // not implemented properly |
| 638 | // load a pointer to the asciiz string? |
| 639 | assert(0); |
| 640 | emit_post_push_imm(emit, VTYPE_PTR, (machine_uint_t)qstr_str(qstr)); |
| 641 | } else { |
| 642 | emit_call_with_imm_arg(emit, RT_F_LOAD_CONST_STR, rt_load_const_str, qstr, REG_ARG_1); |
| 643 | emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); |
| 644 | } |
| 645 | } |
| 646 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 647 | static void emit_native_load_const_verbatim_str(emit_t *emit, const char *str) { |
| 648 | // not supported/needed for viper |
| 649 | assert(0); |
| 650 | } |
| 651 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 652 | static void emit_native_load_fast(emit_t *emit, qstr qstr, int local_num) { |
| 653 | vtype_kind_t vtype = emit->local_vtype[local_num]; |
| 654 | if (vtype == VTYPE_UNBOUND) { |
| 655 | printf("ViperTypeError: local %s used before type known\n", qstr_str(qstr)); |
| 656 | } |
| 657 | emit_pre(emit); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 658 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 659 | if (local_num == 0) { |
| 660 | emit_post_push_reg(emit, vtype, REG_LOCAL_1); |
| 661 | } else { |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 662 | need_reg_single(emit, REG_RAX, 0); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 663 | asm_x64_mov_local_to_r64(emit->as, local_num - 1, REG_RAX); |
| 664 | emit_post_push_reg(emit, vtype, REG_RAX); |
| 665 | } |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 666 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 667 | if (local_num == 0) { |
| 668 | emit_post_push_reg(emit, vtype, REG_LOCAL_1); |
| 669 | } else if (local_num == 1) { |
| 670 | emit_post_push_reg(emit, vtype, REG_LOCAL_2); |
| 671 | } else if (local_num == 2) { |
| 672 | emit_post_push_reg(emit, vtype, REG_LOCAL_3); |
| 673 | } else { |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 674 | need_reg_single(emit, REG_R0, 0); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 675 | asm_thumb_mov_reg_local(emit->as, REG_R0, local_num - 1); |
| 676 | emit_post_push_reg(emit, vtype, REG_R0); |
| 677 | } |
| 678 | #endif |
| 679 | } |
| 680 | |
Damien | 9ecbcff | 2013-12-11 00:41:43 +0000 | [diff] [blame] | 681 | static void emit_native_load_deref(emit_t *emit, qstr qstr, int local_num) { |
| 682 | // not implemented |
| 683 | // in principle could support this quite easily (ldr r0, [r0, #0]) and then get closed over variables! |
| 684 | assert(0); |
| 685 | } |
| 686 | |
| 687 | static void emit_native_load_closure(emit_t *emit, qstr qstr, int local_num) { |
| 688 | // not implemented |
| 689 | assert(0); |
| 690 | } |
| 691 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 692 | static void emit_native_load_name(emit_t *emit, qstr qstr) { |
| 693 | emit_pre(emit); |
| 694 | emit_call_with_imm_arg(emit, RT_F_LOAD_NAME, rt_load_name, qstr, REG_ARG_1); |
| 695 | emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); |
| 696 | } |
| 697 | |
| 698 | static void emit_native_load_global(emit_t *emit, qstr qstr) { |
| 699 | emit_pre(emit); |
| 700 | emit_call_with_imm_arg(emit, RT_F_LOAD_GLOBAL, rt_load_global, qstr, REG_ARG_1); |
| 701 | emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); |
| 702 | } |
| 703 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 704 | static void emit_native_load_attr(emit_t *emit, qstr qstr) { |
| 705 | // depends on type of subject: |
| 706 | // - integer, function, pointer to integers: error |
| 707 | // - pointer to structure: get member, quite easy |
| 708 | // - Python object: call rt_load_attr, and needs to be typed to convert result |
| 709 | vtype_kind_t vtype_base; |
| 710 | emit_pre_pop_reg(emit, &vtype_base, REG_ARG_1); // arg1 = base |
| 711 | assert(vtype_base == VTYPE_PYOBJ); |
| 712 | emit_call_with_imm_arg(emit, RT_F_LOAD_ATTR, rt_load_attr, qstr, REG_ARG_2); // arg2 = attribute name |
| 713 | emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); |
| 714 | } |
| 715 | |
| 716 | static void emit_native_load_method(emit_t *emit, qstr qstr) { |
| 717 | vtype_kind_t vtype_base; |
| 718 | emit_pre_pop_reg(emit, &vtype_base, REG_ARG_1); // arg1 = base |
| 719 | assert(vtype_base == VTYPE_PYOBJ); |
| 720 | emit_get_stack_pointer_to_reg_for_push(emit, REG_ARG_3, 2); // arg3 = dest ptr |
| 721 | emit_call_with_imm_arg(emit, RT_F_LOAD_METHOD, rt_load_method, qstr, REG_ARG_2); // arg2 = method name |
| 722 | } |
| 723 | |
| 724 | static void emit_native_load_build_class(emit_t *emit) { |
Damien | 7f5dacf | 2013-10-10 11:24:39 +0100 | [diff] [blame] | 725 | emit_pre(emit); |
| 726 | emit_call(emit, RT_F_LOAD_BUILD_CLASS, rt_load_build_class); |
| 727 | emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | static void emit_native_store_fast(emit_t *emit, qstr qstr, int local_num) { |
| 731 | vtype_kind_t vtype; |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 732 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 733 | if (local_num == 0) { |
| 734 | emit_pre_pop_reg(emit, &vtype, REG_LOCAL_1); |
| 735 | } else { |
| 736 | emit_pre_pop_reg(emit, &vtype, REG_RAX); |
| 737 | asm_x64_mov_r64_to_local(emit->as, REG_RAX, local_num - 1); |
| 738 | } |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 739 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 740 | if (local_num == 0) { |
| 741 | emit_pre_pop_reg(emit, &vtype, REG_LOCAL_1); |
| 742 | } else if (local_num == 1) { |
| 743 | emit_pre_pop_reg(emit, &vtype, REG_LOCAL_2); |
| 744 | } else if (local_num == 2) { |
| 745 | emit_pre_pop_reg(emit, &vtype, REG_LOCAL_3); |
| 746 | } else { |
| 747 | emit_pre_pop_reg(emit, &vtype, REG_R0); |
| 748 | asm_thumb_mov_local_reg(emit->as, local_num - 1, REG_R0); |
| 749 | } |
| 750 | #endif |
| 751 | |
| 752 | emit_post(emit); |
| 753 | |
| 754 | // check types |
| 755 | if (emit->local_vtype[local_num] == VTYPE_UNBOUND) { |
| 756 | // first time this local is assigned, so give it a type of the object stored in it |
| 757 | emit->local_vtype[local_num] = vtype; |
| 758 | } else if (emit->local_vtype[local_num] != vtype) { |
| 759 | // type of local is not the same as object stored in it |
| 760 | printf("ViperTypeError: type mismatch, local %s has type %d but source object has type %d\n", qstr_str(qstr), emit->local_vtype[local_num], vtype); |
| 761 | } |
| 762 | } |
| 763 | |
Damien | 9ecbcff | 2013-12-11 00:41:43 +0000 | [diff] [blame] | 764 | static void emit_native_store_deref(emit_t *emit, qstr qstr, int local_num) { |
| 765 | // not implemented |
| 766 | assert(0); |
| 767 | } |
| 768 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 769 | static void emit_native_store_name(emit_t *emit, qstr qstr) { |
| 770 | // rt_store_name, but needs conversion of object (maybe have rt_viper_store_name(obj, type)) |
| 771 | vtype_kind_t vtype; |
| 772 | emit_pre_pop_reg(emit, &vtype, REG_ARG_2); |
| 773 | assert(vtype == VTYPE_PYOBJ); |
| 774 | emit_call_with_imm_arg(emit, RT_F_STORE_NAME, rt_store_name, qstr, REG_ARG_1); // arg1 = name |
| 775 | emit_post(emit); |
| 776 | } |
| 777 | |
| 778 | static void emit_native_store_global(emit_t *emit, qstr qstr) { |
| 779 | // not implemented |
| 780 | assert(0); |
| 781 | } |
| 782 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 783 | static void emit_native_store_attr(emit_t *emit, qstr qstr) { |
Damien | 7f5dacf | 2013-10-10 11:24:39 +0100 | [diff] [blame] | 784 | vtype_kind_t vtype_base, vtype_val; |
| 785 | emit_pre_pop_reg_reg(emit, &vtype_base, REG_ARG_1, &vtype_val, REG_ARG_3); // arg1 = base, arg3 = value |
| 786 | assert(vtype_base == VTYPE_PYOBJ); |
| 787 | assert(vtype_val == VTYPE_PYOBJ); |
| 788 | emit_call_with_imm_arg(emit, RT_F_STORE_ATTR, rt_store_attr, qstr, REG_ARG_2); // arg2 = attribute name |
| 789 | emit_post(emit); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 790 | } |
| 791 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 792 | static void emit_native_store_subscr(emit_t *emit) { |
| 793 | // depends on type of subject: |
| 794 | // - integer, function, pointer to structure: error |
| 795 | // - pointer to integers: store as per array |
| 796 | // - Python object: call runtime with converted object or type info |
| 797 | vtype_kind_t vtype_index, vtype_base, vtype_value; |
| 798 | emit_pre_pop_reg_reg_reg(emit, &vtype_index, REG_ARG_2, &vtype_base, REG_ARG_1, &vtype_value, REG_ARG_3); // index, base, value to store |
| 799 | assert(vtype_index == VTYPE_PYOBJ); |
| 800 | assert(vtype_base == VTYPE_PYOBJ); |
| 801 | assert(vtype_value == VTYPE_PYOBJ); |
| 802 | emit_call(emit, RT_F_STORE_SUBSCR, rt_store_subscr); |
| 803 | } |
| 804 | |
Damien | a397776 | 2013-10-09 23:10:10 +0100 | [diff] [blame] | 805 | static void emit_native_store_locals(emit_t *emit) { |
| 806 | // not needed |
| 807 | vtype_kind_t vtype; |
| 808 | emit_pre_pop_reg(emit, &vtype, REG_TEMP0); |
| 809 | emit_post(emit); |
| 810 | } |
| 811 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 812 | static void emit_native_delete_fast(emit_t *emit, qstr qstr, int local_num) { |
| 813 | // not implemented |
| 814 | // could support for Python types, just set to None (so GC can reclaim it) |
| 815 | assert(0); |
| 816 | } |
| 817 | |
Damien | 9ecbcff | 2013-12-11 00:41:43 +0000 | [diff] [blame] | 818 | static void emit_native_delete_deref(emit_t *emit, qstr qstr, int local_num) { |
| 819 | // not supported |
| 820 | assert(0); |
| 821 | } |
| 822 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 823 | static void emit_native_delete_name(emit_t *emit, qstr qstr) { |
| 824 | // not implemented |
| 825 | // use rt_delete_name |
| 826 | assert(0); |
| 827 | } |
| 828 | |
| 829 | static void emit_native_delete_global(emit_t *emit, qstr qstr) { |
| 830 | // not implemented |
| 831 | // use rt_delete_global |
| 832 | assert(0); |
| 833 | } |
| 834 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 835 | static void emit_native_delete_attr(emit_t *emit, qstr qstr) { |
| 836 | // not supported |
| 837 | assert(0); |
| 838 | } |
| 839 | |
| 840 | static void emit_native_delete_subscr(emit_t *emit) { |
| 841 | // not supported |
| 842 | assert(0); |
| 843 | } |
| 844 | |
| 845 | static void emit_native_dup_top(emit_t *emit) { |
| 846 | vtype_kind_t vtype; |
| 847 | emit_pre_pop_reg(emit, &vtype, REG_TEMP0); |
| 848 | emit_post_push_reg_reg(emit, vtype, REG_TEMP0, vtype, REG_TEMP0); |
| 849 | } |
| 850 | |
| 851 | static void emit_native_dup_top_two(emit_t *emit) { |
| 852 | vtype_kind_t vtype0, vtype1; |
| 853 | emit_pre_pop_reg_reg(emit, &vtype0, REG_TEMP0, &vtype1, REG_TEMP1); |
| 854 | emit_post_push_reg_reg_reg_reg(emit, vtype1, REG_TEMP1, vtype0, REG_TEMP0, vtype1, REG_TEMP1, vtype0, REG_TEMP0); |
| 855 | } |
| 856 | |
| 857 | static void emit_native_pop_top(emit_t *emit) { |
| 858 | vtype_kind_t vtype; |
| 859 | emit_pre_pop_reg(emit, &vtype, REG_TEMP0); |
| 860 | emit_post(emit); |
| 861 | } |
| 862 | |
| 863 | static void emit_native_rot_two(emit_t *emit) { |
Damien | ff8ed77 | 2013-10-08 22:18:32 +0100 | [diff] [blame] | 864 | vtype_kind_t vtype0, vtype1; |
| 865 | emit_pre_pop_reg_reg(emit, &vtype0, REG_TEMP0, &vtype1, REG_TEMP1); |
| 866 | emit_post_push_reg_reg(emit, vtype0, REG_TEMP0, vtype1, REG_TEMP1); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | static void emit_native_rot_three(emit_t *emit) { |
| 870 | vtype_kind_t vtype0, vtype1, vtype2; |
| 871 | emit_pre_pop_reg_reg_reg(emit, &vtype0, REG_TEMP0, &vtype1, REG_TEMP1, &vtype2, REG_TEMP2); |
| 872 | emit_post_push_reg_reg_reg(emit, vtype0, REG_TEMP0, vtype2, REG_TEMP2, vtype1, REG_TEMP1); |
| 873 | } |
| 874 | |
| 875 | static void emit_native_jump(emit_t *emit, int label) { |
| 876 | emit_pre(emit); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 877 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 878 | asm_x64_jmp_label(emit->as, label); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 879 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 880 | asm_thumb_b_label(emit->as, label); |
| 881 | #endif |
| 882 | emit_post(emit); |
| 883 | } |
| 884 | |
Damien | 1a6633a | 2013-11-03 13:58:19 +0000 | [diff] [blame] | 885 | static void emit_native_pop_jump_pre_helper(emit_t *emit, int label) { |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 886 | vtype_kind_t vtype = peek_vtype(emit); |
| 887 | if (vtype == VTYPE_BOOL) { |
| 888 | emit_pre_pop_reg(emit, &vtype, REG_RET); |
| 889 | } else if (vtype == VTYPE_PYOBJ) { |
| 890 | emit_pre_pop_reg(emit, &vtype, REG_ARG_1); |
| 891 | emit_call(emit, RT_F_IS_TRUE, rt_is_true); |
| 892 | } else { |
| 893 | printf("ViperTypeError: expecting a bool or pyobj, got %d\n", vtype); |
| 894 | assert(0); |
| 895 | } |
Damien | 1a6633a | 2013-11-03 13:58:19 +0000 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | static void emit_native_pop_jump_if_false(emit_t *emit, int label) { |
| 899 | emit_native_pop_jump_pre_helper(emit, label); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 900 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 901 | asm_x64_test_r8_with_r8(emit->as, REG_RET, REG_RET); |
| 902 | asm_x64_jcc_label(emit->as, JCC_JZ, label); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 903 | #elif N_THUMB |
Damien | 1a6633a | 2013-11-03 13:58:19 +0000 | [diff] [blame] | 904 | asm_thumb_cmp_rlo_i8(emit->as, REG_RET, 0); |
| 905 | asm_thumb_bcc_label(emit->as, THUMB_CC_EQ, label); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 906 | #endif |
| 907 | emit_post(emit); |
| 908 | } |
| 909 | |
| 910 | static void emit_native_pop_jump_if_true(emit_t *emit, int label) { |
Damien | 1a6633a | 2013-11-03 13:58:19 +0000 | [diff] [blame] | 911 | emit_native_pop_jump_pre_helper(emit, label); |
| 912 | #if N_X64 |
| 913 | asm_x64_test_r8_with_r8(emit->as, REG_RET, REG_RET); |
| 914 | asm_x64_jcc_label(emit->as, JCC_JNZ, label); |
| 915 | #elif N_THUMB |
| 916 | asm_thumb_cmp_rlo_i8(emit->as, REG_RET, 0); |
| 917 | asm_thumb_bcc_label(emit->as, THUMB_CC_NE, label); |
| 918 | #endif |
| 919 | emit_post(emit); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 920 | } |
Damien | 1a6633a | 2013-11-03 13:58:19 +0000 | [diff] [blame] | 921 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 922 | static void emit_native_jump_if_true_or_pop(emit_t *emit, int label) { |
| 923 | assert(0); |
| 924 | } |
| 925 | static void emit_native_jump_if_false_or_pop(emit_t *emit, int label) { |
| 926 | assert(0); |
| 927 | } |
| 928 | |
| 929 | static void emit_native_setup_loop(emit_t *emit, int label) { |
| 930 | emit_pre(emit); |
| 931 | emit_post(emit); |
| 932 | } |
| 933 | |
| 934 | static void emit_native_break_loop(emit_t *emit, int label) { |
Damien | 6ba1314 | 2013-11-02 20:34:54 +0000 | [diff] [blame] | 935 | emit_native_jump(emit, label); // TODO properly |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 936 | } |
| 937 | static void emit_native_continue_loop(emit_t *emit, int label) { |
| 938 | assert(0); |
| 939 | } |
| 940 | static void emit_native_setup_with(emit_t *emit, int label) { |
| 941 | // not supported, or could be with runtime call |
| 942 | assert(0); |
| 943 | } |
| 944 | static void emit_native_with_cleanup(emit_t *emit) { |
| 945 | assert(0); |
| 946 | } |
| 947 | static void emit_native_setup_except(emit_t *emit, int label) { |
| 948 | assert(0); |
| 949 | } |
| 950 | static void emit_native_setup_finally(emit_t *emit, int label) { |
| 951 | assert(0); |
| 952 | } |
| 953 | static void emit_native_end_finally(emit_t *emit) { |
| 954 | assert(0); |
| 955 | } |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 956 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 957 | static void emit_native_get_iter(emit_t *emit) { |
| 958 | // perhaps the difficult one, as we want to rewrite for loops using native code |
| 959 | // in cases where we iterate over a Python object, can we use normal runtime calls? |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 960 | |
| 961 | vtype_kind_t vtype; |
| 962 | emit_pre_pop_reg(emit, &vtype, REG_ARG_1); |
| 963 | assert(vtype == VTYPE_PYOBJ); |
| 964 | emit_call(emit, RT_F_GETITER, rt_getiter); |
| 965 | emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 966 | } |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 967 | |
| 968 | static void emit_native_for_iter(emit_t *emit, int label) { |
| 969 | emit_pre(emit); |
| 970 | vtype_kind_t vtype; |
| 971 | emit_access_stack(emit, 1, &vtype, REG_ARG_1); |
| 972 | assert(vtype == VTYPE_PYOBJ); |
| 973 | emit_call(emit, RT_F_ITERNEXT, rt_iternext); |
Damien | d99b052 | 2013-12-21 18:17:45 +0000 | [diff] [blame] | 974 | 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] | 975 | #if N_X64 |
| 976 | asm_x64_cmp_r64_with_r64(emit->as, REG_RET, REG_TEMP1); |
| 977 | asm_x64_jcc_label(emit->as, JCC_JE, label); |
| 978 | #elif N_THUMB |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 979 | asm_thumb_cmp_reg_reg(emit->as, REG_RET, REG_TEMP1); |
Damien | 9b9e996 | 2013-11-03 14:25:43 +0000 | [diff] [blame] | 980 | asm_thumb_bcc_label(emit->as, THUMB_CC_EQ, label); |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 981 | #endif |
| 982 | emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); |
| 983 | } |
| 984 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 985 | static void emit_native_for_iter_end(emit_t *emit) { |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 986 | // adjust stack counter (we get here from for_iter ending, which popped the value for us) |
| 987 | emit_pre(emit); |
| 988 | adjust_stack(emit, -1); |
| 989 | emit_post(emit); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | static void emit_native_pop_block(emit_t *emit) { |
| 993 | emit_pre(emit); |
| 994 | emit_post(emit); |
| 995 | } |
| 996 | |
| 997 | static void emit_native_pop_except(emit_t *emit) { |
| 998 | assert(0); |
| 999 | } |
| 1000 | |
| 1001 | static void emit_native_unary_op(emit_t *emit, rt_unary_op_t op) { |
| 1002 | vtype_kind_t vtype; |
| 1003 | emit_pre_pop_reg(emit, &vtype, REG_ARG_2); |
| 1004 | assert(vtype == VTYPE_PYOBJ); |
| 1005 | emit_call_with_imm_arg(emit, RT_F_UNARY_OP, rt_unary_op, op, REG_ARG_1); |
| 1006 | emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); |
| 1007 | } |
| 1008 | |
| 1009 | static void emit_native_binary_op(emit_t *emit, rt_binary_op_t op) { |
| 1010 | vtype_kind_t vtype_lhs, vtype_rhs; |
| 1011 | emit_pre_pop_reg_reg(emit, &vtype_rhs, REG_ARG_3, &vtype_lhs, REG_ARG_2); |
| 1012 | if (vtype_lhs == VTYPE_INT && vtype_rhs == VTYPE_INT) { |
Damien George | bc1d369 | 2014-01-11 09:47:06 +0000 | [diff] [blame] | 1013 | if (op == RT_BINARY_OP_ADD || op == RT_BINARY_OP_INPLACE_ADD) { |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 1014 | #if N_X64 |
Damien George | bc1d369 | 2014-01-11 09:47:06 +0000 | [diff] [blame] | 1015 | 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] | 1016 | #elif N_THUMB |
Damien George | bc1d369 | 2014-01-11 09:47:06 +0000 | [diff] [blame] | 1017 | 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] | 1018 | #endif |
Damien George | bc1d369 | 2014-01-11 09:47:06 +0000 | [diff] [blame] | 1019 | emit_post_push_reg(emit, VTYPE_INT, REG_ARG_2); |
| 1020 | } else if (op == RT_COMPARE_OP_LESS) { |
| 1021 | #if N_X64 |
| 1022 | asm_x64_xor_r64_to_r64(emit->as, REG_RET, REG_RET); |
| 1023 | asm_x64_cmp_r64_with_r64(emit->as, REG_ARG_3, REG_ARG_2); |
| 1024 | asm_x64_setcc_r8(emit->as, JCC_JL, REG_RET); |
| 1025 | #elif N_THUMB |
| 1026 | asm_thumb_cmp_reg_reg(emit->as, REG_ARG_2, REG_ARG_3); |
| 1027 | asm_thumb_ite_ge(emit->as); |
| 1028 | asm_thumb_movs_rlo_i8(emit->as, REG_RET, 0); // if r0 >= r1 |
| 1029 | asm_thumb_movs_rlo_i8(emit->as, REG_RET, 1); // if r0 < r1 |
| 1030 | #endif |
| 1031 | emit_post_push_reg(emit, VTYPE_BOOL, REG_RET); |
| 1032 | } else { |
| 1033 | // TODO other ops not yet implemented |
| 1034 | assert(0); |
| 1035 | } |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1036 | } else if (vtype_lhs == VTYPE_PYOBJ && vtype_rhs == VTYPE_PYOBJ) { |
| 1037 | emit_call_with_imm_arg(emit, RT_F_BINARY_OP, rt_binary_op, op, REG_ARG_1); |
| 1038 | emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); |
| 1039 | } else { |
| 1040 | printf("ViperTypeError: can't do binary op between types %d and %d\n", vtype_lhs, vtype_rhs); |
| 1041 | assert(0); |
| 1042 | } |
| 1043 | } |
| 1044 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1045 | static void emit_native_build_tuple(emit_t *emit, int n_args) { |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 1046 | // for viper: call runtime, with types of args |
| 1047 | // if wrapped in byte_array, or something, allocates memory and fills it |
| 1048 | emit_pre(emit); |
| 1049 | emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, n_args); // pointer to items in reverse order |
| 1050 | emit_call_with_imm_arg(emit, RT_F_BUILD_TUPLE, rt_build_tuple, n_args, REG_ARG_1); |
| 1051 | emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new tuple |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | static void emit_native_build_list(emit_t *emit, int n_args) { |
| 1055 | emit_pre(emit); |
| 1056 | emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, n_args); // pointer to items in reverse order |
| 1057 | emit_call_with_imm_arg(emit, RT_F_BUILD_LIST, rt_build_list, n_args, REG_ARG_1); |
| 1058 | emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new list |
| 1059 | } |
| 1060 | |
| 1061 | static void emit_native_list_append(emit_t *emit, int list_index) { |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 1062 | // only used in list comprehension |
| 1063 | vtype_kind_t vtype_list, vtype_item; |
| 1064 | emit_pre_pop_reg(emit, &vtype_item, REG_ARG_2); |
| 1065 | emit_access_stack(emit, list_index, &vtype_list, REG_ARG_1); |
| 1066 | assert(vtype_list == VTYPE_PYOBJ); |
| 1067 | assert(vtype_item == VTYPE_PYOBJ); |
| 1068 | emit_call(emit, RT_F_LIST_APPEND, rt_list_append); |
| 1069 | emit_post(emit); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | static void emit_native_build_map(emit_t *emit, int n_args) { |
| 1073 | emit_pre(emit); |
| 1074 | emit_call_with_imm_arg(emit, RT_F_BUILD_MAP, rt_build_map, n_args, REG_ARG_1); |
| 1075 | emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new map |
| 1076 | } |
| 1077 | |
| 1078 | static void emit_native_store_map(emit_t *emit) { |
| 1079 | vtype_kind_t vtype_key, vtype_value, vtype_map; |
| 1080 | emit_pre_pop_reg_reg_reg(emit, &vtype_key, REG_ARG_2, &vtype_value, REG_ARG_3, &vtype_map, REG_ARG_1); // key, value, map |
| 1081 | assert(vtype_key == VTYPE_PYOBJ); |
| 1082 | assert(vtype_value == VTYPE_PYOBJ); |
| 1083 | assert(vtype_map == VTYPE_PYOBJ); |
| 1084 | emit_call(emit, RT_F_STORE_MAP, rt_store_map); |
| 1085 | emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // map |
| 1086 | } |
| 1087 | |
| 1088 | static void emit_native_map_add(emit_t *emit, int map_index) { |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 1089 | // only used in list comprehension |
| 1090 | vtype_kind_t vtype_map, vtype_key, vtype_value; |
| 1091 | emit_pre_pop_reg_reg(emit, &vtype_key, REG_ARG_2, &vtype_value, REG_ARG_3); |
| 1092 | emit_access_stack(emit, map_index, &vtype_map, REG_ARG_1); |
| 1093 | assert(vtype_map == VTYPE_PYOBJ); |
| 1094 | assert(vtype_key == VTYPE_PYOBJ); |
| 1095 | assert(vtype_value == VTYPE_PYOBJ); |
| 1096 | emit_call(emit, RT_F_STORE_MAP, rt_store_map); |
| 1097 | emit_post(emit); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | static void emit_native_build_set(emit_t *emit, int n_args) { |
| 1101 | emit_pre(emit); |
| 1102 | emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, n_args); // pointer to items in reverse order |
| 1103 | emit_call_with_imm_arg(emit, RT_F_BUILD_SET, rt_build_set, n_args, REG_ARG_1); |
| 1104 | emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new set |
| 1105 | } |
| 1106 | |
| 1107 | static void emit_native_set_add(emit_t *emit, int set_index) { |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 1108 | // only used in set comprehension |
| 1109 | vtype_kind_t vtype_set, vtype_item; |
| 1110 | emit_pre_pop_reg(emit, &vtype_item, REG_ARG_2); |
| 1111 | emit_access_stack(emit, set_index, &vtype_set, REG_ARG_1); |
| 1112 | assert(vtype_set == VTYPE_PYOBJ); |
| 1113 | assert(vtype_item == VTYPE_PYOBJ); |
| 1114 | emit_call(emit, RT_F_STORE_SET, rt_store_set); |
| 1115 | emit_post(emit); |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1116 | } |
Damien | d2755ec | 2013-10-16 23:58:48 +0100 | [diff] [blame] | 1117 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1118 | static void emit_native_build_slice(emit_t *emit, int n_args) { |
| 1119 | assert(0); |
| 1120 | } |
| 1121 | static void emit_native_unpack_sequence(emit_t *emit, int n_args) { |
| 1122 | // call runtime, needs type decl |
| 1123 | assert(0); |
| 1124 | } |
| 1125 | static void emit_native_unpack_ex(emit_t *emit, int n_left, int n_right) { |
| 1126 | assert(0); |
| 1127 | } |
| 1128 | |
| 1129 | static void emit_native_make_function(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) { |
| 1130 | // call runtime, with type info for args, or don't support dict/default params, or only support Python objects for them |
| 1131 | assert(n_default_params == 0 && n_dict_params == 0); |
| 1132 | emit_pre(emit); |
| 1133 | emit_call_with_imm_arg(emit, RT_F_MAKE_FUNCTION_FROM_ID, rt_make_function_from_id, scope->unique_code_id, REG_ARG_1); |
| 1134 | emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); |
| 1135 | } |
| 1136 | |
| 1137 | static void emit_native_make_closure(emit_t *emit, scope_t *scope, int n_dict_params, int n_default_params) { |
| 1138 | assert(0); |
| 1139 | } |
| 1140 | |
| 1141 | static void emit_native_call_function(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) { |
| 1142 | // call special viper runtime routine with type info for args, and wanted type info for return |
| 1143 | assert(n_keyword == 0 && !have_star_arg && !have_dbl_star_arg); |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 1144 | /* |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1145 | if (n_positional == 0) { |
| 1146 | vtype_kind_t vtype_fun; |
| 1147 | emit_pre_pop_reg(emit, &vtype_fun, REG_ARG_1); // the function |
| 1148 | assert(vtype_fun == VTYPE_PYOBJ); |
| 1149 | emit_call(emit, RT_F_CALL_FUNCTION_0, rt_call_function_0); |
| 1150 | } else if (n_positional == 1) { |
| 1151 | vtype_kind_t vtype_fun, vtype_arg1; |
| 1152 | emit_pre_pop_reg_reg(emit, &vtype_arg1, REG_ARG_2, &vtype_fun, REG_ARG_1); // the single argument, the function |
| 1153 | assert(vtype_fun == VTYPE_PYOBJ); |
| 1154 | assert(vtype_arg1 == VTYPE_PYOBJ); |
| 1155 | emit_call(emit, RT_F_CALL_FUNCTION_1, rt_call_function_1); |
| 1156 | } else if (n_positional == 2) { |
| 1157 | vtype_kind_t vtype_fun, vtype_arg1, vtype_arg2; |
| 1158 | emit_pre_pop_reg_reg_reg(emit, &vtype_arg2, REG_ARG_3, &vtype_arg1, REG_ARG_2, &vtype_fun, REG_ARG_1); // the second argument, the first argument, the function |
| 1159 | assert(vtype_fun == VTYPE_PYOBJ); |
| 1160 | assert(vtype_arg1 == VTYPE_PYOBJ); |
| 1161 | assert(vtype_arg2 == VTYPE_PYOBJ); |
| 1162 | emit_call(emit, RT_F_CALL_FUNCTION_2, rt_call_function_2); |
| 1163 | } else { |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 1164 | */ |
| 1165 | emit_pre(emit); |
| 1166 | if (n_positional != 0) { |
| 1167 | emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_3, n_positional); // pointer to args in reverse order |
| 1168 | } |
| 1169 | vtype_kind_t vtype_fun; |
| 1170 | emit_pre_pop_reg(emit, &vtype_fun, REG_ARG_1); // the function |
| 1171 | assert(vtype_fun == VTYPE_PYOBJ); |
Damien George | 20006db | 2014-01-18 14:10:48 +0000 | [diff] [blame] | 1172 | // XXX rt_call_function_n now merged with rt_call_function_n_kw |
| 1173 | //emit_call_with_imm_arg(emit, RT_F_CALL_FUNCTION_N, rt_call_function_n, n_positional, REG_ARG_2); |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 1174 | //} |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1175 | emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); |
| 1176 | } |
| 1177 | |
| 1178 | static void emit_native_call_method(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) { |
| 1179 | assert(n_keyword == 0 && !have_star_arg && !have_dbl_star_arg); |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 1180 | /* |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1181 | if (n_positional == 0) { |
| 1182 | vtype_kind_t vtype_meth, vtype_self; |
| 1183 | emit_pre_pop_reg_reg(emit, &vtype_self, REG_ARG_2, &vtype_meth, REG_ARG_1); // the self object (or NULL), the method |
| 1184 | assert(vtype_meth == VTYPE_PYOBJ); |
| 1185 | assert(vtype_self == VTYPE_PYOBJ); |
| 1186 | emit_call(emit, RT_F_CALL_METHOD_1, rt_call_method_1); |
| 1187 | } else if (n_positional == 1) { |
| 1188 | vtype_kind_t vtype_meth, vtype_self, vtype_arg1; |
| 1189 | emit_pre_pop_reg_reg_reg(emit, &vtype_arg1, REG_ARG_3, &vtype_self, REG_ARG_2, &vtype_meth, REG_ARG_1); // the first argument, the self object (or NULL), the method |
| 1190 | assert(vtype_meth == VTYPE_PYOBJ); |
| 1191 | assert(vtype_self == VTYPE_PYOBJ); |
| 1192 | assert(vtype_arg1 == VTYPE_PYOBJ); |
| 1193 | emit_call(emit, RT_F_CALL_METHOD_2, rt_call_method_2); |
| 1194 | } else { |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 1195 | */ |
Damien | 7f5dacf | 2013-10-10 11:24:39 +0100 | [diff] [blame] | 1196 | emit_pre(emit); |
| 1197 | emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, n_positional + 2); // pointer to items in reverse order, including meth and self |
Damien George | 20006db | 2014-01-18 14:10:48 +0000 | [diff] [blame] | 1198 | // XXX rt_call_method_n now merged with rt_call_method_n_kw |
| 1199 | //emit_call_with_imm_arg(emit, RT_F_CALL_METHOD_N, rt_call_method_n, n_positional, REG_ARG_1); |
Damien | eb19efb | 2013-10-10 22:06:54 +0100 | [diff] [blame] | 1200 | //} |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1201 | emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); |
| 1202 | } |
| 1203 | |
| 1204 | static void emit_native_return_value(emit_t *emit) { |
| 1205 | // easy. since we don't know who we return to, just return the raw value. |
| 1206 | // runtime needs then to know our type signature, but I think that's possible. |
| 1207 | vtype_kind_t vtype; |
| 1208 | emit_pre_pop_reg(emit, &vtype, REG_RET); |
| 1209 | if (emit->do_viper_types) { |
| 1210 | assert(vtype == VTYPE_PTR_NONE); |
| 1211 | } else { |
| 1212 | assert(vtype == VTYPE_PYOBJ); |
| 1213 | } |
| 1214 | emit->last_emit_was_return_value = true; |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 1215 | #if N_X64 |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1216 | //asm_x64_call_ind(emit->as, 0, REG_RAX); to seg fault for debugging with gdb |
| 1217 | asm_x64_exit(emit->as); |
Damien | 3ef4abb | 2013-10-12 16:53:13 +0100 | [diff] [blame] | 1218 | #elif N_THUMB |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1219 | //asm_thumb_call_ind(emit->as, 0, REG_R0); to seg fault for debugging with gdb |
| 1220 | asm_thumb_exit(emit->as); |
| 1221 | #endif |
| 1222 | } |
| 1223 | |
| 1224 | static void emit_native_raise_varargs(emit_t *emit, int n_args) { |
| 1225 | // call runtime |
| 1226 | assert(0); |
| 1227 | } |
| 1228 | static void emit_native_yield_value(emit_t *emit) { |
| 1229 | // not supported (for now) |
| 1230 | assert(0); |
| 1231 | } |
| 1232 | static void emit_native_yield_from(emit_t *emit) { |
| 1233 | // not supported (for now) |
| 1234 | assert(0); |
| 1235 | } |
| 1236 | |
| 1237 | const emit_method_table_t EXPORT_FUN(method_table) = { |
Paul Sokolovsky | f46d87a | 2014-01-24 16:20:11 +0200 | [diff] [blame^] | 1238 | emit_native_free, |
| 1239 | |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1240 | emit_native_set_viper_types, |
| 1241 | emit_native_start_pass, |
| 1242 | emit_native_end_pass, |
| 1243 | emit_native_last_emit_was_return_value, |
| 1244 | emit_native_get_stack_size, |
| 1245 | emit_native_set_stack_size, |
Damien George | 0833500 | 2014-01-18 23:24:36 +0000 | [diff] [blame] | 1246 | emit_native_set_source_line, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1247 | |
| 1248 | emit_native_load_id, |
| 1249 | emit_native_store_id, |
| 1250 | emit_native_delete_id, |
| 1251 | |
| 1252 | emit_native_label_assign, |
| 1253 | emit_native_import_name, |
| 1254 | emit_native_import_from, |
| 1255 | emit_native_import_star, |
| 1256 | emit_native_load_const_tok, |
| 1257 | emit_native_load_const_small_int, |
| 1258 | emit_native_load_const_int, |
| 1259 | emit_native_load_const_dec, |
| 1260 | emit_native_load_const_id, |
| 1261 | emit_native_load_const_str, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1262 | emit_native_load_const_verbatim_str, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1263 | emit_native_load_fast, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1264 | emit_native_load_deref, |
| 1265 | emit_native_load_closure, |
Damien | 9ecbcff | 2013-12-11 00:41:43 +0000 | [diff] [blame] | 1266 | emit_native_load_name, |
| 1267 | emit_native_load_global, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1268 | emit_native_load_attr, |
| 1269 | emit_native_load_method, |
| 1270 | emit_native_load_build_class, |
| 1271 | emit_native_store_fast, |
Damien | 9ecbcff | 2013-12-11 00:41:43 +0000 | [diff] [blame] | 1272 | emit_native_store_deref, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1273 | emit_native_store_name, |
| 1274 | emit_native_store_global, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1275 | emit_native_store_attr, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1276 | emit_native_store_subscr, |
Damien | a397776 | 2013-10-09 23:10:10 +0100 | [diff] [blame] | 1277 | emit_native_store_locals, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1278 | emit_native_delete_fast, |
Damien | 9ecbcff | 2013-12-11 00:41:43 +0000 | [diff] [blame] | 1279 | emit_native_delete_deref, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1280 | emit_native_delete_name, |
| 1281 | emit_native_delete_global, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1282 | emit_native_delete_attr, |
| 1283 | emit_native_delete_subscr, |
| 1284 | emit_native_dup_top, |
| 1285 | emit_native_dup_top_two, |
| 1286 | emit_native_pop_top, |
| 1287 | emit_native_rot_two, |
| 1288 | emit_native_rot_three, |
| 1289 | emit_native_jump, |
| 1290 | emit_native_pop_jump_if_true, |
| 1291 | emit_native_pop_jump_if_false, |
| 1292 | emit_native_jump_if_true_or_pop, |
| 1293 | emit_native_jump_if_false_or_pop, |
| 1294 | emit_native_setup_loop, |
| 1295 | emit_native_break_loop, |
| 1296 | emit_native_continue_loop, |
| 1297 | emit_native_setup_with, |
| 1298 | emit_native_with_cleanup, |
| 1299 | emit_native_setup_except, |
| 1300 | emit_native_setup_finally, |
| 1301 | emit_native_end_finally, |
| 1302 | emit_native_get_iter, |
| 1303 | emit_native_for_iter, |
| 1304 | emit_native_for_iter_end, |
| 1305 | emit_native_pop_block, |
| 1306 | emit_native_pop_except, |
| 1307 | emit_native_unary_op, |
| 1308 | emit_native_binary_op, |
Damien | 13ed3a6 | 2013-10-08 09:05:10 +0100 | [diff] [blame] | 1309 | emit_native_build_tuple, |
| 1310 | emit_native_build_list, |
| 1311 | emit_native_list_append, |
| 1312 | emit_native_build_map, |
| 1313 | emit_native_store_map, |
| 1314 | emit_native_map_add, |
| 1315 | emit_native_build_set, |
| 1316 | emit_native_set_add, |
| 1317 | emit_native_build_slice, |
| 1318 | emit_native_unpack_sequence, |
| 1319 | emit_native_unpack_ex, |
| 1320 | emit_native_make_function, |
| 1321 | emit_native_make_closure, |
| 1322 | emit_native_call_function, |
| 1323 | emit_native_call_method, |
| 1324 | emit_native_return_value, |
| 1325 | emit_native_raise_varargs, |
| 1326 | emit_native_yield_value, |
| 1327 | emit_native_yield_from, |
| 1328 | }; |
| 1329 | |
Damien George | e67ed5d | 2014-01-04 13:55:24 +0000 | [diff] [blame] | 1330 | #endif // (MICROPY_EMIT_X64 && N_X64) || (MICROPY_EMIT_THUMB && N_THUMB) |