plum

#treesitter#compiler#wasm

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

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


7444c01 — Peter John 2026-11-04T20:31:35+05:30
docs: language simplification scope (errors, =, generators, variadics, value enums, struct)
docs/backlog.md CHANGED
@@ -8,7 +8,7 @@ Open work, in the order the user queued it, plus smaller items found during buil
8
8
  - **Explicit function generics** (user 2026-11-04: right after cleanup phase 2) — functions declare their generics (`fun map[B](...)`) instead of every single capital letter being a generic; allows longer generic names and one-letter concrete types/tags. Grammar change + about 140 signatures in std/examples. Phase 2's "generics by scope" makes this mostly a grammar + signature rewrite.
9
9
  - **Io as a built-in primitive with extern methods** (user 2026-11-04: LAST, once the whole compiler refactor and explicit generics are done) — `docs/plans/2026-11-04-io-primitive-extern-methods.review.md`. `primitive Io` with `extern fun f(self, ..)` methods replaces the ~55 top-level externs + forwarding `record Io` methods. A fake/recording `Io` comes later via a trait or language mocks.
10
10
  - **Move the Rust code into `compiler/`** (user 2026-11-04: once all the refactoring is done) — every Rust crate (plum-core, plum-checker, plum-wasm-codegen, plum-cli, plum-lsp, plum-host, plum-test-support, plum-runtime, plum-game) goes under `compiler/`; `plum-std` and `plum-examples` stay at the top level. Mechanical but touches hardcoded paths: workspace `Cargo.toml` members, every `CARGO_MANIFEST_DIR/..` repoRoot (test-support, tests, cli), the loader's std lookup, the checker's `isStdFile`/`isIoFile` path tests, `cmdBuild`'s runtime manifest path, plum-game web-test fixtures, scripts/, Makefile.toml, plum-tooling (vscode/tree-sitter paths), README and docs links. Open question for then: keep the `plum-` prefixes inside `compiler/` or drop them (`compiler/core`, …).
11
- 2. **Simplify the language: no traits, no union enums, native inline variants** (decided by the user 2026-11-04; runs right after compiler-cleanup phase 3a, before explicit generics and 3b; decision record §13). Traits are removed as a language feature and replaced by records embedding records with subtyping + `override` dispatch (a `Ship` embedding `Node` is accepted wherever a `Node` is, and calls dispatch to Ship's overrides — the scene graph's `trait Actor` becomes a base record). Union enums (`enum X = A | B` of records) are removed: `JsonParse` and the union examples become inline-variant enums, union syntax becomes an error. Inline variants compile natively as struct subtypes of their enum, deleting `hoistInlineVariants`, the `List__Cons(Cons(..))` wrappers, union forwarders, `union_lower` and the checker's union plan. `unboxed_variants.plum` is a compiler probe: move it to a codegen test. Needs its own review plan.
11
+ 2. **Simplify the language: no traits, no union enums, native inline variants** (decided by the user 2026-11-04; runs right after compiler-cleanup phase 3a, before explicit generics and 3b; decision record §13). Traits are removed as a language feature and replaced by records embedding records with subtyping + `override` dispatch (a `Ship` embedding `Node` is accepted wherever a `Node` is, and calls dispatch to Ship's overrides — the scene graph's `trait Actor` becomes a base record). Union enums (`enum X = A | B` of records) are removed: `JsonParse` and the union examples become inline-variant enums, union syntax becomes an error. Inline variants compile natively as struct subtypes of their enum, deleting `hoistInlineVariants`, the `List__Cons(Cons(..))` wrappers, union forwarders, `union_lower` and the checker's union plan. `unboxed_variants.plum` is a compiler probe: move it to a codegen test. Same plan also covers (user 2026-11-04): one error mechanism (`T!E` + `T?`), `=` reassign-only, no generators (`fun*`/`yield`; rewrite Seq), no variadics (`...T`), no value enums, and `record` merged into `struct` now (decision record §13). Needs its own review plan.
12
12
  3. **Benchmark** before FBIP (user: FBIP waits for it).
13
13
  4. **FBIP: no heap mutation** — persistent std collections updated in place when unique, Koka-style `fip` functions as a checked in-place guarantee, a reference count used only as a uniqueness check if static proof falls short. Worklist = the `mut` fields left today (see below). (Decision record §9.)
14
14
  5. **One product type, `struct`** — after FBIP, merge `record` into an immutable `struct` with compiler-chosen boxing (optional hint, shown by `--explain`). (Decision record §9b.)
docs/decisions/2026-11-language-and-scene-decisions.md CHANGED
@@ -128,6 +128,13 @@ The user decided to simplify the language before the compiler is refactored furt
128
128
  - **Why:** both features are the main sources of the compiler's extra lowering passes (trait stand-ins in embeds/ctors, hidden records for inline variants, union_lower and the address-keyed union plan that forces repeated type checks). Removing them first shrinks every later cleanup phase and simplifies codegen.
129
129
  - **Order:** right after compiler-cleanup phase 3a; then explicit function generics; then cleanup 3b, 4, 5, 6.
130
130
  - This supersedes §11's "has traits" and the enum/union split in §8b.
131
+ - **Same plan, also decided 2026-11-04** (user: "1 to 6 all can be done"):
132
+ 1. One error mechanism: `T!E` (with error sets) and `T?` stay; `Try[T,E]`, `??`-style fallbacks that duplicate them, `? |e|` and the `?.` → `andThen` special case are folded into those two (exact surface decided in the plan).
133
+ 2. `=` only reassigns; `:=` is the only declaration (no declare-on-first-use).
134
+ 3. Generators (`fun*`/`yield`) are removed; `Seq` and their std/example users (Seq.plum, Map, Int, List, functional/sequences examples) are rewritten on plain functions/loops.
135
+ 4. Variadics `...T` are removed; callers pass a list/slice literal (`List.init`, `Map(...)`).
136
+ 5. Value enums (explicit discriminants) are removed — no longer used. Ordinary enums (`A | B(..)`, inline variants) are the only enum kind.
137
+ 6. `record` merges into one product type `struct` now, not after FBIP (§9b moves forward; boxing chosen by the compiler).
131
138
 
132
139
  ## 12. Smaller decisions
133
140