TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

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

461 点作者 doublextremevil大约 10 年前

25 条评论

btown大约 10 年前
This is glorious. From <a href="https:&#x2F;&#x2F;github.com&#x2F;rfk&#x2F;pypyjs&#x2F;blob&#x2F;master&#x2F;CONTRIBUTING.rst" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;rfk&#x2F;pypyjs&#x2F;blob&#x2F;master&#x2F;CONTRIBUTING.rst</a> :<p>&gt; We have the following major components in the PyPy repo:<p>&gt;&gt; An &quot;emscripten&quot; build platform definition, which teaches pypy&#x27;s rpython toolchain how to compile things with emscripten: .&#x2F;deps&#x2F;pypy&#x2F;rpython&#x2F;translator&#x2F;platform&#x2F;emscripten_platform&#x2F;.<p>&gt;&gt; An rpython JIT backend that emits asmjs at runtime: .&#x2F;deps&#x2F;pypy&#x2F;rpython&#x2F;jit&#x2F;backend&#x2F;asmjs&#x2F;.<p>&gt;&gt; A &quot;js&quot; builtin module for the resulting interperter, to allow interaction with the host javascript environment: .&#x2F;deps&#x2F;pypy&#x2F;pypy&#x2F;module&#x2F;js&#x2F;.<p>&gt;Along with these wrappers to help working with the resulting interpreter:<p>&gt;&gt; A wrapper to load up the compiled VM and expose it via a nice javascript API: .&#x2F;lib&#x2F;pypy.js.<p>&gt;&gt; A script for bundling python modules into an indexed format that can be easily loaded into the browser: .&#x2F;tools&#x2F;module_bundler.py.<p>In <a href="https:&#x2F;&#x2F;github.com&#x2F;rfk&#x2F;pypy&#x2F;blob&#x2F;master&#x2F;rpython&#x2F;jit&#x2F;backend&#x2F;asmjs&#x2F;assembler.py" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;rfk&#x2F;pypy&#x2F;blob&#x2F;master&#x2F;rpython&#x2F;jit&#x2F;backend&#x2F;...</a> alone, there are 2887 lines of custom Python code to emit asm.js for function and block JITing.<p>And at 3.26 seconds to initialize from cache on a 4-year-old machine, 5MB gzipped (not too much worse than your average high-quality gif) and only 1.5x slower than CPython... this is actually approaching viable if you needed to run Python business logic in the browser. Which I never thought I would see.
评论 #9496944 未加载
评论 #9497525 未加载
评论 #9497957 未加载
评论 #9497517 未加载
评论 #9497010 未加载
brachi大约 10 年前
I watched the presentation in Pycon 2015[1], and I really liked how honest&#x2F;aware they are about the challenges and tradeoffs (so far, the performance it&#x27;s pretty bad compared to javascript, and the download size is still an issue). At the end is answered why python can&#x27;t be directly included in Firefox or other browsers(the presenter&#x2F;main developer works for Mozilla)<p>[1]<a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=PiBfOFqDIAI" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=PiBfOFqDIAI</a>
评论 #9500683 未加载
评论 #9497791 未加载
评论 #9496896 未加载
评论 #9497042 未加载
bayesianhorse大约 10 年前
Besides the big download size, it does several things very &quot;right&quot;: Full Python data model, access to the full javascript model (albeit slowly currently).<p>Also PyPy is the right choice as the basis for this (as opposed to CPython) because its ecosystem is generally more &quot;pure&quot; Python than CPython&#x27;s. C Extensions would only get in the way.
评论 #9496859 未加载
评论 #9496900 未加载
jedberg大约 10 年前
So does this mean that since I&#x27;m better at Python than Javascript, I can now use this to make my web frontends in Python? Because that would be pretty sweet.
评论 #9496907 未加载
评论 #9496862 未加载
评论 #9497115 未加载
评论 #9496863 未加载
nosir33大约 10 年前
Sample code to execute some Javascript code inside PyPy.js. I couldn&#x27;t find any examples.<p><pre><code> import js js.eval(&quot;console.log(\&quot;hi!\&quot;)&quot;)</code></pre>
评论 #9497374 未加载
评论 #9497427 未加载
评论 #9497087 未加载
评论 #9497126 未加载
评论 #9497467 未加载
Nitramp大约 10 年前
I think there is no point in trying to emulate different language semantics on top of JavaScript.<p>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).<p>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&#x2F;undefined dichotomy, or 64 bit integer math), or you end up with odd semantics that don&#x27;t quite fit the language you&#x27;re compiling from, or a mix of both, which is a usability disaster.<p>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&#x27;d be TypeScript.
评论 #9500126 未加载
Tossrock大约 10 年前
Looks like there are some issues to iron out...<p><pre><code> &gt;&gt;&gt; from datetime import datetime &gt;&gt;&gt; datetime.now() Traceback (most recent call last): File &quot;&lt;console&gt;&quot;, line 1, in &lt;module&gt; File &quot;&#x2F;lib&#x2F;pypyjs&#x2F;lib_pypy&#x2F;datetime.py&quot;, line 1548, in now return cls.fromtimestamp(t, tz) File &quot;&#x2F;lib&#x2F;pypyjs&#x2F;lib_pypy&#x2F;datetime.py&quot;, line 1522, in fromtimestamp result = cls(y, m, d, hh, mm, ss, us, tz) File &quot;&#x2F;lib&#x2F;pypyjs&#x2F;lib_pypy&#x2F;datetime.py&quot;, line 1459, in __new__ hour, minute, second, microsecond) File &quot;&#x2F;lib&#x2F;pypyjs&#x2F;lib_pypy&#x2F;datetime.py&quot;, line 312, in _check_time_fields raise ValueError(&#x27;microsecond must be in 0..999999&#x27;, microsecond) ValueError: (&#x27;microsecond must be in 0..999999&#x27;, 1716000)</code></pre>
评论 #9501385 未加载
评论 #9500962 未加载
nighthawk454大约 10 年前
Sadly, &quot;import antigravity&quot; doesn&#x27;t work
评论 #9497444 未加载
评论 #9497140 未加载
dulvac大约 10 年前
I can imagine a way to include language extensions in the browser and have them loaded up lazily in a sandbox. And a checkbox that says &quot;Allow websites to run code&quot; or something. Then you could develop an extension for your favourite language and either install them manually or have some popular ones bundled with the browser.<p>If we&#x27;re going to run everything in the browser, why use javascript as the low-level language that stuff compiles to?<p>I know portability and existing standards are a limitation, but those can be influenced by the 3 (?) major browsers if needed.<p>I think asm.js is an awesome cute little thing, but the fact that it&#x27;s taken seriously is worrisome to me.<p>Am I completely crazy here?
bootload大约 10 年前
If software is eating the world, JavaScript is eating the languages.
评论 #9497760 未加载
henryaj大约 10 年前
Please humour my lack of knowledge: is there much difference between something like this and Opal[0]?<p>[0] - <a href="http:&#x2F;&#x2F;opalrb.org" rel="nofollow">http:&#x2F;&#x2F;opalrb.org</a>
评论 #9497643 未加载
pc2g4d大约 10 年前
Not working for me:<p>&quot;Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at <a href="http:&#x2F;&#x2F;10.30.229.27:15871&#x2F;cgi-bin&#x2F;blockpage.cgi?ws-session=18446744072937828300" rel="nofollow">http:&#x2F;&#x2F;10.30.229.27:15871&#x2F;cgi-bin&#x2F;blockpage.cgi?ws-session=1...</a>. This can be fixed by moving the resource to the same domain or enabling CORS.&quot;<p>Firefox 37.0.1
acron0大约 10 年前
Obligatory link to Atwood&#x27;s Law: <a href="http:&#x2F;&#x2F;blog.codinghorror.com&#x2F;the-principle-of-least-power&#x2F;" rel="nofollow">http:&#x2F;&#x2F;blog.codinghorror.com&#x2F;the-principle-of-least-power&#x2F;</a><p>Although I appreciate that this isn&#x27;t technically &quot;written in JavaScript&quot; but it follows the principle.
MBlume大约 10 年前
I&#x27;m curious -- since the custom emitter is tied to the RPython JIT and not to the Python interpreter, could one easily plug in the existing Ruby or PHP interpreters written in RPython and get similar performance?
estomagordo大约 10 年前
Unfortunately, this is of little use to me. Why? Well, with my Swedish keyboard layout, some alt-combinations are crucial (mainly square brackets, []). And these keypresses do not seem to work.
评论 #9497668 未加载
hurin大约 10 年前
&gt;&gt;&gt; def foo(x,y):<p>... return x,y<p>debug: OperationError:<p>debug: operror-type: SyntaxError<p>debug: operror-value: (&#x27;EOL while scanning string literal&#x27;, (&#x27;c callback&#x27;, 1, 12, &quot;r = c.push(&#x27;def foo(x,y):\n&quot;, 0))<p>&gt;&gt;&gt;
acbart大约 10 年前
I use Skulpt for a lot of my research - I&#x27;d love to see a comparison against it in terms of speed, accuracy, etc.
gdw2大约 10 年前
Can the client-side python access the DOM?
评论 #9499662 未加载
dlitz大约 10 年前
Is there a Python 3 version of this?
评论 #9497540 未加载
评论 #9509784 未加载
forgottenuser大约 10 年前
How is this different than Brython or Skulpt?<p>Also python implementations that run in the browser.<p>[1] skulpt.org [2] brython.info
xiaq大约 10 年前
The next level is to run a Python implementation of JavaScript inside that...
nirai大约 10 年前
Doesn&#x27;t seem to work well on chrome on a modern tablet.
raymondh大约 10 年前
This is pretty cool.
retrogradeorbit大约 10 年前
6.6 Megs of binary blob download (pypy.vm.js.mem). Plus 593K of index.json. Yuck.<p>Curious. Interesting tech. But hardly practical.
morekozhambu大约 10 年前
This is super awesome.