diff options
author | Damien <damien.p.george@gmail.com> | 2013-12-21 18:17:45 +0000 |
---|---|---|
committer | Damien <damien.p.george@gmail.com> | 2013-12-21 18:17:45 +0000 |
commit | d99b05282d14ceb0163cbcd059aa37bdb415af43 (patch) | |
tree | 978135f9fe83d3c4d5b3c95f84cb104c0092936a /py/runtime.h | |
parent | e2880aa2fdc75298df487df7519d483acb03959c (diff) | |
download | micropython-d99b05282d14ceb0163cbcd059aa37bdb415af43.tar.gz micropython-d99b05282d14ceb0163cbcd059aa37bdb415af43.zip |
Change object representation from 1 big union to individual structs.
A big change. Micro Python objects are allocated as individual structs
with the first element being a pointer to the type information (which
is itself an object). This scheme follows CPython. Much more flexible,
not necessarily slower, uses same heap memory, and can allocate objects
statically.
Also change name prefix, from py_ to mp_ (mp for Micro Python).
Diffstat (limited to 'py/runtime.h')
-rw-r--r-- | py/runtime.h | 190 |
1 files changed, 44 insertions, 146 deletions
diff --git a/py/runtime.h b/py/runtime.h index d5d160535f..37b036852f 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -1,91 +1,3 @@ -typedef enum { - RT_UNARY_OP_NOT, - RT_UNARY_OP_POSITIVE, - RT_UNARY_OP_NEGATIVE, - RT_UNARY_OP_INVERT, -} rt_unary_op_t; - -typedef enum { - RT_BINARY_OP_SUBSCR, - RT_BINARY_OP_OR, - RT_BINARY_OP_XOR, - RT_BINARY_OP_AND, - RT_BINARY_OP_LSHIFT, - RT_BINARY_OP_RSHIFT, - RT_BINARY_OP_ADD, - RT_BINARY_OP_SUBTRACT, - RT_BINARY_OP_MULTIPLY, - RT_BINARY_OP_FLOOR_DIVIDE, - RT_BINARY_OP_TRUE_DIVIDE, - RT_BINARY_OP_MODULO, - RT_BINARY_OP_POWER, - RT_BINARY_OP_INPLACE_OR, - RT_BINARY_OP_INPLACE_XOR, - RT_BINARY_OP_INPLACE_AND, - RT_BINARY_OP_INPLACE_LSHIFT, - RT_BINARY_OP_INPLACE_RSHIFT, - RT_BINARY_OP_INPLACE_ADD, - RT_BINARY_OP_INPLACE_SUBTRACT, - RT_BINARY_OP_INPLACE_MULTIPLY, - RT_BINARY_OP_INPLACE_FLOOR_DIVIDE, - RT_BINARY_OP_INPLACE_TRUE_DIVIDE, - RT_BINARY_OP_INPLACE_MODULO, - RT_BINARY_OP_INPLACE_POWER, -} rt_binary_op_t; - -typedef enum { - RT_COMPARE_OP_LESS, - RT_COMPARE_OP_MORE, - RT_COMPARE_OP_EQUAL, - RT_COMPARE_OP_LESS_EQUAL, - RT_COMPARE_OP_MORE_EQUAL, - RT_COMPARE_OP_NOT_EQUAL, - RT_COMPARE_OP_IN, - RT_COMPARE_OP_NOT_IN, - RT_COMPARE_OP_IS, - RT_COMPARE_OP_IS_NOT, - RT_COMPARE_OP_EXCEPTION_MATCH, -} rt_compare_op_t; - -typedef enum { - RT_F_LOAD_CONST_DEC = 0, - RT_F_LOAD_CONST_STR, - RT_F_LOAD_NAME, - RT_F_LOAD_GLOBAL, - RT_F_LOAD_BUILD_CLASS, - RT_F_LOAD_ATTR, - RT_F_LOAD_METHOD, - RT_F_STORE_NAME, - RT_F_STORE_ATTR, - RT_F_STORE_SUBSCR, - RT_F_IS_TRUE, - RT_F_UNARY_OP, - RT_F_BUILD_TUPLE, - RT_F_BUILD_LIST, - RT_F_LIST_APPEND, - RT_F_BUILD_MAP, - RT_F_STORE_MAP, - RT_F_BUILD_SET, - RT_F_STORE_SET, - RT_F_MAKE_FUNCTION_FROM_ID, - RT_F_CALL_FUNCTION_N, - RT_F_CALL_METHOD_N, - RT_F_BINARY_OP, - RT_F_COMPARE_OP, - RT_F_GETITER, - RT_F_ITERNEXT, - RT_F_NUMBER_OF, -} rt_fun_kind_t; - -extern void *const rt_fun_table[RT_F_NUMBER_OF]; - -typedef machine_ptr_t py_obj_t; // must be of pointer size -typedef py_obj_t (*py_fun_0_t)(void); -typedef py_obj_t (*py_fun_1_t)(py_obj_t); -typedef py_obj_t (*py_fun_2_t)(py_obj_t, py_obj_t); -typedef py_obj_t (*py_fun_t)(void); -typedef py_obj_t (*py_fun_var_t)(int n, const py_obj_t *); - extern qstr rt_q_append; extern qstr rt_q_pop; extern qstr rt_q_sort; @@ -101,61 +13,47 @@ extern qstr rt_q_TypeError; extern qstr rt_q_SyntaxError; extern qstr rt_q_ValueError; -extern py_obj_t py_const_none; -extern py_obj_t py_const_false; -extern py_obj_t py_const_true; -extern py_obj_t py_const_stop_iteration; // special object indicating end of iteration (not StopIteration exception!) - -void rt_init(void); -void rt_deinit(void); -int rt_get_unique_code_id(bool is_main_module); -void rt_assign_byte_code(int unique_code_id, byte *code, uint len, int n_args, int n_locals, int n_cells, int n_stack, bool is_generator); -void rt_assign_native_code(int unique_code_id, py_fun_t f, uint len, int n_args); -void rt_assign_inline_asm_code(int unique_code_id, py_fun_t f, uint len, int n_args); - -int rt_is_true(py_obj_t arg); - -py_obj_t rt_load_const_dec(qstr qstr); -py_obj_t rt_load_const_str(qstr qstr); -py_obj_t rt_load_name(qstr qstr); -py_obj_t rt_load_global(qstr qstr); -py_obj_t rt_load_build_class(void); -py_obj_t rt_get_cell(py_obj_t cell); -void rt_set_cell(py_obj_t cell, py_obj_t val); -void rt_store_name(qstr qstr, py_obj_t obj); -void rt_store_global(qstr qstr, py_obj_t obj); -py_obj_t rt_unary_op(int op, py_obj_t arg); -py_obj_t rt_binary_op(int op, py_obj_t lhs, py_obj_t rhs); -py_obj_t rt_compare_op(int op, py_obj_t lhs, py_obj_t rhs); -py_obj_t rt_make_function_from_id(int unique_code_id); -py_obj_t rt_make_function_0(py_fun_0_t f); -py_obj_t rt_make_function_1(py_fun_1_t f); -py_obj_t rt_make_function_2(py_fun_2_t f); -py_obj_t rt_make_function(int n_args, py_fun_t code); -py_obj_t rt_make_function_var(int n_fixed_args, py_fun_var_t f); -py_obj_t rt_make_closure_from_id(int unique_code_id, py_obj_t closure_tuple); -py_obj_t rt_call_function_0(py_obj_t fun); -py_obj_t rt_call_function_1(py_obj_t fun, py_obj_t arg); -py_obj_t rt_call_function_2(py_obj_t fun, py_obj_t arg1, py_obj_t arg2); -py_obj_t rt_call_function_n(py_obj_t fun, int n_args, const py_obj_t *args); -py_obj_t rt_call_function_n_kw(py_obj_t fun, uint n_args, uint n_kw, const py_obj_t *args); -py_obj_t rt_call_method_n(uint n_args, const py_obj_t *args); -py_obj_t rt_call_method_n_kw(uint n_args, uint n_kw, const py_obj_t *args); -py_obj_t rt_build_tuple(int n_args, py_obj_t *items); -py_obj_t rt_build_list(int n_args, py_obj_t *items); -py_obj_t rt_list_append(py_obj_t list, py_obj_t arg); -py_obj_t rt_build_set(int n_args, py_obj_t *items); -py_obj_t rt_store_set(py_obj_t set, py_obj_t item); -void rt_unpack_sequence(py_obj_t seq, uint num, py_obj_t *items); -py_obj_t rt_build_map(int n_args); -py_obj_t rt_store_map(py_obj_t map, py_obj_t key, py_obj_t value); -py_obj_t rt_load_attr(py_obj_t base, qstr attr); -void rt_load_method(py_obj_t base, qstr attr, py_obj_t *dest); -void rt_store_attr(py_obj_t base, qstr attr, py_obj_t val); -void rt_store_subscr(py_obj_t base, py_obj_t index, py_obj_t val); -py_obj_t rt_getiter(py_obj_t o); -py_obj_t rt_iternext(py_obj_t o); -py_obj_t rt_import_name(qstr name, py_obj_t fromlist, py_obj_t level); -py_obj_t rt_import_from(py_obj_t module, qstr name); - -py_obj_t rt_gen_instance_next(py_obj_t self_in); +int rt_is_true(mp_obj_t arg); + +mp_obj_t rt_load_const_dec(qstr qstr); +mp_obj_t rt_load_const_str(qstr qstr); +mp_obj_t rt_load_name(qstr qstr); +mp_obj_t rt_load_global(qstr qstr); +mp_obj_t rt_load_build_class(void); +mp_obj_t rt_get_cell(mp_obj_t cell); +void rt_set_cell(mp_obj_t cell, mp_obj_t val); +void rt_store_name(qstr qstr, mp_obj_t obj); +void rt_store_global(qstr qstr, mp_obj_t obj); +mp_obj_t rt_unary_op(int op, mp_obj_t arg); +mp_obj_t rt_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs); +mp_obj_t rt_compare_op(int op, mp_obj_t lhs, mp_obj_t rhs); +mp_obj_t rt_make_function_from_id(int unique_code_id); +mp_obj_t rt_make_function_0(mp_fun_0_t f); +mp_obj_t rt_make_function_1(mp_fun_1_t f); +mp_obj_t rt_make_function_2(mp_fun_2_t f); +mp_obj_t rt_make_function_var(int n_args_min, mp_fun_var_t f); +mp_obj_t rt_make_function_var_between(int n_args_min, int n_args_max, mp_fun_var_t fun); // min and max are inclusive +mp_obj_t rt_make_closure_from_id(int unique_code_id, mp_obj_t closure_tuple); +mp_obj_t rt_call_function_0(mp_obj_t fun); +mp_obj_t rt_call_function_1(mp_obj_t fun, mp_obj_t arg); +mp_obj_t rt_call_function_2(mp_obj_t fun, mp_obj_t arg1, mp_obj_t arg2); +mp_obj_t rt_call_function_n(mp_obj_t fun, int n_args, const mp_obj_t *args); +mp_obj_t rt_call_function_n_kw(mp_obj_t fun, uint n_args, uint n_kw, const mp_obj_t *args); +mp_obj_t rt_call_method_n(uint n_args, const mp_obj_t *args); +mp_obj_t rt_call_method_n_kw(uint n_args, uint n_kw, const mp_obj_t *args); +mp_obj_t rt_build_tuple(int n_args, mp_obj_t *items); +mp_obj_t rt_build_list(int n_args, mp_obj_t *items); +mp_obj_t rt_list_append(mp_obj_t list, mp_obj_t arg); +mp_obj_t rt_build_set(int n_args, mp_obj_t *items); +mp_obj_t rt_store_set(mp_obj_t set, mp_obj_t item); +void rt_unpack_sequence(mp_obj_t seq, uint num, mp_obj_t *items); +mp_obj_t rt_build_map(int n_args); +mp_obj_t rt_store_map(mp_obj_t map, mp_obj_t key, mp_obj_t value); +mp_obj_t rt_load_attr(mp_obj_t base, qstr attr); +void rt_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest); +void rt_store_attr(mp_obj_t base, qstr attr, mp_obj_t val); +void rt_store_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t val); +mp_obj_t rt_getiter(mp_obj_t o); +mp_obj_t rt_iternext(mp_obj_t o); +mp_obj_t rt_import_name(qstr name, mp_obj_t fromlist, mp_obj_t level); +mp_obj_t rt_import_from(mp_obj_t module, qstr name); |