plum

#treesitter#compiler#wasm

git clone https://git.pyrossh.dev/plum

A statically typed, imperative programming language inspired by rust, python


b53566d — Peter John 2026-11-10T10:51:32+05:30
Backlog: trait list form decided, struct Ship<M>[Actor<M>, Clickable](..)
Files changed (1) hide show
  1. docs/backlog.md +1 -1
docs/backlog.md CHANGED
@@ -27,7 +27,7 @@ Open work, in the order the user queued it, plus smaller items found during buil
27
27
 
28
28
  ## Planned, not yet placed in the queue
29
29
 
30
- - **Generics in `<>`, traits in `[]`** (user 2026-11-09, later): `struct Ship<M>[Actor<M>, Clickable](x: Float, y: Float)`, `fun map<B>(..) -> Option<B>`, `Slice<Jv>()`, `stage.updateAs<Orb>(id, f)`; replaces `[]` generics and the `is` clause. In expressions `<` is also less-than: parse `name<...>` as type arguments only when the matching `>` is directly followed by `(`, `.` or `)` (C#/Kotlin rule; `a < B > (c)` would compare a Bool), and split `>>` in nested types. Mechanical but touches every generic in std, examples, tests, docs, the parser, tree-sitter and type-printing snapshots; do it as one task. An intermediate option discussed: `struct Ship(Actor, Clickable)(x: Float, y: Float)` with `[]` generics kept.
30
+ - **Generics in `<>`, traits in `[]`** (user 2026-11-09, later; form DECIDED 2026-11-10: `struct Ship<M>[Actor<M>, Clickable](x: Float, y: Float)`, over `struct Ship[M](Actor[M], Clickable)(..)` and over keeping `is`; built as wave 1 of `docs/plans/2026-11-09-comptime-generics.review.md`): `struct Ship<M>[Actor<M>, Clickable](x: Float, y: Float)`, `fun map<B>(..) -> Option<B>`, `Slice<Jv>()`, `stage.updateAs<Orb>(id, f)`; replaces `[]` generics and the `is` clause. In expressions `<` is also less-than: parse `name<...>` as type arguments only when the matching `>` is directly followed by `(`, `.` or `)` (C#/Kotlin rule; `a < B > (c)` would compare a Bool), and split `>>` in nested types. Mechanical but touches every generic in std, examples, tests, docs, the parser, tree-sitter and type-printing snapshots; do it as one task. An intermediate option discussed: `struct Ship(Actor, Clickable)(x: Float, y: Float)` with `[]` generics kept.
31
31
  - **Optional or automatic actor keys** (user 2026-11-09, after the actor-trait plan). Store does not replace `key`: the Store holds game state, while `key` names one actor in the tree for `Kill(id)`, `updateAs[T](id, f)`, `findAs[T](id)` and messages like `Collected(id)`. Most actors don't need one: self-removal uses `gone`, messages can carry data (`Collected(points: 10)`), and singletons can be found by type (`findAs[Player]()`). Options: (a) make `key` a default method `fun key(self) -> Option[Int] = None`, overridden only by actors a rule must pick out; (b) have the tree hand out ids itself: a counter in `SceneTree`, the id stored in the tree node next to the actor (not in the actor), given on `Spawn`, and returned by queries such as `findAll[Orb]() -> List[Pair[Int, Orb]]`. Use a counter, not a random id: it is unique, needs no `Random` and keeps replays deterministic. Not an index or path in the tree, which changes after a kill. Open: how a spawner learns its child's id (maybe `Spawn(actor, onId: fn(Int) -> M)`).
32
32
  - **Faster SceneTree step, staying functional** (user 2026-11-09: backlog it; bring it up only if the master vs simpler-language benchmark is really bad). No mutation in the language: better data structures, caching and FBIP. Today `stepChain` (std/game/scene/SceneTree.plum) rebuilds an `FRoseNode` per live actor per step, recurses down `nextSibling` (10k-deep for 10k siblings), and makes 3–5 trait dispatches per actor (`gone` before and after `step`, `key`, `place`, `opacity`). In order:
33
33
  1. **Keep unchanged nodes:** tried 2026-11-09; the mechanism landed, the step walk kept its rebuild. std's `ref.same(a, b)` (std/ref.plum: one `ref.eq`; the checker allows heap types only; a variable passed to it is never updated in place, `plum_core::uniqueness`) now keeps unchanged nodes in `inputChain`, `withRoot` and Game's `liveAt`, `shown`, `spliced`, `replaceKid` and `onScreen` (a `react` that returns its tree, as for every `Tick`, leaves the game's tree as it was). In `stepChain` and `applyChain` it was slower, also on the new "mostly still" workloads 10 and 11 of benchmarks/scene_trees (10,000 actors, 1% moving: 148 ms rebuilding vs 240 ms sharing): keeping a node needs its later siblings' result before it is built, so the walk recurses along each sibling chain, and that loses the compiler's tail-modulo-cons loop, which builds a chain front to back without recursion. In a left-child right-sibling chain only a suffix after the last changed sibling could be kept anyway. Sharing in the step needs item 3 first (a chunked children vector, where a still chunk is kept whole), or a codegen loop that defers the copy of an unchanged run of siblings and links the old run at the end. The cached per-node "subtree can change" flag (skip still subtrees whole, like Flutter `const` or React `memo`) is not done: a node needs a field `FRoseTree` doesn't have, an actor needs a way to say its `step` is the default (returning `self` is not enough, `step` may push commands), and a `Spawn`/`Kill` batch into a still subtree must still walk it.