[HN Gopher] Wasm2Mpy: Compiling WASM to MicroPython so it can ru...
       ___________________________________________________________________
        
       Wasm2Mpy: Compiling WASM to MicroPython so it can run on Raspberrys
        
       Author : syrusakbary
       Score  : 33 points
       Date   : 2024-09-20 07:10 UTC (4 days ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | bragr wrote:
       | 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 wrote:
         | Probably at least one of "it's cool" or "I'm already using
         | MicroPython"
        
         | kragen wrote:
         | i 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 wrote:
           | > 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 wrote:
             | In 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
        
             | jononor wrote:
             | .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 wrote:
               | Oh, I didn't know MicroPython was fully AOT. I'm
               | surprised, since vanilla Python is typically interpreted
               | with maybe a bytecode cache, right?
        
       | szundi wrote:
       | Can we have python compiled to wasm compiled to python compiled
       | to wasm compiled to python - just for obfuscation reasons?
        
         | cyanydeez wrote:
         | Best add a LLM into the loop for real speed.
        
       | oulipo wrote:
       | What would be the recommendation to run on ESP32?
       | 
       | https://github.com/wasm3/wasm3? https://github.com/espressif/esp-
       | wasmachine ? https://github.com/bytecodealliance/wasm-micro-
       | runtime/tree/... ? https://github.com/TOPLLab/WARDuino ?
        
       ___________________________________________________________________
       (page generated 2024-09-24 23:00 UTC)