blob: 6b3c8dc1d047e82da0885b8a03cf4ea5451cd801 [file] [log] [blame]
Damienc226dca2013-10-16 16:12:52 +01001// in principle, rt_xxx functions are called only by vm/native/viper and make assumptions about args
Damiend99b0522013-12-21 18:17:45 +00002// mp_xxx functions are safer and can be called by anyone
Damienbd254452013-10-16 20:39:12 +01003// note that rt_assign_xxx are called only from emit*, and maybe we can rename them to reflect this
Damienc226dca2013-10-16 16:12:52 +01004
Damien429d7192013-10-04 19:53:11 +01005#include <stdint.h>
6#include <stdlib.h>
7#include <stdio.h>
8#include <string.h>
9#include <assert.h>
10
Damience89a212013-10-15 22:25:17 +010011#include "nlr.h"
Damien429d7192013-10-04 19:53:11 +010012#include "misc.h"
Damiend99b0522013-12-21 18:17:45 +000013#include "mpconfig.h"
Damien George55baff42014-01-21 21:40:13 +000014#include "qstr.h"
Damien660365e2013-12-17 18:27:24 +000015#include "obj.h"
Damiend99b0522013-12-21 18:17:45 +000016#include "runtime0.h"
17#include "runtime.h"
18#include "map.h"
Damien660365e2013-12-17 18:27:24 +000019#include "builtin.h"
Paul Sokolovsky427905c2014-01-18 19:24:47 +020020#include "objarray.h"
Damien George5fa93b62014-01-22 14:35:10 +000021#include "bc.h"
Damien660365e2013-12-17 18:27:24 +000022
Damien7f5dacf2013-10-10 11:24:39 +010023#if 0 // print debugging info
Damiena1ddfcc2013-10-10 23:25:50 +010024#define DEBUG_PRINT (1)
Damien0446a0d2013-11-17 13:16:36 +000025#define WRITE_CODE (1)
Damien7f5dacf2013-10-10 11:24:39 +010026#define DEBUG_printf(args...) printf(args)
27#define DEBUG_OP_printf(args...) printf(args)
28#else // don't print debugging info
Damiena3977762013-10-09 23:10:10 +010029#define DEBUG_printf(args...) (void)0
Damien429d7192013-10-04 19:53:11 +010030#define DEBUG_OP_printf(args...) (void)0
Damien7f5dacf2013-10-10 11:24:39 +010031#endif
Damien429d7192013-10-04 19:53:11 +010032
Damieneb19efb2013-10-10 22:06:54 +010033// locals and globals need to be pointers because they can be the same in outer module scope
Damiend99b0522013-12-21 18:17:45 +000034static mp_map_t *map_locals;
35static mp_map_t *map_globals;
36static mp_map_t map_builtins;
Damien George0d028742014-01-22 23:59:20 +000037static mp_map_t map_loaded_modules; // TODO: expose as sys.modules
Damienbd254452013-10-16 20:39:12 +010038
Damien429d7192013-10-04 19:53:11 +010039typedef enum {
Damiend99b0522013-12-21 18:17:45 +000040 MP_CODE_NONE,
41 MP_CODE_BYTE,
42 MP_CODE_NATIVE,
43 MP_CODE_INLINE_ASM,
44} mp_code_kind_t;
Damien429d7192013-10-04 19:53:11 +010045
Damiend99b0522013-12-21 18:17:45 +000046typedef struct _mp_code_t {
Damien Georged0691cc2014-01-29 20:30:52 +000047 struct {
48 mp_code_kind_t kind : 8;
49 bool is_generator : 1;
50 };
51 struct {
52 uint n_args : 16;
53 uint n_state : 16;
54 };
Damien429d7192013-10-04 19:53:11 +010055 union {
56 struct {
Damien429d7192013-10-04 19:53:11 +010057 byte *code;
58 uint len;
59 } u_byte;
Damien826005c2013-10-05 23:17:28 +010060 struct {
Damiend99b0522013-12-21 18:17:45 +000061 mp_fun_t fun;
Damien826005c2013-10-05 23:17:28 +010062 } u_native;
63 struct {
Damiene4af64f2013-10-06 12:04:13 +010064 void *fun;
Damien826005c2013-10-05 23:17:28 +010065 } u_inline_asm;
Damien429d7192013-10-04 19:53:11 +010066 };
Damiend99b0522013-12-21 18:17:45 +000067} mp_code_t;
Damien429d7192013-10-04 19:53:11 +010068
Damien Georged0691cc2014-01-29 20:30:52 +000069static uint next_unique_code_id;
John R. Lenton9c83ec02014-01-07 23:06:46 +000070static machine_uint_t unique_codes_alloc = 0;
71static mp_code_t *unique_codes = NULL;
Damien429d7192013-10-04 19:53:11 +010072
Damien0446a0d2013-11-17 13:16:36 +000073#ifdef WRITE_CODE
74FILE *fp_write_code = NULL;
Damiena1ddfcc2013-10-10 23:25:50 +010075#endif
Damien429d7192013-10-04 19:53:11 +010076
Damien George38a2da62014-01-08 17:33:12 +000077// a good optimising compiler will inline this if necessary
78static void mp_map_add_qstr(mp_map_t *map, qstr qstr, mp_obj_t value) {
79 mp_map_lookup(map, MP_OBJ_NEW_QSTR(qstr), MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)->value = value;
80}
81
Damien8b3a7c22013-10-23 20:20:17 +010082void rt_init(void) {
Damieneb19efb2013-10-10 22:06:54 +010083 // locals = globals for outer module (see Objects/frameobject.c/PyFrame_New())
Damien George38a2da62014-01-08 17:33:12 +000084 map_locals = map_globals = mp_map_new(1);
Damien George5fa93b62014-01-22 14:35:10 +000085 mp_map_add_qstr(map_globals, MP_QSTR___name__, MP_OBJ_NEW_QSTR(MP_QSTR___main__));
Damien429d7192013-10-04 19:53:11 +010086
Damienb86e3f92013-12-29 17:17:43 +000087 // init built-in hash table
Damien George38a2da62014-01-08 17:33:12 +000088 mp_map_init(&map_builtins, 3);
Damienb86e3f92013-12-29 17:17:43 +000089
Damien George0d028742014-01-22 23:59:20 +000090 // init loaded modules table
91 mp_map_init(&map_loaded_modules, 3);
92
Damien George7c9c6672014-01-25 00:17:36 +000093 // built-in exceptions (TODO, make these proper classes, and const if possible)
Damien George38a2da62014-01-08 17:33:12 +000094 mp_map_add_qstr(&map_builtins, MP_QSTR_AttributeError, mp_obj_new_exception(MP_QSTR_AttributeError));
95 mp_map_add_qstr(&map_builtins, MP_QSTR_IndexError, mp_obj_new_exception(MP_QSTR_IndexError));
96 mp_map_add_qstr(&map_builtins, MP_QSTR_KeyError, mp_obj_new_exception(MP_QSTR_KeyError));
97 mp_map_add_qstr(&map_builtins, MP_QSTR_NameError, mp_obj_new_exception(MP_QSTR_NameError));
98 mp_map_add_qstr(&map_builtins, MP_QSTR_TypeError, mp_obj_new_exception(MP_QSTR_TypeError));
99 mp_map_add_qstr(&map_builtins, MP_QSTR_SyntaxError, mp_obj_new_exception(MP_QSTR_SyntaxError));
100 mp_map_add_qstr(&map_builtins, MP_QSTR_ValueError, mp_obj_new_exception(MP_QSTR_ValueError));
Paul Sokolovsky166bb402014-01-18 12:46:43 +0200101 // Somehow CPython managed to have OverflowError not inherit from ValueError ;-/
102 // TODO: For MICROPY_CPYTHON_COMPAT==0 use ValueError to avoid exc proliferation
103 mp_map_add_qstr(&map_builtins, MP_QSTR_OverflowError, mp_obj_new_exception(MP_QSTR_OverflowError));
Damien George38a2da62014-01-08 17:33:12 +0000104 mp_map_add_qstr(&map_builtins, MP_QSTR_OSError, mp_obj_new_exception(MP_QSTR_OSError));
Paul Sokolovskyb81e1fd2014-01-11 16:33:32 +0200105 mp_map_add_qstr(&map_builtins, MP_QSTR_AssertionError, mp_obj_new_exception(MP_QSTR_AssertionError));
Damien George7c9c6672014-01-25 00:17:36 +0000106 mp_map_add_qstr(&map_builtins, MP_QSTR_StopIteration, mp_obj_new_exception(MP_QSTR_StopIteration));
Damienb86e3f92013-12-29 17:17:43 +0000107
Damien Georgee9906ac2014-01-04 18:44:46 +0000108 // built-in objects
Damien George38a2da62014-01-08 17:33:12 +0000109 mp_map_add_qstr(&map_builtins, MP_QSTR_Ellipsis, mp_const_ellipsis);
Damien Georgee9906ac2014-01-04 18:44:46 +0000110
Damienb86e3f92013-12-29 17:17:43 +0000111 // built-in core functions
Damien George38a2da62014-01-08 17:33:12 +0000112 mp_map_add_qstr(&map_builtins, MP_QSTR___build_class__, (mp_obj_t)&mp_builtin___build_class___obj);
Damien George23005372014-01-13 19:39:01 +0000113 mp_map_add_qstr(&map_builtins, MP_QSTR___repl_print__, (mp_obj_t)&mp_builtin___repl_print___obj);
Damienb86e3f92013-12-29 17:17:43 +0000114
Damien George71c51812014-01-04 20:21:15 +0000115 // built-in types
Damien George38a2da62014-01-08 17:33:12 +0000116 mp_map_add_qstr(&map_builtins, MP_QSTR_bool, (mp_obj_t)&bool_type);
Damien George71c51812014-01-04 20:21:15 +0000117#if MICROPY_ENABLE_FLOAT
Damien George38a2da62014-01-08 17:33:12 +0000118 mp_map_add_qstr(&map_builtins, MP_QSTR_complex, (mp_obj_t)&complex_type);
Damien George71c51812014-01-04 20:21:15 +0000119#endif
Damien George38a2da62014-01-08 17:33:12 +0000120 mp_map_add_qstr(&map_builtins, MP_QSTR_dict, (mp_obj_t)&dict_type);
John R. Lenton9daa7892014-01-14 23:55:01 +0000121 mp_map_add_qstr(&map_builtins, MP_QSTR_enumerate, (mp_obj_t)&enumerate_type);
John R. Lentonfca456b2014-01-15 01:37:08 +0000122 mp_map_add_qstr(&map_builtins, MP_QSTR_filter, (mp_obj_t)&filter_type);
Damien George71c51812014-01-04 20:21:15 +0000123#if MICROPY_ENABLE_FLOAT
Damien George38a2da62014-01-08 17:33:12 +0000124 mp_map_add_qstr(&map_builtins, MP_QSTR_float, (mp_obj_t)&float_type);
Damien George71c51812014-01-04 20:21:15 +0000125#endif
Damien George38a2da62014-01-08 17:33:12 +0000126 mp_map_add_qstr(&map_builtins, MP_QSTR_int, (mp_obj_t)&int_type);
127 mp_map_add_qstr(&map_builtins, MP_QSTR_list, (mp_obj_t)&list_type);
John R. Lenton39b174e2014-01-15 01:10:09 +0000128 mp_map_add_qstr(&map_builtins, MP_QSTR_map, (mp_obj_t)&map_type);
Damien George38a2da62014-01-08 17:33:12 +0000129 mp_map_add_qstr(&map_builtins, MP_QSTR_set, (mp_obj_t)&set_type);
130 mp_map_add_qstr(&map_builtins, MP_QSTR_tuple, (mp_obj_t)&tuple_type);
Damien George93a9b5b2014-01-08 18:48:12 +0000131 mp_map_add_qstr(&map_builtins, MP_QSTR_type, (mp_obj_t)&mp_const_type);
John R. Lenton07205ec2014-01-13 02:31:00 +0000132 mp_map_add_qstr(&map_builtins, MP_QSTR_zip, (mp_obj_t)&zip_type);
Damien George71c51812014-01-04 20:21:15 +0000133
Paul Sokolovsky427905c2014-01-18 19:24:47 +0200134 mp_obj_t m_array = mp_obj_new_module(MP_QSTR_array);
135 rt_store_attr(m_array, MP_QSTR_array, (mp_obj_t)&array_type);
Paul Sokolovsky427905c2014-01-18 19:24:47 +0200136
Damien George23005372014-01-13 19:39:01 +0000137 // built-in user functions
138 mp_map_add_qstr(&map_builtins, MP_QSTR_abs, (mp_obj_t)&mp_builtin_abs_obj);
139 mp_map_add_qstr(&map_builtins, MP_QSTR_all, (mp_obj_t)&mp_builtin_all_obj);
140 mp_map_add_qstr(&map_builtins, MP_QSTR_any, (mp_obj_t)&mp_builtin_any_obj);
Paul Sokolovskya80ff042014-01-20 20:32:50 +0200141 mp_map_add_qstr(&map_builtins, MP_QSTR_bytes, (mp_obj_t)&mp_builtin_bytes_obj);
Damien George23005372014-01-13 19:39:01 +0000142 mp_map_add_qstr(&map_builtins, MP_QSTR_callable, (mp_obj_t)&mp_builtin_callable_obj);
143 mp_map_add_qstr(&map_builtins, MP_QSTR_chr, (mp_obj_t)&mp_builtin_chr_obj);
144 mp_map_add_qstr(&map_builtins, MP_QSTR_divmod, (mp_obj_t)&mp_builtin_divmod_obj);
Damien Georged02c6d82014-01-15 22:14:03 +0000145 mp_map_add_qstr(&map_builtins, MP_QSTR_eval, (mp_obj_t)&mp_builtin_eval_obj);
Damien George38a2da62014-01-08 17:33:12 +0000146 mp_map_add_qstr(&map_builtins, MP_QSTR_hash, (mp_obj_t)&mp_builtin_hash_obj);
Damien George004cdce2014-01-09 21:43:51 +0000147 mp_map_add_qstr(&map_builtins, MP_QSTR_isinstance, (mp_obj_t)&mp_builtin_isinstance_obj);
148 mp_map_add_qstr(&map_builtins, MP_QSTR_issubclass, (mp_obj_t)&mp_builtin_issubclass_obj);
Damien George38a2da62014-01-08 17:33:12 +0000149 mp_map_add_qstr(&map_builtins, MP_QSTR_iter, (mp_obj_t)&mp_builtin_iter_obj);
Damien George23005372014-01-13 19:39:01 +0000150 mp_map_add_qstr(&map_builtins, MP_QSTR_len, (mp_obj_t)&mp_builtin_len_obj);
151 mp_map_add_qstr(&map_builtins, MP_QSTR_max, (mp_obj_t)&mp_builtin_max_obj);
152 mp_map_add_qstr(&map_builtins, MP_QSTR_min, (mp_obj_t)&mp_builtin_min_obj);
Damien George38a2da62014-01-08 17:33:12 +0000153 mp_map_add_qstr(&map_builtins, MP_QSTR_next, (mp_obj_t)&mp_builtin_next_obj);
Damien George23005372014-01-13 19:39:01 +0000154 mp_map_add_qstr(&map_builtins, MP_QSTR_ord, (mp_obj_t)&mp_builtin_ord_obj);
155 mp_map_add_qstr(&map_builtins, MP_QSTR_pow, (mp_obj_t)&mp_builtin_pow_obj);
156 mp_map_add_qstr(&map_builtins, MP_QSTR_print, (mp_obj_t)&mp_builtin_print_obj);
157 mp_map_add_qstr(&map_builtins, MP_QSTR_range, (mp_obj_t)&mp_builtin_range_obj);
Damien Georgee2fb2ba2014-01-15 21:40:48 +0000158 mp_map_add_qstr(&map_builtins, MP_QSTR_repr, (mp_obj_t)&mp_builtin_repr_obj);
John R. Lenton5c768392014-01-13 05:12:50 +0000159 mp_map_add_qstr(&map_builtins, MP_QSTR_sorted, (mp_obj_t)&mp_builtin_sorted_obj);
Damien George23005372014-01-13 19:39:01 +0000160 mp_map_add_qstr(&map_builtins, MP_QSTR_sum, (mp_obj_t)&mp_builtin_sum_obj);
Paul Sokolovsky36c44992014-01-13 19:20:46 +0200161 mp_map_add_qstr(&map_builtins, MP_QSTR_str, (mp_obj_t)&mp_builtin_str_obj);
Paul Sokolovsky427905c2014-01-18 19:24:47 +0200162 mp_map_add_qstr(&map_builtins, MP_QSTR_bytearray, (mp_obj_t)&mp_builtin_bytearray_obj);
Damien429d7192013-10-04 19:53:11 +0100163
Paul Sokolovskydcac8802014-01-16 19:19:50 +0200164#if MICROPY_CPYTHON_COMPAT
Paul Sokolovsky159c0f72014-01-20 01:57:20 +0200165 // Precreate sys module, so "import sys" didn't throw exceptions.
Damien George55baff42014-01-21 21:40:13 +0000166 mp_obj_new_module(QSTR_FROM_STR_STATIC("sys"));
Paul Sokolovskydcac8802014-01-16 19:19:50 +0200167#endif
168
Damien George91d457a2014-01-20 10:30:24 +0000169 mp_module_micropython_init();
Paul Sokolovsky440cc3f2014-01-20 01:53:15 +0200170
Paul Sokolovskyc1d200e2014-01-25 00:04:14 +0200171 // TODO: wastes one mp_code_t structure in mem
Damien Georgeeb7bfcb2014-01-04 15:57:35 +0000172 next_unique_code_id = 1; // 0 indicates "no code"
John R. Lenton9c83ec02014-01-07 23:06:46 +0000173 unique_codes_alloc = 0;
Damien429d7192013-10-04 19:53:11 +0100174 unique_codes = NULL;
175
Damien0446a0d2013-11-17 13:16:36 +0000176#ifdef WRITE_CODE
177 fp_write_code = fopen("out-code", "wb");
Damiena1ddfcc2013-10-10 23:25:50 +0100178#endif
Damien429d7192013-10-04 19:53:11 +0100179}
180
Damien8b3a7c22013-10-23 20:20:17 +0100181void rt_deinit(void) {
John R. Lenton9c83ec02014-01-07 23:06:46 +0000182 m_del(mp_code_t, unique_codes, unique_codes_alloc);
Paul Sokolovskyc1d200e2014-01-25 00:04:14 +0200183 mp_map_free(map_globals);
184 mp_map_deinit(&map_loaded_modules);
185 mp_map_deinit(&map_builtins);
Damien0446a0d2013-11-17 13:16:36 +0000186#ifdef WRITE_CODE
187 if (fp_write_code != NULL) {
188 fclose(fp_write_code);
Damien429d7192013-10-04 19:53:11 +0100189 }
Damiena1ddfcc2013-10-10 23:25:50 +0100190#endif
Damien429d7192013-10-04 19:53:11 +0100191}
192
Damien Georged0691cc2014-01-29 20:30:52 +0000193uint rt_get_unique_code_id(void) {
Damien Georgeeb7bfcb2014-01-04 15:57:35 +0000194 return next_unique_code_id++;
Damien429d7192013-10-04 19:53:11 +0100195}
196
Damien8b3a7c22013-10-23 20:20:17 +0100197static void alloc_unique_codes(void) {
John R. Lenton9c83ec02014-01-07 23:06:46 +0000198 if (next_unique_code_id > unique_codes_alloc) {
Damien Georged0691cc2014-01-29 20:30:52 +0000199 DEBUG_printf("allocate more unique codes: " UINT_FMT " -> %u\n", unique_codes_alloc, next_unique_code_id);
John R. Lenton9c83ec02014-01-07 23:06:46 +0000200 // increase size of unique_codes table
201 unique_codes = m_renew(mp_code_t, unique_codes, unique_codes_alloc, next_unique_code_id);
Damien Georged0691cc2014-01-29 20:30:52 +0000202 for (uint i = unique_codes_alloc; i < next_unique_code_id; i++) {
Damiend99b0522013-12-21 18:17:45 +0000203 unique_codes[i].kind = MP_CODE_NONE;
Damien826005c2013-10-05 23:17:28 +0100204 }
John R. Lenton9c83ec02014-01-07 23:06:46 +0000205 unique_codes_alloc = next_unique_code_id;
Damien429d7192013-10-04 19:53:11 +0100206 }
Damien826005c2013-10-05 23:17:28 +0100207}
208
Damien Georged0691cc2014-01-29 20:30:52 +0000209void rt_assign_byte_code(uint unique_code_id, byte *code, uint len, int n_args, int n_locals, int n_stack, bool is_generator) {
Damien826005c2013-10-05 23:17:28 +0100210 alloc_unique_codes();
211
John R. Lenton9c83ec02014-01-07 23:06:46 +0000212 assert(1 <= unique_code_id && unique_code_id < next_unique_code_id && unique_codes[unique_code_id].kind == MP_CODE_NONE);
Damiend99b0522013-12-21 18:17:45 +0000213 unique_codes[unique_code_id].kind = MP_CODE_BYTE;
Damienbd254452013-10-16 20:39:12 +0100214 unique_codes[unique_code_id].is_generator = is_generator;
Damien Georged0691cc2014-01-29 20:30:52 +0000215 unique_codes[unique_code_id].n_args = n_args;
216 unique_codes[unique_code_id].n_state = n_locals + n_stack;
Damien826005c2013-10-05 23:17:28 +0100217 unique_codes[unique_code_id].u_byte.code = code;
218 unique_codes[unique_code_id].u_byte.len = len;
219
Damien9ecbcff2013-12-11 00:41:43 +0000220 //printf("byte code: %d bytes\n", len);
Damien0446a0d2013-11-17 13:16:36 +0000221
222#ifdef DEBUG_PRINT
Damien George08d07552014-01-29 18:58:52 +0000223 DEBUG_printf("assign byte code: id=%d code=%p len=%u n_args=%d n_locals=%d n_stack=%d\n", unique_code_id, code, len, n_args, n_locals, n_stack);
Damien0446a0d2013-11-17 13:16:36 +0000224 for (int i = 0; i < 128 && i < len; i++) {
225 if (i > 0 && i % 16 == 0) {
226 DEBUG_printf("\n");
227 }
228 DEBUG_printf(" %02x", code[i]);
229 }
230 DEBUG_printf("\n");
Damien Georgecbd2f742014-01-19 11:48:48 +0000231#if MICROPY_DEBUG_PRINTERS
232 mp_byte_code_print(code, len);
Damien George062478e2014-01-09 20:57:50 +0000233#endif
Damien0446a0d2013-11-17 13:16:36 +0000234
235#ifdef WRITE_CODE
236 if (fp_write_code != NULL) {
237 fwrite(code, len, 1, fp_write_code);
238 fflush(fp_write_code);
239 }
240#endif
241#endif
Damien826005c2013-10-05 23:17:28 +0100242}
243
Damien Georged0691cc2014-01-29 20:30:52 +0000244void rt_assign_native_code(uint unique_code_id, void *fun, uint len, int n_args) {
Damien826005c2013-10-05 23:17:28 +0100245 alloc_unique_codes();
246
John R. Lenton9c83ec02014-01-07 23:06:46 +0000247 assert(1 <= unique_code_id && unique_code_id < next_unique_code_id && unique_codes[unique_code_id].kind == MP_CODE_NONE);
Damiend99b0522013-12-21 18:17:45 +0000248 unique_codes[unique_code_id].kind = MP_CODE_NATIVE;
Damienbd254452013-10-16 20:39:12 +0100249 unique_codes[unique_code_id].is_generator = false;
Damien Georged0691cc2014-01-29 20:30:52 +0000250 unique_codes[unique_code_id].n_args = n_args;
251 unique_codes[unique_code_id].n_state = 0;
Damien429d7192013-10-04 19:53:11 +0100252 unique_codes[unique_code_id].u_native.fun = fun;
253
Damien George8cc96a32013-12-30 18:23:50 +0000254 //printf("native code: %d bytes\n", len);
Damien0446a0d2013-11-17 13:16:36 +0000255
Damiena1ddfcc2013-10-10 23:25:50 +0100256#ifdef DEBUG_PRINT
Damien429d7192013-10-04 19:53:11 +0100257 DEBUG_printf("assign native code: id=%d fun=%p len=%u n_args=%d\n", unique_code_id, fun, len, n_args);
258 byte *fun_data = (byte*)(((machine_uint_t)fun) & (~1)); // need to clear lower bit in case it's thumb code
259 for (int i = 0; i < 128 && i < len; i++) {
260 if (i > 0 && i % 16 == 0) {
261 DEBUG_printf("\n");
262 }
263 DEBUG_printf(" %02x", fun_data[i]);
264 }
265 DEBUG_printf("\n");
266
Damien0446a0d2013-11-17 13:16:36 +0000267#ifdef WRITE_CODE
268 if (fp_write_code != NULL) {
269 fwrite(fun_data, len, 1, fp_write_code);
270 fflush(fp_write_code);
Damien429d7192013-10-04 19:53:11 +0100271 }
Damiena1ddfcc2013-10-10 23:25:50 +0100272#endif
273#endif
Damien429d7192013-10-04 19:53:11 +0100274}
275
Damien Georged0691cc2014-01-29 20:30:52 +0000276void rt_assign_inline_asm_code(uint unique_code_id, void *fun, uint len, int n_args) {
Damien826005c2013-10-05 23:17:28 +0100277 alloc_unique_codes();
Damien429d7192013-10-04 19:53:11 +0100278
John R. Lenton9c83ec02014-01-07 23:06:46 +0000279 assert(1 <= unique_code_id && unique_code_id < next_unique_code_id && unique_codes[unique_code_id].kind == MP_CODE_NONE);
Damiend99b0522013-12-21 18:17:45 +0000280 unique_codes[unique_code_id].kind = MP_CODE_INLINE_ASM;
Damienbd254452013-10-16 20:39:12 +0100281 unique_codes[unique_code_id].is_generator = false;
Damien Georged0691cc2014-01-29 20:30:52 +0000282 unique_codes[unique_code_id].n_args = n_args;
283 unique_codes[unique_code_id].n_state = 0;
Damien826005c2013-10-05 23:17:28 +0100284 unique_codes[unique_code_id].u_inline_asm.fun = fun;
285
Damiena1ddfcc2013-10-10 23:25:50 +0100286#ifdef DEBUG_PRINT
Damien826005c2013-10-05 23:17:28 +0100287 DEBUG_printf("assign inline asm code: id=%d fun=%p len=%u n_args=%d\n", unique_code_id, fun, len, n_args);
288 byte *fun_data = (byte*)(((machine_uint_t)fun) & (~1)); // need to clear lower bit in case it's thumb code
289 for (int i = 0; i < 128 && i < len; i++) {
290 if (i > 0 && i % 16 == 0) {
291 DEBUG_printf("\n");
292 }
293 DEBUG_printf(" %02x", fun_data[i]);
294 }
295 DEBUG_printf("\n");
296
Damien0446a0d2013-11-17 13:16:36 +0000297#ifdef WRITE_CODE
298 if (fp_write_code != NULL) {
299 fwrite(fun_data, len, 1, fp_write_code);
Damien826005c2013-10-05 23:17:28 +0100300 }
Damiena1ddfcc2013-10-10 23:25:50 +0100301#endif
302#endif
Damien429d7192013-10-04 19:53:11 +0100303}
304
Damiend99b0522013-12-21 18:17:45 +0000305int rt_is_true(mp_obj_t arg) {
306 DEBUG_OP_printf("is true %p\n", arg);
307 if (MP_OBJ_IS_SMALL_INT(arg)) {
308 if (MP_OBJ_SMALL_INT_VALUE(arg) == 0) {
309 return 0;
310 } else {
311 return 1;
312 }
313 } else if (arg == mp_const_none) {
314 return 0;
315 } else if (arg == mp_const_false) {
316 return 0;
317 } else if (arg == mp_const_true) {
318 return 1;
319 } else {
Paul Sokolovskyc1d9bbc2014-01-30 04:37:19 +0200320 mp_obj_type_t *type = mp_obj_get_type(arg);
321 if (type->unary_op != NULL) {
322 mp_obj_t result = type->unary_op(RT_UNARY_OP_BOOL, arg);
323 if (result != NULL) {
324 return result == mp_const_true;
325 }
326 }
327
Damien Georgee4b6a072014-01-28 23:27:35 +0000328 mp_obj_t len = mp_obj_len_maybe(arg);
329 if (len != MP_OBJ_NULL) {
330 // obj has a length, truth determined if len != 0
331 return len != MP_OBJ_NEW_SMALL_INT(0);
332 } else {
Paul Sokolovskyc1d9bbc2014-01-30 04:37:19 +0200333 // any other obj is true per Python semantics
Damien Georgee4b6a072014-01-28 23:27:35 +0000334 return 1;
335 }
Damiend99b0522013-12-21 18:17:45 +0000336 }
337}
338
339mp_obj_t rt_list_append(mp_obj_t self_in, mp_obj_t arg) {
340 return mp_obj_list_append(self_in, arg);
341}
342
Damien7410e442013-11-02 19:47:57 +0000343#define PARSE_DEC_IN_INTG (1)
344#define PARSE_DEC_IN_FRAC (2)
345#define PARSE_DEC_IN_EXP (3)
346
Damiend99b0522013-12-21 18:17:45 +0000347mp_obj_t rt_load_const_dec(qstr qstr) {
Damien7410e442013-11-02 19:47:57 +0000348#if MICROPY_ENABLE_FLOAT
349 DEBUG_OP_printf("load '%s'\n", qstr_str(qstr));
350 const char *s = qstr_str(qstr);
351 int in = PARSE_DEC_IN_INTG;
Damiend99b0522013-12-21 18:17:45 +0000352 mp_float_t dec_val = 0;
Damien7410e442013-11-02 19:47:57 +0000353 bool exp_neg = false;
354 int exp_val = 0;
355 int exp_extra = 0;
356 bool imag = false;
357 for (; *s; s++) {
358 int dig = *s;
359 if ('0' <= dig && dig <= '9') {
360 dig -= '0';
361 if (in == PARSE_DEC_IN_EXP) {
362 exp_val = 10 * exp_val + dig;
363 } else {
364 dec_val = 10 * dec_val + dig;
365 if (in == PARSE_DEC_IN_FRAC) {
366 exp_extra -= 1;
367 }
368 }
369 } else if (in == PARSE_DEC_IN_INTG && dig == '.') {
370 in = PARSE_DEC_IN_FRAC;
371 } else if (in != PARSE_DEC_IN_EXP && (dig == 'E' || dig == 'e')) {
372 in = PARSE_DEC_IN_EXP;
373 if (s[1] == '+') {
374 s++;
375 } else if (s[1] == '-') {
376 s++;
377 exp_neg = true;
378 }
379 } else if (dig == 'J' || dig == 'j') {
380 s++;
381 imag = true;
382 break;
383 } else {
384 // unknown character
385 break;
386 }
387 }
388 if (*s != 0) {
Damien Georgeeb7bfcb2014-01-04 15:57:35 +0000389 nlr_jump(mp_obj_new_exception_msg(MP_QSTR_SyntaxError, "invalid syntax for number"));
Damien7410e442013-11-02 19:47:57 +0000390 }
391 if (exp_neg) {
392 exp_val = -exp_val;
393 }
394 exp_val += exp_extra;
395 for (; exp_val > 0; exp_val--) {
396 dec_val *= 10;
397 }
398 for (; exp_val < 0; exp_val++) {
399 dec_val *= 0.1;
400 }
401 if (imag) {
Damiend99b0522013-12-21 18:17:45 +0000402 return mp_obj_new_complex(0, dec_val);
Damien7410e442013-11-02 19:47:57 +0000403 } else {
Damiend99b0522013-12-21 18:17:45 +0000404 return mp_obj_new_float(dec_val);
Damien7410e442013-11-02 19:47:57 +0000405 }
406#else
Damien Georgeeb7bfcb2014-01-04 15:57:35 +0000407 nlr_jump(mp_obj_new_exception_msg(MP_QSTR_SyntaxError, "decimal numbers not supported"));
Damien7410e442013-11-02 19:47:57 +0000408#endif
409}
410
Damiend99b0522013-12-21 18:17:45 +0000411mp_obj_t rt_load_const_str(qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100412 DEBUG_OP_printf("load '%s'\n", qstr_str(qstr));
Damien George5fa93b62014-01-22 14:35:10 +0000413 return MP_OBJ_NEW_QSTR(qstr);
Damien429d7192013-10-04 19:53:11 +0100414}
415
Paul Sokolovsky91fb1c92014-01-24 22:50:40 +0200416mp_obj_t rt_load_const_bytes(qstr qstr) {
417 DEBUG_OP_printf("load b'%s'\n", qstr_str(qstr));
418 uint len;
419 const byte *data = qstr_data(qstr, &len);
420 return mp_obj_new_bytes(data, len);
421}
422
Damiend99b0522013-12-21 18:17:45 +0000423mp_obj_t rt_load_name(qstr qstr) {
Damien429d7192013-10-04 19:53:11 +0100424 // logic: search locals, globals, builtins
Damiena3977762013-10-09 23:10:10 +0100425 DEBUG_OP_printf("load name %s\n", qstr_str(qstr));
Damien George38a2da62014-01-08 17:33:12 +0000426 mp_map_elem_t *elem = mp_map_lookup(map_locals, MP_OBJ_NEW_QSTR(qstr), MP_MAP_LOOKUP);
Damiena3977762013-10-09 23:10:10 +0100427 if (elem == NULL) {
Damien George38a2da62014-01-08 17:33:12 +0000428 elem = mp_map_lookup(map_globals, MP_OBJ_NEW_QSTR(qstr), MP_MAP_LOOKUP);
Damiena3977762013-10-09 23:10:10 +0100429 if (elem == NULL) {
Damien George38a2da62014-01-08 17:33:12 +0000430 elem = mp_map_lookup(&map_builtins, MP_OBJ_NEW_QSTR(qstr), MP_MAP_LOOKUP);
Damiena3977762013-10-09 23:10:10 +0100431 if (elem == NULL) {
Damien George6c73ca12014-01-08 18:11:23 +0000432 nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_NameError, "name '%s' is not defined", qstr_str(qstr)));
Damiena3977762013-10-09 23:10:10 +0100433 }
434 }
435 }
436 return elem->value;
437}
438
Damiend99b0522013-12-21 18:17:45 +0000439mp_obj_t rt_load_global(qstr qstr) {
Damiena3977762013-10-09 23:10:10 +0100440 // logic: search globals, builtins
441 DEBUG_OP_printf("load global %s\n", qstr_str(qstr));
Damien George38a2da62014-01-08 17:33:12 +0000442 mp_map_elem_t *elem = mp_map_lookup(map_globals, MP_OBJ_NEW_QSTR(qstr), MP_MAP_LOOKUP);
Damien429d7192013-10-04 19:53:11 +0100443 if (elem == NULL) {
Damien George38a2da62014-01-08 17:33:12 +0000444 elem = mp_map_lookup(&map_builtins, MP_OBJ_NEW_QSTR(qstr), MP_MAP_LOOKUP);
Damien429d7192013-10-04 19:53:11 +0100445 if (elem == NULL) {
Damien George6c73ca12014-01-08 18:11:23 +0000446 nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_NameError, "name '%s' is not defined", qstr_str(qstr)));
Damien429d7192013-10-04 19:53:11 +0100447 }
448 }
449 return elem->value;
450}
451
Damiend99b0522013-12-21 18:17:45 +0000452mp_obj_t rt_load_build_class(void) {
Damien429d7192013-10-04 19:53:11 +0100453 DEBUG_OP_printf("load_build_class\n");
Damien George38a2da62014-01-08 17:33:12 +0000454 mp_map_elem_t *elem = mp_map_lookup(&map_builtins, MP_OBJ_NEW_QSTR(MP_QSTR___build_class__), MP_MAP_LOOKUP);
Damien429d7192013-10-04 19:53:11 +0100455 if (elem == NULL) {
Damien Georgeeb7bfcb2014-01-04 15:57:35 +0000456 nlr_jump(mp_obj_new_exception_msg(MP_QSTR_NameError, "name '__build_class__' is not defined"));
Damien429d7192013-10-04 19:53:11 +0100457 }
458 return elem->value;
459}
460
Damiend99b0522013-12-21 18:17:45 +0000461mp_obj_t rt_get_cell(mp_obj_t cell) {
462 return mp_obj_cell_get(cell);
Damien660365e2013-12-17 18:27:24 +0000463}
464
Damiend99b0522013-12-21 18:17:45 +0000465void rt_set_cell(mp_obj_t cell, mp_obj_t val) {
466 mp_obj_cell_set(cell, val);
Damien660365e2013-12-17 18:27:24 +0000467}
468
Damiend99b0522013-12-21 18:17:45 +0000469void rt_store_name(qstr qstr, mp_obj_t obj) {
Damiena3977762013-10-09 23:10:10 +0100470 DEBUG_OP_printf("store name %s <- %p\n", qstr_str(qstr), obj);
Damien George38a2da62014-01-08 17:33:12 +0000471 mp_map_lookup(map_locals, MP_OBJ_NEW_QSTR(qstr), MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)->value = obj;
Damiena3977762013-10-09 23:10:10 +0100472}
473
Damiend99b0522013-12-21 18:17:45 +0000474void rt_store_global(qstr qstr, mp_obj_t obj) {
Damiena3977762013-10-09 23:10:10 +0100475 DEBUG_OP_printf("store global %s <- %p\n", qstr_str(qstr), obj);
Damien George38a2da62014-01-08 17:33:12 +0000476 mp_map_lookup(map_globals, MP_OBJ_NEW_QSTR(qstr), MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)->value = obj;
Damien429d7192013-10-04 19:53:11 +0100477}
478
Damiend99b0522013-12-21 18:17:45 +0000479mp_obj_t rt_unary_op(int op, mp_obj_t arg) {
Damien7410e442013-11-02 19:47:57 +0000480 DEBUG_OP_printf("unary %d %p\n", op, arg);
Damiend99b0522013-12-21 18:17:45 +0000481 if (MP_OBJ_IS_SMALL_INT(arg)) {
482 mp_small_int_t val = MP_OBJ_SMALL_INT_VALUE(arg);
Damien7410e442013-11-02 19:47:57 +0000483 switch (op) {
Paul Sokolovskyc1d9bbc2014-01-30 04:37:19 +0200484 case RT_UNARY_OP_BOOL: return MP_BOOL(val != 0);
Damien7410e442013-11-02 19:47:57 +0000485 case RT_UNARY_OP_POSITIVE: break;
486 case RT_UNARY_OP_NEGATIVE: val = -val; break;
487 case RT_UNARY_OP_INVERT: val = ~val; break;
488 default: assert(0); val = 0;
489 }
Paul Sokolovsky757ac812014-01-12 17:06:25 +0200490 if (MP_OBJ_FITS_SMALL_INT(val)) {
Damiend99b0522013-12-21 18:17:45 +0000491 return MP_OBJ_NEW_SMALL_INT(val);
Damien7410e442013-11-02 19:47:57 +0000492 }
Paul Sokolovsky757ac812014-01-12 17:06:25 +0200493 return mp_obj_new_int(val);
Damien George1e708fe2014-01-23 18:27:51 +0000494 } else {
495 mp_obj_type_t *type = mp_obj_get_type(arg);
496 if (type->unary_op != NULL) {
497 mp_obj_t result = type->unary_op(op, arg);
Damiend99b0522013-12-21 18:17:45 +0000498 if (result != NULL) {
499 return result;
500 }
Damien7410e442013-11-02 19:47:57 +0000501 }
Damiend99b0522013-12-21 18:17:45 +0000502 // TODO specify in error message what the operator is
Damien George1e708fe2014-01-23 18:27:51 +0000503 nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "bad operand type for unary operator: '%s'", type->name));
Damien7410e442013-11-02 19:47:57 +0000504 }
Damien429d7192013-10-04 19:53:11 +0100505}
506
Damiend99b0522013-12-21 18:17:45 +0000507mp_obj_t rt_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
Damien429d7192013-10-04 19:53:11 +0100508 DEBUG_OP_printf("binary %d %p %p\n", op, lhs, rhs);
Damien George14f945c2014-01-03 14:09:31 +0000509
510 // TODO correctly distinguish inplace operators for mutable objects
511 // lookup logic that CPython uses for +=:
512 // check for implemented +=
513 // then check for implemented +
514 // then check for implemented seq.inplace_concat
515 // then check for implemented seq.concat
516 // then fail
517 // note that list does not implement + or +=, so that inplace_concat is reached first for +=
518
Paul Sokolovsky8bc96472014-01-15 00:31:28 +0200519 // deal with is, is not
520 if (op == RT_COMPARE_OP_IS) {
521 // TODO: may need to handle strings specially, CPython appears to
522 // assume all strings are interned (so "is" == "==" for strings)
523 return MP_BOOL(lhs == rhs);
524 }
525 if (op == RT_COMPARE_OP_IS_NOT) {
526 // TODO: may need to handle strings specially, CPython appears to
527 // assume all strings are interned (so "is" == "==" for strings)
528 return MP_BOOL(lhs != rhs);
529 }
530
Damien Georgebcbeea02014-01-11 10:47:22 +0000531 // deal with == and != for all types
532 if (op == RT_COMPARE_OP_EQUAL || op == RT_COMPARE_OP_NOT_EQUAL) {
533 if (mp_obj_equal(lhs, rhs)) {
534 if (op == RT_COMPARE_OP_EQUAL) {
535 return mp_const_true;
536 } else {
537 return mp_const_false;
538 }
539 } else {
540 if (op == RT_COMPARE_OP_EQUAL) {
541 return mp_const_false;
542 } else {
543 return mp_const_true;
544 }
545 }
546 }
547
548 // deal with exception_match for all types
549 if (op == RT_COMPARE_OP_EXCEPTION_MATCH) {
550 // TODO properly! at the moment it just compares the exception identifier for equality
551 if (MP_OBJ_IS_TYPE(lhs, &exception_type) && MP_OBJ_IS_TYPE(rhs, &exception_type)) {
552 if (mp_obj_exception_get_type(lhs) == mp_obj_exception_get_type(rhs)) {
553 return mp_const_true;
554 } else {
555 return mp_const_false;
556 }
557 }
558 }
559
Damien George1a9951d2014-01-06 22:13:00 +0000560 if (MP_OBJ_IS_SMALL_INT(lhs)) {
Damiend99b0522013-12-21 18:17:45 +0000561 mp_small_int_t lhs_val = MP_OBJ_SMALL_INT_VALUE(lhs);
Damien George1a9951d2014-01-06 22:13:00 +0000562 if (MP_OBJ_IS_SMALL_INT(rhs)) {
563 mp_small_int_t rhs_val = MP_OBJ_SMALL_INT_VALUE(rhs);
564 switch (op) {
565 case RT_BINARY_OP_OR:
566 case RT_BINARY_OP_INPLACE_OR: lhs_val |= rhs_val; break;
567 case RT_BINARY_OP_XOR:
568 case RT_BINARY_OP_INPLACE_XOR: lhs_val ^= rhs_val; break;
569 case RT_BINARY_OP_AND:
570 case RT_BINARY_OP_INPLACE_AND: lhs_val &= rhs_val; break;
571 case RT_BINARY_OP_LSHIFT:
572 case RT_BINARY_OP_INPLACE_LSHIFT: lhs_val <<= rhs_val; break;
573 case RT_BINARY_OP_RSHIFT:
574 case RT_BINARY_OP_INPLACE_RSHIFT: lhs_val >>= rhs_val; break;
575 case RT_BINARY_OP_ADD:
576 case RT_BINARY_OP_INPLACE_ADD: lhs_val += rhs_val; break;
577 case RT_BINARY_OP_SUBTRACT:
578 case RT_BINARY_OP_INPLACE_SUBTRACT: lhs_val -= rhs_val; break;
579 case RT_BINARY_OP_MULTIPLY:
580 case RT_BINARY_OP_INPLACE_MULTIPLY: lhs_val *= rhs_val; break;
581 case RT_BINARY_OP_FLOOR_DIVIDE:
582 case RT_BINARY_OP_INPLACE_FLOOR_DIVIDE: lhs_val /= rhs_val; break;
583 #if MICROPY_ENABLE_FLOAT
584 case RT_BINARY_OP_TRUE_DIVIDE:
585 case RT_BINARY_OP_INPLACE_TRUE_DIVIDE: return mp_obj_new_float((mp_float_t)lhs_val / (mp_float_t)rhs_val);
586 #endif
Damiena3dcd9e2013-12-17 21:35:38 +0000587
Damien George1a9951d2014-01-06 22:13:00 +0000588 // TODO implement modulo as specified by Python
589 case RT_BINARY_OP_MODULO:
590 case RT_BINARY_OP_INPLACE_MODULO: lhs_val %= rhs_val; break;
Damiena3dcd9e2013-12-17 21:35:38 +0000591
Damien George1a9951d2014-01-06 22:13:00 +0000592 // TODO check for negative power, and overflow
593 case RT_BINARY_OP_POWER:
594 case RT_BINARY_OP_INPLACE_POWER:
595 {
596 int ans = 1;
597 while (rhs_val > 0) {
598 if (rhs_val & 1) {
599 ans *= lhs_val;
600 }
601 lhs_val *= lhs_val;
602 rhs_val /= 2;
Damiena3dcd9e2013-12-17 21:35:38 +0000603 }
Damien George1a9951d2014-01-06 22:13:00 +0000604 lhs_val = ans;
605 break;
Damien4ebb32f2013-11-02 14:33:10 +0000606 }
John R. Lentonb8698fc2014-01-11 00:58:59 +0000607 case RT_COMPARE_OP_LESS: return MP_BOOL(lhs_val < rhs_val); break;
608 case RT_COMPARE_OP_MORE: return MP_BOOL(lhs_val > rhs_val); break;
609 case RT_COMPARE_OP_LESS_EQUAL: return MP_BOOL(lhs_val <= rhs_val); break;
610 case RT_COMPARE_OP_MORE_EQUAL: return MP_BOOL(lhs_val >= rhs_val); break;
Damiena3dcd9e2013-12-17 21:35:38 +0000611
Damien George1a9951d2014-01-06 22:13:00 +0000612 default: assert(0);
613 }
Paul Sokolovsky757ac812014-01-12 17:06:25 +0200614 // TODO: We just should make mp_obj_new_int() inline and use that
615 if (MP_OBJ_FITS_SMALL_INT(lhs_val)) {
Damien George1a9951d2014-01-06 22:13:00 +0000616 return MP_OBJ_NEW_SMALL_INT(lhs_val);
617 }
Paul Sokolovsky757ac812014-01-12 17:06:25 +0200618 return mp_obj_new_int(lhs_val);
Damien George1a9951d2014-01-06 22:13:00 +0000619 } else if (MP_OBJ_IS_TYPE(rhs, &float_type)) {
620 return mp_obj_float_binary_op(op, lhs_val, rhs);
621 } else if (MP_OBJ_IS_TYPE(rhs, &complex_type)) {
622 return mp_obj_complex_binary_op(op, lhs_val, 0, rhs);
Damien429d7192013-10-04 19:53:11 +0100623 }
John R. Lentonc1bef212014-01-11 12:39:33 +0000624 }
John R. Lentonb8698fc2014-01-11 00:58:59 +0000625
John R. Lentonc1bef212014-01-11 12:39:33 +0000626 /* deal with `in` and `not in`
627 *
628 * NOTE `a in b` is `b.__contains__(a)`, hence why the generic dispatch
629 * needs to go below
630 */
631 if (op == RT_COMPARE_OP_IN || op == RT_COMPARE_OP_NOT_IN) {
Damien George5fa93b62014-01-22 14:35:10 +0000632 mp_obj_type_t *type = mp_obj_get_type(rhs);
633 if (type->binary_op != NULL) {
634 mp_obj_t res = type->binary_op(op, rhs, lhs);
635 if (res != NULL) {
636 return res;
637 }
638 }
639 if (type->getiter != NULL) {
640 /* second attempt, walk the iterator */
641 mp_obj_t next = NULL;
642 mp_obj_t iter = rt_getiter(rhs);
643 while ((next = rt_iternext(iter)) != mp_const_stop_iteration) {
644 if (mp_obj_equal(next, lhs)) {
645 return MP_BOOL(op == RT_COMPARE_OP_IN);
John R. Lentonb8698fc2014-01-11 00:58:59 +0000646 }
Damien7410e442013-11-02 19:47:57 +0000647 }
Damien George5fa93b62014-01-22 14:35:10 +0000648 return MP_BOOL(op != RT_COMPARE_OP_IN);
Damien7410e442013-11-02 19:47:57 +0000649 }
John R. Lentonc1bef212014-01-11 12:39:33 +0000650
651 nlr_jump(mp_obj_new_exception_msg_varg(
652 MP_QSTR_TypeError, "'%s' object is not iterable",
653 mp_obj_get_type_str(rhs)));
654 return mp_const_none;
655 }
656
Damien George5fa93b62014-01-22 14:35:10 +0000657 // generic binary_op supplied by type
658 mp_obj_type_t *type = mp_obj_get_type(lhs);
659 if (type->binary_op != NULL) {
660 mp_obj_t result = type->binary_op(op, lhs, rhs);
661 if (result != MP_OBJ_NULL) {
662 return result;
John R. Lentonc1bef212014-01-11 12:39:33 +0000663 }
Damien429d7192013-10-04 19:53:11 +0100664 }
Damiend99b0522013-12-21 18:17:45 +0000665
Damien George5fa93b62014-01-22 14:35:10 +0000666 // TODO implement dispatch for reverse binary ops
667
Damiend99b0522013-12-21 18:17:45 +0000668 // TODO specify in error message what the operator is
Paul Sokolovskybab5cfb2014-01-10 17:32:22 +0200669 nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError,
670 "unsupported operand types for binary operator: '%s', '%s'",
671 mp_obj_get_type_str(lhs), mp_obj_get_type_str(rhs)));
John R. Lentonc1bef212014-01-11 12:39:33 +0000672 return mp_const_none;
Damien429d7192013-10-04 19:53:11 +0100673}
674
Damiend99b0522013-12-21 18:17:45 +0000675mp_obj_t rt_make_function_from_id(int unique_code_id) {
Damienb05d7072013-10-05 13:37:10 +0100676 DEBUG_OP_printf("make_function_from_id %d\n", unique_code_id);
677 if (unique_code_id < 1 || unique_code_id >= next_unique_code_id) {
Damien429d7192013-10-04 19:53:11 +0100678 // illegal code id
Damiend99b0522013-12-21 18:17:45 +0000679 return mp_const_none;
Damien429d7192013-10-04 19:53:11 +0100680 }
Damiend99b0522013-12-21 18:17:45 +0000681
682 // make the function, depending on the code kind
683 mp_code_t *c = &unique_codes[unique_code_id];
684 mp_obj_t fun;
Damien429d7192013-10-04 19:53:11 +0100685 switch (c->kind) {
Damiend99b0522013-12-21 18:17:45 +0000686 case MP_CODE_BYTE:
Damien Georged0691cc2014-01-29 20:30:52 +0000687 fun = mp_obj_new_fun_bc(c->n_args, c->n_state, c->u_byte.code);
Damien826005c2013-10-05 23:17:28 +0100688 break;
Damiend99b0522013-12-21 18:17:45 +0000689 case MP_CODE_NATIVE:
Damien Georgef62d33a2014-01-13 19:50:05 +0000690 fun = rt_make_function_n(c->n_args, c->u_native.fun);
Damien429d7192013-10-04 19:53:11 +0100691 break;
Damiend99b0522013-12-21 18:17:45 +0000692 case MP_CODE_INLINE_ASM:
693 fun = mp_obj_new_fun_asm(c->n_args, c->u_inline_asm.fun);
Damien429d7192013-10-04 19:53:11 +0100694 break;
695 default:
696 assert(0);
Damiend99b0522013-12-21 18:17:45 +0000697 fun = mp_const_none;
Damien429d7192013-10-04 19:53:11 +0100698 }
Damienbd254452013-10-16 20:39:12 +0100699
700 // check for generator functions and if so wrap in generator object
701 if (c->is_generator) {
Damien Georged0691cc2014-01-29 20:30:52 +0000702 fun = mp_obj_new_gen_wrap(fun);
Damienbd254452013-10-16 20:39:12 +0100703 }
704
Damiend99b0522013-12-21 18:17:45 +0000705 return fun;
Damien429d7192013-10-04 19:53:11 +0100706}
707
Damiend99b0522013-12-21 18:17:45 +0000708mp_obj_t rt_make_closure_from_id(int unique_code_id, mp_obj_t closure_tuple) {
Damien George6baf76e2013-12-30 22:32:17 +0000709 DEBUG_OP_printf("make_closure_from_id %d\n", unique_code_id);
Damiend99b0522013-12-21 18:17:45 +0000710 // make function object
711 mp_obj_t ffun = rt_make_function_from_id(unique_code_id);
Damien9ecbcff2013-12-11 00:41:43 +0000712 // wrap function in closure object
Damiend99b0522013-12-21 18:17:45 +0000713 return mp_obj_new_closure(ffun, closure_tuple);
Damien9ecbcff2013-12-11 00:41:43 +0000714}
715
Damiend99b0522013-12-21 18:17:45 +0000716mp_obj_t rt_call_function_0(mp_obj_t fun) {
Damien George20006db2014-01-18 14:10:48 +0000717 return rt_call_function_n_kw(fun, 0, 0, NULL);
Damieneb19efb2013-10-10 22:06:54 +0100718}
719
Damiend99b0522013-12-21 18:17:45 +0000720mp_obj_t rt_call_function_1(mp_obj_t fun, mp_obj_t arg) {
Damien George20006db2014-01-18 14:10:48 +0000721 return rt_call_function_n_kw(fun, 1, 0, &arg);
Damieneb19efb2013-10-10 22:06:54 +0100722}
723
Damiend99b0522013-12-21 18:17:45 +0000724mp_obj_t rt_call_function_2(mp_obj_t fun, mp_obj_t arg1, mp_obj_t arg2) {
725 mp_obj_t args[2];
Damien George20006db2014-01-18 14:10:48 +0000726 args[0] = arg1;
727 args[1] = arg2;
728 return rt_call_function_n_kw(fun, 2, 0, args);
Damieneb19efb2013-10-10 22:06:54 +0100729}
730
Damien George20006db2014-01-18 14:10:48 +0000731// args contains, eg: arg0 arg1 key0 value0 key1 value1
732mp_obj_t rt_call_function_n_kw(mp_obj_t fun_in, uint n_args, uint n_kw, const mp_obj_t *args) {
Damiend99b0522013-12-21 18:17:45 +0000733 // TODO improve this: fun object can specify its type and we parse here the arguments,
734 // passing to the function arrays of fixed and keyword arguments
Damieneb19efb2013-10-10 22:06:54 +0100735
John R. Lenton9c83ec02014-01-07 23:06:46 +0000736 DEBUG_OP_printf("calling function %p(n_args=%d, n_kw=%d, args=%p)\n", fun_in, n_args, n_kw, args);
737
738 if (MP_OBJ_IS_SMALL_INT(fun_in)) {
739 nlr_jump(mp_obj_new_exception_msg(MP_QSTR_TypeError, "'int' object is not callable"));
740 } else {
741 mp_obj_base_t *fun = fun_in;
Damien George20006db2014-01-18 14:10:48 +0000742 if (fun->type->call != NULL) {
743 return fun->type->call(fun_in, n_args, n_kw, args);
John R. Lenton9c83ec02014-01-07 23:06:46 +0000744 } else {
Damien George6c73ca12014-01-08 18:11:23 +0000745 nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "'%s' object is not callable", fun->type->name));
John R. Lenton9c83ec02014-01-07 23:06:46 +0000746 }
747 }
Damien86c7fc72013-11-26 15:16:41 +0000748}
749
Damien George20006db2014-01-18 14:10:48 +0000750// args contains: fun self/NULL arg(0) ... arg(n_args-2) arg(n_args-1) kw_key(0) kw_val(0) ... kw_key(n_kw-1) kw_val(n_kw-1)
751// if n_args==0 and n_kw==0 then there are only fun and self/NULL
Damiend99b0522013-12-21 18:17:45 +0000752mp_obj_t rt_call_method_n_kw(uint n_args, uint n_kw, const mp_obj_t *args) {
Damien George20006db2014-01-18 14:10:48 +0000753 DEBUG_OP_printf("call method (fun=%p, self=%p, n_args=%u, n_kw=%u, args=%p)\n", args[0], args[1], n_args, n_kw, args);
754 int adjust = (args[1] == NULL) ? 0 : 1;
755 return rt_call_function_n_kw(args[0], n_args + adjust, n_kw, args + 2 - adjust);
Damien86c7fc72013-11-26 15:16:41 +0000756}
757
Damiend99b0522013-12-21 18:17:45 +0000758mp_obj_t rt_build_tuple(int n_args, mp_obj_t *items) {
Damien George20006db2014-01-18 14:10:48 +0000759 return mp_obj_new_tuple(n_args, items);
Damienc226dca2013-10-16 16:12:52 +0100760}
761
Damiend99b0522013-12-21 18:17:45 +0000762mp_obj_t rt_build_list(int n_args, mp_obj_t *items) {
Damien George20006db2014-01-18 14:10:48 +0000763 return mp_obj_new_list(n_args, items);
Damien429d7192013-10-04 19:53:11 +0100764}
765
Damiend99b0522013-12-21 18:17:45 +0000766mp_obj_t rt_build_set(int n_args, mp_obj_t *items) {
767 return mp_obj_new_set(n_args, items);
Damien429d7192013-10-04 19:53:11 +0100768}
769
Damiend99b0522013-12-21 18:17:45 +0000770mp_obj_t rt_store_set(mp_obj_t set, mp_obj_t item) {
Damiendae7eb72013-12-29 22:32:51 +0000771 mp_obj_set_store(set, item);
Damienc12aa462013-10-16 20:57:49 +0100772 return set;
773}
774
Damien George932bf1c2014-01-18 23:42:49 +0000775// unpacked items are stored in reverse order into the array pointed to by items
Damiend99b0522013-12-21 18:17:45 +0000776void rt_unpack_sequence(mp_obj_t seq_in, uint num, mp_obj_t *items) {
777 if (MP_OBJ_IS_TYPE(seq_in, &tuple_type) || MP_OBJ_IS_TYPE(seq_in, &list_type)) {
778 uint seq_len;
779 mp_obj_t *seq_items;
780 if (MP_OBJ_IS_TYPE(seq_in, &tuple_type)) {
781 mp_obj_tuple_get(seq_in, &seq_len, &seq_items);
782 } else {
783 mp_obj_list_get(seq_in, &seq_len, &seq_items);
Damien86c7fc72013-11-26 15:16:41 +0000784 }
Damiend99b0522013-12-21 18:17:45 +0000785 if (seq_len < num) {
Damien George6c73ca12014-01-08 18:11:23 +0000786 nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_ValueError, "need more than %d values to unpack", (void*)(machine_uint_t)seq_len));
Damiend99b0522013-12-21 18:17:45 +0000787 } else if (seq_len > num) {
Damien George6c73ca12014-01-08 18:11:23 +0000788 nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_ValueError, "too many values to unpack (expected %d)", (void*)(machine_uint_t)num));
Damiend99b0522013-12-21 18:17:45 +0000789 }
Damien George932bf1c2014-01-18 23:42:49 +0000790 for (uint i = 0; i < num; i++) {
791 items[i] = seq_items[num - 1 - i];
792 }
Damien86c7fc72013-11-26 15:16:41 +0000793 } else {
794 // TODO call rt_getiter and extract via rt_iternext
Damien George6c73ca12014-01-08 18:11:23 +0000795 nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "'%s' object is not iterable", mp_obj_get_type_str(seq_in)));
Damien86c7fc72013-11-26 15:16:41 +0000796 }
797}
798
Damiend99b0522013-12-21 18:17:45 +0000799mp_obj_t rt_build_map(int n_args) {
800 return mp_obj_new_dict(n_args);
Damien429d7192013-10-04 19:53:11 +0100801}
802
Damiend99b0522013-12-21 18:17:45 +0000803mp_obj_t rt_store_map(mp_obj_t map, mp_obj_t key, mp_obj_t value) {
804 // map should always be a dict
805 return mp_obj_dict_store(map, key, value);
Damien429d7192013-10-04 19:53:11 +0100806}
807
Damiend99b0522013-12-21 18:17:45 +0000808mp_obj_t rt_load_attr(mp_obj_t base, qstr attr) {
Damien George062478e2014-01-09 20:57:50 +0000809 DEBUG_OP_printf("load attr %p.%s\n", base, qstr_str(attr));
810 // use load_method
811 mp_obj_t dest[2];
812 rt_load_method(base, attr, dest);
Damien George7c9c6672014-01-25 00:17:36 +0000813 if (dest[1] == MP_OBJ_NULL) {
Damien George062478e2014-01-09 20:57:50 +0000814 // load_method returned just a normal attribute
Damien George20006db2014-01-18 14:10:48 +0000815 return dest[0];
Damien George062478e2014-01-09 20:57:50 +0000816 } else {
817 // load_method returned a method, so build a bound method object
818 return mp_obj_new_bound_meth(dest[0], dest[1]);
Damiend99b0522013-12-21 18:17:45 +0000819 }
Damiend99b0522013-12-21 18:17:45 +0000820}
821
Damien George7c9c6672014-01-25 00:17:36 +0000822// no attribute found, returns: dest[0] == MP_OBJ_NULL, dest[1] == MP_OBJ_NULL
823// normal attribute found, returns: dest[0] == <attribute>, dest[1] == MP_OBJ_NULL
824// method attribute found, returns: dest[0] == <method>, dest[1] == <self>
825static void rt_load_method_maybe(mp_obj_t base, qstr attr, mp_obj_t *dest) {
Damien George062478e2014-01-09 20:57:50 +0000826 // clear output to indicate no attribute/method found yet
827 dest[0] = MP_OBJ_NULL;
828 dest[1] = MP_OBJ_NULL;
829
830 // get the type
831 mp_obj_type_t *type = mp_obj_get_type(base);
832
833 // if this type can do its own load, then call it
834 if (type->load_attr != NULL) {
835 type->load_attr(base, attr, dest);
836 }
837
838 // if nothing found yet, look for built-in and generic names
Damien George7c9c6672014-01-25 00:17:36 +0000839 if (dest[0] == MP_OBJ_NULL) {
Damien George062478e2014-01-09 20:57:50 +0000840 if (attr == MP_QSTR___next__ && type->iternext != NULL) {
Damien George20006db2014-01-18 14:10:48 +0000841 dest[0] = (mp_obj_t)&mp_builtin_next_obj;
842 dest[1] = base;
Damien Georgef49ba1b2014-01-18 17:52:41 +0000843 } else if (type->load_attr == NULL) {
844 // generic method lookup if type didn't provide a specific one
Damien Georgeeae16442014-01-11 19:22:29 +0000845 // this is a lookup in the object (ie not class or type)
Damien George062478e2014-01-09 20:57:50 +0000846 const mp_method_t *meth = type->methods;
847 if (meth != NULL) {
848 for (; meth->name != NULL; meth++) {
849 if (strcmp(meth->name, qstr_str(attr)) == 0) {
Damien Georgeeae16442014-01-11 19:22:29 +0000850 // check if the methods are functions, static or class methods
851 // see http://docs.python.org/3.3/howto/descriptor.html
852 if (MP_OBJ_IS_TYPE(meth->fun, &mp_type_staticmethod)) {
853 // return just the function
Damien George20006db2014-01-18 14:10:48 +0000854 dest[0] = ((mp_obj_staticmethod_t*)meth->fun)->fun;
Damien Georgeeae16442014-01-11 19:22:29 +0000855 } else if (MP_OBJ_IS_TYPE(meth->fun, &mp_type_classmethod)) {
856 // return a bound method, with self being the type of this object
Damien George20006db2014-01-18 14:10:48 +0000857 dest[0] = ((mp_obj_classmethod_t*)meth->fun)->fun;
858 dest[1] = mp_obj_get_type(base);
Damien Georgeeae16442014-01-11 19:22:29 +0000859 } else {
860 // return a bound method, with self being this object
Damien George20006db2014-01-18 14:10:48 +0000861 dest[0] = (mp_obj_t)meth->fun;
862 dest[1] = base;
Damien Georgeeae16442014-01-11 19:22:29 +0000863 }
Damien George062478e2014-01-09 20:57:50 +0000864 break;
865 }
John R. Lenton9c83ec02014-01-07 23:06:46 +0000866 }
Damiend57eba52013-11-02 23:58:14 +0000867 }
868 }
Damiena3977762013-10-09 23:10:10 +0100869 }
Damien George7c9c6672014-01-25 00:17:36 +0000870}
Damiena3977762013-10-09 23:10:10 +0100871
Damien George7c9c6672014-01-25 00:17:36 +0000872void rt_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest) {
873 DEBUG_OP_printf("load method %p.%s\n", base, qstr_str(attr));
874
875 rt_load_method_maybe(base, attr, dest);
876
877 if (dest[0] == MP_OBJ_NULL) {
Damien George062478e2014-01-09 20:57:50 +0000878 // no attribute/method called attr
879 // following CPython, we give a more detailed error message for type objects
880 if (MP_OBJ_IS_TYPE(base, &mp_const_type)) {
881 nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_AttributeError, "type object '%s' has no attribute '%s'", ((mp_obj_type_t*)base)->name, qstr_str(attr)));
882 } else {
883 nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_AttributeError, "'%s' object has no attribute '%s'", mp_obj_get_type_str(base), qstr_str(attr)));
884 }
885 }
Damiena3977762013-10-09 23:10:10 +0100886}
887
Damiend99b0522013-12-21 18:17:45 +0000888void rt_store_attr(mp_obj_t base, qstr attr, mp_obj_t value) {
Damien5ac1b2e2013-10-18 19:58:12 +0100889 DEBUG_OP_printf("store attr %p.%s <- %p\n", base, qstr_str(attr), value);
Damien George062478e2014-01-09 20:57:50 +0000890 mp_obj_type_t *type = mp_obj_get_type(base);
891 if (type->store_attr != NULL) {
892 if (type->store_attr(base, attr, value)) {
893 return;
894 }
Damiena3977762013-10-09 23:10:10 +0100895 }
Damien George062478e2014-01-09 20:57:50 +0000896 nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_AttributeError, "'%s' object has no attribute '%s'", mp_obj_get_type_str(base), qstr_str(attr)));
Damiena3977762013-10-09 23:10:10 +0100897}
898
Damiend99b0522013-12-21 18:17:45 +0000899void rt_store_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
Damien5ac1b2e2013-10-18 19:58:12 +0100900 DEBUG_OP_printf("store subscr %p[%p] <- %p\n", base, index, value);
Damiend99b0522013-12-21 18:17:45 +0000901 if (MP_OBJ_IS_TYPE(base, &list_type)) {
Damien429d7192013-10-04 19:53:11 +0100902 // list store
Damiend99b0522013-12-21 18:17:45 +0000903 mp_obj_list_store(base, index, value);
904 } else if (MP_OBJ_IS_TYPE(base, &dict_type)) {
905 // dict store
906 mp_obj_dict_store(base, index, value);
Damien429d7192013-10-04 19:53:11 +0100907 } else {
Paul Sokolovsky6d8edf62014-01-18 13:10:51 +0200908 mp_obj_type_t *type = mp_obj_get_type(base);
909 if (type->store_item != NULL) {
910 bool r = type->store_item(base, index, value);
911 if (r) {
912 return;
913 }
914 // TODO: call base classes here?
915 }
916 nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "'%s' object does not support item assignment", mp_obj_get_type_str(base)));
Damien429d7192013-10-04 19:53:11 +0100917 }
918}
919
Damiend99b0522013-12-21 18:17:45 +0000920mp_obj_t rt_getiter(mp_obj_t o_in) {
Damien George5fa93b62014-01-22 14:35:10 +0000921 mp_obj_type_t *type = mp_obj_get_type(o_in);
922 if (type->getiter != NULL) {
923 return type->getiter(o_in);
Damience89a212013-10-15 22:25:17 +0100924 } else {
Damien George7c9c6672014-01-25 00:17:36 +0000925 // check for __getitem__ method
926 mp_obj_t dest[2];
927 rt_load_method_maybe(o_in, qstr_from_str("__getitem__"), dest);
928 if (dest[0] != MP_OBJ_NULL) {
929 // __getitem__ exists, create an iterator
930 return mp_obj_new_getitem_iter(dest);
931 } else {
932 // object not iterable
933 nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "'%s' object is not iterable", type->name));
934 }
Damience89a212013-10-15 22:25:17 +0100935 }
936}
937
Damiend99b0522013-12-21 18:17:45 +0000938mp_obj_t rt_iternext(mp_obj_t o_in) {
Damien George5fa93b62014-01-22 14:35:10 +0000939 mp_obj_type_t *type = mp_obj_get_type(o_in);
940 if (type->iternext != NULL) {
941 return type->iternext(o_in);
Damience89a212013-10-15 22:25:17 +0100942 } else {
Damien George5fa93b62014-01-22 14:35:10 +0000943 nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "'%s' object is not an iterator", type->name));
Damience89a212013-10-15 22:25:17 +0100944 }
945}
946
Damiend99b0522013-12-21 18:17:45 +0000947mp_obj_t rt_import_name(qstr name, mp_obj_t fromlist, mp_obj_t level) {
Damiendb4c3612013-12-10 17:27:24 +0000948 // build args array
Damiend99b0522013-12-21 18:17:45 +0000949 mp_obj_t args[5];
Damien George5fa93b62014-01-22 14:35:10 +0000950 args[0] = MP_OBJ_NEW_QSTR(name);
Damiend99b0522013-12-21 18:17:45 +0000951 args[1] = mp_const_none; // TODO should be globals
952 args[2] = mp_const_none; // TODO should be locals
Damiendb4c3612013-12-10 17:27:24 +0000953 args[3] = fromlist;
954 args[4] = level; // must be 0; we don't yet support other values
955
956 // TODO lookup __import__ and call that instead of going straight to builtin implementation
Damiend99b0522013-12-21 18:17:45 +0000957 return mp_builtin___import__(5, args);
Damiendb4c3612013-12-10 17:27:24 +0000958}
959
Damiend99b0522013-12-21 18:17:45 +0000960mp_obj_t rt_import_from(mp_obj_t module, qstr name) {
961 mp_obj_t x = rt_load_attr(module, name);
Damiendb4c3612013-12-10 17:27:24 +0000962 /* TODO convert AttributeError to ImportError
963 if (fail) {
964 (ImportError, "cannot import name %s", qstr_str(name), NULL)
965 }
966 */
967 return x;
968}
969
Damien George66028ab2014-01-03 14:03:48 +0000970mp_map_t *rt_locals_get(void) {
971 return map_locals;
972}
973
974void rt_locals_set(mp_map_t *m) {
975 DEBUG_OP_printf("rt_locals_set(%p)\n", m);
976 map_locals = m;
977}
978
979mp_map_t *rt_globals_get(void) {
980 return map_globals;
981}
982
983void rt_globals_set(mp_map_t *m) {
984 DEBUG_OP_printf("rt_globals_set(%p)\n", m);
985 map_globals = m;
986}
987
Damien George0d028742014-01-22 23:59:20 +0000988mp_map_t *rt_loaded_modules_get(void) {
989 return &map_loaded_modules;
990}
991
Damien6ba13142013-11-02 20:34:54 +0000992// these must correspond to the respective enum
Damiendf4b4f32013-10-19 18:28:01 +0100993void *const rt_fun_table[RT_F_NUMBER_OF] = {
Damien6ba13142013-11-02 20:34:54 +0000994 rt_load_const_dec,
Damien429d7192013-10-04 19:53:11 +0100995 rt_load_const_str,
996 rt_load_name,
997 rt_load_global,
Damien7f5dacf2013-10-10 11:24:39 +0100998 rt_load_build_class,
Damien429d7192013-10-04 19:53:11 +0100999 rt_load_attr,
1000 rt_load_method,
1001 rt_store_name,
Damien7f5dacf2013-10-10 11:24:39 +01001002 rt_store_attr,
Damien429d7192013-10-04 19:53:11 +01001003 rt_store_subscr,
1004 rt_is_true,
1005 rt_unary_op,
Damiend2755ec2013-10-16 23:58:48 +01001006 rt_build_tuple,
Damien429d7192013-10-04 19:53:11 +01001007 rt_build_list,
Damiend2755ec2013-10-16 23:58:48 +01001008 rt_list_append,
Damien429d7192013-10-04 19:53:11 +01001009 rt_build_map,
1010 rt_store_map,
1011 rt_build_set,
Damiend2755ec2013-10-16 23:58:48 +01001012 rt_store_set,
Damien429d7192013-10-04 19:53:11 +01001013 rt_make_function_from_id,
Damien George20006db2014-01-18 14:10:48 +00001014 rt_call_function_n_kw,
1015 rt_call_method_n_kw,
Damien429d7192013-10-04 19:53:11 +01001016 rt_binary_op,
Damiend2755ec2013-10-16 23:58:48 +01001017 rt_getiter,
1018 rt_iternext,
Damien429d7192013-10-04 19:53:11 +01001019};
1020
1021/*
1022void rt_f_vector(rt_fun_kind_t fun_kind) {
1023 (rt_f_table[fun_kind])();
1024}
1025*/