mirror of
https://github.com/micropython/micropython.git
synced 2026-01-07 12:40:15 +01:00
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.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user