plum

#treesitter#compiler#wasm

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

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


7b858cd — Peter John 2026-11-10T14:21:21+05:30
std/game: the scene folder is flattened, Clickable gets its own file
Files changed (38) hide show
  1. benchmarks/scene_trees/scene_tree.plum +6 -5
  2. compiler/cli/tests/cli/game_entry_test.rs +1 -1
  3. compiler/driver/tests/driver_tests.rs +2 -2
  4. compiler/game/tests/fixtures/assets_fixture.plum +4 -4
  5. compiler/game/tests/fixtures/host_fixture.plum +4 -4
  6. compiler/game/tests/fixtures/main_game_fixture.plum +4 -4
  7. compiler/game/tests/fixtures/main_missing_fixture.plum +4 -4
  8. compiler/game/tests/fixtures/state_draw_keeps.plum +4 -4
  9. compiler/game/tests/fixtures/state_in_place.plum +4 -4
  10. compiler/game/tests/fixtures/state_main_alias.plum +4 -4
  11. compiler/game/tests/fixtures/state_reset.plum +4 -4
  12. compiler/game/tests/fixtures/target_fixture.plum +4 -4
  13. compiler/game/tests/host_test.rs +4 -4
  14. compiler/game/web-test/fixtures/interleave.plum +4 -4
  15. compiler/game/web-test/fixtures/main_game.plum +4 -4
  16. compiler/game/web-test/fixtures/rendertarget.plum +4 -4
  17. compiler/game/web-test/fixtures/stress.plum +4 -4
  18. compiler/game/web-test/fixtures/stress_scene_port.plum +4 -4
  19. compiler/game/web-test/fixtures/stress_state_view.plum +4 -4
  20. compiler/game/web-test/fixtures/stress_world.plum +4 -4
  21. compiler/game/web-test/fixtures/text_sizes.plum +4 -4
  22. compiler/lsp/src/main.rs +1 -1
  23. docs/game.md +4 -4
  24. examples/games/clicks.plum +4 -4
  25. examples/games/kids/balloon_pop.plum +6 -5
  26. examples/games/orb_run.plum +6 -6
  27. examples/games/two_screens.plum +4 -4
  28. std/collections/RoseTree.plum +2 -2
  29. std/game/{scene/Actor.plum → Actor.plum} +5 -12
  30. std/game/Clickable.plum +13 -0
  31. std/game/{scene/Ctx.plum → Ctx.plum} +1 -1
  32. std/game/Game.plum +6 -5
  33. std/game/{scene/Place.plum → Place.plum} +0 -0
  34. std/game/{scene/SceneTree.plum → SceneTree.plum} +5 -4
  35. std/game/ui.plum +5 -4
  36. std/ref.plum +1 -1
  37. tests/port/game/determinism.plum +4 -4
  38. tests/port/game/replay.plum +4 -4
benchmarks/scene_trees/scene_tree.plum CHANGED
@@ -12,14 +12,15 @@ import std/math/Vec2
12
12
  import std/math/Affine
13
13
  import std/game/Color
14
14
  import std/collections/RoseTree
15
- import std/game/scene/Place
15
+ import std/game/Place
16
- import std/game/scene/Actor
16
+ import std/game/Actor
17
+ import std/game/Clickable
18
+ import std/game/Ctx
17
- import std/game/scene/Ctx
19
+ import std/game/SceneTree
18
- import std/game/scene/SceneTree
19
20
 
20
21
  # Scene-tree benchmark, branch version: master's benchmarks/scene_trees/game_enum_tree.plum
21
22
  # (a persistent tree of immutable bodies, referred to by id) in the branch's language, on
22
- # the branch's scene tree (std/game/scene). It builds the same scene from the same random numbers as
23
+ # the branch's scene tree (std/game/SceneTree). It builds the same scene from the same random numbers as
23
24
  # master's three programs and prints the same checksums; see
24
25
  # docs/benchmarks/2026-11-08-scene-trees-branch.md and run.py.
25
26
  #
compiler/cli/tests/cli/game_entry_test.rs CHANGED
@@ -63,7 +63,7 @@ const HEAD: &str = "module app\nimport std/Int\nimport std/Float\nimport std/Str
63
63
 
64
64
  /// A whole game: one screen with one actor over a state that counts its messages.
65
65
  const GAME: &str = "module app\nimport std/Int\nimport std/Float\nimport std/Str\nimport std/Io\nimport std/game/input\n\
66
- import std/game/Store\nimport std/game/Game\nimport std/game/scene/Place\nimport std/game/scene/Actor\nimport std/game/scene/Ctx\nimport std/game/scene/SceneTree\nimport std/collections/RoseTree\n\n\
66
+ import std/game/Store\nimport std/game/Game\nimport std/game/Place\nimport std/game/Actor\nimport std/game/Ctx\nimport std/game/SceneTree\nimport std/collections/RoseTree\n\n\
67
67
  struct Count(n: Int) is Reducer[Int] =\n fun update(self, msg: Int) -> Count = Count(n: self.n + msg)\n\n\
68
68
  struct Ticker(id: Int) is Actor[Int] =\n fun key(self) -> Int = self.id\n fun place(self) -> Place = place.at(0.0, 0.0)\n \
69
69
  fun step(self, ctx: Ctx[Int], dt: Float) -> Ticker =\n ctx.send(1)\n self\n\n\
compiler/driver/tests/driver_tests.rs CHANGED
@@ -253,8 +253,8 @@ fn aSharedReceiverOfAnotherTypeDoesNotProveItsOwnMethod() {
253
253
  fn gameSource(name: &str, main: &str, step: &str, draw: &str) -> Source {
254
254
  let text = format!(
255
255
  "module {name}\nimport std/Int\nimport std/Float\nimport std/Str\nimport std/Io\nimport std/game/input\n\
256
- import std/game/Store\nimport std/game/Game\nimport std/game/scene/Place\nimport std/game/scene/Actor\n\
256
+ import std/game/Store\nimport std/game/Game\nimport std/game/Place\nimport std/game/Actor\n\
257
- import std/game/scene/Ctx\nimport std/game/scene/SceneTree\nimport std/collections/RoseTree\n\
257
+ import std/game/Ctx\nimport std/game/SceneTree\nimport std/collections/RoseTree\n\
258
258
  Start = Stress(label: \"s\", t: 0)\n\
259
259
  struct Quiet(n: Int) is Reducer[Int] =\n fun update(self, msg: Int) -> Quiet = self\n\
260
260
  struct Stress(label: Str, t: Int) is Actor[Int] =\n \
compiler/game/tests/fixtures/assets_fixture.plum CHANGED
@@ -13,10 +13,10 @@ import std/math/Affine
13
13
  import std/game/Store
14
14
  import std/game/Game
15
15
  import std/collections/RoseTree
16
- import std/game/scene/Place
16
+ import std/game/Place
17
- import std/game/scene/Actor
17
+ import std/game/Actor
18
+ import std/game/Ctx
18
- import std/game/scene/Ctx
19
+ import std/game/SceneTree
19
- import std/game/scene/SceneTree
20
20
 
21
21
  # Loads through the raw `io` (a missing file answers -1 or empty, where `Texture.load`
22
22
  # would crash) and draws through it.
compiler/game/tests/fixtures/host_fixture.plum CHANGED
@@ -13,10 +13,10 @@ import std/math/Affine
13
13
  import std/game/Store
14
14
  import std/game/Game
15
15
  import std/collections/RoseTree
16
- import std/game/scene/Place
16
+ import std/game/Place
17
- import std/game/scene/Actor
17
+ import std/game/Actor
18
+ import std/game/Ctx
18
- import std/game/scene/Ctx
19
+ import std/game/SceneTree
19
- import std/game/scene/SceneTree
20
20
 
21
21
  # One raw host read in `draw` (`mousePos`), so the recorded call order is fixed. The
22
22
  # game is one actor on one screen, counting the ticks.
compiler/game/tests/fixtures/main_game_fixture.plum CHANGED
@@ -13,10 +13,10 @@ import std/math/Affine
13
13
  import std/game/Store
14
14
  import std/game/Game
15
15
  import std/collections/RoseTree
16
- import std/game/scene/Place
16
+ import std/game/Place
17
- import std/game/scene/Actor
17
+ import std/game/Actor
18
+ import std/game/Ctx
18
- import std/game/scene/Ctx
19
+ import std/game/SceneTree
19
- import std/game/scene/SceneTree
20
20
  import std/Io
21
21
 
22
22
  # A game whose entry is `main`, declared to return a `Game`: one actor, `Orbs`, that
compiler/game/tests/fixtures/main_missing_fixture.plum CHANGED
@@ -11,10 +11,10 @@ import std/math/Affine
11
11
  import std/game/Store
12
12
  import std/game/Game
13
13
  import std/collections/RoseTree
14
- import std/game/scene/Place
14
+ import std/game/Place
15
- import std/game/scene/Actor
15
+ import std/game/Actor
16
+ import std/game/Ctx
16
- import std/game/scene/Ctx
17
+ import std/game/SceneTree
17
- import std/game/scene/SceneTree
18
18
 
19
19
  # Its texture is missing: `main` crashes naming it.
20
20
  struct Broken(tex: Texture) is Actor[Int] =
compiler/game/tests/fixtures/state_draw_keeps.plum CHANGED
@@ -11,10 +11,10 @@ import std/math/Affine
11
11
  import std/game/Store
12
12
  import std/game/Game
13
13
  import std/collections/RoseTree
14
- import std/game/scene/Place
14
+ import std/game/Place
15
- import std/game/scene/Actor
15
+ import std/game/Actor
16
+ import std/game/Ctx
16
- import std/game/scene/Ctx
17
+ import std/game/SceneTree
17
- import std/game/scene/SceneTree
18
18
 
19
19
  # `paint` keeps the actor it is given: the next `step` must not write that object in place.
20
20
  struct Log(mut last: Option[Run])
compiler/game/tests/fixtures/state_in_place.plum CHANGED
@@ -11,10 +11,10 @@ import std/math/Affine
11
11
  import std/game/Store
12
12
  import std/game/Game
13
13
  import std/collections/RoseTree
14
- import std/game/scene/Place
14
+ import std/game/Place
15
- import std/game/scene/Actor
15
+ import std/game/Actor
16
+ import std/game/Ctx
16
- import std/game/scene/Ctx
17
+ import std/game/SceneTree
17
- import std/game/scene/SceneTree
18
18
 
19
19
  struct Part(label: Str, x: Int) =
20
20
  fun step(self) -> Part = Part(..self, x: self.x + 1)
compiler/game/tests/fixtures/state_main_alias.plum CHANGED
@@ -11,10 +11,10 @@ import std/math/Affine
11
11
  import std/game/Store
12
12
  import std/game/Game
13
13
  import std/collections/RoseTree
14
- import std/game/scene/Place
14
+ import std/game/Place
15
- import std/game/scene/Actor
15
+ import std/game/Actor
16
+ import std/game/Ctx
16
- import std/game/scene/Ctx
17
+ import std/game/SceneTree
17
- import std/game/scene/SceneTree
18
18
 
19
19
  # `main` starts the game with a local, but the local is a constant: `step` must not write
20
20
  # it in place.
compiler/game/tests/fixtures/state_reset.plum CHANGED
@@ -11,10 +11,10 @@ import std/math/Affine
11
11
  import std/game/Store
12
12
  import std/game/Game
13
13
  import std/collections/RoseTree
14
- import std/game/scene/Place
14
+ import std/game/Place
15
- import std/game/scene/Actor
15
+ import std/game/Actor
16
+ import std/game/Ctx
16
- import std/game/scene/Ctx
17
+ import std/game/SceneTree
17
- import std/game/scene/SceneTree
18
18
 
19
19
  # The actor goes back to a constant: writing it in place would overwrite the constant.
20
20
  Start = Run(label: "start", t: 0)
compiler/game/tests/fixtures/target_fixture.plum CHANGED
@@ -12,10 +12,10 @@ import std/math/Affine
12
12
  import std/game/Store
13
13
  import std/game/Game
14
14
  import std/collections/RoseTree
15
- import std/game/scene/Place
15
+ import std/game/Place
16
- import std/game/scene/Actor
16
+ import std/game/Actor
17
+ import std/game/Ctx
17
- import std/game/scene/Ctx
18
+ import std/game/SceneTree
18
- import std/game/scene/SceneTree
19
19
 
20
20
  # `bad` is a raw `io.textureCreate` of an impossible size: it answers -1 where
21
21
  # `Texture.create` would crash.
compiler/game/tests/host_test.rs CHANGED
@@ -151,7 +151,7 @@ fn unknownImportTraps() {
151
151
  let path = dir.join("m.plum");
152
152
  std::fs::write(
153
153
  &path,
154
- "import std/Int\nimport std/Float\nimport std/Str\nimport std/Io\nimport std/Slice\nimport std/math/Vec2\nimport std/math/Affine\nimport std/game/Color\nimport std/game/gfx\nimport std/game/input\nimport std/game/Store\nimport std/game/Game\nimport std/game/scene/Place\nimport std/game/scene/Actor\nimport std/game/scene/Ctx\nimport std/game/scene/SceneTree\nimport std/collections/RoseTree\nstruct Quiet(n: Int) is Reducer[Int] =\n fun update(self, msg: Int) -> Quiet = self\nstruct PageScreen(id: Int) is Screen[Quiet, Int] =\n fun key(self) -> Int = self.id\n fun place(self) -> Place = place.at(0.0, 0.0)\n fun draw(self, io: Io, shown: SceneTree[Int]) = shown.paint(io)\nfun screenOf(top: Actor[Int]) -> SceneTree[Int] =\n kid: RoseTree[Actor[Int]] := RoseTree.leaf(top)\n page: RoseTree[Actor[Int]] := RoseTree.of(PageScreen(id: -2), [kid])\n SceneTree.ofScreens([page])\nstruct State(n: Int) is Actor[Int] =\n fun key(self) -> Int = 1\n fun place(self) -> Place = place.at(0.0, 0.0)\n fun paint(self, io: Io, m: Affine, alpha: Float) =\n x := io.rawExists(\"a\")\n\nfun main(io: Io) -> Game[Quiet, Int] =\n Game.start(screenOf(State(n: 0)), Quiet(n: 0))\n",
154
+ "import std/Int\nimport std/Float\nimport std/Str\nimport std/Io\nimport std/Slice\nimport std/math/Vec2\nimport std/math/Affine\nimport std/game/Color\nimport std/game/gfx\nimport std/game/input\nimport std/game/Store\nimport std/game/Game\nimport std/game/Place\nimport std/game/Actor\nimport std/game/Ctx\nimport std/game/SceneTree\nimport std/collections/RoseTree\nstruct Quiet(n: Int) is Reducer[Int] =\n fun update(self, msg: Int) -> Quiet = self\nstruct PageScreen(id: Int) is Screen[Quiet, Int] =\n fun key(self) -> Int = self.id\n fun place(self) -> Place = place.at(0.0, 0.0)\n fun draw(self, io: Io, shown: SceneTree[Int]) = shown.paint(io)\nfun screenOf(top: Actor[Int]) -> SceneTree[Int] =\n kid: RoseTree[Actor[Int]] := RoseTree.leaf(top)\n page: RoseTree[Actor[Int]] := RoseTree.of(PageScreen(id: -2), [kid])\n SceneTree.ofScreens([page])\nstruct State(n: Int) is Actor[Int] =\n fun key(self) -> Int = 1\n fun place(self) -> Place = place.at(0.0, 0.0)\n fun paint(self, io: Io, m: Affine, alpha: Float) =\n x := io.rawExists(\"a\")\n\nfun main(io: Io) -> Game[Quiet, Int] =\n Game.start(screenOf(State(n: 0)), Quiet(n: 0))\n",
155
155
  )
156
156
  .unwrap();
157
157
  let wasm = compile(&path);
@@ -366,7 +366,7 @@ fn randomSeedProvidedByHost() {
366
366
  let path = dir.join("m.plum");
367
367
  std::fs::write(
368
368
  &path,
369
- "import std/Int\nimport std/Float\nimport std/Str\nimport std/Io\nimport std/Slice\nimport std/math/Vec2\nimport std/math/Affine\nimport std/game/Color\nimport std/game/gfx\nimport std/game/input\nimport std/game/Store\nimport std/game/Game\nimport std/game/scene/Place\nimport std/game/scene/Actor\nimport std/game/scene/Ctx\nimport std/game/scene/SceneTree\nimport std/collections/RoseTree\nstruct Quiet(n: Int) is Reducer[Int] =\n fun update(self, msg: Int) -> Quiet = self\nstruct PageScreen(id: Int) is Screen[Quiet, Int] =\n fun key(self) -> Int = self.id\n fun place(self) -> Place = place.at(0.0, 0.0)\n fun draw(self, io: Io, shown: SceneTree[Int]) = shown.paint(io)\nfun screenOf(top: Actor[Int]) -> SceneTree[Int] =\n kid: RoseTree[Actor[Int]] := RoseTree.leaf(top)\n page: RoseTree[Actor[Int]] := RoseTree.of(PageScreen(id: -2), [kid])\n SceneTree.ofScreens([page])\nstruct State(seed: Int) is Actor[Int] =\n fun key(self) -> Int = 1\n fun place(self) -> Place = place.at(0.0, 0.0)\n fun paint(self, io: Io, m: Affine, alpha: Float) =\n gfx.drawText(io, \"seed {self.seed}\", 0.0, 0.0, 8.0, Color.White)\n\nfun main(io: Io) -> Game[Quiet, Int] =\n Game.start(screenOf(State(seed: io.randomSeed())), Quiet(n: 0))\n",
369
+ "import std/Int\nimport std/Float\nimport std/Str\nimport std/Io\nimport std/Slice\nimport std/math/Vec2\nimport std/math/Affine\nimport std/game/Color\nimport std/game/gfx\nimport std/game/input\nimport std/game/Store\nimport std/game/Game\nimport std/game/Place\nimport std/game/Actor\nimport std/game/Ctx\nimport std/game/SceneTree\nimport std/collections/RoseTree\nstruct Quiet(n: Int) is Reducer[Int] =\n fun update(self, msg: Int) -> Quiet = self\nstruct PageScreen(id: Int) is Screen[Quiet, Int] =\n fun key(self) -> Int = self.id\n fun place(self) -> Place = place.at(0.0, 0.0)\n fun draw(self, io: Io, shown: SceneTree[Int]) = shown.paint(io)\nfun screenOf(top: Actor[Int]) -> SceneTree[Int] =\n kid: RoseTree[Actor[Int]] := RoseTree.leaf(top)\n page: RoseTree[Actor[Int]] := RoseTree.of(PageScreen(id: -2), [kid])\n SceneTree.ofScreens([page])\nstruct State(seed: Int) is Actor[Int] =\n fun key(self) -> Int = 1\n fun place(self) -> Place = place.at(0.0, 0.0)\n fun paint(self, io: Io, m: Affine, alpha: Float) =\n gfx.drawText(io, \"seed {self.seed}\", 0.0, 0.0, 8.0, Color.White)\n\nfun main(io: Io) -> Game[Quiet, Int] =\n Game.start(screenOf(State(seed: io.randomSeed())), Quiet(n: 0))\n",
370
370
  )
371
371
  .unwrap();
372
372
  let wasm = compile(&path);
@@ -390,7 +390,7 @@ fn seedGame(name: &str) -> Vec<u8> {
390
390
  let path = dir.join("m.plum");
391
391
  std::fs::write(
392
392
  &path,
393
- "import std/Int\nimport std/Float\nimport std/Str\nimport std/Io\nimport std/Slice\nimport std/math/Vec2\nimport std/math/Affine\nimport std/game/Color\nimport std/game/gfx\nimport std/game/input\nimport std/game/Store\nimport std/game/Game\nimport std/game/scene/Place\nimport std/game/scene/Actor\nimport std/game/scene/Ctx\nimport std/game/scene/SceneTree\nimport std/collections/RoseTree\nstruct Quiet(n: Int) is Reducer[Int] =\n fun update(self, msg: Int) -> Quiet = self\nstruct PageScreen(id: Int) is Screen[Quiet, Int] =\n fun key(self) -> Int = self.id\n fun place(self) -> Place = place.at(0.0, 0.0)\n fun draw(self, io: Io, shown: SceneTree[Int]) = shown.paint(io)\nfun screenOf(top: Actor[Int]) -> SceneTree[Int] =\n kid: RoseTree[Actor[Int]] := RoseTree.leaf(top)\n page: RoseTree[Actor[Int]] := RoseTree.of(PageScreen(id: -2), [kid])\n SceneTree.ofScreens([page])\nstruct State(seed: Int, ticks: Int, keys: Int, x: Float, w: Float) is Actor[Int] =\n fun key(self) -> Int = 1\n fun place(self) -> Place = place.at(0.0, 0.0)\n fun step(self, ctx: Ctx[Int], dt: Float) -> State =\n State(..self, ticks: self.ticks + 1, keys: self.keys + ctx.input.held.keys.length(), x: ctx.input.pos.x, w: ctx.view.x)\n fun paint(self, io: Io, m: Affine, alpha: Float) =\n gfx.drawText(io, \"seed {self.seed} ticks {self.ticks} keys {self.keys} x {self.x} w {self.w}\", 0.0, 0.0, 8.0, Color.White)\n\nfun main(io: Io) -> Game[Quiet, Int] =\n Game.start(screenOf(State(seed: io.randomSeed(), ticks: 0, keys: 0, x: 0.0, w: 0.0)), Quiet(n: 0))\n",
393
+ "import std/Int\nimport std/Float\nimport std/Str\nimport std/Io\nimport std/Slice\nimport std/math/Vec2\nimport std/math/Affine\nimport std/game/Color\nimport std/game/gfx\nimport std/game/input\nimport std/game/Store\nimport std/game/Game\nimport std/game/Place\nimport std/game/Actor\nimport std/game/Ctx\nimport std/game/SceneTree\nimport std/collections/RoseTree\nstruct Quiet(n: Int) is Reducer[Int] =\n fun update(self, msg: Int) -> Quiet = self\nstruct PageScreen(id: Int) is Screen[Quiet, Int] =\n fun key(self) -> Int = self.id\n fun place(self) -> Place = place.at(0.0, 0.0)\n fun draw(self, io: Io, shown: SceneTree[Int]) = shown.paint(io)\nfun screenOf(top: Actor[Int]) -> SceneTree[Int] =\n kid: RoseTree[Actor[Int]] := RoseTree.leaf(top)\n page: RoseTree[Actor[Int]] := RoseTree.of(PageScreen(id: -2), [kid])\n SceneTree.ofScreens([page])\nstruct State(seed: Int, ticks: Int, keys: Int, x: Float, w: Float) is Actor[Int] =\n fun key(self) -> Int = 1\n fun place(self) -> Place = place.at(0.0, 0.0)\n fun step(self, ctx: Ctx[Int], dt: Float) -> State =\n State(..self, ticks: self.ticks + 1, keys: self.keys + ctx.input.held.keys.length(), x: ctx.input.pos.x, w: ctx.view.x)\n fun paint(self, io: Io, m: Affine, alpha: Float) =\n gfx.drawText(io, \"seed {self.seed} ticks {self.ticks} keys {self.keys} x {self.x} w {self.w}\", 0.0, 0.0, 8.0, Color.White)\n\nfun main(io: Io) -> Game[Quiet, Int] =\n Game.start(screenOf(State(seed: io.randomSeed(), ticks: 0, keys: 0, x: 0.0, w: 0.0)), Quiet(n: 0))\n",
394
394
  )
395
395
  .unwrap();
396
396
  let wasm = compile(&path);
@@ -465,7 +465,7 @@ fn everySeedOfARecordedRunReplays() {
465
465
  let path = dir.join("m.plum");
466
466
  std::fs::write(
467
467
  &path,
468
- "import std/Int\nimport std/Float\nimport std/Str\nimport std/Io\nimport std/Slice\nimport std/math/Vec2\nimport std/math/Affine\nimport std/game/Color\nimport std/game/gfx\nimport std/game/input\nimport std/game/Store\nimport std/game/Game\nimport std/game/scene/Place\nimport std/game/scene/Actor\nimport std/game/scene/Ctx\nimport std/game/scene/SceneTree\nimport std/collections/RoseTree\nstruct Seeds(mut c: Int)\nstruct Mixed(seeds: Seeds) is Reducer[Int] =\n fun update(self, msg: Int) -> Mixed = self\n fun handle(self, io: Io, msg: Int) =\n self.seeds.c = self.seeds.c ^ io.randomSeed()\nstruct PageScreen(id: Int) is Screen[Mixed, Int] =\n fun key(self) -> Int = self.id\n fun place(self) -> Place = place.at(0.0, 0.0)\n fun draw(self, io: Io, shown: SceneTree[Int]) = shown.paint(io)\nfun screenOf(top: Actor[Int]) -> SceneTree[Int] =\n kid: RoseTree[Actor[Int]] := RoseTree.leaf(top)\n page: RoseTree[Actor[Int]] := RoseTree.of(PageScreen(id: -2), [kid])\n SceneTree.ofScreens([page])\nstruct State(a: Int, b: Int, seeds: Seeds) is Actor[Int] =\n fun key(self) -> Int = 1\n fun place(self) -> Place = place.at(0.0, 0.0)\n fun step(self, ctx: Ctx[Int], dt: Float) -> State =\n ctx.send(1)\n self\n fun paint(self, io: Io, m: Affine, alpha: Float) =\n gfx.drawText(io, \"{self.a} {self.b} {self.seeds.c}\", 0.0, 0.0, 8.0, Color.White)\n\nfun main(io: Io) -> Game[Mixed, Int] =\n a := io.randomSeed()\n seeds := Seeds(c: 0)\n Game.start(screenOf(State(a: a, b: io.randomSeed(), seeds: seeds)), Mixed(seeds: seeds))\n",
468
+ "import std/Int\nimport std/Float\nimport std/Str\nimport std/Io\nimport std/Slice\nimport std/math/Vec2\nimport std/math/Affine\nimport std/game/Color\nimport std/game/gfx\nimport std/game/input\nimport std/game/Store\nimport std/game/Game\nimport std/game/Place\nimport std/game/Actor\nimport std/game/Ctx\nimport std/game/SceneTree\nimport std/collections/RoseTree\nstruct Seeds(mut c: Int)\nstruct Mixed(seeds: Seeds) is Reducer[Int] =\n fun update(self, msg: Int) -> Mixed = self\n fun handle(self, io: Io, msg: Int) =\n self.seeds.c = self.seeds.c ^ io.randomSeed()\nstruct PageScreen(id: Int) is Screen[Mixed, Int] =\n fun key(self) -> Int = self.id\n fun place(self) -> Place = place.at(0.0, 0.0)\n fun draw(self, io: Io, shown: SceneTree[Int]) = shown.paint(io)\nfun screenOf(top: Actor[Int]) -> SceneTree[Int] =\n kid: RoseTree[Actor[Int]] := RoseTree.leaf(top)\n page: RoseTree[Actor[Int]] := RoseTree.of(PageScreen(id: -2), [kid])\n SceneTree.ofScreens([page])\nstruct State(a: Int, b: Int, seeds: Seeds) is Actor[Int] =\n fun key(self) -> Int = 1\n fun place(self) -> Place = place.at(0.0, 0.0)\n fun step(self, ctx: Ctx[Int], dt: Float) -> State =\n ctx.send(1)\n self\n fun paint(self, io: Io, m: Affine, alpha: Float) =\n gfx.drawText(io, \"{self.a} {self.b} {self.seeds.c}\", 0.0, 0.0, 8.0, Color.White)\n\nfun main(io: Io) -> Game[Mixed, Int] =\n a := io.randomSeed()\n seeds := Seeds(c: 0)\n Game.start(screenOf(State(a: a, b: io.randomSeed(), seeds: seeds)), Mixed(seeds: seeds))\n",
469
469
  )
470
470
  .unwrap();
471
471
  let wasm = compile(&path);
compiler/game/web-test/fixtures/interleave.plum CHANGED
@@ -15,10 +15,10 @@ import std/math/Affine
15
15
  import std/game/Store
16
16
  import std/game/Game
17
17
  import std/collections/RoseTree
18
- import std/game/scene/Place
18
+ import std/game/Place
19
- import std/game/scene/Actor
19
+ import std/game/Actor
20
+ import std/game/Ctx
20
- import std/game/scene/Ctx
21
+ import std/game/SceneTree
21
- import std/game/scene/SceneTree
22
22
 
23
23
  Sprites = 4000
24
24
  Textures = 8
compiler/game/web-test/fixtures/main_game.plum CHANGED
@@ -12,10 +12,10 @@ import std/game/input
12
12
  import std/game/Store
13
13
  import std/game/Game
14
14
  import std/collections/RoseTree
15
- import std/game/scene/Place
15
+ import std/game/Place
16
- import std/game/scene/Actor
16
+ import std/game/Actor
17
+ import std/game/Ctx
17
- import std/game/scene/Ctx
18
+ import std/game/SceneTree
18
- import std/game/scene/SceneTree
19
19
 
20
20
  # A game whose `main` returns a `Game`: one screen holding one actor, a square that moves
21
21
  # with the tick count. It sends no messages, so its state never changes.
compiler/game/web-test/fixtures/rendertarget.plum CHANGED
@@ -23,10 +23,10 @@ import std/math/Affine
23
23
  import std/game/Store
24
24
  import std/game/Game
25
25
  import std/collections/RoseTree
26
- import std/game/scene/Place
26
+ import std/game/Place
27
- import std/game/scene/Actor
27
+ import std/game/Actor
28
+ import std/game/Ctx
28
- import std/game/scene/Ctx
29
+ import std/game/SceneTree
29
- import std/game/scene/SceneTree
30
30
 
31
31
  # The game sends no messages, so its state never changes.
32
32
  struct Quiet(n: Int) is Reducer[Int] =
compiler/game/web-test/fixtures/stress.plum CHANGED
@@ -15,10 +15,10 @@ import std/math/Affine
15
15
  import std/game/Store
16
16
  import std/game/Game
17
17
  import std/collections/RoseTree
18
- import std/game/scene/Place
18
+ import std/game/Place
19
- import std/game/scene/Actor
19
+ import std/game/Actor
20
+ import std/game/Ctx
20
- import std/game/scene/Ctx
21
+ import std/game/SceneTree
21
- import std/game/scene/SceneTree
22
22
 
23
23
  Sprites = 5000
24
24
  Rects = 500
compiler/game/web-test/fixtures/stress_scene_port.plum CHANGED
@@ -20,10 +20,10 @@ import std/game/input
20
20
  import std/collections/RoseTree
21
21
  import std/game/Store
22
22
  import std/game/Game
23
- import std/game/scene/Place
23
+ import std/game/Place
24
- import std/game/scene/Actor
24
+ import std/game/Actor
25
+ import std/game/Ctx
25
- import std/game/scene/Ctx
26
+ import std/game/SceneTree
26
- import std/game/scene/SceneTree
27
27
  import std/Io
28
28
 
29
29
  Sprites = 5000
compiler/game/web-test/fixtures/stress_state_view.plum CHANGED
@@ -27,10 +27,10 @@ import std/game/input
27
27
  import std/collections/RoseTree
28
28
  import std/game/Store
29
29
  import std/game/Game
30
- import std/game/scene/Place
30
+ import std/game/Place
31
- import std/game/scene/Actor
31
+ import std/game/Actor
32
+ import std/game/Ctx
32
- import std/game/scene/Ctx
33
+ import std/game/SceneTree
33
- import std/game/scene/SceneTree
34
34
  import std/Io
35
35
 
36
36
  Sprites = 5000
compiler/game/web-test/fixtures/stress_world.plum CHANGED
@@ -20,10 +20,10 @@ import std/game/gfx
20
20
  import std/collections/RoseTree
21
21
  import std/game/Store
22
22
  import std/game/Game
23
- import std/game/scene/Place
23
+ import std/game/Place
24
- import std/game/scene/Actor
24
+ import std/game/Actor
25
+ import std/game/Ctx
25
- import std/game/scene/Ctx
26
+ import std/game/SceneTree
26
- import std/game/scene/SceneTree
27
27
  import std/Io
28
28
  import std/game/input
29
29
 
compiler/game/web-test/fixtures/text_sizes.plum CHANGED
@@ -14,10 +14,10 @@ import std/math/Affine
14
14
  import std/game/Store
15
15
  import std/game/Game
16
16
  import std/collections/RoseTree
17
- import std/game/scene/Place
17
+ import std/game/Place
18
- import std/game/scene/Actor
18
+ import std/game/Actor
19
+ import std/game/Ctx
19
- import std/game/scene/Ctx
20
+ import std/game/SceneTree
20
- import std/game/scene/SceneTree
21
21
 
22
22
  # The game sends no messages, so its state never changes.
23
23
  struct Quiet(n: Int) is Reducer[Int] =
compiler/lsp/src/main.rs CHANGED
@@ -725,7 +725,7 @@ mod tests {
725
725
  ("gfx", "std/game/gfx"),
726
726
  ("input", "std/game/input"),
727
727
  ("Int", "std/Int"),
728
- ("SceneTree", "std/game/scene/SceneTree"),
728
+ ("SceneTree", "std/game/SceneTree"),
729
729
  ("Io", "std/Io"),
730
730
  ("Key", "std/game/input"),
731
731
  ("Vec2", "std/math/Vec2"),
docs/game.md CHANGED
@@ -34,10 +34,10 @@ import std/game/ui
34
34
  import std/game/Store
35
35
  import std/game/Game
36
36
  import std/collections/RoseTree
37
- import std/game/scene/Place
37
+ import std/game/Place
38
- import std/game/scene/Actor
38
+ import std/game/Actor
39
+ import std/game/Ctx
39
- import std/game/scene/Ctx
40
+ import std/game/SceneTree
40
- import std/game/scene/SceneTree
41
41
 
42
42
  # What can happen to the state.
43
43
  enum Msg = Clicked | Cleared
examples/games/clicks.plum CHANGED
@@ -14,10 +14,10 @@ import std/game/ui
14
14
  import std/game/Store
15
15
  import std/game/Game
16
16
  import std/collections/RoseTree
17
- import std/game/scene/Place
17
+ import std/game/Place
18
- import std/game/scene/Actor
18
+ import std/game/Actor
19
+ import std/game/Ctx
19
- import std/game/scene/Ctx
20
+ import std/game/SceneTree
20
- import std/game/scene/SceneTree
21
21
 
22
22
  # What can happen to the state.
23
23
  enum Msg = Clicked | Cleared
examples/games/kids/balloon_pop.plum CHANGED
@@ -5,7 +5,7 @@
5
5
  # confetti. There is no way to lose and no timer.
6
6
  #
7
7
  # The game is a `Game` (std/game/Game) with one screen, `SkyScreen`, in a tree of actors
8
- # (std/game/scene) that lives from frame to frame. Each balloon is a `Balloon` actor that
8
+ # (std/game/SceneTree) that lives from frame to frame. Each balloon is a `Balloon` actor that
9
9
  # rises in its own `step` and is the only `Clickable` actor, so the only one ever hit
10
10
  # (`hit`, its own shape): the game routes a pointer press to the balloon under it
11
11
  # (`input`), which bursts and sends `Popped(id)` to the store. The screen's `rules` send
@@ -41,10 +41,11 @@ import std/game/input
41
41
  import std/game/Store
42
42
  import std/game/Game
43
43
  import std/collections/RoseTree
44
- import std/game/scene/Place
44
+ import std/game/Place
45
- import std/game/scene/Actor
45
+ import std/game/Actor
46
+ import std/game/Clickable
47
+ import std/game/Ctx
46
- import std/game/scene/Ctx
48
+ import std/game/SceneTree
47
- import std/game/scene/SceneTree
48
49
  import std/Io
49
50
 
50
51
  ArenaW = 800.0
examples/games/orb_run.plum CHANGED
@@ -5,7 +5,7 @@
5
5
  #
6
6
  # The game is a `Game` (std/game/Game) of three screens, `TitleScreen`, `PlayScreen` and
7
7
  # `GameOverScreen`, over a store of `State` (std/game/Store). The screens live in one tree
8
- # of actors (std/game/scene) that lives from frame to frame, under the root camera that
8
+ # of actors (std/game/SceneTree) that lives from frame to frame, under the root camera that
9
9
  # fits the arena on screen; the state names the one shown (`State.on`, set by `update`:
10
10
  # `PlayScreen.name()` when a run starts), and only that one steps and is drawn. The play
11
11
  # screen fades in over the title. Every kind of body is its own struct (`Ship`, `Orb`,
@@ -65,10 +65,10 @@ import std/game/input
65
65
  import std/game/Store
66
66
  import std/game/Game
67
67
  import std/collections/RoseTree
68
- import std/game/scene/Place
68
+ import std/game/Place
69
- import std/game/scene/Actor
69
+ import std/game/Actor
70
+ import std/game/Ctx
70
- import std/game/scene/Ctx
71
+ import std/game/SceneTree
71
- import std/game/scene/SceneTree
72
72
  import std/Io
73
73
 
74
74
  ArenaW = 800.0
@@ -190,7 +190,7 @@ fun fitX(sw: Float, sh: Float) -> Float =
190
190
  fun fitY(sw: Float, sh: Float) -> Float =
191
191
  {sh - fitZoom(sw, sh) * ArenaH} / 2.0
192
192
 
193
- # --- painting: an actor paints in its own coordinates, seen through `m` (std/game/scene/Actor
193
+ # --- painting: an actor paints in its own coordinates, seen through `m` (std/game/Actor
194
194
  # has boxes, circles, lines and text) ---
195
195
 
196
196
  # A `size` square cell (col, row) of the sprite sheet with its top-left at (x, y).
examples/games/two_screens.plum CHANGED
@@ -15,10 +15,10 @@ import std/game/ui
15
15
  import std/game/Store
16
16
  import std/game/Game
17
17
  import std/collections/RoseTree
18
- import std/game/scene/Place
18
+ import std/game/Place
19
- import std/game/scene/Actor
19
+ import std/game/Actor
20
+ import std/game/Ctx
20
- import std/game/scene/Ctx
21
+ import std/game/SceneTree
21
- import std/game/scene/SceneTree
22
22
 
23
23
  enum Msg = Start | Back
24
24
 
std/collections/RoseTree.plum CHANGED
@@ -32,12 +32,12 @@ import std/ref
32
32
  # `replace` (`update`) keep the nodes they passed in a list, last on top, and link them
33
33
  # back with tail calls. Only the depth of the tree takes stack.
34
34
  #
35
- # Siblings are kept in order: the first child comes first in every walk (std/game/scene's
35
+ # Siblings are kept in order: the first child comes first in every walk (std/game/SceneTree's
36
36
  # SceneTree draws it first and hits it last). Appending a child copies the link nodes of its earlier
37
37
  # siblings (their values and subtrees are shared), O(children); `appendAll` adds a batch
38
38
  # for the cost of one.
39
39
  #
40
- # Nodes are referred to by what is in them (std/game/scene's actors have a `key()`), not
40
+ # Nodes are referred to by what is in them (std/game/SceneTree's actors have a `key()`), not
41
41
  # by the node itself: after an update the old node is a different, older value.
42
42
  enum RoseTree[T] =
43
43
  | RoseEmpty
std/game/{scene/Actor.plum → Actor.plum} RENAMED
@@ -11,8 +11,9 @@ import std/math/Affine
11
11
  import std/game/Color
12
12
  import std/game/gfx
13
13
  import std/game/input
14
- import std/game/scene/Place
14
+ import std/game/Place
15
+ import std/game/Clickable
15
- import std/game/scene/Ctx
16
+ import std/game/Ctx
16
17
 
17
18
  # One actor of a scene tree (`RoseTree[Actor[M]]` in a `SceneTree[M]`). Each kind of
18
19
  # actor is its own type, with only its own fields, that `is Actor[M]`; `M` is the game's
@@ -43,7 +44,8 @@ import std/game/scene/Ctx
43
44
  # much. The std kinds below, `Group` and `Box` (and std/game/ui's `Button` and `Label`),
44
45
  # are generic in `M` so any game's tree takes them.
45
46
  #
46
- # An actor the pointer can hit is also `Clickable` (below): only those get pointer events.
47
+ # An actor the pointer can hit is also `Clickable` (std/game/Clickable): only those get
48
+ # pointer events.
47
49
  trait Actor[M] =
48
50
  fun key(self) -> Int
49
51
 
@@ -61,15 +63,6 @@ trait Actor[M] =
61
63
 
62
64
  fun opacity(self) -> Float = 1.0
63
65
 
64
- # An actor the pointer can hit, as well as an `Actor[M]`: `struct Button[M](..) is Actor[M],
65
- # Clickable`. `hit` says whether `p`, in the actor's own coordinates, is on it. Only a
66
- # `Clickable` actor gets pointer events (`SceneTree.input`) and is found by
67
- # `SceneTree.hit`; the tree's pointer walk skips every other actor without a test, and
68
- # computes no transform for one without children. A `hit` on an actor that isn't
69
- # `Clickable` is a plain method the tree never calls.
70
- trait Clickable =
71
- fun hit(self, p: Vec2) -> Bool
72
-
73
66
  # An actor that paints nothing and is never hit: a parent for others (a layer).
74
67
  struct Group[M](id: Int, x: Float, y: Float) is Actor[M] =
75
68
  fun key(self) -> Int = self.id
std/game/Clickable.plum ADDED
@@ -0,0 +1,13 @@
1
+ module std
2
+
3
+ import std/Bool
4
+ import std/math/Vec2
5
+
6
+ # An actor the pointer can hit, as well as an `Actor[M]`: `struct Button[M](..) is Actor[M],
7
+ # Clickable`. `hit` says whether `p`, in the actor's own coordinates, is on it. Only a
8
+ # `Clickable` actor gets pointer events (`SceneTree.input`) and is found by
9
+ # `SceneTree.hit`; the tree's pointer walk skips every other actor without a test, and
10
+ # computes no transform for one without children. A `hit` on an actor that isn't
11
+ # `Clickable` is a plain method the tree never calls.
12
+ trait Clickable =
13
+ fun hit(self, p: Vec2) -> Bool
std/game/{scene/Ctx.plum → Ctx.plum} RENAMED
@@ -9,7 +9,7 @@ import std/math/Vec2
9
9
  import std/math/Affine
10
10
  import std/game/input
11
11
  import std/collections/RoseTree
12
- import std/game/scene/Actor
12
+ import std/game/Actor
13
13
 
14
14
  # What a step changes besides the actors. `Spawn` and `Kill` are the tree's: they are
15
15
  # applied once the step's walk is over (`SceneTree.apply`): a new node under the actor
std/game/Game.plum CHANGED
@@ -16,14 +16,15 @@ import std/game/gfx
16
16
  import std/game/input
17
17
  import std/collections/RoseTree
18
18
  import std/game/Store
19
- import std/game/scene/Place
19
+ import std/game/Place
20
- import std/game/scene/Actor
20
+ import std/game/Actor
21
+ import std/game/Clickable
22
+ import std/game/Ctx
21
- import std/game/scene/Ctx
23
+ import std/game/SceneTree
22
- import std/game/scene/SceneTree
23
24
 
24
25
  # The one way to make a game: a `Game[S, M]` over a store of the state `S` (a
25
26
  # `Reducer[M]`, std/game/Store) and one tree of actors (`SceneTree[M]` of `Actor[M]`,
26
- # std/game/scene) whose root's children are the game's screens. `M` is the game's message
27
+ # std/game/SceneTree) whose root's children are the game's screens. `M` is the game's message
27
28
  # type. A game writes its actors, its screens and its reducer; `Game` runs the loop:
28
29
  #
29
30
  # fun main(io: Io) -> Game[RunState, Msg] =
std/game/{scene/Place.plum → Place.plum} RENAMED
File without changes
std/game/{scene/SceneTree.plum → SceneTree.plum} RENAMED
@@ -20,12 +20,13 @@ import std/game/Color
20
20
  import std/game/gfx
21
21
  import std/game/input
22
22
  import std/collections/RoseTree
23
- import std/game/scene/Actor
23
+ import std/game/Actor
24
+ import std/game/Clickable
24
- import std/game/scene/Place
25
+ import std/game/Place
25
- import std/game/scene/Ctx
26
+ import std/game/Ctx
26
27
 
27
28
  # The game's scene: a persistent tree of actors of any kind that `is Actor[M]` (see
28
- # std/game/scene/Actor), `M` being the game's message type. The root is an
29
+ # std/game/Actor), `M` being the game's message type. The root is an
29
30
  # `RoseTree[Actor[M]]`, a left-child, right-sibling tree of actors, and a scene tree is a
30
31
  # value: every change returns a new tree. While something holds the old tree it stays as
31
32
  # it was, a snapshot; when nothing does, the compiler reuses its cells for the new one.
std/game/ui.plum CHANGED
@@ -12,10 +12,11 @@ import std/math/Affine
12
12
  import std/game/Color
13
13
  import std/game/input
14
14
  import std/collections/RoseTree
15
- import std/game/scene/Place
15
+ import std/game/Place
16
- import std/game/scene/Actor
16
+ import std/game/Actor
17
+ import std/game/Clickable
18
+ import std/game/Ctx
17
- import std/game/scene/Ctx
19
+ import std/game/SceneTree
18
- import std/game/scene/SceneTree
19
20
 
20
21
  # Widgets for a scene tree: actors (`is Actor[M]`), so any game's `SceneTree[M]` takes
21
22
  # them. A `Button[M]` sends its `onClick: M` to the game when it is clicked: pressed (a
std/ref.plum CHANGED
@@ -9,7 +9,7 @@ import std/Bool
9
9
  #
10
10
  # It is what a persistent structure uses to keep what did not change: a walk that rebuilds
11
11
  # a node only when a part of it is another object returns the old node otherwise, so an
12
- # unchanged tree comes back as the very same tree (std/game/scene/SceneTree's `input`,
12
+ # unchanged tree comes back as the very same tree (std/game/SceneTree's `input`,
13
13
  # std/game/Game's tick).
14
14
  #
15
15
  # Only for values that live on the heap: a struct that is not flat, an enum, a trait object,
tests/port/game/determinism.plum CHANGED
@@ -11,10 +11,10 @@ import std/math/Affine
11
11
  import std/game/Store
12
12
  import std/game/Game
13
13
  import std/collections/RoseTree
14
- import std/game/scene/Place
14
+ import std/game/Place
15
- import std/game/scene/Actor
15
+ import std/game/Actor
16
+ import std/game/Ctx
16
- import std/game/scene/Ctx
17
+ import std/game/SceneTree
17
- import std/game/scene/SceneTree
18
18
 
19
19
  # Deterministic games: the game's `Clock` (std/game/input) runs fixed 1/60 s ticks, at
20
20
  # most 8 a frame, and hands each tick its input as a value; randomness is a `Random`
tests/port/game/replay.plum CHANGED
@@ -15,10 +15,10 @@ import std/math/Affine
15
15
  import std/game/Store
16
16
  import std/game/Game
17
17
  import std/collections/RoseTree
18
- import std/game/scene/Place
18
+ import std/game/Place
19
- import std/game/scene/Actor
19
+ import std/game/Actor
20
+ import std/game/Ctx
20
- import std/game/scene/Ctx
21
+ import std/game/SceneTree
21
- import std/game/scene/SceneTree
22
22
 
23
23
  # Record and replay (std/game/Replay): a run is its seed and one `Input` per tick, as text
24
24
  # with exact floats. A game's `Clock` records the ticks of each frame and replays them.