micropython/micropython — pull request #661 by pfalcon (2014-06-04 23:32:11+00:00)
Title: REVIEW ONLY! py: Very first step towards handling intra-module constants.

Store module's constant values in __const__ dict. They could be looked up
from there to implement intra-module constant resolution. Except, that's
not going to work that easy. The reason is that constants within current
module are resolved at parse time, while module importing triggered at runtime.
That means that a "main" module won't really be able to use constant from
imported modules, because these modules are not really imported until that
module is parsed, compiled, and then executed.

It's unclear how to resolve that. Or rather, it's clear how to - parser could,
after detecting a (first question - only toplevel?) import, it recursively
parses, compiles, and runs that module before coming back to current module.
It's unclear if it makes sense to do this - for MicroPython. Because this
will lead to drastically higher memory requirements for parsing (up to OOM
completely), may have troubles with import/execution order, etc. Well, it might
be "optimized" by having a "constant-only" parsing stage, whcih first collects
just constants from modules, and then runs another pass over all files for
normal processing. Again, it's unclear if it's worth to have this complexity
in MicroPython core.