AssemblyScript Playground
Write AssemblyScript-style functions, inspect the module and run exports — entirely offline.
AssemblyScript source
17 lines · 326 charsDiagnostics
No diagnostics. Supports export function, let/const, if/else, for, while, trace and abort.
Module & run
2 export(s) · 304 bytes estimatedRun result
Run an export to see its value.
Exports
| Name | Signature |
|---|---|
| fib | (i32) => i32 |
| sumTo | (i32) => i32 |
Imports
- env.abort
- env.trace
- env.seed
Module facts
Memory: 1 page(s) · estimated 304 bytes · 1 custom section(s)
Structural hex preview
0000 00 61 73 6d 01 00 00 00 01 00 00 00 00 00 00 00 .asm............ 0010 30 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0...............
Structural preview of a module with these exports — not compiler-produced wasm bytes.
This playground accepts AssemblyScript-flavoured TypeScript: export function declarations (multi-line or single-line bodies) with i32/u32/f64 types, let/const, if/else, for and while loops, return, and trace/abort host calls. Integer arithmetic follows WebAssembly i32/u32 truncate-and-wrap semantics, including <<, >>, >>> and bitwise & | ^ ~. An offline, step-bounded interpreter evaluates exported functions with line-numbered diagnostics, so fib(10) returns 55 without installing asc. The inspector lists exports, the env import stubs, memory pages and a structural hex preview, while the runtime selector (incremental/minimal/stub) changes module metadata. This is a subset evaluator and structural preview — it does not run the asc compiler and does not produce downloadable wasm bytes. Source is limited to 100 KB, execution to 100,000 steps and recursion to 50 frames; no code leaves the browser.
Fibonacci
export function fib(n: i32): i32 {
if (n < 2) { return n; }
return fib(n - 1) + fib(n - 2);
}Run fib with argument 10 to get 55; recursion is bounded at 50 frames.
Loop with trace
export function sumTo(n: i32): i32 {
let total = 0;
for (let i = 0; i < n; i = i + 1) { total = total + i; }
trace("sumTo", n);
return total;
}sumTo(5) returns 10 and the console pane shows the trace call with both arguments.
Syntax error
export function broken(): i32 {
return 1;A missing closing brace produces a line-numbered diagnostic and blocks execution.
Examples
Fibonacci
fib(10)55Recursive calls are evaluated with a 50-frame depth bound.
Loop and trace
sumTo(5)10, console: sumTo 5The for loop accumulates 0+1+2+3+4; trace prints both arguments.
Arithmetic
scale(7) with return n * 3 + 122Operator precedence follows conventional arithmetic rules.
Syntax error
function missing its closing braceLine 1: unclosed bodyDiagnostics appear under the editor and block execution.
About this tool
The AssemblyScript Playground is a scratchpad for TypeScript-flavoured WebAssembly snippets. Write export function declarations with i32, u32 or f64 types, call them from the Run pane with numeric arguments, and read the result alongside a line-numbered diagnostics list. The classic fib(10) example returns 55, and a loop example demonstrates trace output in the console pane.
Execution uses an offline, step-bounded interpreter for a documented subset: declarations, assignment, arithmetic and comparisons, if/else, for and while loops, function calls, and trace/abort host stubs. The module inspector lists exports and their signatures, env imports, page count, estimated size and a structural hex preview. Runtime choices (incremental, minimal, stub) change the metadata shown so you can compare configurations.
This is deliberately not a replacement for asc: it does not compile to real wasm bytes, support classes, strings returned across the ABI, or multi-file projects. Source is capped at 100 KB, execution at 100,000 steps and recursion at 50 frames. Everything runs in your browser tab.
What this tool does not do
- Offline subset evaluator — no asc compiler, no real wasm artifact, no instruction-level disassembly.
- No classes, generics, multi-file projects, string ABI or custom imports beyond env abort/trace/seed.
- Source capped at 100 KB; execution capped at 100,000 steps and 50 recursive frames.
- Module size and hex preview are structural estimates, not compiler output.
- Drafts are stored in this browser only; no sharing link is generated.
How to use this tool
Load an example
Start with Fibonacci, a loop with trace, or a small arithmetic function; the source field is editable and saved locally.
Inspect diagnostics
The diagnostics strip reports parse errors with line and column numbers, and warnings for unsupported top-level constructs.
Pick a function and arguments
Choose an exported function and pass comma-separated numeric arguments, then click Run export.
Read the module view
Review exports, imports, memory pages, estimated size and the structural hex preview; switch the runtime to compare metadata.
Use cases
First WASM steps
Learn the AssemblyScript function syntax without installing a compiler toolchain.
Snippet verification
Check the arithmetic and control flow of a small kernel before adding it to a real project.
Teaching
Show how exports, imports, memory pages and runtime choices relate to a module.
Debugging logic
Use trace output and line-numbered diagnostics to locate a mistake in a snippet.
Supported language subset
| Construct | Support |
|---|---|
| export function name(a: i32): i32 | Parsed as an export; parameters and return type shown in the inspector. |
| let / const with optional type | Declared in the function scope; assignment updates the value. |
| if / else with braces | Block form only; conditions use numeric truthiness. |
| for (let i = a; i < b; i = i + 1) | Loop with a numeric step expression. |
| while (condition) | Bounded by the global step budget. |
| trace / abort | Host stubs: trace writes to the console pane, abort stops execution. |
| i32 / u32 / f64 casts | Numeric conversions inside expressions. |
Classes, generics, imports, template strings and multi-file projects are outside the subset and produce diagnostics or warnings.
Common mistakes
Mistake:Expecting compiled .wasm bytes.
Fix:This is a subset evaluator and structural preview, not the asc compiler; no downloadable binary is produced.
Mistake:Using classes or string-returning ABIs.
Fix:Keep snippets to numeric functions and the documented statements; unsupported constructs are reported in diagnostics.
Mistake:Writing `} else if` on one line.
Fix:Use block-form else with braces; each branch starts on its own line.
Mistake:Running an infinite loop.
Fix:The 100,000-step guard stops execution and reports the limit instead of freezing the tab.
Mistake:Passing non-numeric arguments.
Fix:Arguments are parsed as finite numbers; invalid values are rejected before execution.
Frequently asked questions
Is this the real AssemblyScript compiler?
No. This is an offline subset evaluator for AssemblyScript-style numeric functions. It parses declarations, loops, conditionals and host calls, and reports line-numbered diagnostics. It does not run asc and does not produce compiled WebAssembly bytes.
Which language features are supported?
export function declarations with i32/u32/f64 types, let and const, assignment, arithmetic and comparisons, if/else blocks, for and while loops, function calls, and the trace and abort host stubs. Classes, generics, string ABIs and multi-file projects are outside the subset.
Which runtime should I pick?
incremental and minimal are the two module profiles shown in the inspector; stub removes the custom-section entry and disallows allocator-dependent examples. This is metadata for comparison, not a switch between real asc compiler backends.
Why does my import error mention env.abort?
The inspector lists the host stubs a typical AssemblyScript module expects: env.abort, env.trace and env.seed. An abort call in a snippet stops evaluation and reports its message.
Can I download the compiled .wasm?
No. The hex preview and estimated byte size are structural summaries of the source you wrote, not compiler output. For a real .wasm artifact, install @assemblyscript/asc locally or use the official AssemblyScript playground.
Are there size limits on the source?
Yes. Source is capped at 100 KB, execution at 100,000 steps and recursion at 50 frames. These guards keep the tab responsive when a snippet contains an accidental infinite loop.
References & standards
Related tools
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.
GraphQL Query Playground
Execute GraphQL queries and mutations against an editable in-memory schema, with JSON results, validation errors and timing — all in-browser.