Hello everyone,
I’m wondering how static-time preprocessing could be handled in MicroPython. Let me explain: imagine you have a Python statement
data = my_heavy_function(args)
where my_heavy_function returns a simple integer from a processing like: lookup in a big file, querying a DB, executing some number-crunching process, etc. Now, imagine that you can make such processing *offline* so that this statement could boils down to
data = 123
or anything light enough to be executed easily in MicroPython. So, I’m wondering how this pre-treatment can be done easily, I mean at any stage before generating MicroPython bytecode. The goal would be of course to minimize the resources/dependencies needed at run-time.
Is it something that have been discussed already? Is there any (Micro)Python feature to make such treatment? Related keywords on the topic are “precompiler”, “preprocessor”, “transpiler”, “compile-time metaprogramming”, etc.
Note that I’m experienced in Python but I’m quite new to MicroPython.
Thanks,
Pierre
Static-time preprocessing?
Re: Static-time preprocessing?
The traditional way to do such task is to write a script or other program that does the desired expensive computation and generates a file (for instance, python code), and then to call that utility from your makefile, together with the commands that pre-compile your programs. Then it's just a matter of running your make command, and the file gets generated only when needed.