Master the fundamental concepts of webassembly internals through this focused micro-challenge.
Browsers refuse to instantiate invalid modules. Validation is a static type and stack check over every function body before execution, catching bad stacks and type mismatches early.
The validator tracks:
Rules mirror the spec: \`i32.add\` requires two \`i32\` values; \`call\` must target a function with compatible params; \`end\` must leave the stack matching the enclosing block signature.
For example, \`i32.add\` with only one \`i32\` on the stack is a validation error, not a runtime surprise.
\`\`\` error: type mismatch at i32.add stack: [i32] (expected [i32 i32]) \`\`\`
Validate before execute on every untrusted module. Browsers depend on this pass for safety; your interpreter should refuse modules that fail stack typing rather than corrupting memory at runtime.
This exercise asks you to implement a validator for a Wasm subset before your interpreter runs code. You will type-check function bodies and reject modules with impossible stack states.
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 validates a simple Wasm function body by checking type consistency on the value stack.
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