{
 "meta": {
  "title": "Crush Overview — The Crush Language Guide",
  "description": "Generated from crush/README.md of The Crush Language Guide (https://docs.crushlang.org/crush/index.html). Edit the guide, not this file: it is regenerated on every build.",
  "frontends": [
   "crush"
  ],
  "author": "The Crush Language Guide",
  "tags": {
   "source": "crush/README.md",
   "guide_url": "https://docs.crushlang.org/crush/index.html",
   "generator": "scripts/build-notebooks.py"
  }
 },
 "cells": [
  {
   "id": "crush-readme-md-1",
   "kind": {
    "type": "markdown"
   },
   "source": "# Crush Overview\n\n> Verified against crush-ast `v0.13.0` (`dc0d0278`, 2026-12-03).\n\n**Crush** is a small, capability-based scripting language with polyglot blocks,\nand the toolchain around it: a parser, a compiler to bytecode, a sandboxed VM,\nand an intermediate representation (CAST) that other languages can be translated\ninto. It is **alpha software** — this guide documents what runs today and says so\nwhen something doesn't.\n\n## What Crush is\n\n- **A language.** `let`, `fn`, `if`/`while`/`for`, `match`, `try`/`catch`,\n  arrays and objects, closures and function values, structs with `impl` methods\n  and `trait`s, green tasks, a pipeline operator. Dynamically typed at run time with\n  optional compile-time type hints. See [Syntax](https://docs.crushlang.org/crush/syntax.html).\n- **Capability-gated.** A program can't print files, open sockets or start\n  processes unless the host turns the matching capability on. Capability calls\n  are ordinary dotted calls — `fs.read(\"x\")`, `io.print(\"y\")`. See\n  [Capability System](https://docs.crushlang.org/crush/capabilities.html).\n- **Polyglot.** `@python -> out { }`, `@javascript { }` and `@bash { }` blocks\n  run other languages and exchange variables with Crush. They currently run as\n  ordinary subprocesses **outside** the capability model unless you build the\n  optional sandbox. See [Polyglot Programming](https://docs.crushlang.org/crush/polyglot.html).\n- **A pipeline.** Source becomes CAST (an AST in JSON), then CASM (bytecode), then\n  runs on a VM (`crush-vm`), with a faster VM, a JIT and ahead-of-time backends\n  also in the repository ([Engines, AOT and Walkers](https://docs.crushlang.org/crush/engines.html)). Walkers\n  translate Python, JavaScript, Rust and other languages into the same CAST.\n\n## New since 0.9.0\n\nUp to the pinned commit (v0.13.0); each item links to its page.\n\n- **Imports and packages.** `import a.b [as x] [{ f }]` loads `.crush` files at\n  compile time, through `-L`, `CRUSH_PATH` and crush-pkg dependencies; `pub fn` is\n  enforced per package (since v0.12.0) and a dependency's own dependencies resolve\n  (v0.13.0); a struct or trait name declared in two files is a\n  compile error. ([Modules](https://docs.crushlang.org/crush/modules.html))\n- **`catch` catches run-time faults**: division by zero, a bad index, a failing\n  capability. ([Control Flow](https://docs.crushlang.org/crush/control_flow.html#what-catch-catches))\n- **Calls on any expression** (`fs[0](1)`, `make()(2)`, `S { n: 3 }.size()`), the\n  method form `a.pop()`, `regex.match` callable, exponent literals (`1.5e3`).\n  ([Closures](https://docs.crushlang.org/crush/closures.html#calling-a-function-value), [Types](https://docs.crushlang.org/crush/types.html))\n- **`process.exec` returns a map** `{exit_code, stdout, stderr}`.\n  ([Capability System](https://docs.crushlang.org/crush/capabilities.html#environment-time-processes-network))\n- **Quotas and networking.** `--max-wall-ms N|unlimited` bounds the whole run,\n  `--max-steps unlimited`; `net.*` and `tcp.recv`/`tcp.accept` take\n  `{timeout_ms}`; `net.http_request` returns response headers.\n  ([Capability System](https://docs.crushlang.org/crush/capabilities.html#resource-limits))\n\n## New in 0.9.0\n\nEach item links to the page that documents it (and every example there was run).\n\n- **Slices on strings, and steps.** `s[0:5]`, `s[-5:]`, `s[::2]`, `s[::-1]` on strings\n  and arrays; they lower to `seq.slice`. ([Types](https://docs.crushlang.org/crush/types.html#slicing-strings))\n- **Hex and binary literals.** `0xff`, `0b101`. ([Syntax](https://docs.crushlang.org/crush/syntax.html#literals))\n- **A debugger.** `crush debug FILE --step --inspect`: breakpoints by line, step,\n  watch, print, with the inspection itself a grant. ([Debugging](https://docs.crushlang.org/crush/debugging.html))\n- **Windows.** `crush gui run FILE --ui` and the `ui.*` API, from the separate\n  `crush-gui` package. ([Windows](https://docs.crushlang.org/crush/gui.html))\n- **Raw sockets.** `tcp.*` behind `--tcp` (client) and `--tcp-listen` (server);\n  `--net` stays HTTP-only. `net.*` is compiled into the default build, and the old\n  `http.*` names are refused with their replacement. ([Capability System](https://docs.crushlang.org/crush/capabilities.html#raw-sockets-tcp))\n- **One diagnostics format.** `--message-format json` gives one schema across the\n  tools, and semantic errors carry a line and column. ([Diagnostics](https://docs.crushlang.org/crush/diagnostics.html))\n- **Easier install.** `cargo install crush-lang-sdk` (not `cargo install crush`,\n  which is an unrelated crate), or the prebuilt Linux binaries on the GitHub release;\n  v0.9.0 is the first release to have them. ([Getting Started](https://docs.crushlang.org/getting-started.html))\n- `@bash` blocks can read Crush variables again, by `$name`. ([Polyglot](https://docs.crushlang.org/crush/polyglot.html#bash))\n\n## Hello, Crush\n",
   "state": {
    "status": "done"
   },
   "meta": {},
   "outputs": []
  },
  {
   "id": "crush-readme-1",
   "kind": {
    "type": "crush"
   },
   "source": "print(\"Hello, Crush!\")\n",
   "state": {
    "status": "pending"
   },
   "meta": {
    "tags": [
     "guide",
     "runnable"
    ],
    "extra": {
     "guide": {
      "src": "crush/README.md:74",
      "browser": "run",
      "expect_output": "Hello, Crush!\n"
     }
    }
   },
   "outputs": []
  },
  {
   "id": "crush-readme-md-3",
   "kind": {
    "type": "markdown"
   },
   "source": "Run it with the toolchain built from [crush-ast](https://github.com/nixpt/crush-ast)\n(see [Getting Started](https://docs.crushlang.org/getting-started.html)):\n\n```sh\ncrush run hello.crush\n```\n\n## A taste\n",
   "state": {
    "status": "done"
   },
   "meta": {},
   "outputs": []
  },
  {
   "id": "crush-readme-2",
   "kind": {
    "type": "crush"
   },
   "source": "struct Point { x: Int, y: Int }\nimpl Point {\n    fn distance_sq(self) { return self.x * self.x + self.y * self.y }\n}\n\nlet points = [Point { x: 3, y: 4 }, Point { x: 1, y: 1 }]\nlet far = |p| p.distance_sq() > 10\nlet i = 0\nwhile i < len(points) {\n    let p = points[i]\n    if far(p) {\n        print(\"far: \" + p.distance_sq())\n    }\n    i = i + 1\n}\n",
   "state": {
    "status": "pending"
   },
   "meta": {
    "tags": [
     "guide",
     "runnable"
    ],
    "extra": {
     "guide": {
      "src": "crush/README.md:92",
      "browser": "run",
      "expect_output": "far: 25\n"
     }
    }
   },
   "outputs": []
  },
  {
   "id": "crush-readme-md-5",
   "kind": {
    "type": "markdown"
   },
   "source": "## Security model, in short\n\n1. **Deny by default.** Every capability group (`--fs`, `--net`, `--process`,\n   `--polyglot`, …) is off until you enable it on the command line (or register\n   it, when embedding).\n2. **Quotas.** Instruction count, stack depth, output size, call depth and\n   wall-clock time for polyglot blocks are bounded.\n3. **Honest limits.** Polyglot blocks run with the host's authority in the default\n   build; the bubblewrap sandbox is opt-in at build time. The\n   [capability chapter](https://docs.crushlang.org/crush/capabilities.html#what-is-not-enforced) lists what is *not*\n   enforced.\n\n## Where things stand\n\n| Area | Status |\n|---|---|\n| Core language (functions, loops, `try`/`catch`, `match`) | works |\n| Closures and function values | works on the VM; AOT refuses them by name |\n| Structs, `impl`, `trait`, `@kind`, struct patterns | works on the VM; AOT refuses method calls by name |\n| `spawn` / `yield` / `await`, `parallel_map` | works on the VM |\n| `import` (multi-file programs), crush-pkg packages | works, resolved at compile time; visibility is per package, a private function used from another package is the warning `W-VIS01` ([Modules](https://docs.crushlang.org/crush/modules.html)) |\n| Capabilities, `@capabilities`, the standard library | works; the standard library is on by default |\n| Polyglot: Python, JavaScript (declared `->` outputs), Bash | works (host authority by default); `@bash` reads the Crush variables it names as `$name` |\n| Polyglot sandbox | opt-in build, verified on Linux with `bwrap` |\n| CAST / CASM formats | documented in their own sections |\n\n## Next Steps\n\n- **[Syntax & Grammar](https://docs.crushlang.org/crush/syntax.html)**\n- **[Types](https://docs.crushlang.org/crush/types.html)**\n- **[Closures](https://docs.crushlang.org/crush/closures.html)** and **[Structs, Methods and Kinds](https://docs.crushlang.org/crush/structs.html)**\n- **[Capability System](https://docs.crushlang.org/crush/capabilities.html)**\n- **[Polyglot Programming](https://docs.crushlang.org/crush/polyglot.html)**\n",
   "state": {
    "status": "done"
   },
   "meta": {},
   "outputs": []
  }
 ]
}
