diff options
author | John R. Lenton <jlenton@gmail.com> | 2014-01-07 18:01:08 +0000 |
---|---|---|
committer | John R. Lenton <jlenton@gmail.com> | 2014-01-07 18:01:08 +0000 |
commit | 270112f7312f724e46ae34649dfce3ec43b697e0 (patch) | |
tree | d7438ae877350aede062d8ac7e62e52ab35cb018 /py/runtime.c | |
parent | c06763a0207dde7f2060f7b1670a0b99298a01f8 (diff) | |
parent | fd04bb3bacf5dbc4d79c04a49520e3e81abb7352 (diff) | |
download | micropython-270112f7312f724e46ae34649dfce3ec43b697e0.tar.gz micropython-270112f7312f724e46ae34649dfce3ec43b697e0.zip |
Merge remote-tracking branch 'upstream/master' into listsort. Lots of conflict fun.
Conflicts:
py/obj.h
py/objbool.c
py/objboundmeth.c
py/objcell.c
py/objclass.c
py/objclosure.c
py/objcomplex.c
py/objdict.c
py/objexcept.c
py/objfun.c
py/objgenerator.c
py/objinstance.c
py/objmodule.c
py/objrange.c
py/objset.c
py/objslice.c
Diffstat (limited to 'py/runtime.c')
-rw-r--r-- | py/runtime.c | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/py/runtime.c b/py/runtime.c index d1625f6e3d..83f26952eb 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -61,7 +61,8 @@ typedef struct _mp_code_t { } mp_code_t; static int next_unique_code_id; -static mp_code_t *unique_codes; +static machine_uint_t unique_codes_alloc = 0; +static mp_code_t *unique_codes = NULL; #ifdef WRITE_CODE FILE *fp_write_code = NULL; @@ -126,6 +127,7 @@ void rt_init(void) { mp_qstr_map_lookup(&map_builtins, MP_QSTR_sum, true)->value = rt_make_function_var(1, mp_builtin_sum); next_unique_code_id = 1; // 0 indicates "no code" + unique_codes_alloc = 0; unique_codes = NULL; #ifdef WRITE_CODE @@ -134,6 +136,7 @@ void rt_init(void) { } void rt_deinit(void) { + m_del(mp_code_t, unique_codes, unique_codes_alloc); #ifdef WRITE_CODE if (fp_write_code != NULL) { fclose(fp_write_code); @@ -146,18 +149,20 @@ int rt_get_unique_code_id(void) { } static void alloc_unique_codes(void) { - if (unique_codes == NULL) { - unique_codes = m_new(mp_code_t, next_unique_code_id + 10); // XXX hack until we fix the REPL allocation problem - for (int i = 0; i < next_unique_code_id; i++) { + if (next_unique_code_id > unique_codes_alloc) { + // increase size of unique_codes table + unique_codes = m_renew(mp_code_t, unique_codes, unique_codes_alloc, next_unique_code_id); + for (int i = unique_codes_alloc; i < next_unique_code_id; i++) { unique_codes[i].kind = MP_CODE_NONE; } + unique_codes_alloc = next_unique_code_id; } } void rt_assign_byte_code(int unique_code_id, byte *code, uint len, int n_args, int n_locals, int n_stack, bool is_generator) { alloc_unique_codes(); - assert(1 <= unique_code_id && unique_code_id < next_unique_code_id); + assert(1 <= unique_code_id && unique_code_id < next_unique_code_id && unique_codes[unique_code_id].kind == MP_CODE_NONE); unique_codes[unique_code_id].kind = MP_CODE_BYTE; unique_codes[unique_code_id].n_args = n_args; unique_codes[unique_code_id].n_locals = n_locals; @@ -192,7 +197,7 @@ void rt_assign_byte_code(int unique_code_id, byte *code, uint len, int n_args, i void rt_assign_native_code(int unique_code_id, void *fun, uint len, int n_args) { alloc_unique_codes(); - assert(1 <= unique_code_id && unique_code_id < next_unique_code_id); + assert(1 <= unique_code_id && unique_code_id < next_unique_code_id && unique_codes[unique_code_id].kind == MP_CODE_NONE); unique_codes[unique_code_id].kind = MP_CODE_NATIVE; unique_codes[unique_code_id].n_args = n_args; unique_codes[unique_code_id].n_locals = 0; @@ -225,7 +230,7 @@ void rt_assign_native_code(int unique_code_id, void *fun, uint len, int n_args) void rt_assign_inline_asm_code(int unique_code_id, void *fun, uint len, int n_args) { alloc_unique_codes(); - assert(1 <= unique_code_id && unique_code_id < next_unique_code_id); + assert(1 <= unique_code_id && unique_code_id < next_unique_code_id && unique_codes[unique_code_id].kind == MP_CODE_NONE); unique_codes[unique_code_id].kind = MP_CODE_INLINE_ASM; unique_codes[unique_code_id].n_args = n_args; unique_codes[unique_code_id].n_locals = 0; @@ -785,10 +790,12 @@ mp_obj_t rt_load_attr(mp_obj_t base, qstr attr) { } else if (MP_OBJ_IS_OBJ(base)) { // generic method lookup mp_obj_base_t *o = base; - const mp_method_t *meth = &o->type->methods[0]; - for (; meth->name != NULL; meth++) { - if (strcmp(meth->name, qstr_str(attr)) == 0) { - return mp_obj_new_bound_meth(base, (mp_obj_t)meth->fun); + const mp_method_t *meth = o->type->methods; + if (meth != NULL) { + for (; meth->name != NULL; meth++) { + if (strcmp(meth->name, qstr_str(attr)) == 0) { + return mp_obj_new_bound_meth(base, (mp_obj_t)meth->fun); + } } } } @@ -809,12 +816,14 @@ void rt_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest) { } else if (MP_OBJ_IS_OBJ(base)) { // generic method lookup mp_obj_base_t *o = base; - const mp_method_t *meth = &o->type->methods[0]; - for (; meth->name != NULL; meth++) { - if (strcmp(meth->name, qstr_str(attr)) == 0) { - dest[1] = (mp_obj_t)meth->fun; - dest[0] = base; - return; + const mp_method_t *meth = o->type->methods; + if (meth != NULL) { + for (; meth->name != NULL; meth++) { + if (strcmp(meth->name, qstr_str(attr)) == 0) { + dest[1] = (mp_obj_t)meth->fun; + dest[0] = base; + return; + } } } } |