Live data from Hacker News

PyPy.js: A fast, compliant Python implementation for the web

pypyjs.org

101–110 of 144 posts

Re: PyPy.js: A fast, compliant Python implementation for the web

#101

Earlier quoted context omitted.

I work on a machine that has two hypervisors, one third in plan, and more abstraction layers than a lasagna software. It is still very very efficient.

How can you have multiple hypervisors...? Do they both run in ring -1?

http://en.wikipedia.org/wiki/Virtualization#Nested_virtualiz...

Re: PyPy.js: A fast, compliant Python implementation for the web

#102
post #78
post #70

Earlier quoted context omitted.

> At the end is answered why python can't be directly included in Firefox or other browsers(the presenter/main developer works for Mozilla) Direct link to answer: https://youtu.be/PiBfOFqDIAI?t=1611

"If we ship Python inside of Firefox, no one is going to use it because it's not available in Chrome, it's not available in Internet Explorer." Oh yeah? Try me.

The other issue with Python in the browser is that the significant whitespace requirement prevents minification, which would bloat download size.

Re: PyPy.js: A fast, compliant Python implementation for the web

#103
I think there is no point in trying to emulate different language semantics on top of JavaScript.

asm.js is a weird hack that lives in a totally different world than actual browser APIs (e.g. the DOM), and you have to emulate your entire runtime and environment to get anything useful, which means your binary is going to be huge (as in this example, but similar things apply).

Emulating better semantics than JS based on JS usually leaves you in this uncanny valley where you either trade off performance and size for nicer semantics (e.g. killing the null/undefined dichotomy, or 64 bit integer math), or you end up with odd semantics that don't quite fit the language you're compiling from, or a mix of both, which is a usability disaster.

So the only real chance to improve on the state of JS is being a syntactical shim on top of JS and help users with better syntax, static analysis, and compile time tooling. That'd be TypeScript.

Re: PyPy.js: A fast, compliant Python implementation for the web

#104

Earlier quoted context omitted.

Just playing around: import js c = js.globals.document.createElement("canvas") js.globals.document.body.appendChild(c) ctx = c.getContext("2d") ctx.fillRect(10, 10, 10, 10) Edit: Here is a simple animation: import js import math import time c = js.globals.document.createElement("canvas") js.globals.document.body.appendChild(c) ctx = c.getContext("2d") def render(): ctx.clearRect(0, 0, c.width, c.height) t = time.time…

Sadly, if I paste that in, I get: >>> import js ... c = js.globals.document.createElement("canvas") ... debug: OperationError: debug: operror-type: SyntaxError debug: operror-value: ('EOL while scanning string literal', ('c callback', 1, 12, "r = c.push('import js\n", 0)) debug: OperationError: debug: operror-type: KeyError debug: operror-value: 'r' And then the input window hangs. Strangely enough, if I type it in i…

'that' refers to

    import js
    c = js.globals.document.createElement("canvas")
and not the pastebin. The pastebin works for me, but only the first time. Subsequent runs result in:

    
    RPython traceback:
      ...
    Fatal RPython error:

Re: PyPy.js: A fast, compliant Python implementation for the web

#105

I think there is no point in trying to emulate different language semantics on top of JavaScript. asm.js is a weird hack that lives in a totally different world than actual browser APIs (e.g. the DOM), and you have to emulate your entire runtime and environment to get anything useful, which means your binary is going to be huge (as in this example, but similar things apply). Emulating better semantics than JS based o…

> That'd be TypeScript.

Or CoffeeScript. Or Dart. Or this. In fact, here's a whole big long list of other languages. Most of which don't use the asm.js "weird hack".

https://github.com/jashkenas/coffeescript/wiki/List-of-langu...

Re: PyPy.js: A fast, compliant Python implementation for the web

#106
post #102
post #78

Earlier quoted context omitted.

"If we ship Python inside of Firefox, no one is going to use it because it's not available in Chrome, it's not available in Internet Explorer." Oh yeah? Try me.

The other issue with Python in the browser is that the significant whitespace requirement prevents minification, which would bloat download size.

Significant whitespace (in all languages, really, its a difference of degree rather than kind) constrains, but does not prevent, minification. (Idiomatic python code can be reduced by three chars per indentation level on each line with no impact on semantics, and of course other transformations that aren't whitespace elimination that are past of minification are unaffected.)

Heck, there are existing python minification tools.

Re: PyPy.js: A fast, compliant Python implementation for the web

#107
post #102

Earlier quoted context omitted.

The other issue with Python in the browser is that the significant whitespace requirement prevents minification, which would bloat download size.

Significant whitespace (in all languages, really, its a difference of degree rather than kind) constrains, but does not prevent, minification. (Idiomatic python code can be reduced by three chars per indentation level on each line with no impact on semantics, and of course other transformations that aren't whitespace elimination that are past of minification are unaffected.) Heck, there are existing python minificati…

Also, with SourceMaps you could provide compiled Python code (.pyc), which is already heavily minified.

Re: PyPy.js: A fast, compliant Python implementation for the web

#108
post #96
post #49

Earlier quoted context omitted.

I was more disappointed (but not surprised!) that "import pip" didn't work. If it did (and it has big ramifications for how much of "python" (for some definition of "python" that includes most of the standard library) works. Eg sockets, interacting with some sort of "local" "file-system" etc) one could (this is handy if working on windows, and running python via cmd-r python.exe): import pip # pip.main expects a list…

That would be a total security nightmare and hopefully it's never going to happen. I'd be happy enough with serving .py files with the exact same restrictions and privileges that JS libraries have now.

> That would be a total security nightmare and hopefully it's never going to happen.

Why? You're assuming a lot of things about a hypothetical implementation that is going to have heavy restrictions on in anyway since it's running in the javascript sandbox.

Re: PyPy.js: A fast, compliant Python implementation for the web

#109
post #17

Earlier quoted context omitted.

Glorious indeed. At least three levels of abstraction, two JITs, and a host of supporting code. Can we add some more layers like an emulator or get recursive by getting something like Pyasm running inside it?

I work on a machine that has two hypervisors, one third in plan, and more abstraction layers than a lasagna software. It is still very very efficient.

This crashes my mobile (webview based) web browser.

Re: PyPy.js: A fast, compliant Python implementation for the web

#110
post #78
post #70

Earlier quoted context omitted.

> At the end is answered why python can't be directly included in Firefox or other browsers(the presenter/main developer works for Mozilla) Direct link to answer: https://youtu.be/PiBfOFqDIAI?t=1611

"If we ship Python inside of Firefox, no one is going to use it because it's not available in Chrome, it's not available in Internet Explorer." Oh yeah? Try me.

Here's a possible solution

- Let there be pojs landing page

- Download pypy.js in the background

- Run python code

- Dance with Glee!

Post reply on HN