Whole-book reading guide from stratified index samples; jump to passages in the text
Tip the Site
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat Pay
Alipay
Open WeChat or Alipay and scan. No login required.
AI guide
【One-Line Pitch】
A hands-on, "build-your-own-Wasm" guide that walks through WebAssembly's binary format, instruction set, and interpreter internals using Go, ideal for developers who want to truly understand Wasm rather than just use it.
【Book Arc】
- **Opening (~0%–4%)**: Sets up the book's "wheel-building" philosophy, introduces the four languages used (Go, WAT, Rust, JavaScript), and explains how to set up the toolchain (Go, Rust, WABT) and download the companion code from GitHub.
- **Early (~4%–21%)**: Dives into the binary format (magic number, version, sections) and the instruction set, covering index spaces, LEB128 encoding, and core instructions like variable access and function calls, with WAT examples and hex dumps for hands-on analysis.
- **Early–Middle (~21%–36%)**: Explains the text format (WAT) as a human-readable counterpart to binary, then shifts to building a virtual machine, starting with the operand stack and implementing basic instructions (constants, arithmetic, drop).
- **Middle (~36%–50%)**: Adds memory management (pages, load/store instructions) and introduces function calls, including the call stack and control frames, with a recursive Fibonacci example to test the implementation.
- **Middle–Late (~50%–54%)**: Covers structured control instructions (block, loop, if) and branch instructions (br, br_if), explaining jump labels and how they interact with the control stack, reusing function-call machinery for efficiency.
【Key Takeaways】
- **Index spaces organize all module elements** (Early): Functions, globals, tables, and memories each have their own index space, with imports and definitions sharing the same range; locals and labels are function-scoped. This mental model is crucial for decoding and executing any Wasm module.
- **LEB128 is the backbone of compact binary encoding** (Early): This variable-length, little-endian scheme encodes small integers in fewer bytes, saving space for indices and lengths; understanding its signed/unsigned variants is essential for writing a decoder.
- **The binary format is section-based and order-dependent** (Early): From magic number `\0asm` and version 1, through type, function, table, memory, and data sections, each section has a specific ID and structure; tools like `wasm-objdump` help verify your parsing.
- **WAT is a syntactic sugar over binary** (Early): The text format uses parentheses and keywords (e.g., `module`, `func`, `param`) to express the same structures as binary, with identifiers (`$name`) and folding forms making it more human-friendly; mastering WAT aids in writing test cases.
- **The operand stack is the core of the VM** (Early): A simple stack machine can execute most instructions—constants push, arithmetic pops two and pushes one, and `drop` discards the top; this foundation scales as more components are added.
- **Memory is page-based with explicit bounds checking** (Middle): Wasm memory is a byte array divided into 64KB pages, with `grow` to expand and load/store instructions for reading/writing; boundary checks are critical to prevent crashes, and bulk-memory operations are a proposed optimization.
- **Function calls rely on control frames, not just a call stack** (Middle): A control frame stores opcode, type, instructions, base pointer, and program counter, unifying function calls with structured control instructions; this design simplifies later implementation of blocks and loops.
- **Branches are structured, not arbitrary** (Middle–Late): `br` and `br_if` only jump to labels defined by `block`, `if`, or `loop`, with `block`/`if` targeting the end and `loop` the start; this restriction ensures stack consistency and makes control flow predictable.
【Reading Tips】
- **Skim the setup chapter** (Opening): If you're comfortable with Go and command-line tools, skip ahead; just clone the repo and verify your environment with the provided commands.
- **Deep-read the binary format chapters** (Early): Use `xxd` and `wasm-objdump` alongside the text to trace each section; this hands-on approach makes abstract encodings like LEB128 concrete.
- **Treat WAT examples as executable specs** (Early): Compile and disassemble the provided `.wat` files to see how text maps to bytes; this reinforces both formats simultaneously.
- **Focus on the VM architecture** (Middle): Pay attention to how the operand stack, memory, and control frames are structured in Go; these patterns are reusable for any interpreter project.
- **Don't get stuck on every instruction** (Middle): The book groups similar instructions (e.g., all store variants); understand one pattern (like `i64.store`) and the rest follow—skim the tables and move on.
【Coverage Limits】
Excerpts cover roughly the first half of the book (through control instructions); later topics like indirect calls, linking, validation, and advanced proposals (e.g., bulk memory) are mentioned but not detailed here.
需要把5条变量指令添加到指令表中。这个改动比较简单,就不展示代码了。然后,需要在创建虚拟机实例后,分配并初始化全局变量。我们把全局变量初始化逻辑封装在initGlobals()方法里,代码如下所示。 func (vm *vm) initGlobals() { for _, global := range vm.m...
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.
Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat PayAlipay
Open WeChat or Alipay and scan. No login required.
Add Tag
Enter tag name (max 50 characters)
Share E-Book
WebAssembly原理与核心技术 (张秀宏)(Z-Library)
Scan QR code with your phone to access
Copy the link or scan the QR code to access this e-book on your phone
Share to WeChat Moments
WebAssembly原理与核心技术 (张秀宏)(Z-Library)
Scan the QR code with WeChat to open this book
Tap the ··· menu in the top-right corner
Choose Share to Moments
You are already in WeChat. Tap ··· in the top-right corner and choose Share to Moments.
Share E-Book via Email
Please enter email address
Donation Statistics
¥.00
Total Donations
0
Donation Count
WebAssembly原理与核心技术 (张秀宏)(Z-Library)
Find Your Favorite Books
Only registered users can comment after logging in. Comments need to be reviewed by administrators before being displayed
Loading comments...
Reply to Comment
Edit Comment