blob: 4c842b235ebe766ab589dc126e5a692213b904f3 [file] [log] [blame]
Damien429d7192013-10-04 19:53:11 +01001typedef 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
8typedef 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
36typedef 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
50typedef 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
75extern void *rt_fun_table[RT_F_NUMBER_OF];
76
77typedef machine_ptr_t py_obj_t; // must be of pointer size
78typedef py_obj_t (*py_fun_0_t)();
79typedef py_obj_t (*py_fun_1_t)(py_obj_t);
80typedef py_obj_t (*py_fun_2_t)(py_obj_t, py_obj_t);
81typedef py_obj_t (*py_fun_t)();
82
83extern py_obj_t py_const_none;
84extern py_obj_t py_const_false;
85extern py_obj_t py_const_true;
86
87void rt_init();
88void rt_deinit();
89int rt_get_new_unique_code_id();
90void rt_assign_native_code(int unique_code_id, py_fun_t f, uint len, int n_args);
91void rt_assign_byte_code(int unique_code_id, byte *code, uint len, int n_args);
92py_fun_t rt_get_code(qstr id);
93void py_obj_print(py_obj_t o);
94int rt_is_true(py_obj_t arg);
95int rt_get_int(py_obj_t arg);
96py_obj_t rt_load_const_str(qstr qstr);
97//py_obj_t rt_load_const_code(qstr qstr);
98py_obj_t rt_load_name(qstr qstr);
99py_obj_t rt_load_global(qstr qstr);
100py_obj_t rt_load_build_class();
101void rt_store_name(qstr qstr, py_obj_t obj);
102py_obj_t rt_unary_op(int op, py_obj_t arg);
103py_obj_t rt_binary_op(int op, py_obj_t lhs, py_obj_t rhs);
104py_obj_t rt_compare_op(int op, py_obj_t lhs, py_obj_t rhs);
105py_obj_t rt_make_function_from_id(int unique_code_id);
106py_obj_t rt_make_function_0(py_fun_0_t f);
107py_obj_t rt_make_function_1(py_fun_1_t f);
108py_obj_t rt_make_function_2(py_fun_2_t f);
109py_obj_t rt_make_function(int n_args, py_fun_t code);
110py_obj_t rt_call_function_0(py_obj_t fun);
111py_obj_t rt_call_function_1(py_obj_t fun, py_obj_t arg);
112py_obj_t rt_call_function_2(py_obj_t fun, py_obj_t arg1, py_obj_t arg2);
113py_obj_t rt_call_method_1(py_obj_t fun, py_obj_t self);
114py_obj_t rt_call_method_2(py_obj_t fun, py_obj_t self, py_obj_t arg);
115py_obj_t rt_build_list(int n_args, py_obj_t *items);
116py_obj_t rt_build_map(int n_args);
117py_obj_t rt_store_map(py_obj_t map, py_obj_t key, py_obj_t value);
118py_obj_t rt_build_set(int n_args, py_obj_t *items);
119void rt_store_subscr(py_obj_t base, py_obj_t index, py_obj_t val);
120py_obj_t rt_load_attr(py_obj_t base, qstr attr);
121void rt_load_method(py_obj_t base, qstr attr, py_obj_t *dest);