asm.js 和 WebAssembly 有什么区别? [英] What is the difference between asm.js and WebAssembly?

查看:30
本文介绍了asm.js 和 WebAssembly 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直在阅读有关 asm.js 和 WebAssembly 的文章:

I have been reading about asm.js and WebAssembly recently:

http://ejohn.org/blog/asmjs-javascript-compile-target/

https://brendaneich.com/2015/06/from-asm-js-to-webassembly/

我仍然对一些事情感到困惑:

I am still confused about a few things:

  1. asm.js 代码是否及时编译并运行?编译成什么?
  2. 除了 asm.js 是文本和 wasm(Web 程序集)是二进制之外,两者之间有什么区别?
  3. 这对于在浏览器中运行的其他脚本语言意味着什么?以python为例,会不会
    • python 代码编译成 wasm?或
    • python解释器(Cpython)编译成wasm并解释python?

推荐答案

asm.js 代码是否及时编译并运行?编译成什么?

Is asm.js code compiled in time and run? Compiled into what?

asm.js 是普通的 javascript 代码,和往常一样由 JS 解释器编译成字节码.但是,具有 asm 支持的解释器应该进行提前编译,并且可能由于静态类型而生成更有效的代码表示.有关详细信息,请参阅 http://asmjs.org/.

asm.js is regular javascript code, and is compiled into bytecode by the JS interpreter as always. However, an interpreter with asm support is supposed to do ahead-of-time compilation, and possibly to generate more efficient code representation because of the static typing. See http://asmjs.org/ for details.

asm 和 wasm 之间有什么区别(文本与二进制除外)?

what are the differences between asm and wasm (other than text vs binary)?

暂时没有.wasm 应该是向后兼容的,可编译为 asm(同样可以作为普通 JS 执行).然而,随着对它的支持不断增加,它可能会在未来扩展更多功能.

None, for now. wasm is supposed to be backwards-compatible, compilable to asm (which again is executable as normal JS). It might however be extended with more features in the future as support for it grows.

这对于在浏览器中运行的其他脚本语言意味着什么?

What does this mean for other scripting languages, running in the browser?

后者,相反,因为 Python 仍然需要解释.不需要解释器的脚本语言当然可以直接编译为 (w)asm,前提是有一个编译器(链)支持它作为目标.

The latter, rather, as Python still needs to be interpreted. Scripting languages that don't need an interpreter can of course be directly compiled to (w)asm, given that there is a compiler (chain) that supports it as a target.

这篇关于asm.js 和 WebAssembly 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆