diff --git a/lite-python/Makefile b/lite-python/Makefile index cb61f7088f11d1cf23f9c8ca715807d10451d017..bc6695fa013e98582bf4369629d119805acd5170 100755 --- a/lite-python/Makefile +++ b/lite-python/Makefile @@ -56,16 +56,12 @@ ARFLAGS = rc CSUPEROPT = -Os -LIBS = +LIBS = SRC_C = \ - $(wildcard $(DEVPATH)/*.c) \ - $(LIBPATH)/utils/printf.c \ - $(LIBPATH)/utils/stdout_helpers.c \ - $(LIBPATH)/mp-readline/readline.c \ - $(LIBPATH)/utils/pyexec.c \ - dtpython.c \ - uart_core.c + $(wildcard $(LIBPATH)/utils/*.c) \ + $(wildcard $(DEVPATH)/*.c) \ + dtpython.c OBJ = $(PY_CORE_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) diff --git a/lite-python/demo/Hi3861/dt_python_demo.c b/lite-python/demo/Hi3861/dt_python_demo.c index 60c71862ea43db3b1615f53ea698b36b8d8fe7a1..312bb96fbbef2250b02674fc61e15c8be560db63 100755 --- a/lite-python/demo/Hi3861/dt_python_demo.c +++ b/lite-python/demo/Hi3861/dt_python_demo.c @@ -39,6 +39,9 @@ extern const char* c_gpio_py; // gpio.py extern const char* c_i2c_py; // i2c.py extern const char* c_test_py; // test.py extern const char* c_another_py; // another.py +extern const char* c_main_py; // main.py +extern const char* c_pwm_py; // pwm.py +extern const char* c_math_py; // math.py static int WriteScript(const char* name, const char* script) { @@ -81,14 +84,18 @@ static void PrepareScript(const char* name, const char* script) } } + static void* DTPython_Demo_Task(const char* arg) { printf("[dt4sw] DTPython_Demo_Task()\n"); - PrepareScript("gpio.py", c_gpio_py); - PrepareScript("i2c.py", c_i2c_py); - PrepareScript("test.py", c_test_py); - PrepareScript("another.py", c_another_py); + // PrepareScript("gpio.py", c_gpio_py); + // PrepareScript("i2c.py", c_i2c_py); + // PrepareScript("test.py", c_test_py); + // PrepareScript("another.py", c_another_py); + // PrepareScript("main.py", c_main_py); + // PrepareScript("pwm.py", c_pwm_py); + PrepareScript("math.py", c_math_py); DTPython_Init(); // 初始化Python环境 @@ -98,7 +105,7 @@ static void* DTPython_Demo_Task(const char* arg) DTPython_RunCode("print(s)"); // 执行Python语句:print(s) - DTPython_RunFile("i2c.py"); // 执行Python文件:xxx.py + DTPython_RunFile("math.py"); // 执行Python文件:xxx.py DTPython_RunCode("print(\'Python Code End\')"); // 执行Python语句:print('Python Code End') diff --git a/lite-python/demo/Hi3861/dtpython.h b/lite-python/demo/Hi3861/dtpython.h index e8790f88f07279692c1e7ada8857fc6c4261bae4..a3d0677e5d086aecdb76da4d7a426cd5b9fd540f 100755 --- a/lite-python/demo/Hi3861/dtpython.h +++ b/lite-python/demo/Hi3861/dtpython.h @@ -1,23 +1,30 @@ -/* - ======================================================================================= - File: - dtpython.h +/**************************************************************************** - Description: - This header file is for the interface of DTPython project which is an experiment to make HOS board - to support Python. DTPython is made from MicroPython, but is NOT MicroPython anymore, - because the basic purpose of DTPython is to supply another option to develop HOS device application. +MIT License - Author: - Delphi Tang (唐佐林) - http://www.dt4sw.com/ +Copyright (c) 2021 唐佐林 +WeChat : delphi_tang +EMail: delphi_tang@dt4sw.com - Revision History: - V0.0.1 (Initial Version) - ======================================================================================= +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: -*/ +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*****************************************************************************/ #ifndef DTPYTHON_H #define DTPYTHON_H @@ -70,4 +77,4 @@ void DTPython_RunCode(const char* statement); */ void DTPython_Deinit(void); -#endif \ No newline at end of file +#endif diff --git a/lite-python/demo/Hi3861/sdk_adapter_1.0.c b/lite-python/demo/Hi3861/sdk_adapter_1.0.c index acb14c14706ded2e1711cf77c3cbb87472a883d3..c87c21e1ada74ac87f3a02a8939e7c465eaf9eb3 100755 --- a/lite-python/demo/Hi3861/sdk_adapter_1.0.c +++ b/lite-python/demo/Hi3861/sdk_adapter_1.0.c @@ -246,6 +246,11 @@ unsigned int DTSpiHostRead(unsigned int id, unsigned char *readData, unsigned in return hi_spi_host_read(id, readData, byteLen); } +unsigned int DTSpiHostWriteRead(unsigned int id, unsigned char* writeData, unsigned char* readData, unsigned int byteLen) +{ + return hi_spi_host_writeread(id, writeData, readData, byteLen); +} + unsigned int DTSpiSetInfo(unsigned int id, SpiInfo info) { hi_spi_cfg_basic_info hiInfo = {0}; @@ -276,4 +281,3 @@ unsigned int DTAdcRead(unsigned int channel, unsigned short* data, int equModel, { return hi_adc_read(channel, data, equModel, curBais, rstCnt); } - diff --git a/lite-python/demo/Hi3861/sdk_adapter_1.1.c b/lite-python/demo/Hi3861/sdk_adapter_1.1.c index 6a934e98e9cf0d86638d51faf5d01e112e8367eb..8260c069b7a11ef8b8c66e4cb9ade7c72ee8d8e2 100755 --- a/lite-python/demo/Hi3861/sdk_adapter_1.1.c +++ b/lite-python/demo/Hi3861/sdk_adapter_1.1.c @@ -80,6 +80,11 @@ unsigned int DTSpiHostRead(unsigned int id, unsigned char *readData, unsigned in return hi_spi_host_read(id, readData, byteLen); } +unsigned int DTSpiHostWriteRead(unsigned int id, unsigned char* writeData, unsigned char* readData, unsigned int byteLen) +{ + return hi_spi_host_writeread(id, writeData, readData, byteLen); +} + unsigned int DTSpiSetInfo(unsigned int id, SpiInfo info) { hi_spi_cfg_basic_info hiInfo = {0}; @@ -110,4 +115,3 @@ unsigned int DTAdcRead(unsigned int channel, unsigned short* data, int equModel, { return hi_adc_read(channel, data, equModel, curBais, rstCnt); } - diff --git a/lite-python/demo/Hi3861/test.c b/lite-python/demo/Hi3861/test.c index 5eb0cc5f79071bee352b616d94c1096267d64c21..6a854b3bc144244f7273eff92fc3a1da1bf0edda 100755 --- a/lite-python/demo/Hi3861/test.c +++ b/lite-python/demo/Hi3861/test.c @@ -25,6 +25,117 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *****************************************************************************/ +const char* c_math_py = +{ +"import math\r\n" +"\r\n" +"a = 1.6\r\n" +"b = 0.25\r\n" +"\r\n" +"print(dir(math))\r\n" +"\r\n" +"print(a / b)\r\n" +"print(a ** b)\r\n" +"print(math.floor(9.85))\r\n" +"print(math.fmod(9.85, 9))\r\n" +"print(math.modf(9.85))\r\n" +"print(math.fabs(-0.05))\r\n" +"print(math.e)\r\n" +"print(math.pi)\r\n" +"print(math.isfinite(1.11))\r\n" +"print(math.isinf(1.11))\r\n" +"print(math.isnan(float(\'nan\')))\r\n" +}; + +const char* c_pwm_py = +{ +"import gpio\r\n" +"import pwm\r\n" +"import os\r\n" +"\r\n" +"is1_gpio = 7\r\n" +"pwm_port = 1\r\n" +"pwm_gpio = 8\r\n" +"pwm_on = False\r\n" +"\r\n" +"def is1_callback(arg) :\r\n" +" print(\'is1_callback() is invoked\')\r\n" +" cur_tick = os.get_tick()\r\n" +"\r\n" +" if cur_tick - arg[0] > 30:\r\n" +" global pwm_on\r\n" +" \r\n" +" if not pwm_on :\r\n" +" pwm_on = True\r\n" +" arg[0] = cur_tick\r\n" +" print(\'to beep\')\r\n" +"\r\n" +"def init() :\r\n" +" gpio.gpio_init(is1_gpio)\r\n" +" \r\n" +" func = gpio.query_func_value(is1_gpio, \'gpio\')\r\n" +" \r\n" +" gpio.set_func(is1_gpio, func)\r\n" +" \r\n" +" pull = gpio.query_pull_value(\'down\')\r\n" +" \r\n" +" gpio.set_pull(is1_gpio, pull) \r\n" +" gpio.set_dir(is1_gpio, gpio.dir_in)\r\n" +" gpio.set_isr_mode(is1_gpio, gpio.rise_high)\r\n" +" gpio.register_isr_func(is1_gpio, is1_callback, [os.get_tick()])\r\n" +" \r\n" +" gpio.gpio_init(pwm_gpio)\r\n" +" \r\n" +" func = gpio.query_func_value(pwm_gpio, \'pwm1_out\')\r\n" +" gpio.set_func(pwm_gpio, func)\r\n" +" \r\n" +" gpio.set_dir(pwm_gpio, gpio.dir_out)\r\n" +" \r\n" +" pwm.pwm_init(pwm_port)\r\n" +" \r\n" +"init()\r\n" +"\r\n" +"while True: \r\n" +" if pwm_on :\r\n" +" print(\'beeping...\')\r\n" +" pwm.start(pwm_port, 50, 4000)\r\n" +" os.sleep(3)\r\n" +" pwm.stop(pwm_port)\r\n" +" pwm_on = False\r\n" +" else :\r\n" +" os.usleep(10000) \r\n" +}; + + +const char* c_main_py = +{ +"import gpio\r\n" +"import os\r\n" +"\r\n" +"current = 0\r\n" +"\r\n" +"gpio.gpio_init(12)\r\n" +"\r\n" +"func = gpio.query_func_value(12, \'gpio\') \r\n" +" \r\n" +"gpio.set_func(12, func) \r\n" +"\r\n" +"gpio.set_dir(12, gpio.dir_out) \r\n" +"\r\n" +"\r\n" +"while True :\r\n" +" if current == 0 :\r\n" +" current = 1\r\n" +" else :\r\n" +" current = 0\r\n" +" \r\n" +" gpio.set_output(12, current) \r\n" +" \r\n" +" os.sleep(2)\r\n" +"\r\n" +"gpio.gpio_deinit(12)\r\n" +"\r\n" +}; const char* c_gpio_py = { diff --git a/lite-python/dev/adc_impl.c b/lite-python/dev/adc_impl.c index 92223f7b119ee62d840a6dbc65caa56b3b38ad63..3513ede6c3a7aed19722b30e176cba1538f69a78 100755 --- a/lite-python/dev/adc_impl.c +++ b/lite-python/dev/adc_impl.c @@ -63,7 +63,7 @@ mp_obj_t mp_adc_set_model(mp_obj_t index, mp_obj_t model) unsigned int channel = mp_obj_get_int(index); int equ_model = mp_obj_get_int(model); int r = 0; - + if( channel < ADC_CHANNEL_NUM ) { g_config[channel].model = equ_model; diff --git a/lite-python/dev/modspi.c b/lite-python/dev/modspi.c index 363c48201ab161e4596d9ad880a29cfc87537477..5950b34f7614af075b359f5f6d36eb7da99b75aa 100755 --- a/lite-python/dev/modspi.c +++ b/lite-python/dev/modspi.c @@ -47,7 +47,7 @@ STATIC const MP_DEFINE_CONST_FUN_OBJ_2(mp_spi_init_obj, mp_spi_init); STATIC const MP_DEFINE_CONST_FUN_OBJ_1(mp_spi_deinit_obj, mp_spi_deinit); STATIC const MP_DEFINE_CONST_FUN_OBJ_2(mp_spi_host_write_obj, mp_spi_host_write); STATIC const MP_DEFINE_CONST_FUN_OBJ_2(mp_spi_host_read_obj, mp_spi_host_read); -STATIC const MP_DEFINE_CONST_FUN_OBJ_3(mp_spi_host_write_read_obj, mp_spi_host_write_read); +STATIC const MP_DEFINE_CONST_FUN_OBJ_2(mp_spi_host_write_read_obj, mp_spi_host_write_read); STATIC const MP_DEFINE_CONST_FUN_OBJ_2(mp_spi_set_info_obj, mp_spi_set_info); STATIC const mp_rom_map_elem_t mp_module_spi_globals_table[] = diff --git a/lite-python/dev/spi_ex.h b/lite-python/dev/spi_ex.h index 5f541ba4396215ddc46b4615e7cfb18be51cf16e..5af13497c90c7f92d0467f1a299f7c845ad08750 100755 --- a/lite-python/dev/spi_ex.h +++ b/lite-python/dev/spi_ex.h @@ -43,6 +43,7 @@ unsigned int DTSpiInit(unsigned int id, SpiInfo info); unsigned int DTSpiDeinit(unsigned int id); unsigned int DTSpiHostWrite(unsigned int id, unsigned char* writeData, unsigned int byteLen); unsigned int DTSpiHostRead(unsigned int id, unsigned char* readData, unsigned int byteLen); +unsigned int DTSpiHostWriteRead(unsigned int id, unsigned char* writeData, unsigned char* readData, unsigned int byteLen); unsigned int DTSpiSetInfo(unsigned int id, SpiInfo info); #endif diff --git a/lite-python/dev/spi_impl.c b/lite-python/dev/spi_impl.c index f8445e140d8dd151ec01360a74e924f2c8c05f1e..83cc09754ca0f5a5db49e25291cab98da4e879be 100755 --- a/lite-python/dev/spi_impl.c +++ b/lite-python/dev/spi_impl.c @@ -121,7 +121,7 @@ mp_obj_t mp_spi_host_read(mp_obj_t idx, mp_obj_t len) return mp_obj_new_tuple(2, ret); } -mp_obj_t mp_spi_host_write_read(mp_obj_t idx, mp_obj_t data, mp_obj_t n) +mp_obj_t mp_spi_host_write_read(mp_obj_t idx, mp_obj_t data) { unsigned int r = -1; int id = mp_obj_get_int(idx); @@ -133,19 +133,17 @@ mp_obj_t mp_spi_host_write_read(mp_obj_t idx, mp_obj_t data, mp_obj_t n) if( mp_obj_is_type(data, &mp_type_list) ) { - size_t rlen = mp_obj_get_int(n); unsigned char* bytes = NULL; - size_t slen = pylist_to_integer_array(data, bytes); - unsigned char* buffer = malloc(sizeof(*buffer) * rlen); + size_t n = pylist_to_integer_array(data, bytes); + unsigned char* buffer = malloc(sizeof(*buffer) * n); if( bytes && buffer ) { mp_obj_t pylist = mp_const_none; - r = DTSpiHostWrite(id, bytes, slen) >= 0 ? 0 : -1; - r = (r == 0) ? (DTSpiHostRead(id, buffer, rlen) >= 0 ? 0 : -1) : -1; + r = DTSpiHostWriteRead(id, bytes, buffer, n) >= 0 ? 0 : -1; - if( (r == 0) && ((pylist = integer_array_to_pylist(buffer, rlen)) != mp_const_none) ) + if( (r == 0) && ((pylist = integer_array_to_pylist(buffer, n)) != mp_const_none) ) { ret[0] = mp_obj_new_int(0); ret[1] = pylist; diff --git a/lite-python/dev/spi_impl.h b/lite-python/dev/spi_impl.h index 2d89426ddd64da7cf127430209955a432dbaaff9..880b88e1f78d5ec350d55ff836c8614f1551a746 100755 --- a/lite-python/dev/spi_impl.h +++ b/lite-python/dev/spi_impl.h @@ -39,7 +39,7 @@ mp_obj_t mp_spi_init(mp_obj_t idx, mp_obj_t info); mp_obj_t mp_spi_deinit(mp_obj_t idx); mp_obj_t mp_spi_host_write(mp_obj_t idx, mp_obj_t data); mp_obj_t mp_spi_host_read(mp_obj_t idx, mp_obj_t n); -mp_obj_t mp_spi_host_write_read(mp_obj_t idx, mp_obj_t data, mp_obj_t n); +mp_obj_t mp_spi_host_write_read(mp_obj_t idx, mp_obj_t data); mp_obj_t mp_spi_set_info(mp_obj_t idx, mp_obj_t info); diff --git a/lite-python/dtpython.c b/lite-python/dtpython.c index 20cae80d2ef3f7c5386172e4138422ce2aa45110..19df0abb4b54845ed664d3b01458cae4cb7f2f87 100755 --- a/lite-python/dtpython.c +++ b/lite-python/dtpython.c @@ -32,7 +32,6 @@ SOFTWARE. #include "py/gc.h" #include "py/mperrno.h" #include "py/objstr.h" -#include "utils/pyexec.h" static char* g_stack_top = NULL; static char g_heap[1024 * 25] = {0}; diff --git a/lite-python/lib/embed/__errno.c b/lite-python/lib/embed/__errno.c deleted file mode 100755 index 86417a02dd045f73407047acac5d941837b79ddd..0000000000000000000000000000000000000000 --- a/lite-python/lib/embed/__errno.c +++ /dev/null @@ -1,13 +0,0 @@ -// This file provides a version of __errno() for embedded systems that do not have one. -// This function is needed for expressions of the form: &errno - -static int embed_errno; - -#if defined(__linux__) -int *__errno_location(void) -#else -int *__errno(void) -#endif -{ - return &embed_errno; -} diff --git a/lite-python/lib/embed/abort_.c b/lite-python/lib/embed/abort_.c deleted file mode 100755 index 3051eae81e0ce625c1d848ed6761ba22c6de84ba..0000000000000000000000000000000000000000 --- a/lite-python/lib/embed/abort_.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -NORETURN void abort_(void); - -NORETURN void abort_(void) { - mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("abort() called")); -} diff --git a/lite-python/lib/mp-readline/readline.c b/lite-python/lib/mp-readline/readline.c deleted file mode 100755 index 296c8aa4ab543aaeacb76c036a8abb6820a92936..0000000000000000000000000000000000000000 --- a/lite-python/lib/mp-readline/readline.c +++ /dev/null @@ -1,534 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013, 2014 Damien P. George - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include -#include -#include - -#include "py/mpstate.h" -#include "py/repl.h" -#include "py/mphal.h" -#include "lib/mp-readline/readline.h" - -#if 0 // print debugging info -#define DEBUG_PRINT (1) -#define DEBUG_printf printf -#else // don't print debugging info -#define DEBUG_printf(...) (void)0 -#endif - -#define READLINE_HIST_SIZE (MP_ARRAY_SIZE(MP_STATE_PORT(readline_hist))) - -enum { ESEQ_NONE, ESEQ_ESC, ESEQ_ESC_BRACKET, ESEQ_ESC_BRACKET_DIGIT, ESEQ_ESC_O }; - -void readline_init0(void) { - memset(MP_STATE_PORT(readline_hist), 0, READLINE_HIST_SIZE * sizeof(const char*)); -} - -STATIC char *str_dup_maybe(const char *str) { - uint32_t len = strlen(str); - char *s2 = m_new_maybe(char, len + 1); - if (s2 == NULL) { - return NULL; - } - memcpy(s2, str, len + 1); - return s2; -} - -// By default assume terminal which implements VT100 commands... -#ifndef MICROPY_HAL_HAS_VT100 -#define MICROPY_HAL_HAS_VT100 (1) -#endif - -// ...and provide the implementation using them -#if MICROPY_HAL_HAS_VT100 -STATIC void mp_hal_move_cursor_back(uint pos) { - if (pos <= 4) { - // fast path for most common case of 1 step back - mp_hal_stdout_tx_strn("\b\b\b\b", pos); - } else { - char vt100_command[6]; - // snprintf needs space for the terminating null character - int n = snprintf(&vt100_command[0], sizeof(vt100_command), "\x1b[%u", pos); - if (n > 0) { - assert((unsigned)n < sizeof(vt100_command)); - vt100_command[n] = 'D'; // replace null char - mp_hal_stdout_tx_strn(vt100_command, n + 1); - } - } -} - -STATIC void mp_hal_erase_line_from_cursor(uint n_chars_to_erase) { - (void)n_chars_to_erase; - mp_hal_stdout_tx_strn("\x1b[K", 3); -} -#endif - -typedef struct _readline_t { - vstr_t *line; - size_t orig_line_len; - int escape_seq; - int hist_cur; - size_t cursor_pos; - char escape_seq_buf[1]; - const char *prompt; -} readline_t; - -STATIC readline_t rl; - -#if MICROPY_REPL_EMACS_WORDS_MOVE -STATIC size_t cursor_count_word(int forward) { - const char *line_buf = vstr_str(rl.line); - size_t pos = rl.cursor_pos; - bool in_word = false; - - for (;;) { - // if moving backwards and we've reached 0... break - if (!forward && pos == 0) { - break; - } - // or if moving forwards and we've reached to the end of line... break - else if (forward && pos == vstr_len(rl.line)) { - break; - } - - if (unichar_isalnum(line_buf[pos + (forward - 1)])) { - in_word = true; - } else if (in_word) { - break; - } - - pos += forward ? forward : -1; - } - - return forward ? pos - rl.cursor_pos : rl.cursor_pos - pos; -} -#endif - -int readline_process_char(int c) { - size_t last_line_len = rl.line->len; - int redraw_step_back = 0; - bool redraw_from_cursor = false; - int redraw_step_forward = 0; - if (rl.escape_seq == ESEQ_NONE) { - if (CHAR_CTRL_A <= c && c <= CHAR_CTRL_E && vstr_len(rl.line) == rl.orig_line_len) { - // control character with empty line - return c; - } else if (c == CHAR_CTRL_A) { - // CTRL-A with non-empty line is go-to-start-of-line - goto home_key; - #if MICROPY_REPL_EMACS_KEYS - } else if (c == CHAR_CTRL_B) { - // CTRL-B with non-empty line is go-back-one-char - goto left_arrow_key; - #endif - } else if (c == CHAR_CTRL_C) { - // CTRL-C with non-empty line is cancel - return c; - #if MICROPY_REPL_EMACS_KEYS - } else if (c == CHAR_CTRL_D) { - // CTRL-D with non-empty line is delete-at-cursor - goto delete_key; - #endif - } else if (c == CHAR_CTRL_E) { - // CTRL-E is go-to-end-of-line - goto end_key; - #if MICROPY_REPL_EMACS_KEYS - } else if (c == CHAR_CTRL_F) { - // CTRL-F with non-empty line is go-forward-one-char - 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); - // set redraw parameters - redraw_from_cursor = true; - } else if (c == CHAR_CTRL_N) { - // CTRL-N is go to next line in history - goto down_arrow_key; - } else if (c == CHAR_CTRL_P) { - // CTRL-P is go to previous line in history - goto up_arrow_key; - } else if (c == CHAR_CTRL_U) { - // CTRL-U is kill from beginning-of-line up to cursor - 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; - redraw_from_cursor = true; - #endif - #if MICROPY_REPL_EMACS_EXTRA_WORDS_MOVE - } else if (c == CHAR_CTRL_W) { - goto backward_kill_word; - #endif - } else if (c == '\r') { - // newline - mp_hal_stdout_tx_str("\r\n"); - readline_push_history(vstr_null_terminated_str(rl.line) + rl.orig_line_len); - return 0; - } else if (c == 27) { - // escape sequence - rl.escape_seq = ESEQ_ESC; - } else if (c == 8 || c == 127) { - // backspace/delete - if (rl.cursor_pos > rl.orig_line_len) { - // work out how many chars to backspace - #if MICROPY_REPL_AUTO_INDENT - int nspace = 0; - for (size_t i = rl.orig_line_len; i < rl.cursor_pos; i++) { - if (rl.line->buf[i] != ' ') { - nspace = 0; - break; - } - nspace += 1; - } - if (nspace < 4) { - nspace = 1; - } else { - nspace = 4; - } - #else - int nspace = 1; - #endif - - // do the backspace - vstr_cut_out_bytes(rl.line, rl.cursor_pos - nspace, nspace); - // set redraw parameters - redraw_step_back = nspace; - redraw_from_cursor = true; - } - #if MICROPY_HELPER_REPL - } else if (c == 9) { - // tab magic - const char *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) { - // no match - } else if (compl_len == (size_t)(-1)) { - // many matches - 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); - redraw_from_cursor = true; - } else { - // one match - for (size_t i = 0; i < compl_len; ++i) { - vstr_ins_byte(rl.line, rl.cursor_pos + i, *compl_str++); - } - // set redraw parameters - redraw_from_cursor = true; - redraw_step_forward = compl_len; - } - #endif - } else if (32 <= c && c <= 126) { - // printable character - vstr_ins_char(rl.line, rl.cursor_pos, c); - // set redraw parameters - redraw_from_cursor = true; - redraw_step_forward = 1; - } - } else if (rl.escape_seq == ESEQ_ESC) { - switch (c) { - case '[': - rl.escape_seq = ESEQ_ESC_BRACKET; - break; - case 'O': - rl.escape_seq = ESEQ_ESC_O; - break; - #if MICROPY_REPL_EMACS_WORDS_MOVE - case 'b': -#if MICROPY_REPL_EMACS_EXTRA_WORDS_MOVE -backward_word: -#endif - redraw_step_back = cursor_count_word(0); - rl.escape_seq = ESEQ_NONE; - break; - case 'f': -#if MICROPY_REPL_EMACS_EXTRA_WORDS_MOVE -forward_word: -#endif - redraw_step_forward = cursor_count_word(1); - rl.escape_seq = ESEQ_NONE; - break; - case 'd': - vstr_cut_out_bytes(rl.line, rl.cursor_pos, cursor_count_word(1)); - redraw_from_cursor = true; - rl.escape_seq = ESEQ_NONE; - break; - case 127: -#if MICROPY_REPL_EMACS_EXTRA_WORDS_MOVE -backward_kill_word: -#endif - redraw_step_back = cursor_count_word(0); - vstr_cut_out_bytes(rl.line, rl.cursor_pos - redraw_step_back, redraw_step_back); - redraw_from_cursor = true; - rl.escape_seq = ESEQ_NONE; - break; - #endif - default: - DEBUG_printf("(ESC %d)", c); - rl.escape_seq = ESEQ_NONE; - break; - } - } else if (rl.escape_seq == ESEQ_ESC_BRACKET) { - if ('0' <= c && c <= '9') { - rl.escape_seq = ESEQ_ESC_BRACKET_DIGIT; - rl.escape_seq_buf[0] = c; - } else { - rl.escape_seq = ESEQ_NONE; - if (c == 'A') { -#if MICROPY_REPL_EMACS_KEYS -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) { - // increase hist num - rl.hist_cur += 1; - // set line to history - rl.line->len = rl.orig_line_len; - vstr_add_str(rl.line, MP_STATE_PORT(readline_hist)[rl.hist_cur]); - // set redraw parameters - redraw_step_back = rl.cursor_pos - rl.orig_line_len; - redraw_from_cursor = true; - redraw_step_forward = rl.line->len - rl.orig_line_len; - } - } else if (c == 'B') { -#if MICROPY_REPL_EMACS_KEYS -down_arrow_key: -#endif - // down arrow - if (rl.hist_cur >= 0) { - // decrease hist num - rl.hist_cur -= 1; - // set line to history - vstr_cut_tail_bytes(rl.line, rl.line->len - rl.orig_line_len); - if (rl.hist_cur >= 0) { - vstr_add_str(rl.line, MP_STATE_PORT(readline_hist)[rl.hist_cur]); - } - // set redraw parameters - redraw_step_back = rl.cursor_pos - rl.orig_line_len; - redraw_from_cursor = true; - redraw_step_forward = rl.line->len - rl.orig_line_len; - } - } else if (c == 'C') { -#if MICROPY_REPL_EMACS_KEYS -right_arrow_key: -#endif - // right arrow - if (rl.cursor_pos < rl.line->len) { - redraw_step_forward = 1; - } - } else if (c == 'D') { -#if MICROPY_REPL_EMACS_KEYS -left_arrow_key: -#endif - // left arrow - if (rl.cursor_pos > rl.orig_line_len) { - redraw_step_back = 1; - } - } else if (c == 'H') { - // home - goto home_key; - } else if (c == 'F') { - // end - goto end_key; - } else { - DEBUG_printf("(ESC [ %d)", c); - } - } - } else if (rl.escape_seq == ESEQ_ESC_BRACKET_DIGIT) { - if (c == '~') { - if (rl.escape_seq_buf[0] == '1' || rl.escape_seq_buf[0] == '7') { -home_key: - 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: - redraw_step_forward = rl.line->len - rl.cursor_pos; - } else if (rl.escape_seq_buf[0] == '3') { - // delete -#if MICROPY_REPL_EMACS_KEYS -delete_key: -#endif - if (rl.cursor_pos < rl.line->len) { - vstr_cut_out_bytes(rl.line, rl.cursor_pos, 1); - redraw_from_cursor = true; - } - } else { - DEBUG_printf("(ESC [ %c %d)", rl.escape_seq_buf[0], c); - } - #if MICROPY_REPL_EMACS_EXTRA_WORDS_MOVE - } else if (c == ';' && rl.escape_seq_buf[0] == '1') { - // ';' is used to separate parameters. so first parameter was '1', - // that's used for sequences like ctrl+left, which we will try to parse. - // escape_seq state is reset back to ESEQ_ESC_BRACKET, as if we've just received - // the opening bracket, because more parameters are to come. - // we don't track the parameters themselves to keep low on logic and code size. that - // might be required in the future if more complex sequences are added. - rl.escape_seq = ESEQ_ESC_BRACKET; - // goto away from the state-machine, as rl.escape_seq will be overridden. - goto redraw; - } else if (rl.escape_seq_buf[0] == '5' && c == 'C') { - // ctrl+right - goto forward_word; - } else if (rl.escape_seq_buf[0] == '5' && c == 'D') { - // ctrl+left - goto backward_word; - #endif - } else { - DEBUG_printf("(ESC [ %c %d)", rl.escape_seq_buf[0], c); - } - rl.escape_seq = ESEQ_NONE; - } else if (rl.escape_seq == ESEQ_ESC_O) { - switch (c) { - case 'H': - goto home_key; - case 'F': - goto end_key; - default: - DEBUG_printf("(ESC O %d)", c); - rl.escape_seq = ESEQ_NONE; - } - } else { - rl.escape_seq = ESEQ_NONE; - } - -#if MICROPY_REPL_EMACS_EXTRA_WORDS_MOVE -redraw: -#endif - - // redraw command prompt, efficiently - if (redraw_step_back > 0) { - mp_hal_move_cursor_back(redraw_step_back); - rl.cursor_pos -= redraw_step_back; - } - if (redraw_from_cursor) { - if (rl.line->len < last_line_len) { - // erase old chars - mp_hal_erase_line_from_cursor(last_line_len - rl.cursor_pos); - } - // 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)); - rl.cursor_pos += redraw_step_forward; - } else if (redraw_step_forward > 0) { - // draw over old chars to move cursor forwards - mp_hal_stdout_tx_strn(rl.line->buf + rl.cursor_pos, redraw_step_forward); - rl.cursor_pos += redraw_step_forward; - } - - return -1; -} - -#if MICROPY_REPL_AUTO_INDENT -STATIC void readline_auto_indent(void) { - vstr_t *line = rl.line; - if (line->len > 1 && line->buf[line->len - 1] == '\n') { - int i; - for (i = line->len - 1; i > 0; i--) { - if (line->buf[i - 1] == '\n') { - break; - } - } - size_t j; - for (j = i; j < line->len; j++) { - if (line->buf[j] != ' ') { - break; - } - } - // i=start of line; j=first non-space - if (i > 0 && j + 1 == line->len) { - // previous line is not first line and is all spaces - for (size_t k = i - 1; k > 0; --k) { - if (line->buf[k - 1] == '\n') { - // don't auto-indent if last 2 lines are all spaces - return; - } else if (line->buf[k - 1] != ' ') { - // 2nd previous line is not all spaces - break; - } - } - } - int n = (j - i) / 4; - if (line->buf[line->len - 2] == ':') { - n += 1; - } - while (n-- > 0) { - vstr_add_strn(line, " ", 4); - mp_hal_stdout_tx_strn(" ", 4); - rl.cursor_pos += 4; - } - } -} -#endif - -void readline_note_newline(const char *prompt) { - rl.orig_line_len = rl.line->len; - rl.cursor_pos = rl.orig_line_len; - rl.prompt = prompt; - mp_hal_stdout_tx_str(prompt); - #if MICROPY_REPL_AUTO_INDENT - readline_auto_indent(); - #endif -} - -void readline_init(vstr_t *line, const char *prompt) { - rl.line = line; - rl.orig_line_len = line->len; - rl.escape_seq = ESEQ_NONE; - rl.escape_seq_buf[0] = 0; - rl.hist_cur = -1; - rl.cursor_pos = rl.orig_line_len; - rl.prompt = prompt; - mp_hal_stdout_tx_str(prompt); - #if MICROPY_REPL_AUTO_INDENT - readline_auto_indent(); - #endif -} - -int readline(vstr_t *line, const char *prompt) { - readline_init(line, prompt); - for (;;) { - int c = mp_hal_stdin_rx_chr(); - int r = readline_process_char(c); - if (r >= 0) { - return r; - } - } -} - -void readline_push_history(const char *line) { - if (line[0] != '\0' - && (MP_STATE_PORT(readline_hist)[0] == NULL - || strcmp(MP_STATE_PORT(readline_hist)[0], line) != 0)) { - // a line which is not empty and different from the last one - // so update the history - char *most_recent_hist = str_dup_maybe(line); - if (most_recent_hist != NULL) { - for (int i = READLINE_HIST_SIZE - 1; i > 0; i--) { - MP_STATE_PORT(readline_hist)[i] = MP_STATE_PORT(readline_hist)[i - 1]; - } - MP_STATE_PORT(readline_hist)[0] = most_recent_hist; - } - } -} diff --git a/lite-python/lib/mp-readline/readline.h b/lite-python/lib/mp-readline/readline.h deleted file mode 100755 index a19e1209ab7168102cf7e4b3717f595cef3cd0c0..0000000000000000000000000000000000000000 --- a/lite-python/lib/mp-readline/readline.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013, 2014 Damien P. George - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#ifndef MICROPY_INCLUDED_LIB_MP_READLINE_READLINE_H -#define MICROPY_INCLUDED_LIB_MP_READLINE_READLINE_H - -#define CHAR_CTRL_A (1) -#define CHAR_CTRL_B (2) -#define CHAR_CTRL_C (3) -#define CHAR_CTRL_D (4) -#define CHAR_CTRL_E (5) -#define CHAR_CTRL_F (6) -#define CHAR_CTRL_K (11) -#define CHAR_CTRL_N (14) -#define CHAR_CTRL_P (16) -#define CHAR_CTRL_U (21) -#define CHAR_CTRL_W (23) - -void readline_init0(void); -int readline(vstr_t *line, const char *prompt); -void readline_push_history(const char *line); - -void readline_init(vstr_t *line, const char *prompt); -void readline_note_newline(const char *prompt); -int readline_process_char(int c); - -#endif // MICROPY_INCLUDED_LIB_MP_READLINE_READLINE_H diff --git a/lite-python/lib/utils/gchelper.h b/lite-python/lib/utils/gchelper.h deleted file mode 100755 index 4b6ead6ba650fa9420520b2770dfea16c9666901..0000000000000000000000000000000000000000 --- a/lite-python/lib/utils/gchelper.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2019 Damien P. George - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#ifndef MICROPY_INCLUDED_LIB_UTILS_GCHELPER_H -#define MICROPY_INCLUDED_LIB_UTILS_GCHELPER_H - -#include - -#if MICROPY_GCREGS_SETJMP -#include -typedef jmp_buf gc_helper_regs_t; -#else - -#if defined(__x86_64__) -typedef uintptr_t gc_helper_regs_t[6]; -#elif defined(__i386__) -typedef uintptr_t gc_helper_regs_t[4]; -#elif defined(__thumb2__) || defined(__thumb__) || defined(__arm__) -typedef uintptr_t gc_helper_regs_t[10]; -#endif - -#endif - -void gc_helper_collect_regs_and_stack(void); - -#endif // MICROPY_INCLUDED_LIB_UTILS_GCHELPER_H diff --git a/lite-python/lib/utils/gchelper_generic.c b/lite-python/lib/utils/gchelper_generic.c deleted file mode 100755 index 9750e8b0c837ae058fa5434b084722c69f3e31f9..0000000000000000000000000000000000000000 --- a/lite-python/lib/utils/gchelper_generic.c +++ /dev/null @@ -1,156 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013, 2014 Damien P. George - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include - -#include "py/mpstate.h" -#include "py/gc.h" -#include "lib/utils/gchelper.h" - -#if MICROPY_ENABLE_GC - -// Even if we have specific support for an architecture, it is -// possible to force use of setjmp-based implementation. -#if !MICROPY_GCREGS_SETJMP - -// We capture here callee-save registers, i.e. ones which may contain -// interesting values held there by our callers. It doesn't make sense -// to capture caller-saved registers, because they, well, put on the -// stack already by the caller. -#if defined(__x86_64__) - -STATIC void gc_helper_get_regs(gc_helper_regs_t arr) { - register long rbx asm ("rbx"); - register long rbp asm ("rbp"); - register long r12 asm ("r12"); - register long r13 asm ("r13"); - register long r14 asm ("r14"); - register long r15 asm ("r15"); - #ifdef __clang__ - // TODO: - // This is dirty workaround for Clang. It tries to get around - // uncompliant (wrt to GCC) behavior of handling register variables. - // Application of this patch here is random, and done only to unbreak - // MacOS build. Better, cross-arch ways to deal with Clang issues should - // be found. - asm ("" : "=r" (rbx)); - asm ("" : "=r" (rbp)); - asm ("" : "=r" (r12)); - asm ("" : "=r" (r13)); - asm ("" : "=r" (r14)); - asm ("" : "=r" (r15)); - #endif - arr[0] = rbx; - arr[1] = rbp; - arr[2] = r12; - arr[3] = r13; - arr[4] = r14; - arr[5] = r15; -} - -#elif defined(__i386__) - -STATIC void gc_helper_get_regs(gc_helper_regs_t arr) { - register long ebx asm ("ebx"); - register long esi asm ("esi"); - register long edi asm ("edi"); - register long ebp asm ("ebp"); - #ifdef __clang__ - // TODO: - // This is dirty workaround for Clang. It tries to get around - // uncompliant (wrt to GCC) behavior of handling register variables. - // Application of this patch here is random, and done only to unbreak - // MacOS build. Better, cross-arch ways to deal with Clang issues should - // be found. - asm ("" : "=r" (ebx)); - asm ("" : "=r" (esi)); - asm ("" : "=r" (edi)); - asm ("" : "=r" (ebp)); - #endif - arr[0] = ebx; - arr[1] = esi; - arr[2] = edi; - arr[3] = ebp; -} - -#elif defined(__thumb2__) || defined(__thumb__) || defined(__arm__) - -// Fallback implementation, prefer gchelper_m0.s or gchelper_m3.s - -STATIC void gc_helper_get_regs(gc_helper_regs_t arr) { - register long r4 asm ("r4"); - register long r5 asm ("r5"); - register long r6 asm ("r6"); - register long r7 asm ("r7"); - register long r8 asm ("r8"); - register long r9 asm ("r9"); - register long r10 asm ("r10"); - register long r11 asm ("r11"); - register long r12 asm ("r12"); - register long r13 asm ("r13"); - arr[0] = r4; - arr[1] = r5; - arr[2] = r6; - arr[3] = r7; - arr[4] = r8; - arr[5] = r9; - arr[6] = r10; - arr[7] = r11; - arr[8] = r12; - arr[9] = r13; -} - -#else - -#error "Architecture not supported for gc_helper_get_regs. Set MICROPY_GCREGS_SETJMP to use the fallback implementation." - -#endif - -#else // !MICROPY_GCREGS_SETJMP - -// Even if we have specific support for an architecture, it is -// possible to force use of setjmp-based implementation. - -STATIC void gc_helper_get_regs(gc_helper_regs_t arr) { - setjmp(arr); -} - -#endif // MICROPY_GCREGS_SETJMP - -// Explicitly mark this as noinline to make sure the regs variable -// is effectively at the top of the stack: otherwise, in builds where -// LTO is enabled and a lot of inlining takes place we risk a stack -// layout where regs is lower on the stack than pointers which have -// just been allocated but not yet marked, and get incorrectly sweeped. -MP_NOINLINE void gc_helper_collect_regs_and_stack(void) { - gc_helper_regs_t regs; - gc_helper_get_regs(regs); - // GC stack (and regs because we captured them) - void **regs_ptr = (void **)(void *)®s; - gc_collect_root(regs_ptr, ((uintptr_t)MP_STATE_THREAD(stack_top) - (uintptr_t)®s) / sizeof(uintptr_t)); -} - -#endif // MICROPY_ENABLE_GC diff --git a/lite-python/lib/utils/gchelper_m0.s b/lite-python/lib/utils/gchelper_m0.s deleted file mode 100755 index db0d9738d160dac66d6c23d06468b78b974dc84e..0000000000000000000000000000000000000000 --- a/lite-python/lib/utils/gchelper_m0.s +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Damien P. George - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - - .syntax unified - .cpu cortex-m0 - .thumb - - .section .text - .align 2 - - .global gc_helper_get_regs_and_sp - .type gc_helper_get_regs_and_sp, %function - -@ uint gc_helper_get_regs_and_sp(r0=uint regs[10]) -gc_helper_get_regs_and_sp: - @ store registers into given array - str r4, [r0, #0] - str r5, [r0, #4] - str r6, [r0, #8] - str r7, [r0, #12] - mov r1, r8 - str r1, [r0, #16] - mov r1, r9 - str r1, [r0, #20] - mov r1, r10 - str r1, [r0, #24] - mov r1, r11 - str r1, [r0, #28] - mov r1, r12 - str r1, [r0, #32] - mov r1, r13 - str r1, [r0, #36] - - @ return the sp - mov r0, sp - bx lr - - .size gc_helper_get_regs_and_sp, .-gc_helper_get_regs_and_sp diff --git a/lite-python/lib/utils/gchelper_m3.s b/lite-python/lib/utils/gchelper_m3.s deleted file mode 100755 index 5220fa088360a6ff700a8ef88d80179189223863..0000000000000000000000000000000000000000 --- a/lite-python/lib/utils/gchelper_m3.s +++ /dev/null @@ -1,55 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013-2014 Damien P. George - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - - .syntax unified - .cpu cortex-m3 - .thumb - - .section .text - .align 2 - - .global gc_helper_get_regs_and_sp - .type gc_helper_get_regs_and_sp, %function - -@ uint gc_helper_get_regs_and_sp(r0=uint regs[10]) -gc_helper_get_regs_and_sp: - @ store registers into given array - str r4, [r0], #4 - str r5, [r0], #4 - str r6, [r0], #4 - str r7, [r0], #4 - str r8, [r0], #4 - str r9, [r0], #4 - str r10, [r0], #4 - str r11, [r0], #4 - str r12, [r0], #4 - str r13, [r0], #4 - - @ return the sp - mov r0, sp - bx lr - - .size gc_helper_get_regs_and_sp, .-gc_helper_get_regs_and_sp diff --git a/lite-python/lib/utils/gchelper_native.c b/lite-python/lib/utils/gchelper_native.c deleted file mode 100755 index 6bf386b5192b872836d2146af2b17c73e060a4b2..0000000000000000000000000000000000000000 --- a/lite-python/lib/utils/gchelper_native.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013, 2014 Damien P. George - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include - -#include "py/mpstate.h" -#include "py/gc.h" -#include "lib/utils/gchelper.h" - -#if MICROPY_ENABLE_GC - -// provided by gchelper_*.s -uintptr_t gc_helper_get_regs_and_sp(uintptr_t *regs); - -MP_NOINLINE void gc_helper_collect_regs_and_stack(void) { - // get the registers and the sp - gc_helper_regs_t regs; - uintptr_t sp = gc_helper_get_regs_and_sp(regs); - - // trace the stack, including the registers (since they live on the stack in this function) - gc_collect_root((void **)sp, ((uint32_t)MP_STATE_THREAD(stack_top) - sp) / sizeof(uint32_t)); -} - -#endif diff --git a/lite-python/lib/utils/interrupt_char.c b/lite-python/lib/utils/interrupt_char.c deleted file mode 100755 index 7014ae6a8fc4460a59f0d96a9f60e02b79bc522b..0000000000000000000000000000000000000000 --- a/lite-python/lib/utils/interrupt_char.c +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013-2016 Damien P. George - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "py/obj.h" -#include "py/mpstate.h" - -#if MICROPY_KBD_EXCEPTION - -int mp_interrupt_char = -1; - -void mp_hal_set_interrupt_char(int c) { - mp_interrupt_char = c; -} - -#endif diff --git a/lite-python/lib/utils/interrupt_char.h b/lite-python/lib/utils/interrupt_char.h deleted file mode 100755 index cb086ead9287e7aa5d042f968aa6e448aab52ae4..0000000000000000000000000000000000000000 --- a/lite-python/lib/utils/interrupt_char.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013-2016 Damien P. George - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#ifndef MICROPY_INCLUDED_LIB_UTILS_INTERRUPT_CHAR_H -#define MICROPY_INCLUDED_LIB_UTILS_INTERRUPT_CHAR_H - -extern int mp_interrupt_char; -void mp_hal_set_interrupt_char(int c); - -#endif // MICROPY_INCLUDED_LIB_UTILS_INTERRUPT_CHAR_H diff --git a/lite-python/lib/utils/mpirq.c b/lite-python/lib/utils/mpirq.c deleted file mode 100755 index 663be182248ccdcc5ab28875a84368eb472cf124..0000000000000000000000000000000000000000 --- a/lite-python/lib/utils/mpirq.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2015 Daniel Campora - * 2018 Tobias Badertscher - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include - -#include "py/runtime.h" -#include "py/gc.h" -#include "lib/utils/mpirq.h" - -#if MICROPY_ENABLE_SCHEDULER - -/****************************************************************************** - DECLARE PUBLIC DATA - ******************************************************************************/ - -const mp_arg_t mp_irq_init_args[] = { - { MP_QSTR_handler, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, - { MP_QSTR_trigger, MP_ARG_INT, {.u_int = 0} }, - { MP_QSTR_hard, MP_ARG_BOOL, {.u_bool = false} }, -}; - -/****************************************************************************** - DECLARE PRIVATE DATA - ******************************************************************************/ - -/****************************************************************************** - DEFINE PUBLIC FUNCTIONS - ******************************************************************************/ - -mp_irq_obj_t *mp_irq_new(const mp_irq_methods_t *methods, mp_obj_t parent) { - mp_irq_obj_t *self = m_new0(mp_irq_obj_t, 1); - self->base.type = &mp_irq_type; - self->methods = (mp_irq_methods_t *)methods; - self->parent = parent; - self->handler = mp_const_none; - self->ishard = false; - return self; -} - -void mp_irq_handler(mp_irq_obj_t *self) { - if (self->handler != mp_const_none) { - if (self->ishard) { - // When executing code within a handler we must lock the scheduler to - // prevent any scheduled callbacks from running, and lock the GC to - // prevent any memory allocations. - mp_sched_lock(); - gc_lock(); - nlr_buf_t nlr; - if (nlr_push(&nlr) == 0) { - mp_call_function_1(self->handler, self->parent); - nlr_pop(); - } else { - // Uncaught exception; disable the callback so that it doesn't run again - self->methods->trigger(self->parent, 0); - self->handler = mp_const_none; - printf("Uncaught exception in IRQ callback handler\n"); - mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val)); - } - gc_unlock(); - mp_sched_unlock(); - } else { - // Schedule call to user function - mp_sched_schedule(self->handler, self->parent); - } - } -} - -/******************************************************************************/ -// MicroPython bindings - -STATIC mp_obj_t mp_irq_flags(mp_obj_t self_in) { - mp_irq_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_int(self->methods->info(self->parent, MP_IRQ_INFO_FLAGS)); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_irq_flags_obj, mp_irq_flags); - -STATIC mp_obj_t mp_irq_trigger(size_t n_args, const mp_obj_t *args) { - mp_irq_obj_t *self = MP_OBJ_TO_PTR(args[0]); - mp_obj_t ret_obj = mp_obj_new_int(self->methods->info(self->parent, MP_IRQ_INFO_TRIGGERS)); - if (n_args == 2) { - // Set trigger - self->methods->trigger(self->parent, mp_obj_get_int(args[1])); - } - return ret_obj; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_irq_trigger_obj, 1, 2, mp_irq_trigger); - -STATIC mp_obj_t mp_irq_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { - mp_arg_check_num(n_args, n_kw, 0, 0, false); - mp_irq_handler(MP_OBJ_TO_PTR(self_in)); - return mp_const_none; -} - -STATIC const mp_rom_map_elem_t mp_irq_locals_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_flags), MP_ROM_PTR(&mp_irq_flags_obj) }, - { MP_ROM_QSTR(MP_QSTR_trigger), MP_ROM_PTR(&mp_irq_trigger_obj) }, -}; -STATIC MP_DEFINE_CONST_DICT(mp_irq_locals_dict, mp_irq_locals_dict_table); - -const mp_obj_type_t mp_irq_type = { - { &mp_type_type }, - .name = MP_QSTR_irq, - .call = mp_irq_call, - .locals_dict = (mp_obj_dict_t *)&mp_irq_locals_dict, -}; - -#endif // MICROPY_ENABLE_SCHEDULER diff --git a/lite-python/lib/utils/mpirq.h b/lite-python/lib/utils/mpirq.h deleted file mode 100755 index 548185b531147f8523736e01eb271291729e3479..0000000000000000000000000000000000000000 --- a/lite-python/lib/utils/mpirq.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2015 Daniel Campora - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#ifndef MICROPY_INCLUDED_LIB_UTILS_MPIRQ_H -#define MICROPY_INCLUDED_LIB_UTILS_MPIRQ_H - -/****************************************************************************** - DEFINE CONSTANTS - ******************************************************************************/ - -enum { - MP_IRQ_ARG_INIT_handler = 0, - MP_IRQ_ARG_INIT_trigger, - MP_IRQ_ARG_INIT_hard, - MP_IRQ_ARG_INIT_NUM_ARGS, -}; - -/****************************************************************************** - DEFINE TYPES - ******************************************************************************/ - -typedef mp_obj_t (*mp_irq_init_t)(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args); -typedef mp_uint_t (*mp_irq_uint_method_one_uint_para_t)(mp_obj_t self, mp_uint_t trigger); -typedef mp_uint_t (*mp_irq_int_method_one_para_t)(mp_obj_t self, mp_uint_t info_type); - -enum { - MP_IRQ_INFO_FLAGS, - MP_IRQ_INFO_TRIGGERS, - MP_IRQ_INFO_CNT -}; - -typedef struct _mp_irq_methods_t { - mp_irq_init_t init; - mp_irq_uint_method_one_uint_para_t trigger; - mp_irq_int_method_one_para_t info; -} mp_irq_methods_t; - -typedef struct _mp_irq_obj_t { - mp_obj_base_t base; - mp_irq_methods_t *methods; - mp_obj_t parent; - mp_obj_t handler; - bool ishard; -} mp_irq_obj_t; - -/****************************************************************************** - DECLARE EXPORTED DATA - ******************************************************************************/ - -extern const mp_arg_t mp_irq_init_args[]; -extern const mp_obj_type_t mp_irq_type; - -/****************************************************************************** - DECLARE PUBLIC FUNCTIONS - ******************************************************************************/ - -mp_irq_obj_t *mp_irq_new(const mp_irq_methods_t *methods, mp_obj_t parent); -void mp_irq_handler(mp_irq_obj_t *self); - -#endif // MICROPY_INCLUDED_LIB_UTILS_MPIRQ_H diff --git a/lite-python/lib/utils/printf.c b/lite-python/lib/utils/printf.c deleted file mode 100755 index e8db2b999c1237280ca488979c34f83f3a9f08ab..0000000000000000000000000000000000000000 --- a/lite-python/lib/utils/printf.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013, 2014 Damien P. George - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "py/mpconfig.h" - -#include -#include -#include - -#include "py/obj.h" -#include "py/mphal.h" - -#if MICROPY_PY_BUILTINS_FLOAT -#include "py/formatfloat.h" -#endif - -#if MICROPY_DEBUG_PRINTERS -int DEBUG_printf(const char *fmt, ...) { - va_list ap; - va_start(ap, fmt); - int ret = mp_vprintf(MICROPY_DEBUG_PRINTER, fmt, ap); - va_end(ap); - return ret; -} -#endif - -#if MICROPY_USE_INTERNAL_PRINTF - -#undef putchar // Some stdlibs have a #define for putchar -int printf(const char *fmt, ...); -int vprintf(const char *fmt, va_list ap); -int putchar(int c); -int puts(const char *s); -int vsnprintf(char *str, size_t size, const char *fmt, va_list ap); -int snprintf(char *str, size_t size, const char *fmt, ...); - -int printf(const char *fmt, ...) { - va_list ap; - va_start(ap, fmt); - int ret = mp_vprintf(&mp_plat_print, fmt, ap); - va_end(ap); - return ret; -} - -int vprintf(const char *fmt, va_list ap) { - return mp_vprintf(&mp_plat_print, fmt, ap); -} - -// need this because gcc optimises printf("%c", c) -> putchar(c), and printf("a") -> putchar('a') -int putchar(int c) { - char chr = c; - mp_hal_stdout_tx_strn_cooked(&chr, 1); - return chr; -} - -// need this because gcc optimises printf("string\n") -> puts("string") -int puts(const char *s) { - mp_hal_stdout_tx_strn_cooked(s, strlen(s)); - char chr = '\n'; - mp_hal_stdout_tx_strn_cooked(&chr, 1); - return 1; -} - -typedef struct _strn_print_env_t { - char *cur; - size_t remain; -} strn_print_env_t; - -STATIC void strn_print_strn(void *data, const char *str, size_t len) { - strn_print_env_t *strn_print_env = data; - if (len > strn_print_env->remain) { - len = strn_print_env->remain; - } - memcpy(strn_print_env->cur, str, len); - strn_print_env->cur += len; - strn_print_env->remain -= len; -} - -#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 9 -// uClibc requires this alias to be defined, or there may be link errors -// when linkings against it statically. -// GCC 9 gives a warning about missing attributes so it's excluded until -// uClibc+GCC9 support is needed. -int __GI_vsnprintf(char *str, size_t size, const char *fmt, va_list ap) __attribute__((weak, alias("vsnprintf"))); -#endif - -int vsnprintf(char *str, size_t size, const char *fmt, va_list ap) { - strn_print_env_t strn_print_env = {str, size}; - mp_print_t print = {&strn_print_env, strn_print_strn}; - int len = mp_vprintf(&print, fmt, ap); - // add terminating null byte - if (size > 0) { - if (strn_print_env.remain == 0) { - strn_print_env.cur[-1] = 0; - } else { - strn_print_env.cur[0] = 0; - } - } - return len; -} - -int snprintf(char *str, size_t size, const char *fmt, ...) { - va_list ap; - va_start(ap, fmt); - int ret = vsnprintf(str, size, fmt, ap); - va_end(ap); - return ret; -} - -#endif // MICROPY_USE_INTERNAL_PRINTF diff --git a/lite-python/lib/utils/pyexec.c b/lite-python/lib/utils/pyexec.c deleted file mode 100755 index 2c8ca2de0cecc83d1fe25eacbcbfa2e7b0a3c9f7..0000000000000000000000000000000000000000 --- a/lite-python/lib/utils/pyexec.c +++ /dev/null @@ -1,595 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013, 2014 Damien P. George - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include -#include -#include -#include - -#include "py/compile.h" -#include "py/runtime.h" -#include "py/repl.h" -#include "py/gc.h" -#include "py/frozenmod.h" -#include "py/mphal.h" -#if MICROPY_HW_ENABLE_USB -#include "irq.h" -#include "usb.h" -#endif -#include "lib/mp-readline/readline.h" -#include "lib/utils/pyexec.h" -#include "genhdr/mpversion.h" - -pyexec_mode_kind_t pyexec_mode_kind = PYEXEC_MODE_FRIENDLY_REPL; -int pyexec_system_exit = 0; - -#if MICROPY_REPL_INFO -STATIC bool repl_display_debugging_info = 0; -#endif - -#define EXEC_FLAG_PRINT_EOF (1) -#define EXEC_FLAG_ALLOW_DEBUGGING (2) -#define EXEC_FLAG_IS_REPL (4) -#define EXEC_FLAG_SOURCE_IS_RAW_CODE (8) -#define EXEC_FLAG_SOURCE_IS_VSTR (16) -#define EXEC_FLAG_SOURCE_IS_FILENAME (32) - -// parses, compiles and executes the code in the lexer -// frees the lexer before returning -// EXEC_FLAG_PRINT_EOF prints 2 EOF chars: 1 after normal output, 1 after exception output -// EXEC_FLAG_ALLOW_DEBUGGING allows debugging info to be printed after executing the code -// EXEC_FLAG_IS_REPL is used for REPL inputs (flag passed on to mp_compile) -STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input_kind, int exec_flags) { - int ret = 0; - #if MICROPY_REPL_INFO - uint32_t start = 0; - #endif - - // by default a SystemExit exception returns 0 - pyexec_system_exit = 0; - - nlr_buf_t nlr; - if (nlr_push(&nlr) == 0) { - mp_obj_t module_fun; - #if MICROPY_MODULE_FROZEN_MPY - if (exec_flags & EXEC_FLAG_SOURCE_IS_RAW_CODE) { - // source is a raw_code object, create the function - module_fun = mp_make_function_from_raw_code(source, MP_OBJ_NULL, MP_OBJ_NULL); - } else - #endif - { - #if MICROPY_ENABLE_COMPILER - mp_lexer_t *lex; - if (exec_flags & EXEC_FLAG_SOURCE_IS_VSTR) { - const vstr_t *vstr = source; - lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, vstr->buf, vstr->len, 0); - } else if (exec_flags & EXEC_FLAG_SOURCE_IS_FILENAME) { - lex = mp_lexer_new_from_file(source); - } else { - lex = (mp_lexer_t *)source; - } - // source is a lexer, parse and compile the script - qstr source_name = lex->source_name; - mp_parse_tree_t parse_tree = mp_parse(lex, input_kind); - module_fun = mp_compile(&parse_tree, source_name, exec_flags & EXEC_FLAG_IS_REPL); - #else - mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("script compilation not supported")); - #endif - } - - // execute code - mp_hal_set_interrupt_char(CHAR_CTRL_C); // allow ctrl-C to interrupt us - #if MICROPY_REPL_INFO - start = mp_hal_ticks_ms(); - #endif - mp_call_function_0(module_fun); - mp_hal_set_interrupt_char(-1); // disable interrupt - mp_handle_pending(true); // handle any pending exceptions (and any callbacks) - nlr_pop(); - ret = 1; - if (exec_flags & EXEC_FLAG_PRINT_EOF) { - mp_hal_stdout_tx_strn("\x04", 1); - } - } else { - // uncaught exception - mp_hal_set_interrupt_char(-1); // disable interrupt - mp_handle_pending(false); // clear any pending exceptions (and run any callbacks) - // print EOF after normal output - if (exec_flags & EXEC_FLAG_PRINT_EOF) { - mp_hal_stdout_tx_strn("\x04", 1); - } - // check for SystemExit - if (mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(((mp_obj_base_t *)nlr.ret_val)->type), MP_OBJ_FROM_PTR(&mp_type_SystemExit))) { - // at the moment, the value of SystemExit is unused - ret = pyexec_system_exit; - } else { - mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val)); - ret = 0; - } - } - - #if MICROPY_REPL_INFO - // display debugging info if wanted - if ((exec_flags & EXEC_FLAG_ALLOW_DEBUGGING) && repl_display_debugging_info) { - mp_uint_t ticks = mp_hal_ticks_ms() - start; // TODO implement a function that does this properly - printf("took " UINT_FMT " ms\n", ticks); - // qstr info - { - size_t n_pool, n_qstr, n_str_data_bytes, n_total_bytes; - qstr_pool_info(&n_pool, &n_qstr, &n_str_data_bytes, &n_total_bytes); - printf("qstr:\n n_pool=%u\n n_qstr=%u\n " - "n_str_data_bytes=%u\n n_total_bytes=%u\n", - (unsigned)n_pool, (unsigned)n_qstr, (unsigned)n_str_data_bytes, (unsigned)n_total_bytes); - } - - #if MICROPY_ENABLE_GC - // run collection and print GC info - gc_collect(); - gc_dump_info(); - #endif - } - #endif - - if (exec_flags & EXEC_FLAG_PRINT_EOF) { - mp_hal_stdout_tx_strn("\x04", 1); - } - - return ret; -} - -#if MICROPY_ENABLE_COMPILER -#if MICROPY_REPL_EVENT_DRIVEN - -typedef struct _repl_t { - // This structure originally also held current REPL line, - // but it was moved to MP_STATE_VM(repl_line) as containing - // root pointer. Still keep structure in case more state - // will be added later. - // vstr_t line; - bool cont_line; - bool paste_mode; -} repl_t; - -repl_t repl; - -STATIC int pyexec_raw_repl_process_char(int c); -STATIC int pyexec_friendly_repl_process_char(int c); - -void pyexec_event_repl_init(void) { - MP_STATE_VM(repl_line) = vstr_new(32); - repl.cont_line = false; - repl.paste_mode = false; - // no prompt before printing friendly REPL banner or entering raw REPL - readline_init(MP_STATE_VM(repl_line), ""); - if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) { - pyexec_raw_repl_process_char(CHAR_CTRL_A); - } else { - pyexec_friendly_repl_process_char(CHAR_CTRL_B); - } -} - -STATIC int pyexec_raw_repl_process_char(int c) { - if (c == CHAR_CTRL_A) { - // reset raw REPL - mp_hal_stdout_tx_str("raw REPL; CTRL-B to exit\r\n"); - goto reset; - } else if (c == CHAR_CTRL_B) { - // change to friendly REPL - pyexec_mode_kind = PYEXEC_MODE_FRIENDLY_REPL; - vstr_reset(MP_STATE_VM(repl_line)); - repl.cont_line = false; - repl.paste_mode = false; - pyexec_friendly_repl_process_char(CHAR_CTRL_B); - return 0; - } else if (c == CHAR_CTRL_C) { - // clear line - vstr_reset(MP_STATE_VM(repl_line)); - return 0; - } else if (c == CHAR_CTRL_D) { - // input finished - } else { - // let through any other raw 8-bit value - vstr_add_byte(MP_STATE_VM(repl_line), c); - return 0; - } - - // indicate reception of command - mp_hal_stdout_tx_str("OK"); - - if (MP_STATE_VM(repl_line)->len == 0) { - // exit for a soft reset - mp_hal_stdout_tx_str("\r\n"); - vstr_clear(MP_STATE_VM(repl_line)); - return PYEXEC_FORCED_EXIT; - } - - int ret = parse_compile_execute(MP_STATE_VM(repl_line), MP_PARSE_FILE_INPUT, EXEC_FLAG_PRINT_EOF | EXEC_FLAG_SOURCE_IS_VSTR); - if (ret & PYEXEC_FORCED_EXIT) { - return ret; - } - -reset: - vstr_reset(MP_STATE_VM(repl_line)); - mp_hal_stdout_tx_str(">"); - - return 0; -} - -STATIC int pyexec_friendly_repl_process_char(int c) { - if (repl.paste_mode) { - if (c == CHAR_CTRL_C) { - // cancel everything - mp_hal_stdout_tx_str("\r\n"); - goto input_restart; - } else if (c == CHAR_CTRL_D) { - // end of input - mp_hal_stdout_tx_str("\r\n"); - int ret = parse_compile_execute(MP_STATE_VM(repl_line), MP_PARSE_FILE_INPUT, EXEC_FLAG_ALLOW_DEBUGGING | EXEC_FLAG_IS_REPL | EXEC_FLAG_SOURCE_IS_VSTR); - if (ret & PYEXEC_FORCED_EXIT) { - return ret; - } - goto input_restart; - } else { - // add char to buffer and echo - vstr_add_byte(MP_STATE_VM(repl_line), c); - if (c == '\r') { - mp_hal_stdout_tx_str("\r\n=== "); - } else { - char buf[1] = {c}; - mp_hal_stdout_tx_strn(buf, 1); - } - return 0; - } - } - - int ret = readline_process_char(c); - - if (!repl.cont_line) { - - if (ret == CHAR_CTRL_A) { - // change to raw REPL - pyexec_mode_kind = PYEXEC_MODE_RAW_REPL; - mp_hal_stdout_tx_str("\r\n"); - pyexec_raw_repl_process_char(CHAR_CTRL_A); - return 0; - } else if (ret == CHAR_CTRL_B) { - // reset friendly REPL - mp_hal_stdout_tx_str("\r\n"); - mp_hal_stdout_tx_str("MicroPython " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE "; " MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME "\r\n"); - #if MICROPY_PY_BUILTINS_HELP - mp_hal_stdout_tx_str("Type \"help()\" for more information.\r\n"); - #endif - goto input_restart; - } else if (ret == CHAR_CTRL_C) { - // break - mp_hal_stdout_tx_str("\r\n"); - goto input_restart; - } else if (ret == CHAR_CTRL_D) { - // exit for a soft reset - mp_hal_stdout_tx_str("\r\n"); - vstr_clear(MP_STATE_VM(repl_line)); - return PYEXEC_FORCED_EXIT; - } else if (ret == CHAR_CTRL_E) { - // paste mode - mp_hal_stdout_tx_str("\r\npaste mode; Ctrl-C to cancel, Ctrl-D to finish\r\n=== "); - vstr_reset(MP_STATE_VM(repl_line)); - repl.paste_mode = true; - return 0; - } - - if (ret < 0) { - return 0; - } - - if (!mp_repl_continue_with_input(vstr_null_terminated_str(MP_STATE_VM(repl_line)))) { - goto exec; - } - - vstr_add_byte(MP_STATE_VM(repl_line), '\n'); - repl.cont_line = true; - readline_note_newline("... "); - return 0; - - } else { - - if (ret == CHAR_CTRL_C) { - // cancel everything - mp_hal_stdout_tx_str("\r\n"); - repl.cont_line = false; - goto input_restart; - } else if (ret == CHAR_CTRL_D) { - // stop entering compound statement - goto exec; - } - - if (ret < 0) { - return 0; - } - - if (mp_repl_continue_with_input(vstr_null_terminated_str(MP_STATE_VM(repl_line)))) { - vstr_add_byte(MP_STATE_VM(repl_line), '\n'); - readline_note_newline("... "); - return 0; - } - - exec:; - int ret = parse_compile_execute(MP_STATE_VM(repl_line), MP_PARSE_SINGLE_INPUT, EXEC_FLAG_ALLOW_DEBUGGING | EXEC_FLAG_IS_REPL | EXEC_FLAG_SOURCE_IS_VSTR); - if (ret & PYEXEC_FORCED_EXIT) { - return ret; - } - - input_restart: - vstr_reset(MP_STATE_VM(repl_line)); - repl.cont_line = false; - repl.paste_mode = false; - readline_init(MP_STATE_VM(repl_line), ">>> "); - return 0; - } -} - -uint8_t pyexec_repl_active; -int pyexec_event_repl_process_char(int c) { - pyexec_repl_active = 1; - int res; - if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) { - res = pyexec_raw_repl_process_char(c); - } else { - res = pyexec_friendly_repl_process_char(c); - } - pyexec_repl_active = 0; - return res; -} - -#else // MICROPY_REPL_EVENT_DRIVEN - -int pyexec_raw_repl(void) { - vstr_t line; - vstr_init(&line, 32); - -raw_repl_reset: - mp_hal_stdout_tx_str("raw REPL; CTRL-B to exit\r\n"); - - for (;;) { - vstr_reset(&line); - mp_hal_stdout_tx_str(">"); - for (;;) { - int c = mp_hal_stdin_rx_chr(); - if (c == CHAR_CTRL_A) { - // reset raw REPL - goto raw_repl_reset; - } else if (c == CHAR_CTRL_B) { - // change to friendly REPL - mp_hal_stdout_tx_str("\r\n"); - vstr_clear(&line); - pyexec_mode_kind = PYEXEC_MODE_FRIENDLY_REPL; - return 0; - } else if (c == CHAR_CTRL_C) { - // clear line - vstr_reset(&line); - } else if (c == CHAR_CTRL_D) { - // input finished - break; - } else { - // let through any other raw 8-bit value - vstr_add_byte(&line, c); - } - } - - // indicate reception of command - mp_hal_stdout_tx_str("OK"); - - if (line.len == 0) { - // exit for a soft reset - mp_hal_stdout_tx_str("\r\n"); - vstr_clear(&line); - return PYEXEC_FORCED_EXIT; - } - - int ret = parse_compile_execute(&line, MP_PARSE_FILE_INPUT, EXEC_FLAG_PRINT_EOF | EXEC_FLAG_SOURCE_IS_VSTR); - if (ret & PYEXEC_FORCED_EXIT) { - return ret; - } - } -} - -int pyexec_friendly_repl(void) { - vstr_t line; - vstr_init(&line, 32); - - #if defined(USE_HOST_MODE) && MICROPY_HW_HAS_LCD - // in host mode, we enable the LCD for the repl - mp_obj_t lcd_o = mp_call_function_0(mp_load_name(qstr_from_str("LCD"))); - mp_call_function_1(mp_load_attr(lcd_o, qstr_from_str("light")), mp_const_true); - #endif - -friendly_repl_reset: - mp_hal_stdout_tx_str("MicroPython " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE "; " MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME "\r\n"); - #if MICROPY_PY_BUILTINS_HELP - mp_hal_stdout_tx_str("Type \"help()\" for more information.\r\n"); - #endif - - // to test ctrl-C - /* - { - uint32_t x[4] = {0x424242, 0xdeaddead, 0x242424, 0xdeadbeef}; - for (;;) { - nlr_buf_t nlr; - printf("pyexec_repl: %p\n", x); - mp_hal_set_interrupt_char(CHAR_CTRL_C); - if (nlr_push(&nlr) == 0) { - for (;;) { - } - } else { - printf("break\n"); - } - } - } - */ - - for (;;) { - input_restart: - - #if MICROPY_HW_ENABLE_USB - if (usb_vcp_is_enabled()) { - // If the user gets to here and interrupts are disabled then - // they'll never see the prompt, traceback etc. The USB REPL needs - // interrupts to be enabled or no transfers occur. So we try to - // do the user a favor and reenable interrupts. - if (query_irq() == IRQ_STATE_DISABLED) { - enable_irq(IRQ_STATE_ENABLED); - mp_hal_stdout_tx_str("MPY: enabling IRQs\r\n"); - } - } - #endif - - // If the GC is locked at this point there is no way out except a reset, - // so force the GC to be unlocked to help the user debug what went wrong. - if (MP_STATE_MEM(gc_lock_depth) != 0) { - MP_STATE_MEM(gc_lock_depth) = 0; - } - - vstr_reset(&line); - int ret = readline(&line, ">>> "); - mp_parse_input_kind_t parse_input_kind = MP_PARSE_SINGLE_INPUT; - - if (ret == CHAR_CTRL_A) { - // change to raw REPL - mp_hal_stdout_tx_str("\r\n"); - vstr_clear(&line); - pyexec_mode_kind = PYEXEC_MODE_RAW_REPL; - return 0; - } else if (ret == CHAR_CTRL_B) { - // reset friendly REPL - mp_hal_stdout_tx_str("\r\n"); - goto friendly_repl_reset; - } else if (ret == CHAR_CTRL_C) { - // break - mp_hal_stdout_tx_str("\r\n"); - continue; - } else if (ret == CHAR_CTRL_D) { - // exit for a soft reset - mp_hal_stdout_tx_str("\r\n"); - vstr_clear(&line); - return PYEXEC_FORCED_EXIT; - } else if (ret == CHAR_CTRL_E) { - // paste mode - mp_hal_stdout_tx_str("\r\npaste mode; Ctrl-C to cancel, Ctrl-D to finish\r\n=== "); - vstr_reset(&line); - for (;;) { - char c = mp_hal_stdin_rx_chr(); - if (c == CHAR_CTRL_C) { - // cancel everything - mp_hal_stdout_tx_str("\r\n"); - goto input_restart; - } else if (c == CHAR_CTRL_D) { - // end of input - mp_hal_stdout_tx_str("\r\n"); - break; - } else { - // add char to buffer and echo - vstr_add_byte(&line, c); - if (c == '\r') { - mp_hal_stdout_tx_str("\r\n=== "); - } else { - mp_hal_stdout_tx_strn(&c, 1); - } - } - } - parse_input_kind = MP_PARSE_FILE_INPUT; - } else if (vstr_len(&line) == 0) { - continue; - } 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, "... "); - if (ret == CHAR_CTRL_C) { - // cancel everything - mp_hal_stdout_tx_str("\r\n"); - goto input_restart; - } else if (ret == CHAR_CTRL_D) { - // stop entering compound statement - break; - } - } - } - - ret = parse_compile_execute(&line, parse_input_kind, EXEC_FLAG_ALLOW_DEBUGGING | EXEC_FLAG_IS_REPL | EXEC_FLAG_SOURCE_IS_VSTR); - if (ret & PYEXEC_FORCED_EXIT) { - return ret; - } - } -} - -#endif // MICROPY_REPL_EVENT_DRIVEN -#endif // MICROPY_ENABLE_COMPILER - -int pyexec_file(const char *filename) { - return parse_compile_execute(filename, MP_PARSE_FILE_INPUT, EXEC_FLAG_SOURCE_IS_FILENAME); -} - -int pyexec_file_if_exists(const char *filename) { - #if MICROPY_MODULE_FROZEN - if (mp_frozen_stat(filename) == MP_IMPORT_STAT_FILE) { - return pyexec_frozen_module(filename); - } - #endif - if (mp_import_stat(filename) != MP_IMPORT_STAT_FILE) { - return 1; // success (no file is the same as an empty file executing without fail) - } - return pyexec_file(filename); -} - -#if MICROPY_MODULE_FROZEN -int pyexec_frozen_module(const char *name) { - void *frozen_data; - int frozen_type = mp_find_frozen_module(name, strlen(name), &frozen_data); - - switch (frozen_type) { - #if MICROPY_MODULE_FROZEN_STR - case MP_FROZEN_STR: - return parse_compile_execute(frozen_data, MP_PARSE_FILE_INPUT, 0); - #endif - - #if MICROPY_MODULE_FROZEN_MPY - case MP_FROZEN_MPY: - return parse_compile_execute(frozen_data, MP_PARSE_FILE_INPUT, EXEC_FLAG_SOURCE_IS_RAW_CODE); - #endif - - default: - printf("could not find module '%s'\n", name); - return false; - } -} -#endif - -#if MICROPY_REPL_INFO -mp_obj_t pyb_set_repl_info(mp_obj_t o_value) { - repl_display_debugging_info = mp_obj_get_int(o_value); - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_1(pyb_set_repl_info_obj, pyb_set_repl_info); -#endif diff --git a/lite-python/lib/utils/pyexec.h b/lite-python/lib/utils/pyexec.h deleted file mode 100755 index f69c5ce9a884eb23fd1923da43497bdfd4e43779..0000000000000000000000000000000000000000 --- a/lite-python/lib/utils/pyexec.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013, 2014 Damien P. George - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#ifndef MICROPY_INCLUDED_LIB_UTILS_PYEXEC_H -#define MICROPY_INCLUDED_LIB_UTILS_PYEXEC_H - -#include "py/obj.h" - -typedef enum { - PYEXEC_MODE_FRIENDLY_REPL, - PYEXEC_MODE_RAW_REPL, -} pyexec_mode_kind_t; - -extern pyexec_mode_kind_t pyexec_mode_kind; - -// Set this to the value (eg PYEXEC_FORCED_EXIT) that will be propagated through -// the pyexec functions if a SystemExit exception is raised by the running code. -// It will reset to 0 at the start of each execution (eg each REPL entry). -extern int pyexec_system_exit; - -#define PYEXEC_FORCED_EXIT (0x100) -#define PYEXEC_SWITCH_MODE (0x200) - -int pyexec_raw_repl(void); -int pyexec_friendly_repl(void); -int pyexec_file(const char *filename); -int pyexec_file_if_exists(const char *filename); -int pyexec_frozen_module(const char *name); -void pyexec_event_repl_init(void); -int pyexec_event_repl_process_char(int c); -extern uint8_t pyexec_repl_active; - -#if MICROPY_REPL_INFO -mp_obj_t pyb_set_repl_info(mp_obj_t o_value); -MP_DECLARE_CONST_FUN_OBJ_1(pyb_set_repl_info_obj); -#endif - -#endif // MICROPY_INCLUDED_LIB_UTILS_PYEXEC_H diff --git a/lite-python/lib/utils/stdout.c b/lite-python/lib/utils/stdout.c new file mode 100755 index 0000000000000000000000000000000000000000..87e730c3241962c20b9872e43311411f3f6105e5 --- /dev/null +++ b/lite-python/lib/utils/stdout.c @@ -0,0 +1,69 @@ +/**************************************************************************** + +MIT License + +Copyright (c) 2021 唐佐林 +WeChat : delphi_tang +EMail: delphi_tang@dt4sw.com + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*****************************************************************************/ + +#include +#include +#include +#include "py/mpconfig.h" +#include "py/mphal.h" + +static void mp_hal_stdout_print_native(const char* str, size_t len) +{ + int i = 0; + + while( i < len ) + { + if( str[i] == '\r' ) + { + putchar('\r'); + putchar('\n'); + + if( (str[i+1] == '\n') || (str[i+1] == '\0') ) + { + i++; + } + } + else if( str[i] == '\n' ) + { + putchar('\r'); + putchar('\n'); + } + else + { + putchar(str[i]); + } + + i++; + } +} + +void mp_hal_stdout_tx_strn_cooked(const char* str, size_t len) +{ + mp_hal_stdout_print_native(str, len); +} + diff --git a/lite-python/lib/utils/stdout_helpers.c b/lite-python/lib/utils/stdout_helpers.c deleted file mode 100755 index 3de11975719a845dac413b78ebff98936aa8e8d9..0000000000000000000000000000000000000000 --- a/lite-python/lib/utils/stdout_helpers.c +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include -#include "py/mpconfig.h" -#include "py/mphal.h" - -/* - * Extra stdout functions - * These can be either optimized for a particular port, or reference - * implementation below can be used. - */ - -// Send "cooked" string of given length, where every occurrence of -// LF character is replaced with CR LF. -void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) { - while (len--) { - if (*str == '\n') { - mp_hal_stdout_tx_strn("\r", 1); - } - mp_hal_stdout_tx_strn(str++, 1); - } -} - -// Send zero-terminated string -void mp_hal_stdout_tx_str(const char *str) { - mp_hal_stdout_tx_strn(str, strlen(str)); -} diff --git a/lite-python/lib/utils/sys_stdio_mphal.c b/lite-python/lib/utils/sys_stdio_mphal.c deleted file mode 100755 index e72facb981d9c96a62f0695f72c14ae1193bc6f2..0000000000000000000000000000000000000000 --- a/lite-python/lib/utils/sys_stdio_mphal.c +++ /dev/null @@ -1,175 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013-2019 Damien P. George - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include -#include - -#include "py/obj.h" -#include "py/stream.h" -#include "py/mperrno.h" -#include "py/mphal.h" - -// TODO make stdin, stdout and stderr writable objects so they can -// be changed by Python code. This requires some changes, as these -// objects are in a read-only module (py/modsys.c). - -/******************************************************************************/ -// MicroPython bindings - -#define STDIO_FD_IN (0) -#define STDIO_FD_OUT (1) -#define STDIO_FD_ERR (2) - -typedef struct _sys_stdio_obj_t { - mp_obj_base_t base; - int fd; -} sys_stdio_obj_t; - -#if MICROPY_PY_SYS_STDIO_BUFFER -STATIC const sys_stdio_obj_t stdio_buffer_obj; -#endif - -void stdio_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { - sys_stdio_obj_t *self = MP_OBJ_TO_PTR(self_in); - mp_printf(print, "", self->fd); -} - -STATIC mp_uint_t stdio_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { - sys_stdio_obj_t *self = MP_OBJ_TO_PTR(self_in); - if (self->fd == STDIO_FD_IN) { - for (uint i = 0; i < size; i++) { - int c = mp_hal_stdin_rx_chr(); - if (c == '\r') { - c = '\n'; - } - ((byte *)buf)[i] = c; - } - return size; - } else { - *errcode = MP_EPERM; - return MP_STREAM_ERROR; - } -} - -STATIC mp_uint_t stdio_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { - sys_stdio_obj_t *self = MP_OBJ_TO_PTR(self_in); - if (self->fd == STDIO_FD_OUT || self->fd == STDIO_FD_ERR) { - mp_hal_stdout_tx_strn_cooked(buf, size); - return size; - } else { - *errcode = MP_EPERM; - return MP_STREAM_ERROR; - } -} - -STATIC mp_uint_t stdio_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { - (void)self_in; - if (request == MP_STREAM_POLL) { - return mp_hal_stdio_poll(arg); - } else { - *errcode = MP_EINVAL; - return MP_STREAM_ERROR; - } -} - -STATIC mp_obj_t stdio_obj___exit__(size_t n_args, const mp_obj_t *args) { - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(stdio_obj___exit___obj, 4, 4, stdio_obj___exit__); - -// TODO gc hook to close the file if not already closed - -STATIC const mp_rom_map_elem_t stdio_locals_dict_table[] = { - #if MICROPY_PY_SYS_STDIO_BUFFER - { MP_ROM_QSTR(MP_QSTR_buffer), MP_ROM_PTR(&stdio_buffer_obj) }, - #endif - { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) }, - { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) }, - { MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj)}, - { MP_ROM_QSTR(MP_QSTR_readlines), MP_ROM_PTR(&mp_stream_unbuffered_readlines_obj)}, - { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) }, - { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&mp_identity_obj) }, - { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mp_identity_obj) }, - { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&mp_identity_obj) }, - { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&stdio_obj___exit___obj) }, -}; - -STATIC MP_DEFINE_CONST_DICT(stdio_locals_dict, stdio_locals_dict_table); - -STATIC const mp_stream_p_t stdio_obj_stream_p = { - .read = stdio_read, - .write = stdio_write, - .ioctl = stdio_ioctl, - .is_text = true, -}; - -STATIC const mp_obj_type_t stdio_obj_type = { - { &mp_type_type }, - .name = MP_QSTR_FileIO, - // TODO .make_new? - .print = stdio_obj_print, - .getiter = mp_identity_getiter, - .iternext = mp_stream_unbuffered_iter, - .protocol = &stdio_obj_stream_p, - .locals_dict = (mp_obj_dict_t *)&stdio_locals_dict, -}; - -const sys_stdio_obj_t mp_sys_stdin_obj = {{&stdio_obj_type}, .fd = STDIO_FD_IN}; -const sys_stdio_obj_t mp_sys_stdout_obj = {{&stdio_obj_type}, .fd = STDIO_FD_OUT}; -const sys_stdio_obj_t mp_sys_stderr_obj = {{&stdio_obj_type}, .fd = STDIO_FD_ERR}; - -#if MICROPY_PY_SYS_STDIO_BUFFER -STATIC mp_uint_t stdio_buffer_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { - for (uint i = 0; i < size; i++) { - ((byte *)buf)[i] = mp_hal_stdin_rx_chr(); - } - return size; -} - -STATIC mp_uint_t stdio_buffer_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { - mp_hal_stdout_tx_strn(buf, size); - return size; -} - -STATIC const mp_stream_p_t stdio_buffer_obj_stream_p = { - .read = stdio_buffer_read, - .write = stdio_buffer_write, - .ioctl = stdio_ioctl, - .is_text = false, -}; - -STATIC const mp_obj_type_t stdio_buffer_obj_type = { - { &mp_type_type }, - .name = MP_QSTR_FileIO, - .print = stdio_obj_print, - .getiter = mp_identity_getiter, - .iternext = mp_stream_unbuffered_iter, - .protocol = &stdio_buffer_obj_stream_p, - .locals_dict = (mp_obj_dict_t *)&stdio_locals_dict, -}; - -STATIC const sys_stdio_obj_t stdio_buffer_obj = {{&stdio_buffer_obj_type}, .fd = 0}; // fd unused -#endif diff --git a/lite-python/mpconfigport.h b/lite-python/mpconfigport.h index fa40dc33c94c731ada08c29f08e2bca05b51d0f3..ce0f42fe2e62d3ae9eac3b4a180ae5ee7516e5ec 100755 --- a/lite-python/mpconfigport.h +++ b/lite-python/mpconfigport.h @@ -1,36 +1,13 @@ -/**************************************************************************** - -MIT License - -Copyright (c) 2021 唐佐林 -WeChat : delphi_tang -EMail: delphi_tang@dt4sw.com - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*****************************************************************************/ - #include +// options to control how MicroPython is built + +// You can disable the built-in MicroPython compiler by setting the following +// config option to 0. If you do this then you won't get a REPL prompt, but you +// will still be able to execute pre-compiled scripts, compiled with mpy-cross. #define MICROPY_ENABLE_COMPILER (1) #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ) -// #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT) +#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE) #define MICROPY_QSTR_BYTES_IN_HASH (1) // #define MICROPY_QSTR_EXTRA_POOL mp_qstr_frozen_const_pool #define MICROPY_ALLOC_PATH_MAX (256) diff --git a/lite-python/mphalport.h b/lite-python/mphalport.h deleted file mode 100755 index 5130d19a24ac5fef6608239a86faa40b4689cad7..0000000000000000000000000000000000000000 --- a/lite-python/mphalport.h +++ /dev/null @@ -1,5 +0,0 @@ -static inline mp_uint_t mp_hal_ticks_ms(void) { - return 0; -} -static inline void mp_hal_set_interrupt_char(char c) { -} diff --git a/lite-python/py/modbuiltins.c b/lite-python/py/modbuiltins.c index cfbfc5a25683ee21c01532e0bebcaaf64d65e375..dcffadb02388338f4647574f5d8c2d86baa36387 100755 --- a/lite-python/py/modbuiltins.c +++ b/lite-python/py/modbuiltins.c @@ -470,7 +470,7 @@ STATIC mp_obj_t mp_builtin_repr(mp_obj_t o_in) { return mp_obj_new_str_from_vstr(&mp_type_str, &vstr); } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_repr_obj, mp_builtin_repr); - +/* STATIC mp_obj_t mp_builtin_round(size_t n_args, const mp_obj_t *args) { mp_obj_t o_in = args[0]; if (mp_obj_is_int(o_in)) { @@ -522,7 +522,7 @@ STATIC mp_obj_t mp_builtin_round(size_t n_args, const mp_obj_t *args) { #endif } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_round_obj, 1, 2, mp_builtin_round); - +*/ STATIC mp_obj_t mp_builtin_sum(size_t n_args, const mp_obj_t *args) { mp_obj_t value; switch (n_args) { @@ -733,7 +733,7 @@ STATIC const mp_rom_map_elem_t mp_module_builtins_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_pow), MP_ROM_PTR(&mp_builtin_pow_obj) }, { MP_ROM_QSTR(MP_QSTR_print), MP_ROM_PTR(&mp_builtin_print_obj) }, { MP_ROM_QSTR(MP_QSTR_repr), MP_ROM_PTR(&mp_builtin_repr_obj) }, - { MP_ROM_QSTR(MP_QSTR_round), MP_ROM_PTR(&mp_builtin_round_obj) }, + // { MP_ROM_QSTR(MP_QSTR_round), MP_ROM_PTR(&mp_builtin_round_obj) }, { MP_ROM_QSTR(MP_QSTR_sorted), MP_ROM_PTR(&mp_builtin_sorted_obj) }, { MP_ROM_QSTR(MP_QSTR_sum), MP_ROM_PTR(&mp_builtin_sum_obj) }, diff --git a/lite-python/py/modmath.c b/lite-python/py/modmath.c index b312eeb3d2c01ddcd761b7cf545dc5f9958800c9..b720f3e421806737a3a609fc820d5ed47bb95860 100755 --- a/lite-python/py/modmath.c +++ b/lite-python/py/modmath.c @@ -96,11 +96,11 @@ mp_float_t MICROPY_FLOAT_C_FUN(log2)(mp_float_t x) { #endif // sqrt(x): returns the square root of x -MATH_FUN_1(sqrt, sqrt) +// MATH_FUN_1(sqrt, sqrt) // pow(x, y): returns x to the power of y -MATH_FUN_2(pow, pow) +// MATH_FUN_2(pow, pow) // exp(x) -MATH_FUN_1(exp, exp) +// MATH_FUN_1(exp, exp) #if MICROPY_PY_MATH_SPECIAL_FUNCTIONS // expm1(x) MATH_FUN_1(expm1, expm1) @@ -122,17 +122,17 @@ MATH_FUN_1(asinh, asinh) MATH_FUN_1(atanh, atanh) #endif // cos(x) -MATH_FUN_1(cos, cos) +// MATH_FUN_1(cos, cos) // sin(x) -MATH_FUN_1(sin, sin) +// MATH_FUN_1(sin, sin) // tan(x) -MATH_FUN_1(tan, tan) +// MATH_FUN_1(tan, tan) // acos(x) -MATH_FUN_1(acos, acos) +// MATH_FUN_1(acos, acos) // asin(x) -MATH_FUN_1(asin, asin) +// MATH_FUN_1(asin, asin) // atan(x) -MATH_FUN_1(atan, atan) +// MATH_FUN_1(atan, atan) // atan2(y, x) #if MICROPY_PY_MATH_ATAN2_FIX_INFNAN mp_float_t atan2_func(mp_float_t x, mp_float_t y) { @@ -143,8 +143,9 @@ mp_float_t atan2_func(mp_float_t x, mp_float_t y) { } MATH_FUN_2(atan2, atan2_func) #else -MATH_FUN_2(atan2, atan2) +//MATH_FUN_2(atan2, atan2) #endif +/* // ceil(x) MATH_FUN_1_TO_INT(ceil, ceil) // copysign(x, y) @@ -152,6 +153,7 @@ STATIC mp_float_t MICROPY_FLOAT_C_FUN(copysign_func)(mp_float_t x, mp_float_t y) return MICROPY_FLOAT_C_FUN(copysign)(x, y); } MATH_FUN_2(copysign, copysign_func) +*/ // fabs(x) STATIC mp_float_t MICROPY_FLOAT_C_FUN(fabs_func)(mp_float_t x) { return MICROPY_FLOAT_C_FUN(fabs)(x); @@ -175,9 +177,9 @@ MATH_FUN_1_TO_BOOL(isinf, isinf) // isnan(x) MATH_FUN_1_TO_BOOL(isnan, isnan) // trunc(x) -MATH_FUN_1_TO_INT(trunc, trunc) +// MATH_FUN_1_TO_INT(trunc, trunc) // ldexp(x, exp) -MATH_FUN_2_FLT_INT(ldexp, ldexp) +// MATH_FUN_2_FLT_INT(ldexp, ldexp) #if MICROPY_PY_MATH_SPECIAL_FUNCTIONS // erf(x): return the error function of x MATH_FUN_1(erf, erf) @@ -227,7 +229,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(mp_math_isclose_obj, 2, mp_math_isclose); #endif // Function that takes a variable number of arguments - +/* // log(x[, base]) STATIC mp_obj_t mp_math_log(size_t n_args, const mp_obj_t *args) { mp_float_t x = mp_obj_get_float(args[0]); @@ -248,9 +250,9 @@ STATIC mp_obj_t mp_math_log(size_t n_args, const mp_obj_t *args) { } } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_math_log_obj, 1, 2, mp_math_log); - +*/ // Functions that return a tuple - +/* // frexp(x): converts a floating-point number to fractional and integral components STATIC mp_obj_t mp_math_frexp(mp_obj_t x_obj) { int int_exponent = 0; @@ -261,7 +263,7 @@ STATIC mp_obj_t mp_math_frexp(mp_obj_t x_obj) { return mp_obj_new_tuple(2, tuple); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_frexp_obj, mp_math_frexp); - +*/ // modf(x) STATIC mp_obj_t mp_math_modf(mp_obj_t x_obj) { mp_float_t int_part = 0.0; @@ -278,7 +280,7 @@ STATIC mp_obj_t mp_math_modf(mp_obj_t x_obj) { return mp_obj_new_tuple(2, tuple); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_modf_obj, mp_math_modf); - +/* // Angular conversions // radians(x) @@ -292,7 +294,7 @@ STATIC mp_obj_t mp_math_degrees(mp_obj_t x_obj) { return mp_obj_new_float(mp_obj_get_float(x_obj) * (MICROPY_FLOAT_CONST(180.0) / MP_PI)); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_degrees_obj, mp_math_degrees); - +*/ #if MICROPY_PY_MATH_FACTORIAL #if MICROPY_OPT_MATH_FACTORIAL @@ -361,23 +363,18 @@ STATIC const mp_rom_map_elem_t mp_module_math_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_math) }, { MP_ROM_QSTR(MP_QSTR_e), mp_const_float_e }, { MP_ROM_QSTR(MP_QSTR_pi), mp_const_float_pi }, + { MP_ROM_QSTR(MP_QSTR_fabs), MP_ROM_PTR(&mp_math_fabs_obj) }, + { MP_ROM_QSTR(MP_QSTR_floor), MP_ROM_PTR(&mp_math_floor_obj) }, + { MP_ROM_QSTR(MP_QSTR_fmod), MP_ROM_PTR(&mp_math_fmod_obj) }, + { MP_ROM_QSTR(MP_QSTR_modf), MP_ROM_PTR(&mp_math_modf_obj) }, + { MP_ROM_QSTR(MP_QSTR_isfinite), MP_ROM_PTR(&mp_math_isfinite_obj) }, + { MP_ROM_QSTR(MP_QSTR_isinf), MP_ROM_PTR(&mp_math_isinf_obj) }, + { MP_ROM_QSTR(MP_QSTR_isnan), MP_ROM_PTR(&mp_math_isnan_obj) }, + /* { MP_ROM_QSTR(MP_QSTR_sqrt), MP_ROM_PTR(&mp_math_sqrt_obj) }, { MP_ROM_QSTR(MP_QSTR_pow), MP_ROM_PTR(&mp_math_pow_obj) }, { MP_ROM_QSTR(MP_QSTR_exp), MP_ROM_PTR(&mp_math_exp_obj) }, - #if MICROPY_PY_MATH_SPECIAL_FUNCTIONS - { MP_ROM_QSTR(MP_QSTR_expm1), MP_ROM_PTR(&mp_math_expm1_obj) }, - #endif { MP_ROM_QSTR(MP_QSTR_log), MP_ROM_PTR(&mp_math_log_obj) }, - #if MICROPY_PY_MATH_SPECIAL_FUNCTIONS - { MP_ROM_QSTR(MP_QSTR_log2), MP_ROM_PTR(&mp_math_log2_obj) }, - { MP_ROM_QSTR(MP_QSTR_log10), MP_ROM_PTR(&mp_math_log10_obj) }, - { MP_ROM_QSTR(MP_QSTR_cosh), MP_ROM_PTR(&mp_math_cosh_obj) }, - { MP_ROM_QSTR(MP_QSTR_sinh), MP_ROM_PTR(&mp_math_sinh_obj) }, - { MP_ROM_QSTR(MP_QSTR_tanh), MP_ROM_PTR(&mp_math_tanh_obj) }, - { MP_ROM_QSTR(MP_QSTR_acosh), MP_ROM_PTR(&mp_math_acosh_obj) }, - { MP_ROM_QSTR(MP_QSTR_asinh), MP_ROM_PTR(&mp_math_asinh_obj) }, - { MP_ROM_QSTR(MP_QSTR_atanh), MP_ROM_PTR(&mp_math_atanh_obj) }, - #endif { MP_ROM_QSTR(MP_QSTR_cos), MP_ROM_PTR(&mp_math_cos_obj) }, { MP_ROM_QSTR(MP_QSTR_sin), MP_ROM_PTR(&mp_math_sin_obj) }, { MP_ROM_QSTR(MP_QSTR_tan), MP_ROM_PTR(&mp_math_tan_obj) }, @@ -387,25 +384,28 @@ STATIC const mp_rom_map_elem_t mp_module_math_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_atan2), MP_ROM_PTR(&mp_math_atan2_obj) }, { MP_ROM_QSTR(MP_QSTR_ceil), MP_ROM_PTR(&mp_math_ceil_obj) }, { MP_ROM_QSTR(MP_QSTR_copysign), MP_ROM_PTR(&mp_math_copysign_obj) }, - { MP_ROM_QSTR(MP_QSTR_fabs), MP_ROM_PTR(&mp_math_fabs_obj) }, - { MP_ROM_QSTR(MP_QSTR_floor), MP_ROM_PTR(&mp_math_floor_obj) }, - { MP_ROM_QSTR(MP_QSTR_fmod), MP_ROM_PTR(&mp_math_fmod_obj) }, { MP_ROM_QSTR(MP_QSTR_frexp), MP_ROM_PTR(&mp_math_frexp_obj) }, { MP_ROM_QSTR(MP_QSTR_ldexp), MP_ROM_PTR(&mp_math_ldexp_obj) }, - { MP_ROM_QSTR(MP_QSTR_modf), MP_ROM_PTR(&mp_math_modf_obj) }, - { MP_ROM_QSTR(MP_QSTR_isfinite), MP_ROM_PTR(&mp_math_isfinite_obj) }, - { MP_ROM_QSTR(MP_QSTR_isinf), MP_ROM_PTR(&mp_math_isinf_obj) }, - { MP_ROM_QSTR(MP_QSTR_isnan), MP_ROM_PTR(&mp_math_isnan_obj) }, - #if MICROPY_PY_MATH_ISCLOSE - { MP_ROM_QSTR(MP_QSTR_isclose), MP_ROM_PTR(&mp_math_isclose_obj) }, - #endif { MP_ROM_QSTR(MP_QSTR_trunc), MP_ROM_PTR(&mp_math_trunc_obj) }, { MP_ROM_QSTR(MP_QSTR_radians), MP_ROM_PTR(&mp_math_radians_obj) }, { MP_ROM_QSTR(MP_QSTR_degrees), MP_ROM_PTR(&mp_math_degrees_obj) }, + */ + #if MICROPY_PY_MATH_ISCLOSE + { MP_ROM_QSTR(MP_QSTR_isclose), MP_ROM_PTR(&mp_math_isclose_obj) }, + #endif #if MICROPY_PY_MATH_FACTORIAL { MP_ROM_QSTR(MP_QSTR_factorial), MP_ROM_PTR(&mp_math_factorial_obj) }, #endif #if MICROPY_PY_MATH_SPECIAL_FUNCTIONS + { MP_ROM_QSTR(MP_QSTR_expm1), MP_ROM_PTR(&mp_math_expm1_obj) }, + { MP_ROM_QSTR(MP_QSTR_log2), MP_ROM_PTR(&mp_math_log2_obj) }, + { MP_ROM_QSTR(MP_QSTR_log10), MP_ROM_PTR(&mp_math_log10_obj) }, + { MP_ROM_QSTR(MP_QSTR_cosh), MP_ROM_PTR(&mp_math_cosh_obj) }, + { MP_ROM_QSTR(MP_QSTR_sinh), MP_ROM_PTR(&mp_math_sinh_obj) }, + { MP_ROM_QSTR(MP_QSTR_tanh), MP_ROM_PTR(&mp_math_tanh_obj) }, + { MP_ROM_QSTR(MP_QSTR_acosh), MP_ROM_PTR(&mp_math_acosh_obj) }, + { MP_ROM_QSTR(MP_QSTR_asinh), MP_ROM_PTR(&mp_math_asinh_obj) }, + { MP_ROM_QSTR(MP_QSTR_atanh), MP_ROM_PTR(&mp_math_atanh_obj) }, { MP_ROM_QSTR(MP_QSTR_erf), MP_ROM_PTR(&mp_math_erf_obj) }, { MP_ROM_QSTR(MP_QSTR_erfc), MP_ROM_PTR(&mp_math_erfc_obj) }, { MP_ROM_QSTR(MP_QSTR_gamma), MP_ROM_PTR(&mp_math_gamma_obj) }, diff --git a/lite-python/py/mpconfig.h b/lite-python/py/mpconfig.h index b81191c52872841b9b1f81fe5169fb4168cbb8c9..b7fcf08a776cb8aaf4ac482a14d72508a9ddd316 100755 --- a/lite-python/py/mpconfig.h +++ b/lite-python/py/mpconfig.h @@ -695,11 +695,11 @@ typedef double mp_float_t; #else #define MICROPY_PY_BUILTINS_FLOAT (0) #endif - +/* #ifndef MICROPY_PY_BUILTINS_COMPLEX #define MICROPY_PY_BUILTINS_COMPLEX (MICROPY_PY_BUILTINS_FLOAT) #endif - +*/ // Whether to provide a high-quality hash for float and complex numbers. // Otherwise the default is a very simple but correct hashing function. #ifndef MICROPY_FLOAT_HIGH_QUALITY_HASH diff --git a/lite-python/py/mphal.h b/lite-python/py/mphal.h index 9350477136cbd45aff1cfc0dae085910b9632adf..64393f210f0141fa8ebc45065d5335d85503da8c 100755 --- a/lite-python/py/mphal.h +++ b/lite-python/py/mphal.h @@ -28,13 +28,13 @@ #include #include "py/mpconfig.h" - +/* #ifdef MICROPY_MPHALPORT_H #include MICROPY_MPHALPORT_H #else #include #endif - +*/ #ifndef mp_hal_stdio_poll uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags); #endif diff --git a/lite-python/uart_core.c b/lite-python/uart_core.c deleted file mode 100755 index c7dc6752d32ef83099861d0a8114e0398d881010..0000000000000000000000000000000000000000 --- a/lite-python/uart_core.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include "py/mpconfig.h" - - -// Receive single character -int mp_hal_stdin_rx_chr(void) { - extern int getchar(); - return getchar(); -} - -// Send string of given length -void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) { - extern int putchar(int ch); - while (len--) { - putchar(*str++); - } -}