Skip to content

Commit 8061e8e

Browse files
committed
Names changed to better fit mp style
1 parent b00a25f commit 8061e8e

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

main.c

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,16 @@ typedef struct {
131131
supervisor_allocation *pystack;
132132
#endif
133133
supervisor_allocation *heap;
134-
} stacks;
134+
} vm_memory_t;
135135

136136
static void reset_devices(void) {
137137
#if CIRCUITPY_BLEIO_HCI
138138
bleio_reset();
139139
#endif
140140
}
141141

142-
#if MICROPY_ENABLE_PYSTACK
143-
STATIC stacks __attribute__ ((noinline)) alloc_stacks(void) {
144-
stacks res;
142+
STATIC vm_memory_t allocate_vm_memory(void) {
143+
vm_memory_t res;
145144
#if MICROPY_ENABLE_PYSTACK
146145
mp_int_t pystack_size = CIRCUITPY_PYSTACK_SIZE;
147146
#if CIRCUITPY_OS_GETENV
@@ -164,9 +163,8 @@ STATIC stacks __attribute__ ((noinline)) alloc_stacks(void) {
164163
res.heap = allocate_remaining_memory();
165164
return res;
166165
}
167-
#endif
168166

169-
STATIC void start_mp(stacks combo) {
167+
STATIC void start_mp(vm_memory_t vm_memory) {
170168
supervisor_workflow_reset();
171169

172170
// Stack limit should be less than real stack size, so we have a chance
@@ -194,11 +192,11 @@ STATIC void start_mp(stacks combo) {
194192
readline_init0();
195193

196194
#if MICROPY_ENABLE_PYSTACK
197-
mp_pystack_init(combo.pystack->ptr, combo.pystack->ptr + get_allocation_length(combo.pystack) / sizeof(size_t));
195+
mp_pystack_init(vm_memory.pystack->ptr, vm_memory.pystack->ptr + get_allocation_length(vm_memory.pystack) / sizeof(size_t));
198196
#endif
199197

200198
#if MICROPY_ENABLE_GC
201-
gc_init(combo.heap->ptr, combo.heap->ptr + get_allocation_length(combo.heap) / 4);
199+
gc_init(vm_memory.heap->ptr, vm_memory.heap->ptr + get_allocation_length(vm_memory.heap) / 4);
202200
#endif
203201
mp_init();
204202
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) {
298296
*(size_t *)data += len;
299297
}
300298

301-
STATIC void cleanup_after_vm(stacks combo, mp_obj_t exception) {
299+
STATIC void cleanup_after_vm(vm_memory_t vm_memory, mp_obj_t exception) {
302300
// Get the traceback of any exception from this run off the heap.
303301
// MP_OBJ_SENTINEL means "this run does not contribute to traceback storage, don't touch it"
304302
// 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) {
378376
// Free the heap last because other modules may reference heap memory and need to shut down.
379377
filesystem_flush();
380378
stop_mp();
381-
free_memory(combo.heap);
379+
free_memory(vm_memory.heap);
382380
#if MICROPY_ENABLE_PYSTACK
383-
free_memory(combo.pystack);
381+
free_memory(vm_memory.pystack);
384382
#endif
385383
supervisor_move_memory();
386384

@@ -436,8 +434,8 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) {
436434
};
437435
#endif
438436

439-
stacks combo = alloc_stacks();
440-
start_mp(combo);
437+
vm_memory_t vm_memory = allocate_vm_memory();
438+
start_mp(vm_memory);
441439

442440
#if CIRCUITPY_USB
443441
usb_setup_with_vm();
@@ -485,7 +483,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) {
485483

486484

487485
// Finished executing python code. Cleanup includes filesystem flush and a board reset.
488-
cleanup_after_vm(combo, _exec_result.exception);
486+
cleanup_after_vm(vm_memory, _exec_result.exception);
489487
_exec_result.exception = NULL;
490488

491489
// 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) {
781779

782780
// Do USB setup even if boot.py is not run.
783781

784-
stacks combo = alloc_stacks();
785-
start_mp(combo);
782+
vm_memory_t vm_memory = allocate_vm_memory();
783+
start_mp(vm_memory);
786784

787785
#if CIRCUITPY_USB
788786
// 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) {
868866

869867
port_post_boot_py(true);
870868

871-
cleanup_after_vm(combo, _exec_result.exception);
869+
cleanup_after_vm(vm_memory, _exec_result.exception);
872870
_exec_result.exception = NULL;
873871

874872
port_post_boot_py(false);
@@ -883,8 +881,8 @@ STATIC int run_repl(void) {
883881
int exit_code = PYEXEC_FORCED_EXIT;
884882
stack_resize();
885883
filesystem_flush();
886-
stacks combo = alloc_stacks();
887-
start_mp(combo);
884+
vm_memory_t vm_memory = allocate_vm_memory();
885+
start_mp(vm_memory);
888886

889887
#if CIRCUITPY_USB
890888
usb_setup_with_vm();
@@ -927,7 +925,7 @@ STATIC int run_repl(void) {
927925
exit_code = PYEXEC_DEEP_SLEEP;
928926
}
929927
#endif
930-
cleanup_after_vm(combo, MP_OBJ_SENTINEL);
928+
cleanup_after_vm(vm_memory, MP_OBJ_SENTINEL);
931929

932930
// Also reset bleio. The above call omits it in case workflows should continue. In this case,
933931
// we're switching straight to another VM so we want to reset.

0 commit comments

Comments
 (0)