{
 "meta": {
  "title": "Getting Started — The Crush Language Guide",
  "description": "Generated from getting-started.md of The Crush Language Guide (https://docs.crushlang.org/getting-started.html). Edit the guide, not this file: it is regenerated on every build.",
  "frontends": [
   "crush"
  ],
  "author": "The Crush Language Guide",
  "tags": {
   "source": "getting-started.md",
   "guide_url": "https://docs.crushlang.org/getting-started.html",
   "generator": "scripts/build-notebooks.py"
  }
 },
 "cells": [
  {
   "id": "getting-started-md-1",
   "kind": {
    "type": "markdown"
   },
   "source": "# Getting Started\n\nCrush is alpha software. This page gets you from a clean machine to a running\nprogram, and then shows how to embed the VM in a Rust application.\n\n> Verified against crush-ast `v0.13.0` (`dc0d0278`, 2026-12-03), built from source as the\n> guide's CI does. That commit is newer than the latest release, **v0.11.2**\n> (2026-11-07): a few things on these pages (catching run-time faults, `a.pop()`,\n> calling any expression, the struct-name clash error, `--max-wall-ms`, the\n> `net.*`/`tcp.*` timeouts) are on main only until the next release.\n\n## 1. Install the toolchain\n\nThe language is implemented in [crush-ast](https://github.com/nixpt/crush-ast).\nThere are two ways to get it. Both give you the same `crush`, `crushc`, `crush-run`,\n`crush-compile`, `crush-repl` and `crush-debug`.\n\n**From crates.io** (needs Rust 1.95 or newer):\n\n```sh\ncargo install crush-lang-sdk\n```\n\n> **Not `cargo install crush`.** The `crush` crate on crates.io is an unrelated\n> project. The toolchain is published as **`crush-lang-sdk`**. There is no\n> `crush-ast` crate either; that is the repository's name.\n\n**Prebuilt Linux binaries.** Since v0.9.0 every `vX.Y.Z` tag has a GitHub release\n(a pre-release until 1.0) with a Linux x86_64 tarball, a tarball of the browser\nruntime, and a `SHA256SUMS` file. The newest is v0.11.2:\n\n```sh\ngh release download v0.11.2 --repo nixpt/crush-ast\nsha256sum -c SHA256SUMS\ntar -xzf crush-0.11.2-x86_64-unknown-linux-gnu.tar.gz\nexport PATH=\"$PWD/crush-0.11.2-x86_64-unknown-linux-gnu:$PATH\"\n```\n\nThe tarball holds `crush`, `crushc`, `crush-run`, `crush-compile`, `crush-repl`,\n`crush-debug`, `crush-pkg` and `crush-gui`. `crush doctor` then tells you which\ninterpreters your polyglot blocks can use.\n\n**From source**, to build a particular commit (this is how the guide's CI builds\nthe commit in `CRUSH_AST_COMMIT`):\n\n```sh\ngit clone https://github.com/nixpt/crush-ast\ngit clone https://github.com/nixpt/buckets      # must sit NEXT TO crush-ast\ncd crush-ast\ncargo build --release -p crush-lang-sdk                       # crush, crush-run, crushc, ...\ncargo build --release -p crush-aot                            # optional: crush-aotc (native AOT)\n```\n\nTwo things to know:\n\n- **`buckets` must be a sibling directory.** `crush-vm` has an optional\n  path-dependency on `../buckets` (the sandbox provisioner), and Cargo resolves it\n  even when the feature is off, so a lone `crush-ast` checkout fails with\n  `failed to read .../buckets/Cargo.toml`.\n- **The standard library is built in by default** (crush-ast CRUSH-113): `str.*`,\n  `math.*`, `conv.*`, `collections.*`, `json.*` and friends need no flag. As of\n  0.9.0 the HTTP client (`net.*`) and raw TCP sockets (`tcp.*`) are compiled in by\n  default too; they are still refused unless you pass `--net` / `--tcp` /\n  `--tcp-listen`. Only `db` and `graphics` still need `--features db,graphics`.\n\nThe binaries:\n\n| Binary | What it does |\n|---|---|\n| `crush` | The front door: `crush run FILE`, `crush build FILE`, `crush repl`, `crush debug FILE`, `crush gui run FILE --ui`, `crush doctor` |\n| `crush-run` | Run a `.crush`, `.casm` or `.cvm1` file (all the capability flags live here) |\n| `crushc` | Compile `.crush` to bytecode (`.cvm1`), or `--emit casm\\|ast\\|types`; `-C` only checks |\n| `crush-compile` | Assemble CASM text into a `.cvm1` binary |\n| `crush-repl` | Interactive REPL (`crush repl`; commands are `.help`, `.quit`) |\n| `crush-debug` | The debugger (`crush debug`): see [Debugging](https://docs.crushlang.org/crush/debugging.html) |\n| `crush-gui` | Programs that draw a window (`crush gui run`): a separate package, see [Windows](https://docs.crushlang.org/crush/gui.html) |\n| `crush-diff` | (from a source build) run programs on several engines and report where they disagree |\n| `crush-aotc` | (from `-p crush-aot`) compile `.crush` to a native library via Rust or C, or `crush-aotc run FILE` |\n\nSource builds need Rust 1.95 or newer (crush-ast's CI checks that MSRV).\n\n> **Crates.io.** The newest release on crates.io is `0.11.2` (2026-11-07), published for\n> `crush-lang-sdk` (which installs `crush`, `crushc`, `crush-run`, `crush-compile`,\n> `crush-repl`, `crush-debug` and `crush-diff`) and the library crates, all released\n> together at the workspace version (the guide's pinned commit is newer; see the\n> note at the top). Releases before `0.9.0` (`0.7.1`, `0.8.0`) lack things\n> this guide describes: slices on strings, hex and binary literals, the debugger,\n> `tcp.*`, and the single diagnostics format. **Never depend on `crush-lang-sdk`\n> `0.2`**: that line has been yanked, and it runs `@lang` blocks without the\n> `--polyglot` gate.\n\n## 2. Hello, Crush\n\nSave this as `hello.crush`:\n",
   "state": {
    "status": "done"
   },
   "meta": {},
   "outputs": []
  },
  {
   "id": "getting-started-1",
   "kind": {
    "type": "crush"
   },
   "source": "let name = \"Crush\"\nprint(\"Hello, \" + name + \"!\")\n",
   "state": {
    "status": "pending"
   },
   "meta": {
    "tags": [
     "guide",
     "runnable"
    ],
    "extra": {
     "guide": {
      "src": "getting-started.md:96",
      "browser": "run",
      "expect_output": "Hello, Crush!\n"
     }
    }
   },
   "outputs": []
  },
  {
   "id": "getting-started-md-3",
   "kind": {
    "type": "markdown"
   },
   "source": "Run it:\n\n```sh\ncrush run hello.crush\n```\n\n```text\nHello, Crush!\n[steps=6, stack=0]\n```\n\nThe `[steps=…]` line is a run summary on standard error. Compile-only checking is\n`crushc -C hello.crush`; to see the bytecode, `crushc --emit casm hello.crush`.\n\n### Three file types\n\n`crush run` (and `crush-run run`) takes source, CAST, CASM, assembly or bytecode,\none extension per format (crush-ast #365, since v0.10.0):\n\n```sh\ncrushc hello.crush -o hello.cvm1         # compile to CVM1 bytecode\ncrush run hello.cvm1                     # run the bytecode\ncrushc --emit casm hello.crush -o hello.casm   # CASM IR as JSON\ncrush run hello.casm\ncrushc --emit cvms hello.crush -o hello.cvms   # CVM1 assembly text, with `.cap` lines\ncrush run hello.cvms\n```\n\nAssembly you write by hand (`.cvms`) has no manifest unless you add `.cap NAME`\nlines, so every capability it calls must be named with `--cap` (without it:\n`capability not declared in manifest: io.print`). Assembly text in a `.casm` file\nstill runs, with a note asking you to rename it to `.cvms`.\nArguments after the file name reach the program as `sys.args()`:\n`crush run prog.crush a b` → `[a, b]`.\n\n### Capabilities need flags\n\nA program can only reach the outside world through capabilities, and each group is\noff until you switch it on:\n\n```sh\ncrush run prog.crush                             # str.* math.* conv.* json.* ... need nothing\ncrush run --fs --fs-root ./data prog.crush       # fs.read / fs.write / fs.exists / fs.list\ncrush run --polyglot prog.crush                  # @python / @javascript / @bash blocks\ncrush run --net prog.crush                       # net.http_get / http_post / ... (HTTP only)\ncrush run --tcp prog.crush                       # tcp.connect / send / recv (client sockets)\ncrush-run caps prog.crush                        # what does it need? (runs nothing)\n```\n\nFor example, this reads a file, so it needs `--fs`:\n",
   "state": {
    "status": "done"
   },
   "meta": {},
   "outputs": []
  },
  {
   "id": "getting-started-2",
   "kind": {
    "type": "crush"
   },
   "source": "fn main() {\n    print(fs.read(\"notes.txt\"))\n}\n",
   "state": {
    "status": "pending"
   },
   "meta": {
    "tags": [
     "guide",
     "expected-failure"
    ],
    "extra": {
     "guide": {
      "src": "getting-started.md:158",
      "browser": "fail",
      "why": "this example shows a run-time error",
      "expect_error": "fs.read"
     }
    }
   },
   "outputs": []
  },
  {
   "id": "getting-started-md-5",
   "kind": {
    "type": "markdown"
   },
   "source": "Run it without the flag and nothing runs: `needs capabilities this run does not\ngrant; nothing was run: --fs: fs.read`. The full flag list is in\n[Capability System](https://docs.crushlang.org/crush/capabilities.html) (`crush-run run --help` prints it\ntoo).\n\n### Limits worth knowing on day one\n\n- `crush doctor` reports which polyglot interpreters (`python3`, `node`, `bash`)\n  it can find.\n- Defaults: 1,000,000 instructions, 256 call frames, 1 MiB of output, 30 s per\n  polyglot block (all in [Capability System](https://docs.crushlang.org/crush/capabilities.html#resource-limits)).\n- Named functions can't see top-level variables (lambdas can), and `import`\n  doesn't load code yet — see [Variables](https://docs.crushlang.org/crush/variables.html) and\n  [Syntax](https://docs.crushlang.org/crush/syntax.html#imports-and-exports).\n\n## 3. The crates\n\nEmbedding Crush in a Rust program means depending on the SDK; the lower-level\ncrates give direct access to the IR, bytecode, or VM.\n\n| Crate | What it gives you |\n|---|---|\n| [`crush-lang-sdk`](https://crates.io/crates/crush-lang-sdk) | **Start here.** `Runtime`, `ProgramBuilder`, host-capability registration, and the `compile` module that turns Crush source into a runnable program. |\n| [`crush-frontend`](https://crates.io/crates/crush-frontend) | Parser, semantic analyzer, optimizer, and CASM compiler (`parse_source`). |\n| [`crush-vm`](https://crates.io/crates/crush-vm) | The CVM1 runtime: assembler/disassembler and the sandboxed interpreter with quotas + capability gates; also the FastVM. |\n| [`crush-cast`](https://crates.io/crates/crush-cast) | The CAST intermediate representation. |\n| [`casm`](https://crates.io/crates/casm) | The CASM IR (`casm::Program`, JSON and MessagePack) — see [CASM](https://docs.crushlang.org/casm/index.html). |\n| [`crush-errors`](https://crates.io/crates/crush-errors) | Shared error types. |\n| [`tree-sitter-crush`](https://crates.io/crates/tree-sitter-crush) | Tree-sitter grammar (editor tooling, syntax highlighting). |\n\nSDK Cargo features: the defaults `stdlib` (the standard library), `net` (the HTTP\nclient), `tcp` and `tcp-tls` (raw sockets), `debug` (the debugger),\n`native-plugins`, `polyglot-python`, `polyglot-javascript` and `polyglot-rust` (the\nanalyses that marshal values into and out of `@lang` blocks), plus the optional\n`db`, `graphics`, `gpu`, `repl-helper` and `polyglot-typescript`. A default feature\nonly compiles the capability in; the program still needs the matching flag at run time.\n\n## 4. Embedding\n\nCompile Crush source and run it on the VM — the same thing `crush run` does:\n\n```rust,no_run\nuse crush_lang_sdk::compile::compile_crush_source;\nuse crush_lang_sdk::Runtime;\n\nfn main() -> anyhow::Result<()> {\n    let program = compile_crush_source(r#\"print(\"hello from crush\")\"#)?;\n    let result = Runtime::new().run(&program)?;\n    assert_eq!(result.output, \"hello from crush\\n\");\n    Ok(())\n}\n```\n\nOr hand-write CVM1 assembly (what `crushc --emit casm` prints) with\n`ProgramBuilder`:\n\n```rust,no_run\nuse crush_lang_sdk::{ProgramBuilder, Runtime};\n\nfn main() -> anyhow::Result<()> {\n    let program = ProgramBuilder::new()\n        .permission(\"io.print\")\n        .line(r#\".func main\"#)\n        .line(r#\"PUSH_STR \"hello, cvm1\"\"#)\n        .line(r#\"CAP_CALL \"io.print\" 1\"#)\n        .line(r#\"HALT\"#)\n        .build()?;\n\n    let result = Runtime::new().run(&program)?;\n    assert_eq!(result.output, \"hello, cvm1\\n\");\n    Ok(())\n}\n```\n\nBoth snippets are compiled and run against crush-ast `dc0d0278` by\n`scripts/check-examples.py --crush-ast`. `Runtime::new()` registers only the\nbuilt-in primitives (`io.print`, `io.read`, …); to expose more — the standard\nlibrary, filesystem, polyglot — build a `HostCaps` with `HostCapsBuilder` and pass\nit with `Runtime::with_quotas(..).with_host_caps(..)`, which is exactly what\n`crush-run` does for its flags. The permission names a program may call are part of\nits manifest ([CASM structure](https://docs.crushlang.org/casm/structure.html)).\n\n## 5. Where next\n\n- **[The language](https://docs.crushlang.org/crush/index.html)**: syntax, types, control flow, functions\n- **[Capability System](https://docs.crushlang.org/crush/capabilities.html)** and **[Polyglot](https://docs.crushlang.org/crush/polyglot.html)**:\n  the security model — read the \"what is not enforced\" sections\n- **[Examples](https://docs.crushlang.org/examples/index.html)**: runnable programs\n- **[CAST](https://docs.crushlang.org/cast/index.html)** and **[CASM](https://docs.crushlang.org/casm/index.html)**: the compiler's formats\n",
   "state": {
    "status": "done"
   },
   "meta": {},
   "outputs": []
  }
 ]
}
