6 ms·
I feel like this project is a classic example of the README missing a "Why?" section. Not to justify the project, it just makes it hard to evaluate without unde
by bragr 2y ago
I feel like this project is a classic example of the README missing a "Why?" section. Not to justify the project, it just makes it hard to evaluate without understanding why they choose implementing a transpiler rather than an embedded WASM VM. Or why not transpile to native assembly? I'm sure they have good reasons but they aren't listed here.
- ronsor 2y agoProbably at least one of "it's cool" or "I'm already using MicroPython"
- kragen 2y agoi think your questions are implicitly answered in the top page of the readme, but by showing rather than telling esp32 and stm32 run three different native assembly instruction sets (though this only supports two of them, the others listed in the first line of the readme are all arm) the coremark results seem like an adequate answer to why you'd use a compiler rather than an interpreter i do think it would be clearer, though, to explain up front that the module being built is not made of python code, but rather callable from python code
- kristianp 2y ago> i do think it would be clearer, though, to explain up front that the module being built is not made of python code, but rather callable from python code I know nothing about micropython. Do the modules contain bytecode?
- HALtheWise 2y agoIn this case, the modules contain native code compiled for the target architecture. Micropython has something approximating a dynamic linker to load them. https://docs.micropython.org/en/latest/develop/natmod.html https://docs.micropython.org/en/latest/develop/natmod.html
- westurner 2y agotools/mpy_ld.py: https://github.com/micropython/micropython/blob/master/tools/mpy_ld.py https://github.com/micropython/micropython/blob/master/tools... tools/mpy-tool.py lists opcodes: https://github.com/micropython/micropython/blob/master/tools/mpy-tool.py https://github.com/micropython/micropython/blob/master/tools... Can the same be done with .pyc files; what are the advantages of MicroPython native modules? Why does it need wasm2c?
- vshymanskyy 2y agoI don't think .pyc files can contain native code, but .mpy can! And that's exactly what I'm using here: - compile any language to wasm - translate wasm to C99 - use the native target toolchain to compile C99 to .mpy - run that on the device
- westurner 2y agoIf they're both Turing-complete opcodes instruction sets, Church-Turing says it is possible with just .pyc, too. But that doesn't solve for WASM on a MicroPython device. And that is why smart contracts without costed opcodes could not be built on Python.
- jononor 2y ago.mpy modules can contain MicroPython bytecode and/or native machine code. In this case, WASM is compiled (via C) to native code. So the performance is very good, much better than interpreting either MicroPython bytecode or WASM bytecode. The conventional way of creating native modules for MicroPython is to write them in C. This work allows to use any language that supports WASM output target.
- 01HNNWZ0MV43FF 2y agoOh, I didn't know MicroPython was fully AOT. I'm surprised, since vanilla Python is typically interpreted with maybe a bytecode cache, right?
- dbcurtis 2y agoIt isn’t fully AOT, but support for AOT modules is excellent.
- zorgmonkey 2y agoThanks for the explanation this project makes so much more sense now. If people want a little more detail, they have a brief how it works section in readme https://github.com/vshymanskyy/wasm2mpy?tab=readme-ov-file#how-it-works https://github.com/vshymanskyy/wasm2mpy?tab=readme-ov-file#h...
- 15155 2y agoThere's no scenario where a bespoke WASM interpreter is slower than MicroPython - though this isn't really Python. WASM is an almost "ideal" bytecode target for embedded AOT native compilation as well, though yeah, you'd have to implement all of the backend targets.
- kragen 2y agomaybe if you don't have enough space in flash for both the μpython interpreter and the wasm interpreter? but, yeah, this isn't being compiled to python but to c (for invocation from python)
- vshymanskyy 2y agoThanks for the feedback. I'll improve the README based on your inputs. I was focused on the actual research. Overall, this allows writing code in statically compiled languages and running it (fast) on embedded systems with MicroPython. MicroPython itself is comparatively slow, and this provides tools to deliver more demanding software (AI, signal processing, etc).
- 0points 2y agoThere exists tooling already to compile for wasm from static languages (rust, C++, and so on) and there exists tooling to run this WASM on a raspberry pi (wasmer, etc). That makes me feel the end goal here is not what's described ("make wasm so it can run on a raspberry"), but rather "make wasm run in micropython". Am I missing something?
- vshymanskyy 2y agoYes, we're talking about Raspberry Pi Pico (RP2040) here. Not the Linux-based SBCs (Single Board Computers)
- ssnover 2y agoCurious if you've seen the WAMR runtime which is explicitly designed to be lightweight enough for freestanding embedded systems on some higher end microcontrollers (Cortex-M4F).
- vshymanskyy 2y agoYes, Wasm3 also targets Cortex-M4 and even Cortex-M0 :)
- 0points 2y agoI see, thanks for the clarification!