# Rustba v0.3 — Grammar Sketch (one page)

Status: sketch, not spec. Everything unmarked runs today — in the playground (v0.2) or the 3D viewer (v0.3). Items marked NEW are decided, not yet implemented.

## A program

```
program := top*
top     := hw | state | screen | effect | model | palette | viewer | ai
```

## Hardware comes first

```
hw { battery: 72  network: wifi  thermal: nominal }
```

`hw{}` declares which device resources the program observes. **NEW v0.3:** `soc:`, `memory:`, `storage:` join the block. Undeclared hardware is unreadable — no ambient globals, no reaching past what you declared.

## State is typed (tRust)

```
state counter: Int = 0
state darkmode: Bool = false
```

v0.2 let `state x = 0` slide untyped. v0.3: every state declares its type. A widget writing the wrong type is a compile error, caught before the phone ever sees it. Types are tRust's contribution to the family — small, strict, boring in the good way.

## Screens and constraint-typed layouts

```
screen Main {
  layout: stack(safe)
  title "Rustba Demo"
  text "Taps: {counter}"
  row {
    button "+1" -> counter+1
    button "reset" -> counter=0
  }
  toggle "Dark mode" -> darkmode
  button "Open Viewer" -> Viewer
  on swipe(left) -> Viewer
}
```

A layout that breaks on a phone does not compile. `stack(safe)` is a constraint set checked at compile time: notch and safe-area respected, a widget wider than its row is an error, a fixed pixel width on a phone screen is an error — never a runtime surprise. Widgets (v0.2, unchanged): `title text note input button toggle slider list spacer row`. `{var}` interpolation is type-checked.

## Gestures are syntax

```
on tap -> Screen
on longpress -> Screen
on swipe(left|right|up|down) -> Screen
```

A gesture line *is* navigation. No listeners, no callbacks to wire; typing `on swipe(left)` creates the transition. **NEW v0.3:** `on pinch(in|out) ->` and `on drag ->` for direct manipulation — the drag-anywhere home-icon case from the Winux work gets first-class syntax instead of a viewer hack.

## Effects: resources declared in signatures

```
effect syncModels : Network + Battery {
  needs network != offline
  needs battery > 20
  cache first, sync propose
}
button "Sync" ! syncModels
```

`!` invokes. `needs` guards are checked against live hardware and failure names itself ("sync blocked — offline"). Local state comes first and sync is an explicit proposal: the effect proposes, the device disposes. **NEW v0.3:** capabilities compose (`Network + Battery + Memory`); an effect touching hardware it didn't declare fails to compile. This is the Crown Betta lesson written into the language — hardware awareness as grammar, not a post-hoc patch.

## Models (v0.3, from the viewer)

```
model Obsidian {
  geometry: icosahedron(1.6, 0)
  material: onyx        -- palette key, never a hex
  core: fresnel
  cage: true
  nodes: 80 orbit
}
```

The block declares the *object*; the viewer declares the *interaction*. Grab, pinch, and recenter live in the viewer — the block says nothing about fingers. Materials resolve through the palette system, which is why the whole viewer recolored by changing the palette, not thirty-four blocks.

## Open questions — honest, not deferred

1. `ai:` behavior blocks (the Aquariums): real syntax or viewer convention? Today they exist only inside the APK. They need a written form or they don't exist.
2. `palette`: top-level block or viewer-side config? The recolor win argues for top-level.
3. Gemba (Petri nets): concurrent effect transitions — v0.4 territory, sketched but not designed.
4. Lavemba: the synthesis layer. Later, per N8toriousAi — not this page.

---
*Companion to "Rustba as the Program" (2026-10-09). Grounded in `rustba-playground.html` (v0.2 grammar) and `rustba-3d-viewer.html` / RUSTBA hybrid APK (v0.3 model blocks). v0.1–v0.2 verified in headless; v0.3 model blocks verified in the viewer; NEW items unverified by construction.*
