From d8c834c95d506db979ec871417de90b7951edc30 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 2 Nov 2015 21:55:42 +0000 Subject: py: Add MICROPY_PERSISTENT_CODE_LOAD/SAVE to load/save bytecode. MICROPY_PERSISTENT_CODE must be enabled, and then enabling MICROPY_PERSISTENT_CODE_LOAD/SAVE (either or both) will allow loading and/or saving of code (at the moment just bytecode) from/to a .mpy file. --- py/emitglue.h | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'py/emitglue.h') diff --git a/py/emitglue.h b/py/emitglue.h index 9bb2ba2d7..6da0f6cb4 100644 --- a/py/emitglue.h +++ b/py/emitglue.h @@ -43,10 +43,31 @@ typedef struct _mp_raw_code_t mp_raw_code_t; mp_raw_code_t *mp_emit_glue_new_raw_code(void); -void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, const byte *code, mp_uint_t len, const mp_uint_t *const_table, mp_uint_t scope_flags); +void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, const byte *code, mp_uint_t len, + const mp_uint_t *const_table, + #if MICROPY_PERSISTENT_CODE_SAVE + uint16_t n_obj, uint16_t n_raw_code, + #endif + mp_uint_t scope_flags); void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void *fun_data, mp_uint_t fun_len, const mp_uint_t *const_table, mp_uint_t n_pos_args, mp_uint_t scope_flags, mp_uint_t type_sig); mp_obj_t mp_make_function_from_raw_code(mp_raw_code_t *rc, mp_obj_t def_args, mp_obj_t def_kw_args); mp_obj_t mp_make_closure_from_raw_code(mp_raw_code_t *rc, mp_uint_t n_closed_over, const mp_obj_t *args); +#if MICROPY_PERSISTENT_CODE_LOAD +typedef struct _mp_reader_t { + void *data; + mp_uint_t (*read_byte)(void *data); + void (*close)(void *data); +} mp_reader_t; + +mp_raw_code_t *mp_raw_code_load(mp_reader_t *reader); +mp_raw_code_t *mp_raw_code_load_file(const char *filename); +#endif + +#if MICROPY_PERSISTENT_CODE_SAVE +void mp_raw_code_save(mp_raw_code_t *rc, mp_print_t *print); +void mp_raw_code_save_file(mp_raw_code_t *rc, const char *filename); +#endif + #endif // __MICROPY_INCLUDED_PY_EMITGLUE_H__ -- cgit v1.2.3