diff options
author | Damien George <damien.p.george@gmail.com> | 2014-01-18 14:10:48 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-01-18 14:10:48 +0000 |
commit | 20006dbba9d2d84ead036fdfab7190e88b2337ce (patch) | |
tree | a83dc966464cbbee17a397bda96360e9d238f8cf /py/builtin.c | |
parent | 8655065f8cec8b978d075adae1f65ffdfa9b51d8 (diff) |
Make VM stack grow upwards, and so no reversed args arrays.
Change state layout in VM so the stack starts at state[0] and grows
upwards. Locals are at the top end of the state and number downwards.
This cleans up a lot of the interface connecting the VM to C: now all
functions that take an array of Micro Python objects are in order (ie no
longer in reverse).
Also clean up C API with keyword arguments (call_n and call_n_kw
replaced with single call method that takes keyword arguments). And now
make_new takes keyword arguments.
emitnative.c has not yet been changed to comply with the new order of
stack layout.
Diffstat (limited to 'py/builtin.c')
-rw-r--r-- | py/builtin.c | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/py/builtin.c b/py/builtin.c index 04bb2681d..fcd58d4ae 100644 --- a/py/builtin.c +++ b/py/builtin.c @@ -45,12 +45,11 @@ static mp_obj_t mp_builtin___build_class__(int n_args, const mp_obj_t *args) { // TODO do proper metaclass resolution for multiple base objects // create the new class using a call to the meta object - // (arguments must be backwards in the array) mp_obj_t meta_args[3]; - meta_args[2] = args[1]; // class name + meta_args[0] = args[1]; // class name meta_args[1] = mp_obj_new_tuple(n_args - 2, args + 2); // tuple of bases - meta_args[0] = class_locals; // dict of members - mp_obj_t new_class = rt_call_function_n(meta, 3, meta_args); + meta_args[2] = class_locals; // dict of members + mp_obj_t new_class = rt_call_function_n_kw(meta, 3, 0, meta_args); // store into cell if neede if (cell != mp_const_none) { @@ -153,10 +152,10 @@ static mp_obj_t mp_builtin_divmod(mp_obj_t o1_in, mp_obj_t o2_in) { if (MP_OBJ_IS_SMALL_INT(o1_in) && MP_OBJ_IS_SMALL_INT(o2_in)) { mp_small_int_t i1 = MP_OBJ_SMALL_INT_VALUE(o1_in); mp_small_int_t i2 = MP_OBJ_SMALL_INT_VALUE(o2_in); - mp_obj_t revs_args[2]; - revs_args[1] = MP_OBJ_NEW_SMALL_INT(i1 / i2); - revs_args[0] = MP_OBJ_NEW_SMALL_INT(i1 % i2); - return rt_build_tuple(2, revs_args); + mp_obj_t args[2]; + args[0] = MP_OBJ_NEW_SMALL_INT(i1 / i2); + args[1] = MP_OBJ_NEW_SMALL_INT(i1 % i2); + return rt_build_tuple(2, args); } else { nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "unsupported operand type(s) for divmod(): '%s' and '%s'", mp_obj_get_type_str(o1_in), mp_obj_get_type_str(o2_in))); } @@ -327,20 +326,14 @@ static mp_obj_t mp_builtin_sum(int n_args, const mp_obj_t *args) { MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_sum_obj, 1, 2, mp_builtin_sum); -static mp_obj_t mp_builtin_sorted(mp_obj_t args, mp_map_t *kwargs) { - mp_obj_t *args_items = NULL; - uint args_len = 0; - - assert(MP_OBJ_IS_TYPE(args, &tuple_type)); - mp_obj_tuple_get(args, &args_len, &args_items); - assert(args_len >= 1); - if (args_len > 1) { +static mp_obj_t mp_builtin_sorted(uint n_args, const mp_obj_t *args, mp_map_t *kwargs) { + assert(n_args >= 1); + if (n_args > 1) { nlr_jump(mp_obj_new_exception_msg(MP_QSTR_TypeError, "must use keyword argument for key function")); } - mp_obj_t self = list_type.make_new((mp_obj_t)&list_type, 1, args_items); - mp_obj_t new_args = rt_build_tuple(1, &self); - mp_obj_list_sort(new_args, kwargs); + mp_obj_t self = list_type.make_new((mp_obj_t)&list_type, 1, 0, args); + mp_obj_list_sort(1, &self, kwargs); return self; } |