summaryrefslogtreecommitdiff
path: root/py/objgenerator.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2019-09-10 13:47:24 +1000
committerDamien George <damien.p.george@gmail.com>2019-10-05 13:42:39 +1000
commit306ec5369a1b82c2c9389cea1dfcb5bf1861c71a (patch)
tree3239d0ec9776b45ced9555318e1c4bd92cf06c92 /py/objgenerator.c
parent3504edc8048f8ab038ace50b0bbdf65b30619cc5 (diff)
py/emitnative: Add support for archs that cannot read executable data.
In which case place the native function prelude in a bytes object, linked from the const_table of that function. An architecture should define N_PRELUDE_AS_BYTES_OBJ to 1 before including py/emitnative.c to emit correct machine code, then enable MICROPY_EMIT_NATIVE_PRELUDE_AS_BYTES_OBJ so the runtime can correctly handle the prelude being in a bytes object.
Diffstat (limited to 'py/objgenerator.c')
-rw-r--r--py/objgenerator.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/py/objgenerator.c b/py/objgenerator.c
index 359dade88..2cfdb12f6 100644
--- a/py/objgenerator.c
+++ b/py/objgenerator.c
@@ -30,6 +30,7 @@
#include "py/runtime.h"
#include "py/bc.h"
+#include "py/objstr.h"
#include "py/objgenerator.h"
#include "py/objfun.h"
#include "py/stackctrl.h"
@@ -88,6 +89,11 @@ STATIC mp_obj_t native_gen_wrap_call(mp_obj_t self_in, size_t n_args, size_t n_k
// Determine start of prelude, and extract n_state from it
uintptr_t prelude_offset = ((uintptr_t*)self_fun->bytecode)[0];
+ #if MICROPY_EMIT_NATIVE_PRELUDE_AS_BYTES_OBJ
+ // Prelude is in bytes object in const_table, at index prelude_offset
+ mp_obj_str_t *prelude_bytes = MP_OBJ_TO_PTR(self_fun->const_table[prelude_offset]);
+ prelude_offset = (const byte*)prelude_bytes->data - self_fun->bytecode;
+ #endif
const uint8_t *ip = self_fun->bytecode + prelude_offset;
size_t n_state, n_exc_stack_unused, scope_flags, n_pos_args, n_kwonly_args, n_def_args;
MP_BC_PRELUDE_SIG_DECODE_INTO(ip, n_state, n_exc_stack_unused, scope_flags, n_pos_args, n_kwonly_args, n_def_args);