diff --git a/ports/sh/console.c b/ports/sh/console.c index 424e6cad1..81e253a5e 100644 --- a/ports/sh/console.c +++ b/ports/sh/console.c @@ -1,3 +1,9 @@ +//---------------------------------------------------------------------------// +// ____ PythonExtra // +//.-'`_ o `;__, A community port of MicroPython for CASIO calculators. // +//.-'` `---` ' License: MIT (except some files; see LICENSE) // +//---------------------------------------------------------------------------// + #include #include #include @@ -122,7 +128,7 @@ int console_line_render(int x, int y, console_line_t *line, int w, int dy, return y; } -//=== Console data storage ===// +//=== Terminal emulator ===// console_t *console_create(int backlog_size) { diff --git a/ports/sh/console.h b/ports/sh/console.h index 4fafab715..70634eac1 100644 --- a/ports/sh/console.h +++ b/ports/sh/console.h @@ -1,3 +1,19 @@ +//---------------------------------------------------------------------------// +// ____ PythonExtra // +//.-'`_ o `;__, A community port of MicroPython for CASIO calculators. // +//.-'` `---` ' License: MIT (except some files; see LICENSE) // +//---------------------------------------------------------------------------// +// pe.console: Terminal emulator +// +// This header implements a basic terminal emulator compatible with +// MicroPython's readline() implementation. +// +// The main features are: +// * Dynamically-sized lines with reflow +// * Cap memory usage based on the total amount of text, not just line count +// * Basic ANSI-escape-based edition features (but only on the last line) +//--- + #ifndef __PYTHONEXTRA_CONSOLE_H #define __PYTHONEXTRA_CONSOLE_H @@ -52,7 +68,7 @@ void console_line_delete(console_line_t *line, int p, int n); /* Update the number of render lines for the chosen width. */ void console_line_update_render_lines(console_line_t *line, int width); -//=== Console data storage ===// +//=== Terminal emulator ===// typedef struct { diff --git a/ports/sh/main.c b/ports/sh/main.c index 4ae0eee57..70e430f81 100644 --- a/ports/sh/main.c +++ b/ports/sh/main.c @@ -1,6 +1,11 @@ +//---------------------------------------------------------------------------// +// ____ PythonExtra // +//.-'`_ o `;__, A community port of MicroPython for CASIO calculators. // +//.-'` `---` ' License: MIT (except some files; see LICENSE) // +//---------------------------------------------------------------------------// + #include "py/compile.h" #include "py/gc.h" -#include "py/mperrno.h" #include "py/stackctrl.h" #include "py/builtin.h" #include "shared/runtime/gchelper.h" @@ -17,9 +22,7 @@ #include "console.h" #include "shell.h" -//=== Console-based standard streams ===// - -ssize_t stdouterr_write(void *data, void const *buf, size_t size) +static ssize_t stdouterr_write(void *data, void const *buf, size_t size) { console_t *cons = data; console_write_at_cursor(cons, buf, size); @@ -33,8 +36,6 @@ fs_descriptor_type_t stdouterr_type = { .close = NULL, }; -//=== Main function ===// - int main(int argc, char **argv) { pe_shell_init(); @@ -77,8 +78,9 @@ int main(int argc, char **argv) return 0; } -// Handle uncaught exceptions (should never be reached in a correct C implementation). -void nlr_jump_fail(void *val) { +/* Handle uncaught exceptions (normally unreachable). */ +void nlr_jump_fail(void *val) +{ dclear(C_BLACK); dtext(2, 2, C_WHITE, "nlr_jump_fail!"); dprint(2, 2, C_WHITE, "val = %p", val); @@ -87,8 +89,9 @@ void nlr_jump_fail(void *val) { getkey(); } -// Do a garbage collection cycle. -void gc_collect(void) { +/* Do a garbage collection cycle. */ +void gc_collect(void) +{ gc_collect_start(); gc_helper_collect_regs_and_stack(); gc_collect_end(); diff --git a/ports/sh/modgint.c b/ports/sh/modgint.c index a0e33fe89..0fa46d33b 100644 --- a/ports/sh/modgint.c +++ b/ports/sh/modgint.c @@ -1,3 +1,14 @@ +//---------------------------------------------------------------------------// +// ____ PythonExtra // +//.-'`_ o `;__, A community port of MicroPython for CASIO calculators. // +//.-'` `---` ' License: MIT (except some files; see LICENSE) // +//---------------------------------------------------------------------------// +// pe.modgint: `gint` module +// +// This module aims to wrap commonly-used gint functions (not all APIs are +// considered relevant for high-level Python development). +//--- + #include "py/runtime.h" #include "py/objtuple.h" #include diff --git a/ports/sh/modtime.c b/ports/sh/modtime.c index f34a4e72e..81eb1af36 100644 --- a/ports/sh/modtime.c +++ b/ports/sh/modtime.c @@ -1,3 +1,10 @@ +//---------------------------------------------------------------------------// +// ____ PythonExtra // +//.-'`_ o `;__, A community port of MicroPython for CASIO calculators. // +//.-'` `---` ' License: MIT (except some files; see LICENSE) // +//---------------------------------------------------------------------------// +// pe.modtime: `time` module (based on the UNIX port under MIT) + /* * This file is part of the MicroPython project, http://micropython.org/ * diff --git a/ports/sh/mpconfigport.h b/ports/sh/mpconfigport.h index e4587a318..846739923 100644 --- a/ports/sh/mpconfigport.h +++ b/ports/sh/mpconfigport.h @@ -1,3 +1,10 @@ +//---------------------------------------------------------------------------// +// ____ PythonExtra // +//.-'`_ o `;__, A community port of MicroPython for CASIO calculators. // +//.-'` `---` ' License: MIT (except some files; see LICENSE) // +//---------------------------------------------------------------------------// +// pe.mpconfigport: MicroPython's main port configuration file + #include #include diff --git a/ports/sh/mphalport.c b/ports/sh/mphalport.c index b1e29600c..a9af9a1a9 100644 --- a/ports/sh/mphalport.c +++ b/ports/sh/mphalport.c @@ -1,14 +1,17 @@ -#include -#include "py/mpconfig.h" +//---------------------------------------------------------------------------// +// ____ PythonExtra // +//.-'`_ o `;__, A community port of MicroPython for CASIO calculators. // +//.-'` `---` ' License: MIT (except some files; see LICENSE) // +//---------------------------------------------------------------------------// + #include "py/mphal.h" #include "../../shared/readline/readline.h" - #include "keymap.h" #include "shell.h" #include #include +#include -// Receive single character, blocking until one is available. int mp_hal_stdin_rx_chr(void) { while(1) { @@ -45,7 +48,6 @@ int mp_hal_stdin_rx_chr(void) } } -// Send the string of given length. void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) { int r = write(STDOUT_FILENO, str, len); diff --git a/ports/sh/mphalport.h b/ports/sh/mphalport.h index 896abde5d..5e3dcbada 100644 --- a/ports/sh/mphalport.h +++ b/ports/sh/mphalport.h @@ -1,34 +1,47 @@ +//---------------------------------------------------------------------------// +// ____ PythonExtra // +//.-'`_ o `;__, A community port of MicroPython for CASIO calculators. // +//.-'` `---` ' License: MIT (except some files; see LICENSE) // +//---------------------------------------------------------------------------// +// pe.mphalport: MicroPython's Hardware Abstraction Layer #include #include +/* Set the interrupt character in the terminal. */ void mp_hal_set_interrupt_char(char c); +/* Receive a single character from shell (blocking). */ +int mp_hal_stdin_rx_chr(void); + +/* Send a string to shell. */ +void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len); + +/* Passive sleep. */ static inline void mp_hal_delay_ms(mp_uint_t ms) { sleep_ms(ms); } - static inline void mp_hal_delay_us(mp_uint_t us) { sleep_us(us); } +/* Time spent executing. */ static inline mp_uint_t mp_hal_ticks_ms(void) { return ((uint64_t)clock() * 1000) / CLOCKS_PER_SEC; } - static inline mp_uint_t mp_hal_ticks_us(void) { return ((uint64_t)clock() * 1000000) / CLOCKS_PER_SEC; } - static inline mp_uint_t mp_hal_ticks_cpu(void) { return clock(); } +/* Time since Epoch in nanoseconds. */ static inline uint64_t mp_hal_time_ns(void) { return (uint64_t)time(NULL) * 1000000000; diff --git a/ports/sh/shell.c b/ports/sh/shell.c index 073fd4daa..4a7579660 100644 --- a/ports/sh/shell.c +++ b/ports/sh/shell.c @@ -1,3 +1,9 @@ +//---------------------------------------------------------------------------// +// ____ PythonExtra // +//.-'`_ o `;__, A community port of MicroPython for CASIO calculators. // +//.-'` `---` ' License: MIT (except some files; see LICENSE) // +//---------------------------------------------------------------------------// + #include "shell.h" #include #include diff --git a/ports/sh/shell.h b/ports/sh/shell.h index 8ea5ece20..7813f16ad 100644 --- a/ports/sh/shell.h +++ b/ports/sh/shell.h @@ -1,3 +1,8 @@ +//---------------------------------------------------------------------------// +// ____ PythonExtra // +//.-'`_ o `;__, A community port of MicroPython for CASIO calculators. // +//.-'` `---` ' License: MIT (except some files; see LICENSE) // +//---------------------------------------------------------------------------// // pe.shell: Shell integration // // This header covers application-integration aspects of the shell. For the