py/repl: Change mp_uint_t to size_t in repl helpers.
This commit is contained in:
parent
7bd10c1ffe
commit
e66fd56852
|
@ -188,17 +188,17 @@ int readline_process_char(int c) {
|
||||||
} else if (c == 9) {
|
} else if (c == 9) {
|
||||||
// tab magic
|
// tab magic
|
||||||
const char *compl_str;
|
const char *compl_str;
|
||||||
mp_uint_t compl_len = mp_repl_autocomplete(rl.line->buf + rl.orig_line_len, rl.cursor_pos - rl.orig_line_len, &mp_plat_print, &compl_str);
|
size_t compl_len = mp_repl_autocomplete(rl.line->buf + rl.orig_line_len, rl.cursor_pos - rl.orig_line_len, &mp_plat_print, &compl_str);
|
||||||
if (compl_len == 0) {
|
if (compl_len == 0) {
|
||||||
// no match
|
// no match
|
||||||
} else if (compl_len == (mp_uint_t)(-1)) {
|
} else if (compl_len == (size_t)(-1)) {
|
||||||
// many matches
|
// many matches
|
||||||
mp_hal_stdout_tx_str(rl.prompt);
|
mp_hal_stdout_tx_str(rl.prompt);
|
||||||
mp_hal_stdout_tx_strn(rl.line->buf + rl.orig_line_len, rl.cursor_pos - rl.orig_line_len);
|
mp_hal_stdout_tx_strn(rl.line->buf + rl.orig_line_len, rl.cursor_pos - rl.orig_line_len);
|
||||||
redraw_from_cursor = true;
|
redraw_from_cursor = true;
|
||||||
} else {
|
} else {
|
||||||
// one match
|
// one match
|
||||||
for (mp_uint_t i = 0; i < compl_len; ++i) {
|
for (size_t i = 0; i < compl_len; ++i) {
|
||||||
vstr_ins_byte(rl.line, rl.cursor_pos + i, *compl_str++);
|
vstr_ins_byte(rl.line, rl.cursor_pos + i, *compl_str++);
|
||||||
}
|
}
|
||||||
// set redraw parameters
|
// set redraw parameters
|
||||||
|
|
18
py/repl.c
18
py/repl.c
|
@ -32,7 +32,7 @@
|
||||||
#if MICROPY_HELPER_REPL
|
#if MICROPY_HELPER_REPL
|
||||||
|
|
||||||
STATIC bool str_startswith_word(const char *str, const char *head) {
|
STATIC bool str_startswith_word(const char *str, const char *head) {
|
||||||
mp_uint_t i;
|
size_t i;
|
||||||
for (i = 0; str[i] && head[i]; i++) {
|
for (i = 0; str[i] && head[i]; i++) {
|
||||||
if (str[i] != head[i]) {
|
if (str[i] != head[i]) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -124,7 +124,7 @@ bool mp_repl_continue_with_input(const char *input) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_uint_t mp_repl_autocomplete(const char *str, mp_uint_t len, const mp_print_t *print, const char **compl_str) {
|
size_t mp_repl_autocomplete(const char *str, size_t len, const mp_print_t *print, const char **compl_str) {
|
||||||
// scan backwards to find start of "a.b.c" chain
|
// scan backwards to find start of "a.b.c" chain
|
||||||
const char *org_str = str;
|
const char *org_str = str;
|
||||||
const char *top = str + len;
|
const char *top = str + len;
|
||||||
|
@ -145,13 +145,13 @@ mp_uint_t mp_repl_autocomplete(const char *str, mp_uint_t len, const mp_print_t
|
||||||
while (str < top && *str != '.') {
|
while (str < top && *str != '.') {
|
||||||
++str;
|
++str;
|
||||||
}
|
}
|
||||||
mp_uint_t s_len = str - s_start;
|
size_t s_len = str - s_start;
|
||||||
|
|
||||||
if (str < top) {
|
if (str < top) {
|
||||||
// a complete word, lookup in current dict
|
// a complete word, lookup in current dict
|
||||||
|
|
||||||
mp_obj_t obj = MP_OBJ_NULL;
|
mp_obj_t obj = MP_OBJ_NULL;
|
||||||
for (mp_uint_t i = 0; i < dict->map.alloc; i++) {
|
for (size_t i = 0; i < dict->map.alloc; i++) {
|
||||||
if (MP_MAP_SLOT_IS_FILLED(&dict->map, i)) {
|
if (MP_MAP_SLOT_IS_FILLED(&dict->map, i)) {
|
||||||
size_t d_len;
|
size_t d_len;
|
||||||
const char *d_str = mp_obj_str_get_data(dict->map.table[i].key, &d_len);
|
const char *d_str = mp_obj_str_get_data(dict->map.table[i].key, &d_len);
|
||||||
|
@ -194,8 +194,8 @@ mp_uint_t mp_repl_autocomplete(const char *str, mp_uint_t len, const mp_print_t
|
||||||
// look for matches
|
// look for matches
|
||||||
int n_found = 0;
|
int n_found = 0;
|
||||||
const char *match_str = NULL;
|
const char *match_str = NULL;
|
||||||
mp_uint_t match_len = 0;
|
size_t match_len = 0;
|
||||||
for (mp_uint_t i = 0; i < dict->map.alloc; i++) {
|
for (size_t i = 0; i < dict->map.alloc; i++) {
|
||||||
if (MP_MAP_SLOT_IS_FILLED(&dict->map, i)) {
|
if (MP_MAP_SLOT_IS_FILLED(&dict->map, i)) {
|
||||||
size_t d_len;
|
size_t d_len;
|
||||||
const char *d_str = mp_obj_str_get_data(dict->map.table[i].key, &d_len);
|
const char *d_str = mp_obj_str_get_data(dict->map.table[i].key, &d_len);
|
||||||
|
@ -206,7 +206,7 @@ mp_uint_t mp_repl_autocomplete(const char *str, mp_uint_t len, const mp_print_t
|
||||||
} else {
|
} else {
|
||||||
// search for longest common prefix of match_str and d_str
|
// search for longest common prefix of match_str and d_str
|
||||||
// (assumes these strings are null-terminated)
|
// (assumes these strings are null-terminated)
|
||||||
for (mp_uint_t j = s_len; j <= match_len && j <= d_len; ++j) {
|
for (size_t j = s_len; j <= match_len && j <= d_len; ++j) {
|
||||||
if (match_str[j] != d_str[j]) {
|
if (match_str[j] != d_str[j]) {
|
||||||
match_len = j;
|
match_len = j;
|
||||||
break;
|
break;
|
||||||
|
@ -245,7 +245,7 @@ mp_uint_t mp_repl_autocomplete(const char *str, mp_uint_t len, const mp_print_t
|
||||||
#define MAX_LINE_LEN (4 * WORD_SLOT_LEN)
|
#define MAX_LINE_LEN (4 * WORD_SLOT_LEN)
|
||||||
|
|
||||||
int line_len = MAX_LINE_LEN; // force a newline for first word
|
int line_len = MAX_LINE_LEN; // force a newline for first word
|
||||||
for (mp_uint_t i = 0; i < dict->map.alloc; i++) {
|
for (size_t i = 0; i < dict->map.alloc; i++) {
|
||||||
if (MP_MAP_SLOT_IS_FILLED(&dict->map, i)) {
|
if (MP_MAP_SLOT_IS_FILLED(&dict->map, i)) {
|
||||||
size_t d_len;
|
size_t d_len;
|
||||||
const char *d_str = mp_obj_str_get_data(dict->map.table[i].key, &d_len);
|
const char *d_str = mp_obj_str_get_data(dict->map.table[i].key, &d_len);
|
||||||
|
@ -270,7 +270,7 @@ mp_uint_t mp_repl_autocomplete(const char *str, mp_uint_t len, const mp_print_t
|
||||||
}
|
}
|
||||||
mp_print_str(print, "\n");
|
mp_print_str(print, "\n");
|
||||||
|
|
||||||
return (mp_uint_t)(-1); // indicate many matches
|
return (size_t)(-1); // indicate many matches
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
#if MICROPY_HELPER_REPL
|
#if MICROPY_HELPER_REPL
|
||||||
bool mp_repl_continue_with_input(const char *input);
|
bool mp_repl_continue_with_input(const char *input);
|
||||||
mp_uint_t mp_repl_autocomplete(const char *str, mp_uint_t len, const mp_print_t *print, const char **compl_str);
|
size_t mp_repl_autocomplete(const char *str, size_t len, const mp_print_t *print, const char **compl_str);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // __MICROPY_INCLUDED_PY_REPL_H__
|
#endif // __MICROPY_INCLUDED_PY_REPL_H__
|
||||||
|
|
|
@ -190,7 +190,7 @@ STATIC mp_obj_t extra_coverage(void) {
|
||||||
mp_printf(&mp_plat_print, "# repl\n");
|
mp_printf(&mp_plat_print, "# repl\n");
|
||||||
|
|
||||||
const char *str;
|
const char *str;
|
||||||
mp_uint_t len = mp_repl_autocomplete("__n", 3, &mp_plat_print, &str);
|
size_t len = mp_repl_autocomplete("__n", 3, &mp_plat_print, &str);
|
||||||
mp_printf(&mp_plat_print, "%.*s\n", (int)len, str);
|
mp_printf(&mp_plat_print, "%.*s\n", (int)len, str);
|
||||||
|
|
||||||
mp_store_global(MP_QSTR_sys, mp_import_name(MP_QSTR_sys, mp_const_none, MP_OBJ_NEW_SMALL_INT(0)));
|
mp_store_global(MP_QSTR_sys, mp_import_name(MP_QSTR_sys, mp_const_none, MP_OBJ_NEW_SMALL_INT(0)));
|
||||||
|
|
Loading…
Reference in New Issue