首发于寒雁Talk
创造一个编程语言最好的时间是10年前,其次是现在。
从Emscripten到asm.js再到WebAssembly,从一个业余项目到W3C标准,差不多是整整10年。
这系列主要是我对WASM研究的笔记,可能内容比较简略。总共包括:
这系列主要是我对WASM研究的笔记,可能内容比较简略。总共包括:
//async version
WebAssembly.compile(bufferSource: ArrayBuffer): Promise<WebAssembly.Module>
WebAssembly.instantiate(bufferSource: ArrayBuffer, importObj?: any): Promise<{module: WebAssembly.Module, instance: WebAssembly.Instance}>
WebAssembly.instantiate(module: WebAssembly.Module, importObj?: any): Promise<WebAssembly.Instance>
WebAssembly.compileStreaming(source: Promise<Responce>): Promise<WebAssembly.Module> // wasm 请求头:Context-type: application/wasm
//sync version
new WebAssembly.Module(bufferSource: ArrayBuffer)
new WebAssembly.Instance(module: WebAssembly.Module, importObj?: any)
// helper
WebAssembly.Module.customSections(module:WebAssembly.Module, sectionName: string): ArrayBuffer[]
WebAssembly.Module.exports(module: WebAssembly.Module): { name: string, kind: "function|table|memory|global" }][]
WebAssembly.Module.imports(module: WebAssembly.Module): { module: string, name: string, kind: "function|table|memory|global" }][]
// validation and error
WebAssembly.validate(bufferSource: ArrayBuffer):boolean
interface CommonError {
message: string
filename: string
lineNumber: number
}
new WebAssembly.CompileError(message: string, fileName: string, lineNumber: number) // 解码,验证阶段
new WebAssembly.LinkError(message: string, fileName: string, lineNumber: number) // 实例化阶段
new WebAssembly.RuntimeError(message: string, fileName: string, lineNumber: number) // 运行阶段
复制代码
fetch('./index.wasm').then(response =>
response.arrayBuffer()
).then(bytes => WebAssembly.instantiate(bytes, {
env: {
yyy: xxx
}
})).then(wasm => {
const { module, instance } = wasm;
}).catch(console.error);
复制代码
const source = fetch('./index.wasm')
WebAssembly.compileStreaming(source).then(module =>
WebAssembly.instantiate(module, {
env: {
xxx: yyy
}
})
).then(instance => {
//xxx
}).catch(console.error);
复制代码
const source = fetch('./index.wasm')
WebAssembly.compileStreaming(source).then(module =>
WebAssembly.instantiate(module, {
env: {
xxx: yyy
}
})
).then(instance => {
//xxx
}).catch(console.error);
复制代码
最好的方式是通过 WebAssembly.compileStreaming
的方式来加载。可以对wasm模块提前进行编译验证。
这系列主要是我对WASM研究的笔记,可能内容比较简略。总共包括:
JS代码首先需要经过词法分析器(Lexer)来生成Token,如a = 1 + 2将被解析成{a, =, 1, +, 2}
五个Token
前言:今天我们聊一聊最近很火热的技术 webAssembly。webAssbemly 作为一项新的技术,自 2015 年诞生之初,就逐渐受到人们的关注。那究竟什么是 webAssembly ?它是一门新的编程语言吗?它跟虚拟机又有什么样的关系呢?它有着什么样的应用场景呢?接下来就让我们用 5-10分钟的时间来回答这些问题。
本文作者:Lin Clark
翻译原文:http://huziketang.com/blog/posts/detail?postId=58ce7fd3a6d8a07e449fdd26
本文是关于 WebAssembly 系列的第六篇文章(本系列共六篇文章),也同时是本系列的收尾文章。如果你没有读先前文章的话,建议先读这里。如果对 WebAssembly 没概念,建议先读这里。
首发于前端大哈
本文作者:Lin Clark
翻译原文:http://huziketang.com/blog/posts/detail?postId=58c77641a6d8a07e449fdd24
本文是关于 WebAssembly 系列的第四篇文章(本系列共六篇文章)。如果你没有读先前文章的话,建议先读这里。如果对 WebAssembly 没概念,建议先读这里。
本文作者:Lin Clark 翻译原文:http://huziketang.com/blog/posts/detail?postId=58c55a3ba6d8a07e449fdd23 英文原文:A crash course in assembly
本文是关于 WebAssembly 系列的第三篇文章**(本系列共六篇文章)。如果你没有读先前文章的话,建议先读这里。如果对 WebAssembly 没概念,建议先读这里。