mirror of
https://github.com/micropython/micropython.git
synced 2026-01-04 11:10:14 +01:00
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.
This commit is contained in:
27
py/objlist.c
27
py/objlist.c
@@ -38,7 +38,9 @@ static void list_print(void (*print)(void *env, const char *fmt, ...), void *env
|
||||
print(env, "]");
|
||||
}
|
||||
|
||||
static mp_obj_t list_make_new(mp_obj_t type_in, int n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t list_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
|
||||
// TODO check n_kw == 0
|
||||
|
||||
switch (n_args) {
|
||||
case 0:
|
||||
// return a new, empty list
|
||||
@@ -248,19 +250,14 @@ static void mp_quicksort(mp_obj_t *head, mp_obj_t *tail, mp_obj_t key_fn, bool r
|
||||
}
|
||||
}
|
||||
|
||||
mp_obj_t mp_obj_list_sort(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);
|
||||
assert(MP_OBJ_IS_TYPE(args_items[0], &list_type));
|
||||
if (args_len > 1) {
|
||||
mp_obj_t mp_obj_list_sort(uint n_args, const mp_obj_t *args, mp_map_t *kwargs) {
|
||||
assert(n_args >= 1);
|
||||
assert(MP_OBJ_IS_TYPE(args[0], &list_type));
|
||||
if (n_args > 1) {
|
||||
nlr_jump(mp_obj_new_exception_msg(MP_QSTR_TypeError,
|
||||
"list.sort takes no positional arguments"));
|
||||
}
|
||||
mp_obj_list_t *self = args_items[0];
|
||||
mp_obj_list_t *self = args[0];
|
||||
if (self->len > 1) {
|
||||
mp_map_elem_t *keyfun = mp_map_lookup(kwargs, MP_OBJ_NEW_QSTR(qstr_from_str_static("key")), MP_MAP_LOOKUP);
|
||||
mp_map_elem_t *reverse = mp_map_lookup(kwargs, MP_OBJ_NEW_QSTR(qstr_from_str_static("reverse")), MP_MAP_LOOKUP);
|
||||
@@ -425,14 +422,6 @@ mp_obj_t mp_obj_new_list(uint n, mp_obj_t *items) {
|
||||
return o;
|
||||
}
|
||||
|
||||
mp_obj_t mp_obj_new_list_reverse(uint n, mp_obj_t *items) {
|
||||
mp_obj_list_t *o = list_new(n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
o->items[i] = items[n - i - 1];
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
void mp_obj_list_get(mp_obj_t self_in, uint *len, mp_obj_t **items) {
|
||||
mp_obj_list_t *self = self_in;
|
||||
*len = self->len;
|
||||
|
||||
Reference in New Issue
Block a user