plum

#treesitter#compiler#wasm

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

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


c147b75 — Peter John 2026-11-06T18:49:24+05:30
Docs: async direction in the design notes
docs/decisions/2026-11-simpler-language-notes.md CHANGED
@@ -117,3 +117,25 @@ Nothing needs to change now. Plum relies on wasm-gc, and the imperative versus f
117
117
  - It might be slower overall. Counting costs time on every shared value, so it could win only on avoiding pauses.
118
118
 
119
119
  If the comparison shows pauses or allocation costs that hurt, the next step is a small prototype on its own branch.
120
+
121
+ ## Async: one event loop, no `async` keyword
122
+
123
+ Agreed direction, not built. It comes after the imperative versus functional comparison.
124
+
125
+ There's one event loop, owned by the host, and two ways of using it:
126
+ - **Games use commands as values.** `update` returns requests, the host runs them, and results come back as messages. This needs no compiler work, and recording the messages suits replay and deterministic simulation.
127
+ - **Servers and CLI tools use code that reads as blocking.** `db.find(io, id)?` just looks like a call. There's no `async` or `await`.
128
+
129
+ **Candidate implementation: CPS chosen by `Io`.** A function without `Io` can't wait, so the compiler can see which functions might. Because it compiles the whole program, it can narrow that to the functions that reach a host call that really waits. Only those get turned into continuations. Wasm stack switching is the alternative.
130
+
131
+ **What "zero cost" means here:**
132
+ - Pure code pays nothing.
133
+ - `io` code that never waits, such as drawing or printing, pays nothing.
134
+ - Code that waits pays for a heap allocation, because its state must outlive the call. That can be one allocation per task rather than one per wait, by compiling a task into a single state struct as Rust does. Plum's per-type generics suit that.
135
+ - The event loop itself has no language cost, since wasm is single-threaded and the browser or host already runs one.
136
+
137
+ **Open problems:**
138
+ - A stored closure that takes `Io` has no visible sign of whether it waits, so it would have to be treated as if it might.
139
+ - Non-tail recursion that waits keeps its frames on the heap.
140
+ - `mut` fields can still change between waits, though never at the same instant.
141
+ - Code size has to be measured.