Skip to main content

Playground

The Nolang Playground is an online environment where you can edit, compile, and run Nolang programs directly in the browser. It compiles the Nolang compiler (no.wasm) and language server (lsp.wasm) to WebAssembly and executes user code inside the browser sandbox via WASI — no local toolchain installation required.

Go now: /playground

Usage​

The Playground page is split into two panes:

  • Left Editor: A code editor based on CodeMirror 6, with Nolang syntax highlighting, auto-indentation, and history.
  • Right Output / stderr / Diagnostics: Execution results, standard error output, and diagnostic messages.

The interface follows the Docusaurus locale (Simplified Chinese / English), and the output panes support both light and dark themes.

Toolbar​

ButtonFunction
▶ RunCompile the current code to WASM and execute via WASI; stdout shown in the right Output pane.
FormatCall no fmt through the LSP to format the current code.
ExamplesLoad a built-in example grouped by category, replacing the editor content.

The right side of the toolbar shows the current status (idle / compiling / running / done / error), and a bilingual description of the selected example appears below the dropdown. The last selected example is remembered in browser local storage.

Examples​

The Examples dropdown ships 24 examples grouped into six topics, all validated in CI through exactly the same --wasm-direct compiler path the browser uses:

CategoryCountCovers
Basics7Hello World, inference, functions & recursion, Fibonacci, arithmetic & bitwise, formatting, strings
Control flow6Short-circuit guards, match, FizzBuzz, four range-loop forms, conditional while, break / continue
Data structures4Fixed arrays, slices, structs, methods
Scalar types4char, bool, f64, byte
Standard library2math.max / math.min / sqrt, rand.rand
Error handling1option and nil with three-arm match

Each example carries a stable expected-output substring. CI compiles every example, executes it with wasmtime, and asserts that substring appears in stdout — so examples cannot silently rot when the language or the Direct-WASM backend evolves.

Selecting an example clears the current Output, stderr, and Diagnostics, then replaces the editor with that example's content.

Diagnostics​

When the LSP detects syntax or type errors, they appear in the Diagnostics area at the bottom-right. Clicking any diagnostic item navigates to the corresponding line and column. file:line:col messages in compiler stderr are additionally parsed into Run Errors markers, with trailing TraceIDs and localized severity prefixes stripped automatically.

Errors and timeouts​

WASM load failures used to go only to console.warn, leaving the user with a Run button that did nothing. The current behaviour:

  • If no.wasm or lsp.wasm cannot be downloaded or compiled, a dismissible error banner at the top of the page names the asset and the reason.
  • A language-server initialization failure also shows a banner; the editor keeps working, but completion, hover, and formatting are unavailable.
  • Every run is timed by a main-thread watchdog (8 seconds by default). wasi.start() is a synchronous call inside the worker, so an infinite loop prevents any timer in that worker from firing — terminating the worker from the main thread is the only way to actually stop it. After a timeout the worker is terminated, recreated lazily on the next run, and WASM warm-up restarts immediately.
  • Repeated Run clicks are rejected by a concurrency guard, and pending edit debounces are cancelled when switching examples or formatting, so stale input cannot overwrite new content.

no.wasm and lsp.wasm are fetched and stream-compiled during browser idle time, so the first Run no longer waits for the full 27 MB download and compile.

Limitations​

Because the Playground runs inside a browser WASM sandbox, some Nolang features are unavailable:

No FFI​

The browser cannot link native C libraries, so #{c}, #{cpp}, #{rust} FFI declarations cannot be used in the Playground. Code that involves FFI (such as sqlite or mysql drivers) cannot execute.

No fork / exec / pipe​

WASI preview1 does not provide process management APIs, so the process standard library (process.start, process.wait, etc.) is not available in the Playground.

Network sockets unavailable​

WASI preview1 does not provide socket APIs, so the following standard libraries are unavailable in the Playground:

  • net (TCP listener / conn)
  • http / http2 / http3 (HTTP client)
  • ws (WebSocket)
  • tls (TLS connection)
  • quic, sse, dns

A stricter constraint on no / lsp themselves: the wasm artifacts may not even import a socket function. The browser instantiates them through @wasmer/wasi, which has no sock_accept / sock_shutdown implementation, so an artifact that pulls net / net/http into the wasip1 link throws:

Failed to instantiate WASI: RuntimeError: JsValue(LinkError: WebAssembly.Instance():
Import #28 "wasi_snapshot_preview1" "sock_accept": function import requires a callable)

and the program never reaches _start — the language service reports "initialization failed" (no completion, hover or formatting, while the editor itself still works), and Run fails the same way. Network code that only makes sense natively therefore lives behind !wasip1, with error stubs on the wasip1 side: cmd/lsp/pprof_wasip1.go, cmd/no/serve_esm_wasip1.go, package/download_net_wasip1.go, package/release_net_wasip1.go. bun scripts/wasm_imports_check.ts (make wasm-imports-check) guards the invariant using the engine's own import table.

poll_oneoff is supplied by the front end​

A clean import table only means the functions exist, not that they work. @wasmer/wasi's poll_oneoff body is Rust unimplemented!(): the moment it is called — even with zero subscriptions — it executes unreachable and traps the whole instance:

Error while running start function: RuntimeError: JsValue(RuntimeError: unreachable)

Go's runtime turns both time.Sleep and netpoll(delay) into a single monotonic-clock subscription, so every Go program hits this: no fmt / no vet / no build all died the first time they slept, while the import check stayed green.

The fix lives in docs/src/playground/wasm-loader.ts: instantiateWasi() builds the import object itself from wasi.getImports() and replaces poll_oneoff with a JS implementation (clock subscriptions sleep to the nearest deadline and report the clock event; fd-only subscriptions report ready immediately so a wait can never block forever). Note that the override cannot be handed to wasi.instantiate(module, overrides) — the glue's own functions win, the override is silently ignored, and the program still traps. Because the import object is built here, callers must pass the instance to wasi.start(instance).

First-run compile time​

Run drives no build --wasm-direct. Measured on hello world it now takes about 0.5 s inside wasm (native no, same command: ~0.6 s). Before the std index was pre-baked (2026-11) the same numbers were ~55 s and ~11 s.

The bottleneck was never codegen — it was parsing the whole std library twice on every cold start: ValidateUndefinedVars collects the exported symbols of all 119 std modules so that module-qualified calls like math.max(...) are recognised, and CollectStdUnionAliases independently parsed the same 119 modules looking for union aliases. genstdsig now bakes both tables (per-module exports, and which modules declare union aliases) into stdsig_gen.go, so the runtime looks them up instead of parsing. Two guards keep the baked tables honest: hir.TestModuleExportsMatchChecker compares every module's exports field-by-field against a fresh HIR computation, and TestUnionAliasNarrowingMatchesFullScan compares the narrowed scan against a full one — a stale table turns tests red instead of silently changing semantics.

The watchdog keeps its two budgets (180 s for load + compile, 5 s for the user program). The first one now has a huge margin; it stays to absorb cold starts, large programs and slow devices.

Virtual filesystem​

WASI preview1 only provides stdin / stdout / stderr file descriptors — there is no real filesystem. Therefore fs, path, os.get-env, os.set-env and other file/environment-related standard libraries may not work as expected in the Playground.

Memory limit​

Browser WASM is typically constrained by a 32-bit address space; the usable memory ceiling is approximately 2 GB – 4 GB (depending on the browser and OS). Programs requiring large memory (such as deep recursion or large arrays) may fail due to out-of-memory.

Browser Compatibility​

The Playground requires a modern browser with WebAssembly support. The following versions or later are recommended:

BrowserMinimum Version
Chrome100+
Firefox100+
Safari16+
Edge100+

If the browser does not support WebAssembly or has JavaScript disabled, the Playground will be unable to load the editor or execute code.

Development and validation​

After changing the Playground, run these checks from a clean build tree:

make playground-demos # compile + execute all examples in-process via the playground's own WASI loader
make playground-demos DEMO_RUN=wasmtime # execute under an external wasmtime instead (cross-check)
make playground-demos DEMO_RUN=none # compile only, output NOT checked (never a release gate)
make wasm-imports-check # rebuild both wasm files, assert no socket imports
make wasm-runtime-smoke # run version/fmt/vet through the worker's loader path
RUN_WASM_LSP=1 RUN_WASM_BUILD=1 make wasm-runtime-smoke # + language service + full compile/run
bun scripts/playground_ui_check.ts # diagnostics, watchdog, recovery, i18n
make playground-smoke # dev server and WASM routes return HTTP 200
cd docs && bun run typecheck # TypeScript typecheck

The playground-demos compiler is the native no, but the artifacts come from the browser's own --wasm-direct -target wasm32-wasi path and are executed through instantiateWasi() in wasi-glue + wasm-loader — the exact code runner.worker runs. No wasmtime install is needed, so CI runs it directly. It asserts three things at once: the snippet compiles, the artifact passes WebAssembly validation (an empty-stack local.set from a field value-match shows up here), and the printed output matches expect (a Direct-WASM backend that silently reports 0 for ?= shows up here too).

The one thing it cannot see is the import table of no.wasm / lsp.wasm themselves — those are not produced from snippets — so wasm-imports-check covers that gap: when @wasmer/wasi lacks sock_*, WebAssembly.Instance throws LinkError and the whole playground (language service included) fails to start. The worker adds one more layer: instantiateWasi() stubs any WASI function @wasmer/wasi lacks with one returning ENOSYS / NOTSUP, so an unexpected import degrades into a failed syscall instead of taking the whole service down.

wasm-imports-check cannot catch "the function exists but its body traps" (the poll_oneoff class above), so make wasm-runtime-smoke closes the last gap: it drives no version / no fmt / no vet through the real instantiateWasi() path and can additionally verify the language service and a full compile + execute.

docs/static/wasm/*.wasm is excluded by .gitignore and local artifacts should never be committed. no.wasm and lsp.wasm are rebuilt by CI from the same source tree with the same StdSigKey, so the in-browser compiler, its embedded std AST blob, and the Direct-WASM backend all come from one build. Version skew between those three was the usual cause of past unreachable traps and WASM validation errors.

CI (pr-verify in .github/workflows/build.yml and the site build in static.yml) runs Go tests, typecheck, UI checks, and the demo gate in order, and only then rebuilds WASM from a clean tree and deploys the site.