diff options
author | mux <freelancer.c@gmail.com> | 2014-04-05 15:49:03 +0200 |
---|---|---|
committer | mux <freelancer.c@gmail.com> | 2014-04-05 15:49:03 +0200 |
commit | cc849f70f478f7442d19ed2f4c0b4297035b2393 (patch) | |
tree | 4b51f36aee08b764ef12e558c2a91246409cb41c /py | |
parent | 4f7e9f5c445b5c0b262d9dfb8fceda4830f4844b (diff) | |
download | micropython-cc849f70f478f7442d19ed2f4c0b4297035b2393.tar.gz micropython-cc849f70f478f7442d19ed2f4c0b4297035b2393.zip |
Move del to locals
Diffstat (limited to 'py')
-rw-r--r-- | py/gc.c | 22 | ||||
-rw-r--r-- | py/obj.h | 2 | ||||
-rw-r--r-- | py/qstrdefs.h | 1 |
3 files changed, 14 insertions, 11 deletions
@@ -8,6 +8,7 @@ #include "misc.h" #include "qstr.h" #include "obj.h" +#include "runtime.h" #if MICROPY_ENABLE_GC @@ -175,12 +176,14 @@ STATIC void gc_sweep(void) { switch (ATB_GET_KIND(block)) { case AT_HEAD: if (ATB_IS_MPOBJ(block)) { - ATB_CLR_MPOBJ(block); // clear mpobj flag - mp_obj_t *self = (mp_obj_t*)PTR_FROM_BLOCK(block); - mp_obj_type_t *type= mp_obj_get_type(self); - if (type->del != NULL) { - type->del(self); + mp_obj_t dest[2]; + mp_load_method((mp_obj_t*)PTR_FROM_BLOCK(block), MP_QSTR___del__, dest); + // load_method returned a method + if (dest[1] != MP_OBJ_NULL) { + mp_call_method_n_kw(0, 0, dest); } + // clear mpobj flag + ATB_CLR_MPOBJ(block); } free_tail = 1; // fall through to free the head @@ -305,16 +308,17 @@ found: // mark first block as used head ATB_FREE_TO_HEAD(start_block); - if (is_mpobj) { - ATB_SET_MPOBJ(start_block); - } - // mark rest of blocks as used tail // TODO for a run of many blocks can make this more efficient for (machine_uint_t bl = start_block + 1; bl <= end_block; bl++) { ATB_FREE_TO_TAIL(bl); } + if (is_mpobj) { + // set mp_obj flag only if it has del + ATB_SET_MPOBJ(start_block); + } + // return pointer to first block return (void*)(gc_pool_start + start_block * WORDS_PER_BLOCK); } @@ -154,7 +154,6 @@ typedef mp_obj_t (*mp_binary_op_fun_t)(int op, mp_obj_t, mp_obj_t); typedef void (*mp_load_attr_fun_t)(mp_obj_t self_in, qstr attr, mp_obj_t *dest); // for fail, do nothing; for attr, dest[0] = value; for method, dest[0] = method, dest[1] = self typedef bool (*mp_store_attr_fun_t)(mp_obj_t self_in, qstr attr, mp_obj_t value); // return true if store succeeded typedef bool (*mp_store_item_fun_t)(mp_obj_t self_in, mp_obj_t index, mp_obj_t value); // return true if store succeeded -typedef void (*mp_del_fun_t)(mp_obj_t self_in); typedef struct _mp_method_t { qstr name; @@ -237,7 +236,6 @@ struct _mp_obj_type_t { unpack seq list tuple */ - mp_del_fun_t del; }; typedef struct _mp_obj_type_t mp_obj_type_t; diff --git a/py/qstrdefs.h b/py/qstrdefs.h index 368b0fc8e1..591c96a948 100644 --- a/py/qstrdefs.h +++ b/py/qstrdefs.h @@ -27,6 +27,7 @@ Q(__sub__) Q(__repr__) Q(__str__) Q(__getattr__) +Q(__del__) Q(micropython) Q(byte_code) |