WAT to WASM Playground
Write WebAssembly Text, run exported functions with typed arguments and inspect the outcome in your browser.
WAT source
Module runner
0 exported function(s) · ~8 bytesNo WAT source yet
Type a module or load the add example to call its exports.
Examples
Add two numbers
(module (func $add (param i32 i32) (result i32) local.get 0 local.get 1 i32.add) (export "add" (func $add)))Exports add; call with 2, 3 → 5Simple function taking two i32 params and returning their sum.
Factorial loop
(module (func $fact (param i32) (result i32) (local i32 i32) local.set 1 (i32.const 1) (loop $l local.get 0 i32.eqz br_if 1 local.set 1 (i32.mul (local.get 1) (local.get 0)) local.set 0 (i32.sub (local.get 0) (i32.const 1)) br 0) local.get 1) (export "fact" (func $fact)))fact(5) → 120Iterative factorial using a loop with branch.
Memory load/store
(module (memory 1) (data (i32.const 0) "hello") (func $read (result i32) i32.load8_u (i32.const 0)) (export "read" (func $read)))read() → 104 ('h')Data segment initializes linear memory; i32.load8_u reads first byte.
About this tool
WAT/WASM Playground parses WebAssembly text format (WAT) and runs it in the browser with a step-bounded interpreter. It replaces a local wasm toolchain install for learning and quick prototyping.
The parser handles the full module grammar: types, imports, functions, tables, memories, globals, data/element segments, and exports. The interpreter executes core instructions with a configurable instruction budget (default 100k steps) and trap safety — no WebAssembly runtime is bundled.
All computation is local and client-side. The WAT is never sent to a server, and the module is never instantiated as a WebAssembly.Module — the interpreter emulates numeric semantics, control flow, linear memory, and data segments in pure TypeScript.
What this tool does not do
- Instruction budget caps execution (default 100k steps). Deep recursion or large loops may hit it.
- Only core numeric types (i32, i64, f32, f64) are supported; v128 SIMD is not implemented.
- No bulk memory, exceptions, threads, or tail-call features.
- call_indirect table is not implemented; only static call is supported.
- No WebAssembly runtime is bundled — this is a learning tool, not a production engine.
- Files are parsed in the tab; very large WAT may be slow on older devices.
How to use this tool
Write or paste WAT
Enter WebAssembly text format directly, or load one of the built-in examples (add, factorial, memory).
Run
Click Run to execute with the default instruction budget. The result shows returned values, final locals, and linear memory state.
Adjust budget
Increase the step limit for longer-running programs (loops, recursion). Traps show the exact instruction that halted execution.
Inspect memory
The Memory panel shows the final linear memory as hex with ASCII, plus data segments and their offsets.
Copy/share
Use Copy to copy the WAT, or Download to save a .wat file. The share link encodes the entire module text.
Use cases
Learn WebAssembly
Write and execute WAT step-by-step without a local toolchain.
Prototype WASM functions
Test numeric algorithms and control flow before compiling to a real module.
Debug trap behavior
See exactly which instruction causes division-by-zero, out-of-bounds, or unreachable.
Teach WebAssembly internals
Inspect linear memory, locals, and stack state after execution.
Supported WAT constructs
| Category | Constructs |
|---|---|
| Types | func, param, result |
| Functions | func, local, export |
| Control flow | block, loop, if, br, br_if, br_table, return, unreachable |
| Calls | call, call_indirect |
| Memory | memory, data, i32.load/store |
| Globals | global, get/set |
| Numeric | i32/i64/f32/f64 ops |
This is a documented subset for learning. Full WebAssembly spec features (bulk memory, SIMD, exceptions, threads, reference types beyond funcref/externref) are not implemented.
Common mistakes
Mistake:Expecting a full WebAssembly runtime.
Fix:This is a learning interpreter — SIMD, exceptions, threads, and advanced features are not implemented.
Mistake:Using unlimited loops without budget.
Fix:Increase the instruction budget or add a loop counter to avoid hitting the step limit.
Mistake:Expecting WebAssembly.Module instantiation.
Fix:The module is never instantiated; the interpreter emulates semantics. Use wabt.js or wasmtime for real execution.
Mistake:Assuming WAT text is the same as binary WASM.
Fix:The tool parses WAT text. For binary .wasm inspection, use the WebAssembly Module Inspector tool.
Mistake:Ignoring trap output.
Fix:Traps halt execution and show the failing instruction with line/column — read them to fix logic errors.
Frequently asked questions
What is WAT?
WAT (WebAssembly Text Format) is the human-readable source representation of a WebAssembly module. It uses S-expression syntax with (module ...) as the root. This tool parses WAT text and executes it with a step-bounded interpreter — no external runtime is needed.
Does it compile WAT to binary WASM?
No. The parser builds an in-memory module structure directly from the text. The interpreter then executes that structure. There is no binary .wasm output; if you need a compiled binary, use wat2wasm from WABT.
What instructions are supported?
Core numeric ops for i32/i64/f32/f64 (arithmetic, bitwise, comparison, conversion), control flow (block, loop, if, br, br_if, br_table, return, unreachable), calls (call, call_indirect — table not implemented yet), locals (get/set/tee), globals (get/set), and memory (load/store with alignment). Data segments initialize linear memory.
Why does my loop stop early?
The interpreter has an instruction budget (default 100,000 steps). Each executed instruction counts toward it; when the budget is exhausted, execution halts with a trap. Increase the budget in the UI or add a loop counter to finish within the limit.
Are traps safe?
Yes. Traps (division by zero, out-of-bounds memory access, unreachable, call to undefined function, stack under/overflow) stop execution immediately and report the failing instruction with line/column context. No WebAssembly code is actually instantiated, so browser memory is never at risk.
Can I use SIMD (v128)?
Not in this build. The interpreter supports only the core scalar types i32, i64, f32, f64 and reference types funcref/externref. v128 SIMD, bulk memory, exceptions, threads, tail calls and extended reference types are not implemented.
What does the Memory panel show?
After execution (or a trap), the Memory panel displays the final linear memory as a hex dump with ASCII. Data segments and their offsets are overlaid. You can copy or download the memory snapshot.
Is my code sent to a server?
No. Everything runs locally in your browser tab. The WAT is parsed and interpreted entirely in JavaScript/TypeScript. Nothing is uploaded, cached, or persisted.
How big a WAT can I run?
The editor accepts up to ~2 MB of text. Very large modules with many functions or large data segments may be slow on older devices because parsing and interpretation are single-threaded in the main thread.
Can I import host functions (e.g., console.log)?
Not in this version. Import resolution is not implemented — the interpreter only runs self-contained modules. For host integration, you would need a full runtime like wasmtime, Wasmer, or a JavaScript WebAssembly.Instance with an import object.
References & standards
Related tools
AssemblyScript Playground
Write AssemblyScript-style functions, inspect a module preview, and run exports with a step-bounded offline evaluator.
Bash Playground
Test bash script snippets in a local mini-shell with seeded files, stdin, stream tags and visible sandbox limits.
C & C++ Playground
Check C and small C++ source for structural problems, map findings to lines and see the compile command for a local toolchain.
C# Playground & Snippet Checker
Static pre-flight checks for C# snippets — diagnostics, detected features and metrics, entirely in-browser.
Dart Playground
Write Dart, press Run, and see print output in your browser.
DBML Playground
Write DBML and see an ER diagram plus SQL DDL for Postgres, MySQL, SQLite and MSSQL, all in your browser.