diff options
author | Damien George <damien.p.george@gmail.com> | 2014-04-13 11:04:33 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-04-13 11:04:33 +0100 |
commit | df8127a17eeb3057e820180e318ec3d915111b6a (patch) | |
tree | 55fa023ce2de910492c9c713bfa15f6e6df475c2 /py/scope.c | |
parent | 68e7c5146ce24a593889df67d50d8f9c0cfa528e (diff) | |
download | micropython-df8127a17eeb3057e820180e318ec3d915111b6a.tar.gz micropython-df8127a17eeb3057e820180e318ec3d915111b6a.zip |
py: Remove unique_codes from emitglue.c. Replace with pointers.
Attempt to address issue #386. unique_code_id's have been removed and
replaced with a pointer to the "raw code" information. This pointer is
stored in the actual byte code (aligned, so the GC can trace it), so
that raw code (ie byte code, native code and inline assembler) is kept
only for as long as it is needed. In memory it's now like a tree: the
outer module's byte code points directly to its children's raw code. So
when the outer code gets freed, if there are no remaining functions that
need the raw code, then the children's code gets freed as well.
This is pretty much like CPython does it, except that CPython stores
indexes in the byte code rather than machine pointers. These indices
index the per-function constant table in order to find the relevant
code.
Diffstat (limited to 'py/scope.c')
-rw-r--r-- | py/scope.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/py/scope.c b/py/scope.c index 51701727e6..391ad5da87 100644 --- a/py/scope.c +++ b/py/scope.c @@ -6,10 +6,12 @@ #include "misc.h" #include "mpconfig.h" #include "qstr.h" +#include "obj.h" #include "parse.h" +#include "emitglue.h" #include "scope.h" -scope_t *scope_new(scope_kind_t kind, mp_parse_node_t pn, qstr source_file, uint unique_code_id, uint emit_options) { +scope_t *scope_new(scope_kind_t kind, mp_parse_node_t pn, qstr source_file, uint emit_options) { scope_t *scope = m_new0(scope_t, 1); scope->kind = kind; scope->pn = pn; @@ -41,7 +43,7 @@ scope_t *scope_new(scope_kind_t kind, mp_parse_node_t pn, qstr source_file, uint default: assert(0); } - scope->unique_code_id = unique_code_id; + scope->raw_code = mp_emit_glue_new_raw_code(); scope->emit_options = emit_options; scope->id_info_alloc = 8; scope->id_info = m_new(id_info_t, scope->id_info_alloc); |