summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
Diffstat (limited to 'py')
-rw-r--r--py/modsys.c4
-rw-r--r--py/mpconfig.h7
-rw-r--r--py/mpstate.h4
-rw-r--r--py/qstrdefs.h4
-rw-r--r--py/repl.c10
-rw-r--r--py/repl.h26
-rw-r--r--py/runtime.c5
7 files changed, 59 insertions, 1 deletions
diff --git a/py/modsys.c b/py/modsys.c
index c44c7ed45..ac9077622 100644
--- a/py/modsys.c
+++ b/py/modsys.c
@@ -185,6 +185,10 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_settrace_obj, mp_sys_settrace);
#if MICROPY_PY_SYS_ATTR_DELEGATION
STATIC const uint16_t sys_mutable_keys[] = {
+ #if MICROPY_PY_SYS_PS1_PS2
+ MP_QSTR_ps1,
+ MP_QSTR_ps2,
+ #endif
#if MICROPY_PY_SYS_TRACEBACKLIMIT
MP_QSTR_tracebacklimit,
#endif
diff --git a/py/mpconfig.h b/py/mpconfig.h
index be967e698..47c16ed96 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -1356,6 +1356,11 @@ typedef double mp_float_t;
#define MICROPY_PY_SYS_ATEXIT (0)
#endif
+// Whether to provide sys.{ps1,ps2} mutable attributes, to control REPL prompts
+#ifndef MICROPY_PY_SYS_PS1_PS2
+#define MICROPY_PY_SYS_PS1_PS2 (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
+#endif
+
// Whether to provide "sys.settrace" function
#ifndef MICROPY_PY_SYS_SETTRACE
#define MICROPY_PY_SYS_SETTRACE (0)
@@ -1385,7 +1390,7 @@ typedef double mp_float_t;
// Whether the sys module supports attribute delegation
// This is enabled automatically when needed by other features
#ifndef MICROPY_PY_SYS_ATTR_DELEGATION
-#define MICROPY_PY_SYS_ATTR_DELEGATION (MICROPY_PY_SYS_TRACEBACKLIMIT)
+#define MICROPY_PY_SYS_ATTR_DELEGATION (MICROPY_PY_SYS_PS1_PS2 || MICROPY_PY_SYS_TRACEBACKLIMIT)
#endif
// Whether to provide "uerrno" module
diff --git a/py/mpstate.h b/py/mpstate.h
index 499d86351..a493b780a 100644
--- a/py/mpstate.h
+++ b/py/mpstate.h
@@ -41,6 +41,10 @@
// variable, but in the future it is hoped that the state can become local.
enum {
+ #if MICROPY_PY_SYS_PS1_PS2
+ MP_SYS_MUTABLE_PS1,
+ MP_SYS_MUTABLE_PS2,
+ #endif
#if MICROPY_PY_SYS_TRACEBACKLIMIT
MP_SYS_MUTABLE_TRACEBACKLIMIT,
#endif
diff --git a/py/qstrdefs.h b/py/qstrdefs.h
index 405813941..5003636df 100644
--- a/py/qstrdefs.h
+++ b/py/qstrdefs.h
@@ -39,6 +39,10 @@ Q()
Q(*)
Q(_)
Q(/)
+#if MICROPY_PY_SYS_PS1_PS2
+Q(>>> )
+Q(... )
+#endif
#if MICROPY_PY_BUILTINS_STR_OP_MODULO
Q(%#o)
Q(%#x)
diff --git a/py/repl.c b/py/repl.c
index 822e385ab..4e47cf784 100644
--- a/py/repl.c
+++ b/py/repl.c
@@ -33,6 +33,16 @@
#if MICROPY_HELPER_REPL
+#if MICROPY_PY_SYS_PS1_PS2
+const char *mp_repl_get_psx(unsigned int entry) {
+ if (mp_obj_is_str(MP_STATE_VM(sys_mutable)[entry])) {
+ return mp_obj_str_get_str(MP_STATE_VM(sys_mutable)[entry]);
+ } else {
+ return "";
+ }
+}
+#endif
+
STATIC bool str_startswith_word(const char *str, const char *head) {
size_t i;
for (i = 0; str[i] && head[i]; i++) {
diff --git a/py/repl.h b/py/repl.h
index a7a4136ca..9e8f7f1dd 100644
--- a/py/repl.h
+++ b/py/repl.h
@@ -31,8 +31,34 @@
#include "py/mpprint.h"
#if MICROPY_HELPER_REPL
+
+#if MICROPY_PY_SYS_PS1_PS2
+
+const char *mp_repl_get_psx(unsigned int entry);
+
+static inline const char *mp_repl_get_ps1(void) {
+ return mp_repl_get_psx(MP_SYS_MUTABLE_PS1);
+}
+
+static inline const char *mp_repl_get_ps2(void) {
+ return mp_repl_get_psx(MP_SYS_MUTABLE_PS2);
+}
+
+#else
+
+static inline const char *mp_repl_get_ps1(void) {
+ return ">>> ";
+}
+
+static inline const char *mp_repl_get_ps2(void) {
+ return "... ";
+}
+
+#endif
+
bool mp_repl_continue_with_input(const char *input);
size_t mp_repl_autocomplete(const char *str, size_t len, const mp_print_t *print, const char **compl_str);
+
#endif
#endif // MICROPY_INCLUDED_PY_REPL_H
diff --git a/py/runtime.c b/py/runtime.c
index 665c9f220..ba3fbe7fa 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -135,6 +135,11 @@ void mp_init(void) {
MP_STATE_VM(sys_exitfunc) = mp_const_none;
#endif
+ #if MICROPY_PY_SYS_PS1_PS2
+ MP_STATE_VM(sys_mutable[MP_SYS_MUTABLE_PS1]) = MP_OBJ_NEW_QSTR(MP_QSTR__gt__gt__gt__space_);
+ MP_STATE_VM(sys_mutable[MP_SYS_MUTABLE_PS2]) = MP_OBJ_NEW_QSTR(MP_QSTR__dot__dot__dot__space_);
+ #endif
+
#if MICROPY_PY_SYS_SETTRACE
MP_STATE_THREAD(prof_trace_callback) = MP_OBJ_NULL;
MP_STATE_THREAD(prof_callback_is_executing) = false;