py/builtinimport: Refactor module importing.
Simplify and document/comment the handling of builtin import for:
- already-loaded modules
- built-in modules
- built-in umodules (formerly weak links)
- filesystem modules
Retains existing functionality with smaller code size but should also
facilitate potential new features (built-in packages, controlling the
frozen path).
Also makes the (unix-only) -m behavior a bit more obvious and configurable.
Code size change with this commit:
bare-arm: +0 +0.000%
minimal x86: -64 -0.039%
unix x64: -32 -0.006%
unix nanbox: -4 -0.001%
stm32: -184 -0.047% PYBV10
cc3200: -120 -0.065%
esp8266: -228 -0.033% GENERIC
esp32: -268 -0.018% GENERIC[incl +16(data)]
nrf: -152 -0.087% pca10040
rp2: -256 -0.052% PICO
samd: -80 -0.057% ADAFRUIT_ITSYBITSY_M4_EXPRESS
diff --git a/py/mpconfig.h b/py/mpconfig.h
index 06c46b8..308a776 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -829,6 +829,12 @@
#define MICROPY_MODULE_WEAK_LINKS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
#endif
+// Whether to enable importing foo.py with __name__ set to '__main__'
+// Used by the unix port for the -m flag.
+#ifndef MICROPY_MODULE_OVERRIDE_MAIN_IMPORT
+#define MICROPY_MODULE_OVERRIDE_MAIN_IMPORT (0)
+#endif
+
// Whether frozen modules are supported in the form of strings
#ifndef MICROPY_MODULE_FROZEN_STR
#define MICROPY_MODULE_FROZEN_STR (0)