Skip to content

spacestation13/dm-playground

Repository files navigation

DM Playground

This is the repository for the DM Playground.

The playground allows you to experiment with DM code purely in your browser.

Architecture

The frontend is powered by React, while v86 emulates x86 running a Linux environment where BYOND is installed. Everything happens 100% client-side.

Embedding the playground

Use the playground in an iframe with ?embed to show an editor/output-only layout.

<iframe
  src="https://play.dm-lang.org/?embed#<share-b64>"
  width="800"
  height="500"
></iframe>

Supported URL parameters:

  • embed: enables the minimized embedded layout.
  • autorun: runs the snippet automatically after the runtime is ready.
  • theme=<themeId>: sets the editor theme for the embed. Example values: vs-light, one-dark, dracula.
  • code=<base64>: seeds the editor with base64 text.
  • #<share-b64>: the anchor seeds the editor in the compressed share string format.

Embed requirements:

  • If you must sandbox it, the minimum flags are allow-scripts allow-same-origin allow-popups.

Share payload helpers

Compressed share payloads use zlib compression for efficient serialization.

You can use the Share Code button in the playground, or use the following scripts:

# From a file
pnpm run share:encode -- ./main.dm
pnpm run share:encode:json -- ./payload.json

# From stdin (bash)
cat payload.json | pnpm run share:encode:json

# From stdin (PowerShell)
Get-Content .\payload.json -Raw | pnpm run share:encode:json

pnpm run share:decode -- "<share-b64>"

If you omit the argument, the script reads from stdin when piped or prompts interactively otherwise.

Example (payload.json):

{
  "v": 1,
  "f": {
    "main": "/proc/main()\n  world.log << \"hello\"\n"
  }
}

Development

The serial controller is found here: https://github.com/spacestation13/dm-playground_controller

The buildroot linux image code is found here: https://github.com/spacestation13/dm-playground-linux

If you change the emulator runtime files or BIOS/runtime URLs, bump the cache version so existing entries are invalidated.

Build the UI

pnpm install
pnpm run dev # Starts development server with hot reload

Build the disassembler

The bytecode panel relies on a Rust library compiled for i686 Linux. You need the i686 cross-compilation toolchain installed:

rustup target add i686-unknown-linux-gnu
sudo apt-get install gcc-multilib # Debian/Ubuntu

pnpm run build:disasm

Build for production

pnpm run build   # Type-check and build
pnpm run preview # Preview production build

Code quality

pnpm run lint   # Lint with Biome
pnpm run format # Format with Biome
pnpm run test   # Run playwright tests

License

MIT

About

A browser interface to execute the DM language in the browser

Topics

Resources

License

Stars

3 stars

Watchers

1 watching

Forks

Contributors