beeware / batavia

A JavaScript implementation of the Python virtual machine.
http://pybee.org/batavia
Other
1.39k stars 424 forks source link

Compiling a module to bytecode in the build process #759

Open lielfr opened 5 years ago

lielfr commented 5 years ago

Hi. So, I'm trying to implement the exec builtin. As you may know, it requires the ability to execute python code directly from batavia, which AFAIK is not possible because CPython is required for compiling into bytecode. The two possibilites I though about are implementing a compiler in javascript and making a bridge module and compiling it when building batavia. Which one is better for that purpose? Thanks.

freakboy3742 commented 5 years ago

A self-hosting Python compiler will the better long term solution; but exposing the server-side implementation of exec() as something that can be invoked over a HTTP call will be the easier approach to implement.

The server-side version will be a lot slower to run, and obviously won't work if the webpage is offline, but will probably be sufficient for many purposes.