kopia lustrzana https://github.com/micropython/micropython
ports/unix: Add embedded mode.
Embedded mode means that * boot.py is executed, if present * the same REPL as on embedded systems is used that is, ^A switches to raw mode. This change does not yet(?) * modify the terminal mode Workaround: wrap with `stty raw; micropython -e …; stty -raw` * support a restart via `machine.reset()` Signed-off-by: Matthias Urlichs <matthias@urlichs.de>pull/12807/head
rodzic
5b4a2baff6
commit
74003eda2f
|
@ -217,6 +217,7 @@ SRC_C += \
|
|||
SHARED_SRC_C += $(addprefix shared/,\
|
||||
runtime/gchelper_generic.c \
|
||||
timeutils/timeutils.c \
|
||||
runtime/pyexec.c \
|
||||
$(SHARED_SRC_C_EXTRA) \
|
||||
)
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@
|
|||
#include "extmod/vfs_posix.h"
|
||||
#include "genhdr/mpversion.h"
|
||||
#include "input.h"
|
||||
#include "shared/runtime/pyexec.h"
|
||||
|
||||
// Command line options, with their defaults
|
||||
STATIC bool compile_only = false;
|
||||
|
@ -319,6 +320,7 @@ STATIC void print_help(char **argv) {
|
|||
"usage: %s [<opts>] [-X <implopt>] [-c <command> | -m <module> | <filename>]\n"
|
||||
"Options:\n"
|
||||
"-h : print this help message\n"
|
||||
"-e : embedded mode: run 'boot.py', enable raw input\n"
|
||||
"-i : enable inspection via REPL after running command/module/file\n"
|
||||
#if MICROPY_DEBUG_PRINTERS
|
||||
"-v : verbose (trace various operations); can be multiple\n"
|
||||
|
@ -622,6 +624,7 @@ MP_NOINLINE int main_(int argc, char **argv) {
|
|||
const int NOTHING_EXECUTED = -2;
|
||||
int ret = NOTHING_EXECUTED;
|
||||
bool inspect = false;
|
||||
bool embed = false;
|
||||
for (int a = 1; a < argc; a++) {
|
||||
if (argv[a][0] == '-') {
|
||||
if (strcmp(argv[a], "-i") == 0) {
|
||||
|
@ -634,6 +637,9 @@ MP_NOINLINE int main_(int argc, char **argv) {
|
|||
set_sys_argv(argv, argc, a + 2); // Then what comes after the command
|
||||
ret = do_str(argv[a + 1]);
|
||||
break;
|
||||
} else if (strcmp(argv[a], "-e") == 0) {
|
||||
embed = true;
|
||||
pyexec_file_if_exists("boot.py");
|
||||
} else if (strcmp(argv[a], "-m") == 0) {
|
||||
if (a + 1 >= argc) {
|
||||
return invalid_args();
|
||||
|
@ -729,7 +735,27 @@ MP_NOINLINE int main_(int argc, char **argv) {
|
|||
inspect = true;
|
||||
}
|
||||
if (ret == NOTHING_EXECUTED || inspect) {
|
||||
if (isatty(0) || inspect) {
|
||||
if (embed) {
|
||||
// Run main.py if not told otherwise
|
||||
if (ret == NOTHING_EXECUTED) {
|
||||
ret = pyexec_file_if_exists("main.py");
|
||||
if (ret & PYEXEC_FORCED_EXIT) {
|
||||
goto soft_reset_exit;
|
||||
}
|
||||
}
|
||||
ret = 0;
|
||||
for (;;) {
|
||||
if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) {
|
||||
if (pyexec_raw_repl() != 0) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (pyexec_friendly_repl() != 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (isatty(0) || inspect) {
|
||||
prompt_read_history();
|
||||
ret = do_repl();
|
||||
prompt_write_history();
|
||||
|
@ -738,6 +764,8 @@ MP_NOINLINE int main_(int argc, char **argv) {
|
|||
}
|
||||
}
|
||||
|
||||
soft_reset_exit:
|
||||
|
||||
#if MICROPY_PY_SYS_SETTRACE
|
||||
MP_STATE_THREAD(prof_trace_callback) = MP_OBJ_NULL;
|
||||
#endif
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "shared/readline/readline.h"
|
||||
#include "shared/runtime/pyexec.h"
|
||||
#include "genhdr/mpversion.h"
|
||||
#include "extmod/modplatform.h"
|
||||
|
||||
pyexec_mode_kind_t pyexec_mode_kind = PYEXEC_MODE_FRIENDLY_REPL;
|
||||
int pyexec_system_exit = 0;
|
||||
|
|
Ładowanie…
Reference in New Issue