Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: 于航

Rating No ratings yet

WebAssembly技术现在已经被计划设计成W3C的标准,众多浏览器厂商已经提供了对其MVP版本标准的支持。在Google I/O 2017大会上,Google首次针对WebAssembly技术进行了公开演讲和推广,其Post-MVP版本标准更是对诸如DOM操作、多线程和GC等特性提供了支持。WebAssembly所带来的Web技术变革势不可挡。本书力求从一些简单的实践入手,深入理论,到复杂的具有实际业务价值的综合实践,深入浅出地介绍Wasm技术发展至今,其背后所涉及的各种底层设计原理与实现、相关工具链以及未来发展方向等多方面内容。本书内容包括:WebAssembly技术的发展历程,从PNaCl到ASM.js再到WebAssembly,以及这些技术的基本应用方法与性能对比;WebAssembly的标准上层API、底层堆栈机的设计原理,以及对MVP标准理论的深入解读;与WebAssembly标准相关的进阶内容,如单指令多数据流(SIMD)、动态链接(DL)等;LLVM工具链与WAT可读文本格式的相关内容;基于Emscripten工具链开发WebAssembly应用的基本流程,以及工具链的一些基本常用功能和特性;基于Emscripten工具链实现C/C++语言动态关系绑定技术;Emscripten工具链所提供的一些如WebGL支持、虚拟文件系统、应用优化以及HTML 5事件系统等高级应用特性;构建一个具有实际业务价值的WebAssembly应用,现阶段Wasm生态的发展情况,以及在Post-MVP标准中制订的一些WebAssembly未来发展规划。本书的目标读者为Web前端开发人员、C/C++开发人员和对WebAssembly技术感兴趣的人员。

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A ground-up guide to WebAssembly that connects the technology's history, its stack-machine internals, and the LLVM/Emscripten toolchain to real, buildable applications. Best for front-end developers and C/C++ programmers who want to understand *why* Wasm works, not just how to call it. 【Book Arc】 - **Opening (~0%–15%)**: Sets up the "big front-end" convergence and traces the lineage from PNaCl and ASM.js to WebAssembly, using performance comparisons and simple demos to explain why earlier approaches failed. - **Early (~15%–31%)**: Introduces the standard upper-level JavaScript API — module compilation, instantiation, tables, memory, and error types — alongside the first hands-on Wasm examples. - **Middle (~31%–62%)**: Dives into the stack-machine design: RPN evaluation, the data/type stacks, structured control flow, binary encoding (LEB-128, OpCodes, sections), linear memory and addressing, plus ELF-style dynamic linking and SIMD. - **Late (~62%–77%)**: Moves to tooling — LLVM-IR, Clang/llc, WAT text format, and a from-scratch static compiler for a toy language — then introduces the Emscripten toolchain and its runtime environment. - **Ending (~77%+)**: Applies Emscripten to C/C++ binding, virtual file systems, WebGL, optimization, and HTML5 events, culminating in a business-value application and a look at the Post-MVP roadmap. 【Key Takeaways】 - **Wasm is a portable, sandboxed binary format, not a language** (Opening): it targets near-native speed across CPU architectures, unlike architecture-specific NaCl/PNaCl. - **The stack machine is the conceptual core** (Middle): RPN expressions, data/type stacks, and structured control flow (block/if/br) explain how Wasm validates and executes safely. - **Binary encoding matters** (Middle): LEB-128, section structures, and OpCodes determine module size and load speed — understanding them demystifies the format. - **Dynamic linking is table-based** (Middle): Wasm simulates a simplified GOT/PLT via the Table segment and `call_indirect`, since it cannot use ELF-style linking directly. - **LLVM is the bridge from C/C++ to Wasm** (Late): LLVM-IR, Clang, and `llc` (with wasm32/wasm64 targets) form the compilation backbone. - **Emscripten is the practical toolkit** (Late): emcc, the runtime environment, ccall/cwrap bindings, and virtual file systems let existing C/C++ code run in the browser with minimal changes. - **Real applications require more than compilation** (Ending): WebGL, file system choices (MEMFS/IDBFS/NODEFS), optimization, and event handling are needed for production value. - **The ecosystem is still evolving** (Ending): Post-MVP plans cover DOM, threads, and GC, so readers should track updates rather than treat the book as final. 【Reading Tips】 - Deep-read the stack-machine and binary-encoding chapters (Middle) — they are the intellectual core and hardest to skim. - Skim the historical PNaCl/ASM.js narrative (Opening) if you already know the background; focus on the performance comparisons. - Treat the LLVM/Emscripten chapters (Late) as a hands-on lab: build the examples rather than only reading them. - Note the author's caveat that Emscripten changes weekly; check the companion GitHub repo for errata and updates. 【Coverage Limits】 This guide is based on stratified excerpts covering roughly the first three-quarters of the book; the final application chapter and Post-MVP roadmap are summarized from the blurb and later excerpts rather than fully detailed.
Excerpt 1
pt 6对应ECMAScript 2015)。 从十年前擅长直接操作DOM对象的jQuery到十年后以MVVM模式架构 见长的React以及Vue.js等框架,前端框架的发展突飞猛进,不断地改 变着人们在前端应用领域的日常开发模式。从最初碎片组件化的开发 模式到现在已经逐渐成体系化、完整组件化和分层次的开发模式,...
View in text
Excerpt 2
完成对Wasm模块的初始化操 作时,脚本会将模块暴露给JavaScript环境的所有可用方法整合到 Module对象中。因此,只有当Module对象完成初始化后,我们才能进 行后续的模块方法调用过程。为此,需要把这些在Wasm模块完成初始 化后才能够进行调用的代码,全部放到script.onload这个脚本加载完...
View in text
Excerpt 3
。接下来仍以该地址作为首地址,并分别读取长度为3、2、1 字节的数据。我们发现,这些读取到的数据均可以被成功地转换为十 六进制数字值“4A”(只是含有占位字节00)。与“00 00 00 4A”相 比尽管取出的数据长度不同,但数据的最高有效位与最低有效位均存 在且完全相同,因此对应的十进制数字值也相同。这便是小端...
View in text
Excerpt 4
表示代码进行优化会更加简单和高效。这也是大部 分现代编译器的代码优化目标,比如基于LLVM优化器与LLVM-IR构建的 Clang编译器。 4.1.5 LLVM命令行工具 本节我们将了解在LLVM工具链套件内提供的一系列非常实用的命 令行工具。通过这些工具,我们可以方便地在本地对基于LLVM开发的 各类项目、源代...
View in text
Excerpt 5
bc和libcxx库的浏览器实现,同时还构建了一个浏 览器端的虚拟文件系统,以便能够正常编译并在Web浏览器上运行使用 了标准库文件操作相关API的C/C++程序,而不用进行任何修改。 相比于传统的本地文件系统,Emscripten 所构建的虚拟文件系则 需要在应用运行前进行初始化。所谓的初始化是指将应用需要在本...
View in text
Excerpt 6
对该文件中记录的接口定义关系进行优化,并同时生 成与其相对应的JavaScript“胶水”代码。通过使用这些“胶水”代 码,我们便可以在 JavaScript 环境中间接地使用在原始 C/C++代码 中定义的接口和数据元素。 在Emscripten工具链中通过WebIDL来实现语言关系绑定分为三个 步骤。 (1)...
View in text
Excerpt 7
+代码中,我们通过标准库中三种不同的输入/输出 流对象,分别使用了三种基本类型的I/O流。接下来,我们便可以通过 FS.init函数来设置Emscripten在上层JavaScript环境中处理这三种 I/O流时的具体表现形式。 这里FS.init函数一共接收三个匿名函数作为其参数,按照顺序它 们依次分别对应于“...
View in text
Tags
AI categories
Web TechnologyProgramming LanguageSoftware
Publish Year: 2018
Language: Chinese
File Format: PDF
File Size: 16.5 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…