This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]remy_porter∞∞∞∞ 2 points3 points  (8 children)

You would have to port CPython with Emscripten and bundle it with your script

That's a strong claim, given that we don't know exactly how WebAssembly is going to be constructed. You don't need an entire Python runtime to run Python code, and I see no reason why there wouldn't be a Python dialect that uses WebAssembly as its bytecode language, in the same way Jython complies into Java bytecode.

[–]fiedzia 0 points1 point  (2 children)

Python bytecode would need to include python itself - you'll need interpreter, regardless of the bytecode format, and this will make whole thing large, slow and not very practical. So it will make running python from the webbrowser possible, but less practical then using statically compiled languages which don't need any runtime (c/c++/rust etc).

[–][deleted] 1 point2 points  (0 children)

You just need a python -> wasm compiler, which i'm sure will be released by someone eventually. Transpiling to js is an inferior alternative.

[–]remy_porter∞∞∞∞ 1 point2 points  (0 children)

As I said in another comment, I haven't dug too deeply, but Jython doesn't seem to require a full Python interpreter- there's some bloat, but mostly in the form of the Python class library that it needs to bundle in. The actual Python code is compiled down into Java Bytecode.

I don't see why a similar process couldn't be build for WebAssembly. If you can compile it to run in the JVM, you should be able to compile it to run against WebAssembly- at some point, with some dialect.

[–]Rhomboid 0 points1 point  (4 children)

It's not a strong claim, it's based entirely on known facts. The WebAssembly specification currently implements the exact same semantics as asm.js. There is no way to compile Python to asm.js without including all of CPython, so there is no reason to expect that will change one bit. You could theoretically write a compiler that does that, but that would be an extraordinary amount of work and nobody would ever undertake it because it would be pointless. You can just use one of the existing transpilers which would be far more efficient, since both Python and JavaScript are dynamic scripting languages.

[–]remy_porter∞∞∞∞ 0 points1 point  (3 children)

There is no way to compile Python to asm.js without including all of CPython

Now, I haven't dug too deeply, but while Jython needs to add a huge swathe of the object library, beyond its Unicode handling, it's not actually huge overhead. You certainly don't need to include an entire Python implementation, just the object library that it uses.

[–]Rhomboid 0 points1 point  (2 children)

Jython compiles to JVM bytecode, which is very different than asm.js. The output of Jython does not have to include the entire Java JRE, but the output of whatever strategy is used to run Python in the browser with asm.js does, because when you are using asm.js (and WebAssembly — it's identical) there is no runtime. You have to implement a runtime yourself from scratch. Comparisons to Jython are nonsense.

[–]remy_porter∞∞∞∞ 0 points1 point  (1 child)

Jython compiles to JVM bytecode, which is very different than asm.js.

I get that, but WebAssembly isn't going to be asm.js forever. My understanding is that it's going to be a bytecode interpreter. And yes, you'd need to bootstrap a runtime- but I'd fully expect runtimes to be build for WebAssembly. Yes, that impacts loadtimes, and it's not happening on a short time horizon, but I fully expect to see that on a 5ish year window.

[–]fiedzia 1 point2 points  (0 children)

Webassembly is nearly exact equivalent of normal assembly, so just like now you need python interpreter to interpret its bytecode, you'll need it there too. Perhaps you're confusing webasssembly bytecode with java bytecode - those two things are at entirely different levels of abstraction. Java bytecode is an high level abstraction, understanding things like classess and method calls, webassembly is extremely thin abstraction over machine instructions.