py: Remove old "run time" functions that were 1 liners.

This commit is contained in:
Damien George 2014-03-31 16:28:13 +01:00
parent f78b6df192
commit 15d18069c5
12 changed files with 36 additions and 83 deletions

View File

@ -192,7 +192,7 @@ STATIC mp_obj_t mp_builtin_divmod(mp_obj_t o1_in, mp_obj_t o2_in) {
mp_obj_t args[2];
args[0] = MP_OBJ_NEW_SMALL_INT(i1 / i2);
args[1] = MP_OBJ_NEW_SMALL_INT(i1 % i2);
return mp_build_tuple(2, args);
return mp_obj_new_tuple(2, args);
} else {
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "unsupported operand type(s) for divmod(): '%s' and '%s'", mp_obj_get_type_str(o1_in), mp_obj_get_type_str(o2_in)));
}

View File

@ -1063,14 +1063,14 @@ STATIC void emit_native_build_tuple(emit_t *emit, int n_args) {
// if wrapped in byte_array, or something, allocates memory and fills it
emit_native_pre(emit);
emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, n_args); // pointer to items
emit_call_with_imm_arg(emit, MP_F_BUILD_TUPLE, mp_build_tuple, n_args, REG_ARG_1);
emit_call_with_imm_arg(emit, MP_F_BUILD_TUPLE, mp_obj_new_tuple, n_args, REG_ARG_1);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new tuple
}
STATIC void emit_native_build_list(emit_t *emit, int n_args) {
emit_native_pre(emit);
emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, n_args); // pointer to items
emit_call_with_imm_arg(emit, MP_F_BUILD_LIST, mp_build_list, n_args, REG_ARG_1);
emit_call_with_imm_arg(emit, MP_F_BUILD_LIST, mp_obj_new_list, n_args, REG_ARG_1);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new list
}
@ -1081,13 +1081,13 @@ STATIC void emit_native_list_append(emit_t *emit, int list_index) {
emit_access_stack(emit, list_index, &vtype_list, REG_ARG_1);
assert(vtype_list == VTYPE_PYOBJ);
assert(vtype_item == VTYPE_PYOBJ);
emit_call(emit, MP_F_LIST_APPEND, mp_list_append);
emit_call(emit, MP_F_LIST_APPEND, mp_obj_list_append);
emit_post(emit);
}
STATIC void emit_native_build_map(emit_t *emit, int n_args) {
emit_native_pre(emit);
emit_call_with_imm_arg(emit, MP_F_BUILD_MAP, mp_build_map, n_args, REG_ARG_1);
emit_call_with_imm_arg(emit, MP_F_BUILD_MAP, mp_obj_new_dict, n_args, REG_ARG_1);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new map
}
@ -1097,7 +1097,7 @@ STATIC void emit_native_store_map(emit_t *emit) {
assert(vtype_key == VTYPE_PYOBJ);
assert(vtype_value == VTYPE_PYOBJ);
assert(vtype_map == VTYPE_PYOBJ);
emit_call(emit, MP_F_STORE_MAP, mp_store_map);
emit_call(emit, MP_F_STORE_MAP, mp_obj_dict_store);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // map
}
@ -1109,14 +1109,14 @@ STATIC void emit_native_map_add(emit_t *emit, int map_index) {
assert(vtype_map == VTYPE_PYOBJ);
assert(vtype_key == VTYPE_PYOBJ);
assert(vtype_value == VTYPE_PYOBJ);
emit_call(emit, MP_F_STORE_MAP, mp_store_map);
emit_call(emit, MP_F_STORE_MAP, mp_obj_dict_store);
emit_post(emit);
}
STATIC void emit_native_build_set(emit_t *emit, int n_args) {
emit_native_pre(emit);
emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, n_args); // pointer to items
emit_call_with_imm_arg(emit, MP_F_BUILD_SET, mp_build_set, n_args, REG_ARG_1);
emit_call_with_imm_arg(emit, MP_F_BUILD_SET, mp_obj_new_set, n_args, REG_ARG_1);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new set
}
@ -1127,7 +1127,7 @@ STATIC void emit_native_set_add(emit_t *emit, int set_index) {
emit_access_stack(emit, set_index, &vtype_set, REG_ARG_1);
assert(vtype_set == VTYPE_PYOBJ);
assert(vtype_item == VTYPE_PYOBJ);
emit_call(emit, MP_F_STORE_SET, mp_store_set);
emit_call(emit, MP_F_STORE_SET, mp_obj_set_store);
emit_post(emit);
}

View File

@ -33,7 +33,7 @@ STATIC void dict_print(void (*print)(void *env, const char *fmt, ...), void *env
STATIC mp_obj_t dict_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
// TODO create from an iterable!
return mp_build_map(0);
return mp_obj_new_dict(0);
}
STATIC mp_obj_t dict_unary_op(int op, mp_obj_t self_in) {

View File

@ -372,7 +372,7 @@ STATIC mp_obj_t str_split(uint n_args, const mp_obj_t *args) {
while (s < top && splits != 0) {
start = s;
while (s < top && !is_ws(*s)) s++;
mp_list_append(res, mp_obj_new_str(start, s - start, false));
mp_obj_list_append(res, mp_obj_new_str(start, s - start, false));
if (s >= top) {
break;
}
@ -383,7 +383,7 @@ STATIC mp_obj_t str_split(uint n_args, const mp_obj_t *args) {
}
if (s < top) {
mp_list_append(res, mp_obj_new_str(s, top - s, false));
mp_obj_list_append(res, mp_obj_new_str(s, top - s, false));
}
return res;

View File

@ -72,10 +72,6 @@ void mp_deinit(void) {
mp_emit_glue_deinit();
}
mp_obj_t mp_list_append(mp_obj_t self_in, mp_obj_t arg) {
return mp_obj_list_append(self_in, arg);
}
mp_obj_t mp_load_const_dec(qstr qstr) {
DEBUG_OP_printf("load '%s'\n", qstr_str(qstr));
uint len;
@ -136,14 +132,6 @@ mp_obj_t mp_load_build_class(void) {
}
}
mp_obj_t mp_get_cell(mp_obj_t cell) {
return mp_obj_cell_get(cell);
}
void mp_set_cell(mp_obj_t cell, mp_obj_t val) {
mp_obj_cell_set(cell, val);
}
void mp_store_name(qstr qstr, mp_obj_t obj) {
DEBUG_OP_printf("store name %s <- %p\n", qstr_str(qstr), obj);
mp_map_lookup(map_locals, MP_OBJ_NEW_QSTR(qstr), MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)->value = obj;
@ -656,23 +644,6 @@ mp_obj_t mp_call_method_n_kw_var(bool have_self, uint n_args_n_kw, const mp_obj_
return res;
}
mp_obj_t mp_build_tuple(int n_args, mp_obj_t *items) {
return mp_obj_new_tuple(n_args, items);
}
mp_obj_t mp_build_list(int n_args, mp_obj_t *items) {
return mp_obj_new_list(n_args, items);
}
mp_obj_t mp_build_set(int n_args, mp_obj_t *items) {
return mp_obj_new_set(n_args, items);
}
mp_obj_t mp_store_set(mp_obj_t set, mp_obj_t item) {
mp_obj_set_store(set, item);
return set;
}
// unpacked items are stored in reverse order into the array pointed to by items
void mp_unpack_sequence(mp_obj_t seq_in, uint num, mp_obj_t *items) {
uint seq_len;
@ -713,15 +684,6 @@ too_long:
nlr_jump(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "too many values to unpack (expected %d)", num));
}
mp_obj_t mp_build_map(int n_args) {
return mp_obj_new_dict(n_args);
}
mp_obj_t mp_store_map(mp_obj_t map, mp_obj_t key, mp_obj_t value) {
// map should always be a dict
return mp_obj_dict_store(map, key, value);
}
mp_obj_t mp_load_attr(mp_obj_t base, qstr attr) {
DEBUG_OP_printf("load attr %p.%s\n", base, qstr_str(attr));
// use load_method
@ -1057,13 +1019,13 @@ void *const mp_fun_table[MP_F_NUMBER_OF] = {
mp_obj_is_true,
mp_unary_op,
mp_binary_op,
mp_build_tuple,
mp_build_list,
mp_list_append,
mp_build_map,
mp_store_map,
mp_build_set,
mp_store_set,
mp_obj_new_tuple,
mp_obj_new_list,
mp_obj_list_append,
mp_obj_new_dict,
mp_obj_dict_store,
mp_obj_new_set,
mp_obj_set_store,
mp_make_function_from_id,
mp_call_function_n_kw_for_native,
mp_call_method_n_kw,

View File

@ -28,9 +28,6 @@ mp_obj_t mp_load_const_dec(qstr qstr);
mp_obj_t mp_load_const_str(qstr qstr);
mp_obj_t mp_load_const_bytes(qstr qstr);
mp_obj_t mp_get_cell(mp_obj_t cell);
void mp_set_cell(mp_obj_t cell, mp_obj_t val);
mp_obj_t mp_make_function_from_id(uint unique_code_id, bool free_unique_code, mp_obj_t def_args, mp_obj_t def_kw_args);
mp_obj_t mp_make_function_n(int n_args, void *fun); // fun must have the correct signature for n_args fixed arguments
mp_obj_t mp_make_function_var(int n_args_min, mp_fun_var_t fun);
@ -45,13 +42,7 @@ mp_obj_t mp_call_function_n_kw(mp_obj_t fun, uint n_args, uint n_kw, const mp_ob
mp_obj_t mp_call_method_n_kw(uint n_args, uint n_kw, const mp_obj_t *args);
mp_obj_t mp_call_method_n_kw_var(bool have_self, uint n_args_n_kw, const mp_obj_t *args);
mp_obj_t mp_build_tuple(int n_args, mp_obj_t *items);
mp_obj_t mp_build_list(int n_args, mp_obj_t *items);
mp_obj_t mp_list_append(mp_obj_t list, mp_obj_t arg);
mp_obj_t mp_build_set(int n_args, mp_obj_t *items);
mp_obj_t mp_store_set(mp_obj_t set, mp_obj_t item);
void mp_unpack_sequence(mp_obj_t seq, uint num, mp_obj_t *items);
mp_obj_t mp_build_map(int n_args);
mp_obj_t mp_store_map(mp_obj_t map, mp_obj_t key, mp_obj_t value);
mp_obj_t mp_load_attr(mp_obj_t base, qstr attr);
void mp_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest);

20
py/vm.c
View File

@ -243,7 +243,7 @@ dispatch_loop:
case MP_BC_LOAD_DEREF:
DECODE_UINT;
PUSH(mp_get_cell(fastn[-unum]));
PUSH(mp_obj_cell_get(fastn[-unum]));
break;
case MP_BC_LOAD_NAME:
@ -290,7 +290,7 @@ dispatch_loop:
case MP_BC_STORE_DEREF:
DECODE_UINT;
mp_set_cell(fastn[-unum], POP());
mp_obj_cell_set(fastn[-unum], POP());
break;
case MP_BC_STORE_NAME:
@ -580,49 +580,49 @@ unwind_jump:
case MP_BC_BUILD_TUPLE:
DECODE_UINT;
sp -= unum - 1;
SET_TOP(mp_build_tuple(unum, sp));
SET_TOP(mp_obj_new_tuple(unum, sp));
break;
case MP_BC_BUILD_LIST:
DECODE_UINT;
sp -= unum - 1;
SET_TOP(mp_build_list(unum, sp));
SET_TOP(mp_obj_new_list(unum, sp));
break;
case MP_BC_LIST_APPEND:
DECODE_UINT;
// I think it's guaranteed by the compiler that sp[unum] is a list
mp_list_append(sp[-unum], sp[0]);
mp_obj_list_append(sp[-unum], sp[0]);
sp--;
break;
case MP_BC_BUILD_MAP:
DECODE_UINT;
PUSH(mp_build_map(unum));
PUSH(mp_obj_new_dict(unum));
break;
case MP_BC_STORE_MAP:
sp -= 2;
mp_store_map(sp[0], sp[2], sp[1]);
mp_obj_dict_store(sp[0], sp[2], sp[1]);
break;
case MP_BC_MAP_ADD:
DECODE_UINT;
// I think it's guaranteed by the compiler that sp[-unum - 1] is a map
mp_store_map(sp[-unum - 1], sp[0], sp[-1]);
mp_obj_dict_store(sp[-unum - 1], sp[0], sp[-1]);
sp -= 2;
break;
case MP_BC_BUILD_SET:
DECODE_UINT;
sp -= unum - 1;
SET_TOP(mp_build_set(unum, sp));
SET_TOP(mp_obj_new_set(unum, sp));
break;
case MP_BC_SET_ADD:
DECODE_UINT;
// I think it's guaranteed by the compiler that sp[-unum] is a set
mp_store_set(sp[-unum], sp[0]);
mp_obj_set_store(sp[-unum], sp[0]);
sp--;
break;

View File

@ -268,7 +268,7 @@ mp_obj_t pyb_accel_read(void) {
data[2] = mp_obj_new_int(accel_buf[2] + accel_buf[5] + accel_buf[8] + accel_buf[11]);
data[3] = mp_obj_new_int(jolt_info);
return mp_build_tuple(4, data);
return mp_obj_new_tuple(4, data);
}
MP_DEFINE_CONST_FUN_OBJ_0(pyb_accel_read_obj, pyb_accel_read);
@ -283,7 +283,7 @@ mp_obj_t pyb_accel_read_all(void) {
}
data[10] = mp_obj_new_int(accel_read_nack());
return mp_build_tuple(11, data);
return mp_obj_new_tuple(11, data);
}
MP_DEFINE_CONST_FUN_OBJ_0(pyb_accel_read_all_obj, pyb_accel_read_all);

View File

@ -134,7 +134,7 @@ STATIC mp_obj_t pyb_accel_filtered_xyz(mp_obj_t self_in) {
tuple[i] = mp_obj_new_int(val);
}
return mp_build_tuple(3, tuple);
return mp_obj_new_tuple(3, tuple);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_accel_filtered_xyz_obj, pyb_accel_filtered_xyz);

View File

@ -377,7 +377,7 @@ int main(int argc, char **argv) {
free(basedir);
}
for (int i = a; i < argc; i++) {
mp_list_append(py_argv, MP_OBJ_NEW_QSTR(qstr_from_str(argv[i])));
mp_obj_list_append(py_argv, MP_OBJ_NEW_QSTR(qstr_from_str(argv[i])));
}
do_file(argv[a]);
executed = true;

View File

@ -313,7 +313,7 @@ static mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) {
}
assert(addr);
mp_obj_t list = mp_build_list(0, NULL);
mp_obj_t list = mp_obj_new_list(0, NULL);
for (; addr; addr = addr->ai_next) {
mp_obj_tuple_t *t = mp_obj_new_tuple(5, NULL);
t->items[0] = MP_OBJ_NEW_SMALL_INT((machine_int_t)addr->ai_family);
@ -327,7 +327,7 @@ static mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) {
t->items[3] = mp_const_none;
}
t->items[4] = mp_obj_new_bytearray(addr->ai_addrlen, addr->ai_addr);
mp_list_append(list, t);
mp_obj_list_append(list, t);
}
return list;
}

View File

@ -217,7 +217,7 @@ int main(int argc, char **argv) {
}
} else {
for (int i = a; i < argc; i++) {
mp_list_append(py_argv, MP_OBJ_NEW_QSTR(qstr_from_str(argv[i])));
mp_obj_list_append(py_argv, MP_OBJ_NEW_QSTR(qstr_from_str(argv[i])));
}
do_file(argv[a]);
break;