Names changed to better fit mp style

This commit is contained in:
Bill Sideris 2023-02-16 11:05:29 +02:00
parent b00a25fecc
commit 8061e8e7c6
No known key found for this signature in database
GPG Key ID: 1BEF1BCEBA58EA33
1 changed files with 18 additions and 20 deletions

38
main.c
View File

@ -131,7 +131,7 @@ typedef struct {
supervisor_allocation *pystack; supervisor_allocation *pystack;
#endif #endif
supervisor_allocation *heap; supervisor_allocation *heap;
} stacks; } vm_memory_t;
static void reset_devices(void) { static void reset_devices(void) {
#if CIRCUITPY_BLEIO_HCI #if CIRCUITPY_BLEIO_HCI
@ -139,9 +139,8 @@ static void reset_devices(void) {
#endif #endif
} }
#if MICROPY_ENABLE_PYSTACK STATIC vm_memory_t allocate_vm_memory(void) {
STATIC stacks __attribute__ ((noinline)) alloc_stacks(void) { vm_memory_t res;
stacks res;
#if MICROPY_ENABLE_PYSTACK #if MICROPY_ENABLE_PYSTACK
mp_int_t pystack_size = CIRCUITPY_PYSTACK_SIZE; mp_int_t pystack_size = CIRCUITPY_PYSTACK_SIZE;
#if CIRCUITPY_OS_GETENV #if CIRCUITPY_OS_GETENV
@ -164,9 +163,8 @@ STATIC stacks __attribute__ ((noinline)) alloc_stacks(void) {
res.heap = allocate_remaining_memory(); res.heap = allocate_remaining_memory();
return res; return res;
} }
#endif
STATIC void start_mp(stacks combo) { STATIC void start_mp(vm_memory_t vm_memory) {
supervisor_workflow_reset(); supervisor_workflow_reset();
// Stack limit should be less than real stack size, so we have a chance // Stack limit should be less than real stack size, so we have a chance
@ -194,11 +192,11 @@ STATIC void start_mp(stacks combo) {
readline_init0(); readline_init0();
#if MICROPY_ENABLE_PYSTACK #if MICROPY_ENABLE_PYSTACK
mp_pystack_init(combo.pystack->ptr, combo.pystack->ptr + get_allocation_length(combo.pystack) / sizeof(size_t)); mp_pystack_init(vm_memory.pystack->ptr, vm_memory.pystack->ptr + get_allocation_length(vm_memory.pystack) / sizeof(size_t));
#endif #endif
#if MICROPY_ENABLE_GC #if MICROPY_ENABLE_GC
gc_init(combo.heap->ptr, combo.heap->ptr + get_allocation_length(combo.heap) / 4); gc_init(vm_memory.heap->ptr, vm_memory.heap->ptr + get_allocation_length(vm_memory.heap) / 4);
#endif #endif
mp_init(); mp_init();
mp_obj_list_init((mp_obj_list_t *)mp_sys_path, 0); mp_obj_list_init((mp_obj_list_t *)mp_sys_path, 0);
@ -298,7 +296,7 @@ STATIC void count_strn(void *data, const char *str, size_t len) {
*(size_t *)data += len; *(size_t *)data += len;
} }
STATIC void cleanup_after_vm(stacks combo, mp_obj_t exception) { STATIC void cleanup_after_vm(vm_memory_t vm_memory, mp_obj_t exception) {
// Get the traceback of any exception from this run off the heap. // Get the traceback of any exception from this run off the heap.
// MP_OBJ_SENTINEL means "this run does not contribute to traceback storage, don't touch it" // MP_OBJ_SENTINEL means "this run does not contribute to traceback storage, don't touch it"
// MP_OBJ_NULL (=0) means "this run completed successfully, clear any stored traceback" // MP_OBJ_NULL (=0) means "this run completed successfully, clear any stored traceback"
@ -378,9 +376,9 @@ STATIC void cleanup_after_vm(stacks combo, mp_obj_t exception) {
// Free the heap last because other modules may reference heap memory and need to shut down. // Free the heap last because other modules may reference heap memory and need to shut down.
filesystem_flush(); filesystem_flush();
stop_mp(); stop_mp();
free_memory(combo.heap); free_memory(vm_memory.heap);
#if MICROPY_ENABLE_PYSTACK #if MICROPY_ENABLE_PYSTACK
free_memory(combo.pystack); free_memory(vm_memory.pystack);
#endif #endif
supervisor_move_memory(); supervisor_move_memory();
@ -436,8 +434,8 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) {
}; };
#endif #endif
stacks combo = alloc_stacks(); vm_memory_t vm_memory = allocate_vm_memory();
start_mp(combo); start_mp(vm_memory);
#if CIRCUITPY_USB #if CIRCUITPY_USB
usb_setup_with_vm(); usb_setup_with_vm();
@ -485,7 +483,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) {
// Finished executing python code. Cleanup includes filesystem flush and a board reset. // Finished executing python code. Cleanup includes filesystem flush and a board reset.
cleanup_after_vm(combo, _exec_result.exception); cleanup_after_vm(vm_memory, _exec_result.exception);
_exec_result.exception = NULL; _exec_result.exception = NULL;
// If a new next code file was set, that is a reason to keep it (obviously). Stuff this into // If a new next code file was set, that is a reason to keep it (obviously). Stuff this into
@ -781,8 +779,8 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
// Do USB setup even if boot.py is not run. // Do USB setup even if boot.py is not run.
stacks combo = alloc_stacks(); vm_memory_t vm_memory = allocate_vm_memory();
start_mp(combo); start_mp(vm_memory);
#if CIRCUITPY_USB #if CIRCUITPY_USB
// Set up default USB values after boot.py VM starts but before running boot.py. // Set up default USB values after boot.py VM starts but before running boot.py.
@ -868,7 +866,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
port_post_boot_py(true); port_post_boot_py(true);
cleanup_after_vm(combo, _exec_result.exception); cleanup_after_vm(vm_memory, _exec_result.exception);
_exec_result.exception = NULL; _exec_result.exception = NULL;
port_post_boot_py(false); port_post_boot_py(false);
@ -883,8 +881,8 @@ STATIC int run_repl(void) {
int exit_code = PYEXEC_FORCED_EXIT; int exit_code = PYEXEC_FORCED_EXIT;
stack_resize(); stack_resize();
filesystem_flush(); filesystem_flush();
stacks combo = alloc_stacks(); vm_memory_t vm_memory = allocate_vm_memory();
start_mp(combo); start_mp(vm_memory);
#if CIRCUITPY_USB #if CIRCUITPY_USB
usb_setup_with_vm(); usb_setup_with_vm();
@ -927,7 +925,7 @@ STATIC int run_repl(void) {
exit_code = PYEXEC_DEEP_SLEEP; exit_code = PYEXEC_DEEP_SLEEP;
} }
#endif #endif
cleanup_after_vm(combo, MP_OBJ_SENTINEL); cleanup_after_vm(vm_memory, MP_OBJ_SENTINEL);
// Also reset bleio. The above call omits it in case workflows should continue. In this case, // Also reset bleio. The above call omits it in case workflows should continue. In this case,
// we're switching straight to another VM so we want to reset. // we're switching straight to another VM so we want to reset.