summaryrefslogtreecommitdiffstatshomepage
path: root/py/runtime.c
diff options
context:
space:
mode:
Diffstat (limited to 'py/runtime.c')
-rw-r--r--py/runtime.c70
1 files changed, 22 insertions, 48 deletions
diff --git a/py/runtime.c b/py/runtime.c
index f827fd831e..daa555e4a2 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -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
@@ -915,6 +877,7 @@ mp_obj_t mp_iternext(mp_obj_t o_in) {
// TODO: Unclear what to do with StopIterarion exception here.
mp_vm_return_kind_t mp_resume(mp_obj_t self_in, mp_obj_t send_value, mp_obj_t throw_value, mp_obj_t *ret_val) {
+ assert((send_value != MP_OBJ_NULL) ^ (throw_value != MP_OBJ_NULL));
mp_obj_type_t *type = mp_obj_get_type(self_in);
if (type == &mp_type_gen_instance) {
@@ -960,9 +923,20 @@ mp_vm_return_kind_t mp_resume(mp_obj_t self_in, mp_obj_t send_value, mp_obj_t th
return MP_VM_RETURN_NORMAL;
}
}
- mp_load_method(self_in, MP_QSTR_throw, dest);
- *ret_val = mp_call_method_n_kw(1, 0, &throw_value);
- return MP_VM_RETURN_YIELD;
+ mp_load_method_maybe(self_in, MP_QSTR_throw, dest);
+ if (dest[0] != MP_OBJ_NULL) {
+ *ret_val = mp_call_method_n_kw(1, 0, &throw_value);
+ // If .throw() method returned, we assume it's value to yield
+ // - any exception would be thrown with nlr_jump().
+ return MP_VM_RETURN_YIELD;
+ }
+ // If there's nowhere to throw exception into, then we assume that object
+ // is just incapable to handle it, so any exception thrown into it
+ // will be propagated up. This behavior is approved by test_pep380.py
+ // test_delegation_of_close_to_non_generator(),
+ // test_delegating_throw_to_non_generator()
+ *ret_val = throw_value;
+ return MP_VM_RETURN_EXCEPTION;
}
assert(0);
@@ -1057,13 +1031,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,