Playground
The playground runs the real Pyle interpreter in your browser. It is libpyle compiled to WebAssembly with Emscripten, not a JavaScript reimplementation.
What is included
Section titled “What is included”The build links libpyle and registers the core modules:
The global built-ins are available: print, printf, format, typeof, pcall, Bytes, BytesBuilder, Coro, Future, input, and the rest.
input() reads a line from the page. When a script calls it, the worker suspends, an input bar appears under the toolbar, and the script resumes after you send a line. The 8-second run timer is paused while the bar is open.
What is not included
Section titled “What is not included”The CLI-only modules are absent:
import("json") in the playground fails with NameError. The same applies to the other interpreter modules.
How a run works
Section titled “How a run works”- The page starts a Web Worker.
- The worker loads
pyle_wasm.jsand the.wasmbinary. - The worker calls an Embind wrapper around
pyle::Pyle. - The wrapper creates a fresh interpreter, registers the core natives, compiles the source, and runs it.
std::coutandstderrare routed toModule.printandModule.printErr, which the worker forwards to the page.input()is bound to a host callback. The build is linked with Asyncify, so the WASM stack suspends while the page collects a line and resumes when it arrives.
Every run starts from a clean VM. Globals, files, and other state do not persist between runs.
Controls
Section titled “Controls”| Control | Behavior |
|---|---|
| Run | Compile and execute the current script |
| Ctrl+Enter | Run from the editor |
| Stop | Terminate the worker and start a fresh one |
| Reset | Restore the default example |
| Example menu | Load a bundled example |
| Clear | Clear the output panel |
Your code is saved to localStorage as you type, so a reload does not lose it.
Timeouts and errors
Section titled “Timeouts and errors”Scripts are terminated after 8 seconds. This is a hard limit enforced by the page, not by the language. An infinite loop cannot freeze the tab because execution happens in a worker. The timer is paused while the page is waiting for input() and resumes when a line is sent.
Browser-specific os behavior (no shell, in-memory filesystem, Emscripten environment) is covered in os.
Runtime errors are printed with the usual Pyle error format. The playground highlights the reported line in the editor when it can parse the location from the message.
Compiler errors are reported before execution starts and include the source location.
Building the WASM artifacts
Section titled “Building the WASM artifacts”The artifacts are built from the vendor/pyle submodule with Emscripten and CMake:
npm run wasmThis produces public/playground/pyle_wasm.js and public/playground/pyle_wasm.wasm. The build script auto-detects an emsdk installation and sets EMSDK, EM_CONFIG, and PATH. Set EMSDK explicitly if yours lives somewhere unusual.
The artifacts are generated files and are not committed. A fresh clone needs either a WASM build or the prebuilt files from CI.
Host glue
Section titled “Host glue”The glue lives in this repository:
wasm/glue.cppexposesrun(source)andversion()through Embind and binds the hostinputcallback.wasm/async_input.jsimplements the asyncinputimport that Asyncify suspends on.wasm/CMakeLists.txtbuilds the library and links the glue.public/playground/worker.jsloads the module and forwards output and input requests.src/pages/playground.astroowns the editor, output panel, input bar, and worker lifecycle.
libpyle itself contains no Emscripten APIs, so the host supplies the JavaScript and the Embind boundary.
Why the interpreter is fresh per run
Section titled “Why the interpreter is fresh per run”Pyle’s VM is not designed to be reset in place. Creating a new pyle::Pyle per run is simpler and avoids state leaking between scripts. It also makes the Stop button safe: terminating the worker discards the entire VM.
Related
Section titled “Related”- Embedding in C++ for the native side of the same API.
- Install & Build for the WASM build steps.
- Limitations for the full list of unavailable features.