kopia lustrzana https://github.com/micropython/micropython
Merge 554ba06782
into 7b050b366b
commit
b28eeaeae0
|
@ -124,8 +124,10 @@ endif
|
||||||
|
|
||||||
ifeq ($(MICROPY_USE_READLINE),1)
|
ifeq ($(MICROPY_USE_READLINE),1)
|
||||||
INC += -I$(TOP)/shared/readline
|
INC += -I$(TOP)/shared/readline
|
||||||
|
INC += -I$(TOP)/shared/runtime
|
||||||
CFLAGS += -DMICROPY_USE_READLINE=1
|
CFLAGS += -DMICROPY_USE_READLINE=1
|
||||||
SHARED_SRC_C_EXTRA += readline/readline.c
|
SHARED_SRC_C_EXTRA += readline/readline.c
|
||||||
|
SHARED_SRC_C_EXTRA += runtime/pyexec.c
|
||||||
endif
|
endif
|
||||||
ifeq ($(MICROPY_PY_TERMIOS),1)
|
ifeq ($(MICROPY_PY_TERMIOS),1)
|
||||||
CFLAGS += -DMICROPY_PY_TERMIOS=1
|
CFLAGS += -DMICROPY_PY_TERMIOS=1
|
||||||
|
|
|
@ -53,6 +53,7 @@
|
||||||
#include "extmod/vfs_posix.h"
|
#include "extmod/vfs_posix.h"
|
||||||
#include "genhdr/mpversion.h"
|
#include "genhdr/mpversion.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
|
#include "shared/runtime/pyexec.h"
|
||||||
|
|
||||||
// Command line options, with their defaults
|
// Command line options, with their defaults
|
||||||
static bool compile_only = false;
|
static bool compile_only = false;
|
||||||
|
@ -193,92 +194,28 @@ static char *strjoin(const char *s1, int sep_char, const char *s2) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int do_repl(void) {
|
static int do_repl(void) {
|
||||||
|
int ret = 0;
|
||||||
|
#if MICROPY_USE_READLINE == 1
|
||||||
|
// use MicroPython supplied readline based repl
|
||||||
|
mp_hal_stdio_mode_raw();
|
||||||
|
for (;;) {
|
||||||
|
if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) {
|
||||||
|
if ((ret = pyexec_raw_repl()) != 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ((ret = pyexec_friendly_repl()) != 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mp_hal_stdio_mode_orig();
|
||||||
|
#else
|
||||||
|
// use simple readline
|
||||||
mp_hal_stdout_tx_str(MICROPY_BANNER_NAME_AND_VERSION);
|
mp_hal_stdout_tx_str(MICROPY_BANNER_NAME_AND_VERSION);
|
||||||
mp_hal_stdout_tx_str("; " MICROPY_BANNER_MACHINE);
|
mp_hal_stdout_tx_str("; " MICROPY_BANNER_MACHINE);
|
||||||
mp_hal_stdout_tx_str("\nUse Ctrl-D to exit, Ctrl-E for paste mode\n");
|
mp_hal_stdout_tx_str("\nUse Ctrl-D to exit, Ctrl-E for paste mode\n");
|
||||||
|
|
||||||
#if MICROPY_USE_READLINE == 1
|
|
||||||
|
|
||||||
// use MicroPython supplied readline
|
|
||||||
|
|
||||||
vstr_t line;
|
|
||||||
vstr_init(&line, 16);
|
|
||||||
for (;;) {
|
|
||||||
mp_hal_stdio_mode_raw();
|
|
||||||
|
|
||||||
input_restart:
|
|
||||||
vstr_reset(&line);
|
|
||||||
int ret = readline(&line, mp_repl_get_ps1());
|
|
||||||
mp_parse_input_kind_t parse_input_kind = MP_PARSE_SINGLE_INPUT;
|
|
||||||
|
|
||||||
if (ret == CHAR_CTRL_C) {
|
|
||||||
// cancel input
|
|
||||||
mp_hal_stdout_tx_str("\r\n");
|
|
||||||
goto input_restart;
|
|
||||||
} else if (ret == CHAR_CTRL_D) {
|
|
||||||
// EOF
|
|
||||||
printf("\n");
|
|
||||||
mp_hal_stdio_mode_orig();
|
|
||||||
vstr_clear(&line);
|
|
||||||
return 0;
|
|
||||||
} else if (ret == CHAR_CTRL_E) {
|
|
||||||
// paste mode
|
|
||||||
mp_hal_stdout_tx_str("\npaste mode; Ctrl-C to cancel, Ctrl-D to finish\n=== ");
|
|
||||||
vstr_reset(&line);
|
|
||||||
for (;;) {
|
|
||||||
char c = mp_hal_stdin_rx_chr();
|
|
||||||
if (c == CHAR_CTRL_C) {
|
|
||||||
// cancel everything
|
|
||||||
mp_hal_stdout_tx_str("\n");
|
|
||||||
goto input_restart;
|
|
||||||
} else if (c == CHAR_CTRL_D) {
|
|
||||||
// end of input
|
|
||||||
mp_hal_stdout_tx_str("\n");
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
// add char to buffer and echo
|
|
||||||
vstr_add_byte(&line, c);
|
|
||||||
if (c == '\r') {
|
|
||||||
mp_hal_stdout_tx_str("\n=== ");
|
|
||||||
} else {
|
|
||||||
mp_hal_stdout_tx_strn(&c, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
parse_input_kind = MP_PARSE_FILE_INPUT;
|
|
||||||
} else if (line.len == 0) {
|
|
||||||
if (ret != 0) {
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
goto input_restart;
|
|
||||||
} else {
|
|
||||||
// got a line with non-zero length, see if it needs continuing
|
|
||||||
while (mp_repl_continue_with_input(vstr_null_terminated_str(&line))) {
|
|
||||||
vstr_add_byte(&line, '\n');
|
|
||||||
ret = readline(&line, mp_repl_get_ps2());
|
|
||||||
if (ret == CHAR_CTRL_C) {
|
|
||||||
// cancel everything
|
|
||||||
printf("\n");
|
|
||||||
goto input_restart;
|
|
||||||
} else if (ret == CHAR_CTRL_D) {
|
|
||||||
// stop entering compound statement
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mp_hal_stdio_mode_orig();
|
|
||||||
|
|
||||||
ret = execute_from_lexer(LEX_SRC_VSTR, &line, parse_input_kind, true);
|
|
||||||
if (ret & FORCED_EXIT) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
// use simple readline
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
char *line = prompt((char *)mp_repl_get_ps1());
|
char *line = prompt((char *)mp_repl_get_ps1());
|
||||||
if (line == NULL) {
|
if (line == NULL) {
|
||||||
|
@ -296,16 +233,14 @@ static int do_repl(void) {
|
||||||
line = line3;
|
line = line3;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret = execute_from_lexer(LEX_SRC_STR, line, MP_PARSE_SINGLE_INPUT, true);
|
ret = execute_from_lexer(LEX_SRC_STR, line, MP_PARSE_SINGLE_INPUT, true);
|
||||||
free(line);
|
free(line);
|
||||||
if (ret & FORCED_EXIT) {
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int do_file(const char *file) {
|
static int do_file(const char *file) {
|
||||||
return execute_from_lexer(LEX_SRC_FILENAME, file, MP_PARSE_FILE_INPUT, false);
|
return execute_from_lexer(LEX_SRC_FILENAME, file, MP_PARSE_FILE_INPUT, false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,9 +36,6 @@
|
||||||
#define MICROPY_PAGE_MASK (MICROPY_PAGE_SIZE - 1)
|
#define MICROPY_PAGE_MASK (MICROPY_PAGE_SIZE - 1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// This variable is needed for machine.soft_reset(), but the variable is otherwise unused.
|
|
||||||
int pyexec_system_exit = 0;
|
|
||||||
|
|
||||||
uintptr_t mod_machine_mem_get_addr(mp_obj_t addr_o, uint align) {
|
uintptr_t mod_machine_mem_get_addr(mp_obj_t addr_o, uint align) {
|
||||||
uintptr_t addr = mp_obj_get_int_truncated(addr_o);
|
uintptr_t addr = mp_obj_get_int_truncated(addr_o);
|
||||||
if ((addr & (align - 1)) != 0) {
|
if ((addr & (align - 1)) != 0) {
|
||||||
|
|
|
@ -48,6 +48,12 @@ void mp_hal_set_interrupt_char(char c);
|
||||||
void mp_hal_stdio_mode_raw(void);
|
void mp_hal_stdio_mode_raw(void);
|
||||||
void mp_hal_stdio_mode_orig(void);
|
void mp_hal_stdio_mode_orig(void);
|
||||||
|
|
||||||
|
// pyexec/repl needs stdio to be in raw mode, but this may be cleared before running code.
|
||||||
|
#if MICROPY_REPL_RESET_RAW_BEFORE_EXEC
|
||||||
|
#define MICROPY_BOARD_BEFORE_PYTHON_EXEC(input_kind, exec_flags) mp_hal_stdio_mode_orig()
|
||||||
|
#define MICROPY_BOARD_AFTER_PYTHON_EXEC(input_kind, exec_flags, ret_val, ret) mp_hal_stdio_mode_raw()
|
||||||
|
#endif
|
||||||
|
|
||||||
#if MICROPY_PY_BUILTINS_INPUT && MICROPY_USE_READLINE == 0
|
#if MICROPY_PY_BUILTINS_INPUT && MICROPY_USE_READLINE == 0
|
||||||
|
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
|
|
@ -75,6 +75,7 @@ OBJ += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o))
|
||||||
ifeq ($(MICROPY_USE_READLINE),1)
|
ifeq ($(MICROPY_USE_READLINE),1)
|
||||||
CFLAGS += -DMICROPY_USE_READLINE=1
|
CFLAGS += -DMICROPY_USE_READLINE=1
|
||||||
SRC_C += shared/readline/readline.c
|
SRC_C += shared/readline/readline.c
|
||||||
|
SRC_C += shared/runtime/pyexec.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
LIB += -lws2_32
|
LIB += -lws2_32
|
||||||
|
|
|
@ -89,6 +89,7 @@
|
||||||
<ClCompile Include="@(PyExtModSource)" />
|
<ClCompile Include="@(PyExtModSource)" />
|
||||||
<ClCompile Include="$(PyBaseDir)shared\readline\*.c" />
|
<ClCompile Include="$(PyBaseDir)shared\readline\*.c" />
|
||||||
<ClCompile Include="$(PyBaseDir)shared\runtime\gchelper_generic.c" />
|
<ClCompile Include="$(PyBaseDir)shared\runtime\gchelper_generic.c" />
|
||||||
|
<ClCompile Include="$(PyBaseDir)shared\runtime\pyexec.c" />
|
||||||
<ClCompile Include="$(PyBaseDir)ports\windows\*.c" />
|
<ClCompile Include="$(PyBaseDir)ports\windows\*.c" />
|
||||||
<ClCompile Include="$(PyBaseDir)ports\windows\msvc\*.c" />
|
<ClCompile Include="$(PyBaseDir)ports\windows\msvc\*.c" />
|
||||||
<ClCompile Include="$(PyBaseDir)ports\unix\gccollect.c"/>
|
<ClCompile Include="$(PyBaseDir)ports\unix\gccollect.c"/>
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
#endif
|
#endif
|
||||||
#include "shared/readline/readline.h"
|
#include "shared/readline/readline.h"
|
||||||
#include "shared/runtime/pyexec.h"
|
#include "shared/runtime/pyexec.h"
|
||||||
|
#include "extmod/modplatform.h"
|
||||||
#include "genhdr/mpversion.h"
|
#include "genhdr/mpversion.h"
|
||||||
|
|
||||||
pyexec_mode_kind_t pyexec_mode_kind = PYEXEC_MODE_FRIENDLY_REPL;
|
pyexec_mode_kind_t pyexec_mode_kind = PYEXEC_MODE_FRIENDLY_REPL;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
MicroPython \.\+ version
|
MicroPython \.\+ version
|
||||||
Use \.\+
|
Type "help()" for more information.
|
||||||
>>> # tests for autocompletion
|
>>> # tests for autocompletion
|
||||||
>>> import sys
|
>>> import sys
|
||||||
>>> not_exist.[K[K[K[K[K[K[K[K[K[K
|
>>> not_exist.[K[K[K[K[K[K[K[K[K[K
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
MicroPython \.\+ version
|
MicroPython \.\+ version
|
||||||
Use \.\+
|
Type "help()" for more information.
|
||||||
>>> # tests for autoindent
|
>>> # tests for autoindent
|
||||||
>>> if 1:
|
>>> if 1:
|
||||||
... print(1)
|
... print(1)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
MicroPython \.\+ version
|
MicroPython \.\+ version
|
||||||
Use \.\+
|
Type "help()" for more information.
|
||||||
>>> # basic REPL tests
|
>>> # basic REPL tests
|
||||||
>>> print(1)
|
>>> print(1)
|
||||||
1
|
1
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
MicroPython \.\+ version
|
MicroPython \.\+ version
|
||||||
Use \.\+
|
Type "help()" for more information.
|
||||||
>>> # check REPL allows to continue input
|
>>> # check REPL allows to continue input
|
||||||
>>> 1 \\\\
|
>>> 1 \\\\
|
||||||
... + 2
|
... + 2
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
MicroPython \.\+ version
|
MicroPython \.\+ version
|
||||||
Use \.\+
|
Type "help()" for more information.
|
||||||
>>> # REPL tests of GNU-ish readline navigation
|
>>> # REPL tests of GNU-ish readline navigation
|
||||||
>>> # history buffer navigation
|
>>> # history buffer navigation
|
||||||
>>> 1
|
>>> 1
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
test
|
test
|
||||||
MicroPython \.\+ version
|
MicroPython \.\+ version
|
||||||
Use \.\+
|
Type "help()" for more information.
|
||||||
>>> # cmdline: -i -c print("test")
|
>>> # cmdline: -i -c print("test")
|
||||||
>>> # -c option combined with -i option results in REPL
|
>>> # -c option combined with -i option results in REPL
|
||||||
>>>
|
>>>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
MicroPython \.\+ version
|
MicroPython \.\+ version
|
||||||
Use \.\+
|
Type "help()" for more information.
|
||||||
>>> # cmdline: cmdline/repl_micropyinspect
|
>>> # cmdline: cmdline/repl_micropyinspect
|
||||||
>>> # setting MICROPYINSPECT environment variable before program exit triggers REPL
|
>>> # setting MICROPYINSPECT environment variable before program exit triggers REPL
|
||||||
>>>
|
>>>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
MicroPython \.\+ version
|
MicroPython \.\+ version
|
||||||
Use \.\+
|
Type "help()" for more information.
|
||||||
>>> # test changing ps1/ps2
|
>>> # test changing ps1/ps2
|
||||||
>>> import sys
|
>>> import sys
|
||||||
>>> sys.ps1 = "PS1"
|
>>> sys.ps1 = "PS1"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
MicroPython \.\+ version
|
MicroPython \.\+ version
|
||||||
Use \.\+
|
Type "help()" for more information.
|
||||||
>>> # word movement
|
>>> # word movement
|
||||||
>>> # backward-word, start in word
|
>>> # backward-word, start in word
|
||||||
>>> \.\+
|
>>> \.\+
|
||||||
|
|
|
@ -214,6 +214,7 @@ def run_micropython(pyb, args, test_file, test_file_abspath, is_special=False):
|
||||||
# Need to use a PTY to test command line editing
|
# Need to use a PTY to test command line editing
|
||||||
try:
|
try:
|
||||||
import pty
|
import pty
|
||||||
|
import termios
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# in case pty module is not available, like on Windows
|
# in case pty module is not available, like on Windows
|
||||||
return b"SKIP\n"
|
return b"SKIP\n"
|
||||||
|
@ -240,6 +241,11 @@ def run_micropython(pyb, args, test_file, test_file_abspath, is_special=False):
|
||||||
with open(test_file, "rb") as f:
|
with open(test_file, "rb") as f:
|
||||||
# instead of: output_mupy = subprocess.check_output(args, stdin=f)
|
# instead of: output_mupy = subprocess.check_output(args, stdin=f)
|
||||||
master, slave = pty.openpty()
|
master, slave = pty.openpty()
|
||||||
|
# disable auto newline conversion on the pty terminal.
|
||||||
|
attrs = termios.tcgetattr(slave)
|
||||||
|
attrs[1] = attrs[1] & (~termios.ONLCR) | termios.ONLRET
|
||||||
|
termios.tcsetattr(slave, termios.TCSANOW, attrs)
|
||||||
|
|
||||||
p = subprocess.Popen(
|
p = subprocess.Popen(
|
||||||
args, stdin=slave, stdout=slave, stderr=subprocess.STDOUT, bufsize=0
|
args, stdin=slave, stdout=slave, stderr=subprocess.STDOUT, bufsize=0
|
||||||
)
|
)
|
||||||
|
|
Ładowanie…
Reference in New Issue