diff --git a/README.md b/README.md index 7e5f4c48a..06d0f57fd 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ Bugs to fix: - Fix not world switching during filesystem accesses (very unstable) - Fix the console not garbage collecting its lines (enable and test the feature) - Fix not resetting the shell when importing a file from command-line +- Fix current working directory not changing during a module import (for + relative imports) Python features: - Compare features with existing implementations and other brands diff --git a/ports/sh/debug.c b/ports/sh/debug.c index 530034cdd..9c2f7cea0 100644 --- a/ports/sh/debug.c +++ b/ports/sh/debug.c @@ -3,8 +3,23 @@ #include #include #include +#include #include #include +#include + +void pe_debug_panic(char const *msg) +{ + int dy = dfont_default()->line_height + 2; + + dclear(C_BLACK); + dtext(1, 1, C_WHITE, "PythonExtra panic!"); + dtext(1, 1+dy, C_WHITE, msg); + dupdate(); + + getkey(); + exit(1); +} #if PE_DEBUG diff --git a/ports/sh/debug.h b/ports/sh/debug.h index 5e2dedf9d..4f31bee69 100644 --- a/ports/sh/debug.h +++ b/ports/sh/debug.h @@ -7,7 +7,7 @@ // // Most of the debugging occurs via USB. This module also includes screenshots // and other developer-only utilities. The interface always exists but it's -// completely no-oped if PE_DEBUG isn't set. +// almost entirely no-oped if PE_DEBUG isn't set. //--- #ifndef __PYTHONEXTRA_DEBUG_H @@ -19,6 +19,10 @@ /* Initialize debugging resources (mostly the USB connection). */ void pe_debug_init(void); +/* Panic with a message (available even if PE_DEBUG=0). */ +void pe_debug_panic(char const *msg) +__attribute__((noreturn)); + /* Print to the debug stream. This function is also called DEBUG_printf in MicroPython code. */ void pe_debug_printf(char const *fmt, ...); diff --git a/ports/sh/main.c b/ports/sh/main.c index 8b03e619a..d4776c00d 100644 --- a/ports/sh/main.c +++ b/ports/sh/main.c @@ -140,26 +140,27 @@ int main(int argc, char **argv) open_generic(&stdouterr_type, pe_shell_console, STDOUT_FILENO); open_generic(&stdouterr_type, pe_shell_console, STDERR_FILENO); - /* Initialize MicroPython */ - #define HEAP_SIZE 32768 - void *heap = malloc(32768); - if(!heap) { - dclear(C_WHITE); - dtext(1, 1, C_BLACK, "No heap!"); - getkey(); - return 1; - } - + /* Initialize the MicroPython GC with most available memory */ mp_stack_ctrl_init(); - gc_init(heap, heap + HEAP_SIZE); - // TODO: gc_add(start, end) for each area we want to allocate to - // fx-9860G III: - // * (nothing? x_x) - // fx-CG 50: - // * The entirety of _uram - // * The entirety of the extra VRAM - // * Possibly memory past 2M - // * (keep the OS heap for normal malloc()) +#ifdef FX9860G + /* Get *some* memory from the OS heap */ + void *gc_area = malloc(32768); + if(!gc_area) + pe_debug_panic("No heap!"); + gc_init(gc_area, gc_area + 32768); +#else + /* Get everything from the OS stack (~ 350 ko) */ + size_t gc_area_size; + void *gc_area = kmalloc_max(&gc_area_size, "_ostk"); + gc_init(gc_area, gc_area + gc_area_size); + + /* Other options: + - All of _uram (leaving the OS heap for the shell/GUI/etc) + - The OS' extra VRAM + - Memory past the 2 MB boundary on tested OSes */ + // gc_add(start, end)... +#endif + mp_init(); /* TODO: Add an option for the shorter prompt */