Master the fundamental concepts of webassembly internals through this focused micro-challenge.
A \`.wasm\` file is a sequence of sections, each with an ID, size, and payload. Parsers walk them in order to build types, functions, memories, and code bodies.
Standard sections include:
LEB128 encodes variable-length integers compactly. Function bodies prefix local decls then expr bytecode terminated by \`end\`.
For example, a module exporting \`add\` might have type section entry \`(func (param i32 i32) (result i32))\`, export name \`add\`, and a two-instruction body: \`local.get 0; local.get 1; i32.add\`.
Magic: \`00 61 73 6D\` (\`\\0asm\`), version \`01 00 00 00\`.
LEB128 decode errors cascade: one wrong length corrupts every following section offset. Parse section sizes strictly and bounds-check before advancing the cursor.
This exercise asks you to parse Wasm section headers and dump structure. You will read magic, version, and section IDs from bytes the way wasm-tools and browsers do at load time.
You will use the same mental model here when reading production interpreter source later in the track. Sketch one concrete input on paper, predict the outcome, then confirm with code. That discipline catches logic errors early and makes debugging far faster when you extend the implementation in follow-on tasks.
Write a C program that parses a minimal Wasm binary module and prints section headers, types, and export names.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github