summaryrefslogtreecommitdiff
path: root/py/compile.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-04-13 11:04:33 +0100
committerDamien George <damien.p.george@gmail.com>2014-04-13 11:04:33 +0100
commitdf8127a17eeb3057e820180e318ec3d915111b6a (patch)
tree55fa023ce2de910492c9c713bfa15f6e6df475c2 /py/compile.c
parent68e7c5146ce24a593889df67d50d8f9c0cfa528e (diff)
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/compile.c')
-rw-r--r--py/compile.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/py/compile.c b/py/compile.c
index f397501f1..7a3d810f9 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -10,11 +10,11 @@
#include "qstr.h"
#include "lexer.h"
#include "parse.h"
-#include "scope.h"
#include "runtime0.h"
-#include "emit.h"
-#include "emitglue.h"
#include "obj.h"
+#include "emitglue.h"
+#include "scope.h"
+#include "emit.h"
#include "compile.h"
#include "runtime.h"
#include "builtin.h"
@@ -283,7 +283,7 @@ STATIC void compile_decrease_except_level(compiler_t *comp) {
}
STATIC scope_t *scope_new_and_link(compiler_t *comp, scope_kind_t kind, mp_parse_node_t pn, uint emit_options) {
- scope_t *scope = scope_new(kind, pn, comp->source_file, mp_emit_glue_get_unique_code_id(), emit_options);
+ scope_t *scope = scope_new(kind, pn, comp->source_file, emit_options);
scope->parent = comp->scope_cur;
scope->next = NULL;
if (comp->scope_head == NULL) {
@@ -3454,7 +3454,7 @@ mp_obj_t mp_compile(mp_parse_node_t pn, qstr source_file, uint emit_opt, bool is
#endif // !MICROPY_EMIT_CPYTHON
// free the scopes
- uint unique_code_id = module_scope->unique_code_id;
+ mp_raw_code_t *outer_raw_code = module_scope->raw_code;
for (scope_t *s = module_scope; s;) {
scope_t *next = s->next;
scope_free(s);
@@ -3471,12 +3471,11 @@ mp_obj_t mp_compile(mp_parse_node_t pn, qstr source_file, uint emit_opt, bool is
} else {
#if MICROPY_EMIT_CPYTHON
// can't create code, so just return true
- (void)unique_code_id; // to suppress warning that unique_code_id is unused
+ (void)outer_raw_code; // to suppress warning that outer_raw_code is unused
return mp_const_true;
#else
// return function that executes the outer module
- // we can free the unique_code slot because no-one has reference to this unique_code_id anymore
- return mp_make_function_from_id_and_free(unique_code_id, MP_OBJ_NULL, MP_OBJ_NULL);
+ return mp_make_function_from_raw_code(outer_raw_code, MP_OBJ_NULL, MP_OBJ_NULL);
#endif
}
}