kopia lustrzana https://github.com/micropython/micropython
Merge eed0df3260
into 7b050b366b
commit
692e2548a3
|
@ -8,7 +8,7 @@ Command line options
|
|||
|
||||
Usage::
|
||||
|
||||
micropython [ -h ] [ -i ] [ -O<level> ] [ -v ] [ -X <option> ] [ -c <command> | -m <module> | <script> ] [ <args> ]
|
||||
micropython [ -h ] [ -i ] [ -e ] [ -O<level> ] [ -v ] [ -X <option> ] [ -c <command> | -m <module> | <script> ] [ <args> ]
|
||||
|
||||
|
||||
Invocation options:
|
||||
|
@ -17,6 +17,20 @@ Invocation options:
|
|||
|
||||
Runs the code in ``<command>``. The code can be one or more Python statements.
|
||||
|
||||
.. option:: -e
|
||||
|
||||
Runs MicroPython in "embedded mode":
|
||||
|
||||
* ``boot.py`` and ``main.py`` are executed; boot.py unconditionally,
|
||||
``main.py`` only if no script argument is used.
|
||||
|
||||
* Instead of the ``readline`` library, MicroPython uses the same REPL as
|
||||
on embedded systems.
|
||||
|
||||
This mode is mainly useful for running MicroPython as a subprocess, e.g.
|
||||
for testing. For interactive use, a ``stty raw; micropython -e …; stty
|
||||
-raw`` wrapper is required.
|
||||
|
||||
.. option:: -m <module>
|
||||
|
||||
Runs the module ``<module>``. The module must be in ``sys.path``.
|
||||
|
|
|
@ -216,6 +216,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,9 @@ 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"
|
||||
#if MICROPY_USE_READLINE == 1
|
||||
"-e : embedded mode: run 'boot.py', enable raw input\n"
|
||||
#endif
|
||||
"-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 +626,9 @@ MP_NOINLINE int main_(int argc, char **argv) {
|
|||
const int NOTHING_EXECUTED = -2;
|
||||
int ret = NOTHING_EXECUTED;
|
||||
bool inspect = false;
|
||||
#if MICROPY_USE_READLINE == 1
|
||||
bool embed = false;
|
||||
#endif
|
||||
for (int a = 1; a < argc; a++) {
|
||||
if (argv[a][0] == '-') {
|
||||
if (strcmp(argv[a], "-i") == 0) {
|
||||
|
@ -634,6 +641,11 @@ 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;
|
||||
#if MICROPY_USE_READLINE == 1
|
||||
} else if (strcmp(argv[a], "-e") == 0) {
|
||||
embed = true;
|
||||
pyexec_file_if_exists("boot.py");
|
||||
#endif
|
||||
} else if (strcmp(argv[a], "-m") == 0) {
|
||||
if (a + 1 >= argc) {
|
||||
return invalid_args();
|
||||
|
@ -729,6 +741,29 @@ MP_NOINLINE int main_(int argc, char **argv) {
|
|||
inspect = true;
|
||||
}
|
||||
if (ret == NOTHING_EXECUTED || inspect) {
|
||||
#if MICROPY_USE_READLINE == 1
|
||||
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
|
||||
#endif
|
||||
if (isatty(0) || inspect) {
|
||||
prompt_read_history();
|
||||
ret = do_repl();
|
||||
|
@ -738,6 +773,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