Damien | 429d719 | 2013-10-04 19:53:11 +0100 | [diff] [blame^] | 1 | typedef enum { |
| 2 | RT_UNARY_OP_NOT, |
| 3 | RT_UNARY_OP_POSITIVE, |
| 4 | RT_UNARY_OP_NEGATIVE, |
| 5 | RT_UNARY_OP_INVERT, |
| 6 | } rt_unary_op_t; |
| 7 | |
| 8 | typedef enum { |
| 9 | RT_BINARY_OP_SUBSCR, |
| 10 | RT_BINARY_OP_OR, |
| 11 | RT_BINARY_OP_XOR, |
| 12 | RT_BINARY_OP_AND, |
| 13 | RT_BINARY_OP_LSHIFT, |
| 14 | RT_BINARY_OP_RSHIFT, |
| 15 | RT_BINARY_OP_ADD, |
| 16 | RT_BINARY_OP_SUBTRACT, |
| 17 | RT_BINARY_OP_MULTIPLY, |
| 18 | RT_BINARY_OP_FLOOR_DIVIDE, |
| 19 | RT_BINARY_OP_TRUE_DIVIDE, |
| 20 | RT_BINARY_OP_MODULO, |
| 21 | RT_BINARY_OP_POWER, |
| 22 | RT_BINARY_OP_INPLACE_OR, |
| 23 | RT_BINARY_OP_INPLACE_XOR, |
| 24 | RT_BINARY_OP_INPLACE_AND, |
| 25 | RT_BINARY_OP_INPLACE_LSHIFT, |
| 26 | RT_BINARY_OP_INPLACE_RSHIFT, |
| 27 | RT_BINARY_OP_INPLACE_ADD, |
| 28 | RT_BINARY_OP_INPLACE_SUBTRACT, |
| 29 | RT_BINARY_OP_INPLACE_MULTIPLY, |
| 30 | RT_BINARY_OP_INPLACE_FLOOR_DIVIDE, |
| 31 | RT_BINARY_OP_INPLACE_TRUE_DIVIDE, |
| 32 | RT_BINARY_OP_INPLACE_MODULO, |
| 33 | RT_BINARY_OP_INPLACE_POWER, |
| 34 | } rt_binary_op_t; |
| 35 | |
| 36 | typedef enum { |
| 37 | RT_COMPARE_OP_LESS, |
| 38 | RT_COMPARE_OP_MORE, |
| 39 | RT_COMPARE_OP_EQUAL, |
| 40 | RT_COMPARE_OP_LESS_EQUAL, |
| 41 | RT_COMPARE_OP_MORE_EQUAL, |
| 42 | RT_COMPARE_OP_NOT_EQUAL, |
| 43 | RT_COMPARE_OP_IN, |
| 44 | RT_COMPARE_OP_NOT_IN, |
| 45 | RT_COMPARE_OP_IS, |
| 46 | RT_COMPARE_OP_IS_NOT, |
| 47 | RT_COMPARE_OP_EXCEPTION_MATCH, |
| 48 | } rt_compare_op_t; |
| 49 | |
| 50 | typedef enum { |
| 51 | RT_F_LOAD_CONST_STR = 0, |
| 52 | RT_F_LOAD_NAME, |
| 53 | RT_F_LOAD_GLOBAL, |
| 54 | RT_F_LOAD_ATTR, |
| 55 | RT_F_LOAD_METHOD, |
| 56 | RT_F_STORE_NAME, |
| 57 | RT_F_STORE_SUBSCR, |
| 58 | RT_F_IS_TRUE, |
| 59 | RT_F_UNARY_OP, |
| 60 | RT_F_BUILD_LIST, |
| 61 | RT_F_BUILD_MAP, |
| 62 | RT_F_STORE_MAP, |
| 63 | RT_F_BUILD_SET, |
| 64 | RT_F_MAKE_FUNCTION_FROM_ID, |
| 65 | RT_F_CALL_FUNCTION_0, |
| 66 | RT_F_CALL_FUNCTION_1, |
| 67 | RT_F_CALL_FUNCTION_2, |
| 68 | RT_F_CALL_METHOD_1, |
| 69 | RT_F_CALL_METHOD_2, |
| 70 | RT_F_BINARY_OP, |
| 71 | RT_F_COMPARE_OP, |
| 72 | RT_F_NUMBER_OF, |
| 73 | } rt_fun_kind_t; |
| 74 | |
| 75 | extern void *rt_fun_table[RT_F_NUMBER_OF]; |
| 76 | |
| 77 | typedef machine_ptr_t py_obj_t; // must be of pointer size |
| 78 | typedef py_obj_t (*py_fun_0_t)(); |
| 79 | typedef py_obj_t (*py_fun_1_t)(py_obj_t); |
| 80 | typedef py_obj_t (*py_fun_2_t)(py_obj_t, py_obj_t); |
| 81 | typedef py_obj_t (*py_fun_t)(); |
| 82 | |
| 83 | extern py_obj_t py_const_none; |
| 84 | extern py_obj_t py_const_false; |
| 85 | extern py_obj_t py_const_true; |
| 86 | |
| 87 | void rt_init(); |
| 88 | void rt_deinit(); |
| 89 | int rt_get_new_unique_code_id(); |
| 90 | void rt_assign_native_code(int unique_code_id, py_fun_t f, uint len, int n_args); |
| 91 | void rt_assign_byte_code(int unique_code_id, byte *code, uint len, int n_args); |
| 92 | py_fun_t rt_get_code(qstr id); |
| 93 | void py_obj_print(py_obj_t o); |
| 94 | int rt_is_true(py_obj_t arg); |
| 95 | int rt_get_int(py_obj_t arg); |
| 96 | py_obj_t rt_load_const_str(qstr qstr); |
| 97 | //py_obj_t rt_load_const_code(qstr qstr); |
| 98 | py_obj_t rt_load_name(qstr qstr); |
| 99 | py_obj_t rt_load_global(qstr qstr); |
| 100 | py_obj_t rt_load_build_class(); |
| 101 | void rt_store_name(qstr qstr, py_obj_t obj); |
| 102 | py_obj_t rt_unary_op(int op, py_obj_t arg); |
| 103 | py_obj_t rt_binary_op(int op, py_obj_t lhs, py_obj_t rhs); |
| 104 | py_obj_t rt_compare_op(int op, py_obj_t lhs, py_obj_t rhs); |
| 105 | py_obj_t rt_make_function_from_id(int unique_code_id); |
| 106 | py_obj_t rt_make_function_0(py_fun_0_t f); |
| 107 | py_obj_t rt_make_function_1(py_fun_1_t f); |
| 108 | py_obj_t rt_make_function_2(py_fun_2_t f); |
| 109 | py_obj_t rt_make_function(int n_args, py_fun_t code); |
| 110 | py_obj_t rt_call_function_0(py_obj_t fun); |
| 111 | py_obj_t rt_call_function_1(py_obj_t fun, py_obj_t arg); |
| 112 | py_obj_t rt_call_function_2(py_obj_t fun, py_obj_t arg1, py_obj_t arg2); |
| 113 | py_obj_t rt_call_method_1(py_obj_t fun, py_obj_t self); |
| 114 | py_obj_t rt_call_method_2(py_obj_t fun, py_obj_t self, py_obj_t arg); |
| 115 | py_obj_t rt_build_list(int n_args, py_obj_t *items); |
| 116 | py_obj_t rt_build_map(int n_args); |
| 117 | py_obj_t rt_store_map(py_obj_t map, py_obj_t key, py_obj_t value); |
| 118 | py_obj_t rt_build_set(int n_args, py_obj_t *items); |
| 119 | void rt_store_subscr(py_obj_t base, py_obj_t index, py_obj_t val); |
| 120 | py_obj_t rt_load_attr(py_obj_t base, qstr attr); |
| 121 | void rt_load_method(py_obj_t base, qstr attr, py_obj_t *dest); |