Web Assembly
tags: learning wasm source-node programming
questions to answer
- what’s Web Assembly
- what does it do
- what’s WasmEdge?
content
WebAssembly (abbreviated Wasm) is a binary instruction format for a stack-based virtual machine. Wasm is designed as a portable compilation target for programming languages, enabling deployment on the web for client and server applications.
- 本身
.wasm是个 format - 用其他语言写好代码之后, compiled 成
.wasm- 有这样的工具: teavm 把 java compiles 成 js、WebAssembly、C
- 在 python 的 pyodide 有使用例子:
<head>
<script src="https://cdn.jsdelivr.net/pyodide/v0.27.5/full/pyodide.js"></script>
</head>
<body>
Pyodide test page <br>
Open your browser console to see Pyodide output
<script type="text/javascript">
async function main(){
let pyodide = await loadPyodide();
console.log(pyodide.runPython(`
import sys
sys.version
`));
pyodide.runPython("print(1 + 2)");
}
main();
</script>
</body>- Pyodide 本质上是个 python interpreter
- 上面的代码就是在 html page 里引入了个 python interpreter 的一些
.js和.wasm文件, 然后启动一个 interpreter 的 instance
- 上面的代码就是在 html page 里引入了个 python interpreter 的一些
- 值得注意的是, python 代码并没有被编译成
.wasm, 这里的 webassembly 是说, 我的 python code 在已经 WebAssembly 化 的 interpreter 上运行
up
prerequisite: 从代码到执行