Static-time preprocessing?

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
PiDenis
Posts: 1
Joined: Fri Sep 02, 2016 8:11 am

Static-time preprocessing?

Post by PiDenis » Fri Sep 02, 2016 1:19 pm

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

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Static-time preprocessing?

Post by deshipu » Fri Sep 02, 2016 5:30 pm

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.

Post Reply