summaryrefslogtreecommitdiffstatshomepage
path: root/shared/runtime
diff options
context:
space:
mode:
authoriabdalkader <i.abdalkader@gmail.com>2025-02-27 09:03:17 +0100
committerDamien George <damien@micropython.org>2025-03-14 17:10:35 +1100
commitf187c77da8b0ff51927b62cd1f4efd78c03bdb7f (patch)
treeb9a5a8f4eb1fcb76cfd5c797264ff17749aecec6 /shared/runtime
parentdbda43b9e14ac1aa8a293840d3242d3baa489b18 (diff)
downloadmicropython-f187c77da8b0ff51927b62cd1f4efd78c03bdb7f.tar.gz
micropython-f187c77da8b0ff51927b62cd1f4efd78c03bdb7f.zip
shared/runtime/pyexec: Add helper function to execute a vstr.
Add `pyexec_vstr()` to execute Python code from a vstr source. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Diffstat (limited to 'shared/runtime')
-rw-r--r--shared/runtime/pyexec.c5
-rw-r--r--shared/runtime/pyexec.h1
2 files changed, 6 insertions, 0 deletions
diff --git a/shared/runtime/pyexec.c b/shared/runtime/pyexec.c
index 9dc4446ed4..c828c75817 100644
--- a/shared/runtime/pyexec.c
+++ b/shared/runtime/pyexec.c
@@ -720,6 +720,11 @@ int pyexec_frozen_module(const char *name, bool allow_keyboard_interrupt) {
}
#endif
+int pyexec_vstr(vstr_t *str, bool allow_keyboard_interrupt) {
+ mp_uint_t exec_flags = allow_keyboard_interrupt ? 0 : EXEC_FLAG_NO_INTERRUPT;
+ return parse_compile_execute(str, MP_PARSE_FILE_INPUT, exec_flags | EXEC_FLAG_SOURCE_IS_VSTR);
+}
+
#if MICROPY_REPL_INFO
mp_obj_t pyb_set_repl_info(mp_obj_t o_value) {
repl_display_debugging_info = mp_obj_get_int(o_value);
diff --git a/shared/runtime/pyexec.h b/shared/runtime/pyexec.h
index 5779d3e09a..95f4481626 100644
--- a/shared/runtime/pyexec.h
+++ b/shared/runtime/pyexec.h
@@ -42,6 +42,7 @@ int pyexec_friendly_repl(void);
int pyexec_file(const char *filename);
int pyexec_file_if_exists(const char *filename);
int pyexec_frozen_module(const char *name, bool allow_keyboard_interrupt);
+int pyexec_vstr(vstr_t *str, bool allow_keyboard_interrupt);
void pyexec_event_repl_init(void);
int pyexec_event_repl_process_char(int c);
extern uint8_t pyexec_repl_active;