summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavePutz <dwputz@gmail.com>2020-09-14 16:50:40 -0500
committerGitHub <noreply@github.com>2020-09-14 16:50:40 -0500
commit2a2a8d64571bf93e2a166626841555fe1753a565 (patch)
treea4b7ba795a6e17d4d0b32abd942af380b1c36e57 /lib
parent4a3be4df91837a1c71fcbd62e041f7c45cd4dd4b (diff)
parent3d8bac50e41acc286cefbde9e052c5ccb335101e (diff)
Merge pull request #28 from adafruit/main
Merge from adafruit/main
Diffstat (limited to 'lib')
-rw-r--r--lib/libm/ef_rem_pio2.c10
-rw-r--r--lib/libm/fdlibm.h2
-rw-r--r--lib/libm/kf_rem_pio2.c4
-rw-r--r--lib/mp-readline/readline.c78
m---------lib/protomatter0
m---------lib/tinyusb0
-rwxr-xr-xlib/utils/pyexec.c2
7 files changed, 80 insertions, 16 deletions
diff --git a/lib/libm/ef_rem_pio2.c b/lib/libm/ef_rem_pio2.c
index bbb73097d..1a9547503 100644
--- a/lib/libm/ef_rem_pio2.c
+++ b/lib/libm/ef_rem_pio2.c
@@ -35,9 +35,9 @@
* Table of constants for 2/pi, 396 Hex digits (476 decimal) of 2/pi
*/
#ifdef __STDC__
-static const __int32_t two_over_pi[] = {
+static const __uint8_t two_over_pi[] = {
#else
-static __int32_t two_over_pi[] = {
+static __uint8_t two_over_pi[] = {
#endif
0xA2, 0xF9, 0x83, 0x6E, 0x4E, 0x44, 0x15, 0x29, 0xFC,
0x27, 0x57, 0xD1, 0xF5, 0x34, 0xDD, 0xC0, 0xDB, 0x62,
@@ -145,6 +145,7 @@ pio2_3t = 6.1232342629e-17; /* 0x248d3132 */
return -1;
}
}
+#if CIRCUITPY_FULL_BUILD
if(ix<=0x43490f80) { /* |x| ~<= 2^7*(pi/2), medium size */
t = fabsf(x);
n = (__int32_t) (t*invpio2+half);
@@ -180,6 +181,11 @@ pio2_3t = 6.1232342629e-17; /* 0x248d3132 */
if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;}
else return n;
}
+#else
+ // Suppress "defined but not used" diagnostics
+ (void) j; (void) fn; (void) r; (void) t; (void) w; (void) pio2_3t;
+ (void) pio2_3; (void) invpio2; (void)half; (void)npio2_hw;
+#endif
/*
* all other (large) arguments
*/
diff --git a/lib/libm/fdlibm.h b/lib/libm/fdlibm.h
index 67bc622ea..91698a6f9 100644
--- a/lib/libm/fdlibm.h
+++ b/lib/libm/fdlibm.h
@@ -188,7 +188,7 @@ extern float __ieee754_scalbf __P((float,float));
extern float __kernel_sinf __P((float,float,int));
extern float __kernel_cosf __P((float,float));
extern float __kernel_tanf __P((float,float,int));
-extern int __kernel_rem_pio2f __P((float*,float*,int,int,int,const __int32_t*));
+extern int __kernel_rem_pio2f __P((float*,float*,int,int,int,const __uint8_t*));
/* A union which permits us to convert between a float and a 32 bit
int. */
diff --git a/lib/libm/kf_rem_pio2.c b/lib/libm/kf_rem_pio2.c
index 62aa242bc..b27e47ea8 100644
--- a/lib/libm/kf_rem_pio2.c
+++ b/lib/libm/kf_rem_pio2.c
@@ -62,10 +62,10 @@ two8 = 2.5600000000e+02, /* 0x43800000 */
twon8 = 3.9062500000e-03; /* 0x3b800000 */
#ifdef __STDC__
- int __kernel_rem_pio2f(float *x, float *y, int e0, int nx, int prec, const __int32_t *ipio2)
+ int __kernel_rem_pio2f(float *x, float *y, int e0, int nx, int prec, const __uint8_t *ipio2)
#else
int __kernel_rem_pio2f(x,y,e0,nx,prec,ipio2)
- float x[], y[]; int e0,nx,prec; __int32_t ipio2[];
+ float x[], y[]; int e0,nx,prec; __uint8_t ipio2[];
#endif
{
__int32_t jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih;
diff --git a/lib/mp-readline/readline.c b/lib/mp-readline/readline.c
index 432413d50..6da71c40f 100644
--- a/lib/mp-readline/readline.c
+++ b/lib/mp-readline/readline.c
@@ -58,6 +58,16 @@ STATIC char *str_dup_maybe(const char *str) {
return s2;
}
+STATIC size_t count_cont_bytes(char *start, char *end) {
+ int count = 0;
+ for (char *pos = start; pos < end; pos++) {
+ if(UTF8_IS_CONT(*pos)) {
+ count++;
+ }
+ }
+ return count;
+}
+
// By default assume terminal which implements VT100 commands...
#ifndef MICROPY_HAL_HAS_VT100
#define MICROPY_HAL_HAS_VT100 (1)
@@ -92,6 +102,7 @@ typedef struct _readline_t {
int escape_seq;
int hist_cur;
size_t cursor_pos;
+ uint8_t utf8_cont_chars;
char escape_seq_buf[1];
const char *prompt;
} readline_t;
@@ -99,7 +110,8 @@ typedef struct _readline_t {
STATIC readline_t rl;
int readline_process_char(int c) {
- size_t last_line_len = rl.line->len;
+ size_t last_line_len = utf8_charlen((byte *)rl.line->buf, rl.line->len);
+ int cont_chars = 0;
int redraw_step_back = 0;
bool redraw_from_cursor = false;
int redraw_step_forward = 0;
@@ -132,7 +144,7 @@ int readline_process_char(int c) {
goto right_arrow_key;
} else if (c == CHAR_CTRL_K) {
// CTRL-K is kill from cursor to end-of-line, inclusive
- vstr_cut_tail_bytes(rl.line, last_line_len - rl.cursor_pos);
+ vstr_cut_tail_bytes(rl.line, rl.line->len - rl.cursor_pos);
// set redraw parameters
redraw_from_cursor = true;
} else if (c == CHAR_CTRL_N) {
@@ -143,6 +155,7 @@ int readline_process_char(int c) {
goto up_arrow_key;
} else if (c == CHAR_CTRL_U) {
// CTRL-U is kill from beginning-of-line up to cursor
+ cont_chars = count_cont_bytes(rl.line->buf+rl.orig_line_len, rl.line->buf+rl.cursor_pos);
vstr_cut_out_bytes(rl.line, rl.orig_line_len, rl.cursor_pos - rl.orig_line_len);
// set redraw parameters
redraw_step_back = rl.cursor_pos - rl.orig_line_len;
@@ -178,6 +191,12 @@ int readline_process_char(int c) {
int nspace = 1;
#endif
+ // Check if we have moved into a UTF-8 continuation byte
+ while (UTF8_IS_CONT(rl.line->buf[rl.cursor_pos-nspace])) {
+ nspace++;
+ cont_chars++;
+ }
+
// do the backspace
vstr_cut_out_bytes(rl.line, rl.cursor_pos - nspace, nspace);
// set redraw parameters
@@ -206,12 +225,27 @@ int readline_process_char(int c) {
redraw_step_forward = compl_len;
}
#endif
- } else if (32 <= c ) {
+ } else if (32 <= c) {
// printable character
- vstr_ins_char(rl.line, rl.cursor_pos, c);
- // set redraw parameters
- redraw_from_cursor = true;
- redraw_step_forward = 1;
+ char lcp = rl.line->buf[rl.cursor_pos];
+ uint8_t cont_need = 0;
+ if (!UTF8_IS_CONT(c)) {
+ // ASCII or Lead code point
+ rl.utf8_cont_chars = 0;
+ lcp = c;
+ }else {
+ rl.utf8_cont_chars += 1;
+ }
+ if (lcp >= 0xc0 && lcp < 0xf8) {
+ cont_need = (0xe5 >> ((lcp >> 3) & 0x6)) & 3; // From unicode.c L195
+ }
+ vstr_ins_char(rl.line, rl.cursor_pos+rl.utf8_cont_chars, c);
+ // set redraw parameters if we have the entire character
+ if (rl.utf8_cont_chars == cont_need) {
+ redraw_from_cursor = true;
+ redraw_step_forward = rl.utf8_cont_chars+1;
+ cont_chars = rl.utf8_cont_chars;
+ }
}
} else if (rl.escape_seq == ESEQ_ESC) {
switch (c) {
@@ -237,6 +271,8 @@ up_arrow_key:
#endif
// up arrow
if (rl.hist_cur + 1 < (int)READLINE_HIST_SIZE && MP_STATE_PORT(readline_hist)[rl.hist_cur + 1] != NULL) {
+ // Check for continuation characters
+ cont_chars = count_cont_bytes(rl.line->buf+rl.orig_line_len, rl.line->buf+rl.cursor_pos);
// increase hist num
rl.hist_cur += 1;
// set line to history
@@ -253,6 +289,8 @@ down_arrow_key:
#endif
// down arrow
if (rl.hist_cur >= 0) {
+ // Check for continuation characters
+ cont_chars = count_cont_bytes(rl.line->buf+rl.orig_line_len, rl.line->buf+rl.cursor_pos);
// decrease hist num
rl.hist_cur -= 1;
// set line to history
@@ -272,6 +310,11 @@ right_arrow_key:
// right arrow
if (rl.cursor_pos < rl.line->len) {
redraw_step_forward = 1;
+ // Check if we have moved into a UTF-8 continuation byte
+ while (UTF8_IS_CONT(rl.line->buf[rl.cursor_pos+redraw_step_forward]) &&
+ rl.cursor_pos+redraw_step_forward < rl.line->len) {
+ redraw_step_forward++;
+ }
}
} else if (c == 'D') {
#if MICROPY_REPL_EMACS_KEYS
@@ -280,6 +323,11 @@ left_arrow_key:
// left arrow
if (rl.cursor_pos > rl.orig_line_len) {
redraw_step_back = 1;
+ // Check if we have moved into a UTF-8 continuation byte
+ while (UTF8_IS_CONT(rl.line->buf[rl.cursor_pos-redraw_step_back])) {
+ redraw_step_back++;
+ cont_chars++;
+ }
}
} else if (c == 'H') {
// home
@@ -295,6 +343,7 @@ left_arrow_key:
if (c == '~') {
if (rl.escape_seq_buf[0] == '1' || rl.escape_seq_buf[0] == '7') {
home_key:
+ cont_chars = count_cont_bytes(rl.line->buf+rl.orig_line_len, rl.line->buf+rl.cursor_pos);
redraw_step_back = rl.cursor_pos - rl.orig_line_len;
} else if (rl.escape_seq_buf[0] == '4' || rl.escape_seq_buf[0] == '8') {
end_key:
@@ -305,7 +354,12 @@ end_key:
delete_key:
#endif
if (rl.cursor_pos < rl.line->len) {
- vstr_cut_out_bytes(rl.line, rl.cursor_pos, 1);
+ size_t len = 1;
+ while (UTF8_IS_CONT(rl.line->buf[rl.cursor_pos+len]) &&
+ rl.cursor_pos+len < rl.line->len) {
+ len++;
+ }
+ vstr_cut_out_bytes(rl.line, rl.cursor_pos, len);
redraw_from_cursor = true;
}
} else {
@@ -331,18 +385,20 @@ delete_key:
// redraw command prompt, efficiently
if (redraw_step_back > 0) {
- mp_hal_move_cursor_back(redraw_step_back);
+ mp_hal_move_cursor_back(redraw_step_back-cont_chars);
rl.cursor_pos -= redraw_step_back;
}
if (redraw_from_cursor) {
- if (rl.line->len < last_line_len) {
+ if (utf8_charlen((byte *)rl.line->buf, rl.line->len) < last_line_len) {
// erase old chars
mp_hal_erase_line_from_cursor(last_line_len - rl.cursor_pos);
}
+ // Check for continuation characters
+ cont_chars = count_cont_bytes(rl.line->buf+rl.cursor_pos+redraw_step_forward, rl.line->buf+rl.line->len);
// draw new chars
mp_hal_stdout_tx_strn(rl.line->buf + rl.cursor_pos, rl.line->len - rl.cursor_pos);
// move cursor forward if needed (already moved forward by length of line, so move it back)
- mp_hal_move_cursor_back(rl.line->len - (rl.cursor_pos + redraw_step_forward));
+ mp_hal_move_cursor_back(rl.line->len - (rl.cursor_pos + redraw_step_forward) - cont_chars);
rl.cursor_pos += redraw_step_forward;
} else if (redraw_step_forward > 0) {
// draw over old chars to move cursor forwards
diff --git a/lib/protomatter b/lib/protomatter
-Subproject 761d6437e8cd6a131d51de96974337121a9c716
+Subproject 2a1ba8fa4753b2bcb158c9b17351cf18eade0d2
diff --git a/lib/tinyusb b/lib/tinyusb
-Subproject 22100b252fc2eb8f51ed407949645653c4880fd
+Subproject e90cf7a676eddcbd9c35d2d99a0a9cd14686e2c
diff --git a/lib/utils/pyexec.c b/lib/utils/pyexec.c
index 8e99bc209..378fb6267 100755
--- a/lib/utils/pyexec.c
+++ b/lib/utils/pyexec.c
@@ -113,6 +113,8 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input
start = mp_hal_ticks_ms();
mp_call_function_0(module_fun);
mp_hal_set_interrupt_char(-1); // disable interrupt
+ // Handle any ctrl-c interrupt that arrived just in time
+ mp_handle_pending();
nlr_pop();
ret = 0;
if (exec_flags & EXEC_FLAG_PRINT_EOF) {