mirror of
https://github.com/micropython/micropython.git
synced 2026-01-06 20:20:14 +01:00
py/emitnative: Place const objs for native code in separate const table.
This commit changes native code to handle constant objects like bytecode: instead of storing the pointers inside the native code they are now stored in a separate constant table (such pointers include objects like bignum, bytes, and raw code for nested functions). This removes the need for the GC to scan native code for root pointers, and takes a step towards making native code independent of the runtime (eg so it can be compiled offline by mpy-cross). Note that the changes to the struct scope_t did not increase its size: on a 32-bit architecture it is still 48 bytes, and on a 64-bit architecture it decreased from 80 to 72 bytes.
This commit is contained in:
11
py/compile.c
11
py/compile.c
@@ -569,7 +569,7 @@ STATIC void close_over_variables_etc(compiler_t *comp, scope_t *this_scope, int
|
||||
|
||||
#if MICROPY_EMIT_NATIVE
|
||||
// When creating a function/closure it will take a reference to the current globals
|
||||
comp->scope_cur->scope_flags |= MP_SCOPE_FLAG_REFGLOBALS;
|
||||
comp->scope_cur->scope_flags |= MP_SCOPE_FLAG_REFGLOBALS | MP_SCOPE_FLAG_HASCONSTS;
|
||||
#endif
|
||||
|
||||
// make closed over variables, if any
|
||||
@@ -2665,6 +2665,9 @@ STATIC mp_obj_t get_const_object(mp_parse_node_struct_t *pns) {
|
||||
}
|
||||
|
||||
STATIC void compile_const_object(compiler_t *comp, mp_parse_node_struct_t *pns) {
|
||||
#if MICROPY_EMIT_NATIVE
|
||||
comp->scope_cur->scope_flags |= MP_SCOPE_FLAG_HASCONSTS;
|
||||
#endif
|
||||
EMIT_ARG(load_const_obj, get_const_object(pns));
|
||||
}
|
||||
|
||||
@@ -2699,6 +2702,9 @@ STATIC void compile_node(compiler_t *comp, mp_parse_node_t pn) {
|
||||
} else {
|
||||
EMIT_ARG(load_const_obj, mp_obj_new_int_from_ll(arg));
|
||||
}
|
||||
#if MICROPY_EMIT_NATIVE
|
||||
comp->scope_cur->scope_flags |= MP_SCOPE_FLAG_HASCONSTS;
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
EMIT_ARG(load_const_small_int, arg);
|
||||
@@ -2717,6 +2723,9 @@ STATIC void compile_node(compiler_t *comp, mp_parse_node_t pn) {
|
||||
const byte *data = qstr_data(arg, &len);
|
||||
EMIT_ARG(load_const_obj, mp_obj_new_bytes(data, len));
|
||||
}
|
||||
#if MICROPY_EMIT_NATIVE
|
||||
comp->scope_cur->scope_flags |= MP_SCOPE_FLAG_HASCONSTS;
|
||||
#endif
|
||||
break;
|
||||
case MP_PARSE_NODE_TOKEN: default:
|
||||
if (arg == MP_TOKEN_NEWLINE) {
|
||||
|
||||
Reference in New Issue
Block a user