Commit Graph

101 Commits

Author SHA1 Message Date
Ondřej Šebek
8366135ae1
Notify user about newer version (#652)
- query GitHub Releases for a new version
- add `swarm version` command
- show the version notification in the main menu
- add a new app-wide logging queue
- show the app-wide logs in the main menu as Messages
- catch and show the web API failure in the Messages
- closes #66
- closes #627
2022-09-06 07:32:24 +00:00
Ondřej Šebek
68333dd70a
Save scenario completion status (#631)
- save the latest and best completion status for a scenario
  - scenarios are either `not started`/`in progress`/`completed` with the latter two also having time (real and in ticks)
- do not save completion status for `--cheat`ers
- show the completion status in the UI
- closes #357 

Co-authored-by: Brent Yorgey <byorgey@gmail.com>
2022-08-30 06:53:43 +00:00
Brent Yorgey
88d6b72b8d
temporary workaround for TomMD/entropy#75 (#650) 2022-08-23 09:34:50 +00:00
Brent Yorgey
e6defd44b1
update to brick-1.0 (#641)
* Update to `brick-1.0`
* Test with GHC 9.2.4
2022-08-17 12:35:10 -05:00
Tristan de Cacqueray
e9fb04691a
Add debug web service (#623)
This change introduce a new web API for the game.
The initial goal is to expose the internal state using the
`/robots` and `/robot/$id` endpoint to query the json representation
of the robots.

A new command line argument is added:
- When `--port 0` is set, the web service is disabled.
- When `--web port` is set, the game won't start if the web service fail to bind the port.
- Otherwise, when `--web` is not set, the service may start on 5357 if the port is available.

Example usage:

```
 swarm --web 5357
 curl localhost:5357/robots | jq
```

Future improvement may include:

- Ability to load program to the base (to send command from external text editor)
- Serve a html interface for alternative visualization
2022-08-06 19:34:23 +00:00
Ondřej Šebek
dde089c3cf
Split unit test file (#578)
Split the unit test file into a separate file for each test tree (except miscellaneous).

It was already a thousand lines long and hard to read.
2022-08-03 22:13:49 +00:00
Ondřej Šebek
0150b8a901
Update to new brick EventM API (#583)
- closes #561
2022-07-27 21:53:11 +00:00
Tristan de Cacqueray
cf6693b2e5
Add a few more JSON instances (#494)
- part of #347
2022-07-11 01:58:21 +00:00
Brent Yorgey
eb205e61a9
Add require directive (#533)
Add new special syntactic forms `require <string literal>` to require a device to be installed, and `require <int literal> <string literal>` to require a certain number of a given entity in the inventory.

- Replace `Set Capability` with a new `Requirements` type which records various types of requirement.
- Refactor requirements checking into a new function `checkRequirements` which also does device set minimization (#508).  
- `reprogram` will now install extra devices or transfer extra inventory as necessary.
- Add a bunch of tests.
- Add new `installed` command, similar to `has`, which checks whether a given device is installed.

Closes #201.
Closes #508.
2022-07-05 22:36:06 +00:00
Ondřej Šebek
3872c11509
Generate editor keywords (#526)
- part of #344
2022-07-01 18:44:09 +00:00
Ondřej Šebek
8652440607
Make GHC2021 extensions default (#520)
- closes #419
2022-07-01 09:07:41 +00:00
Brent Yorgey
1505e9dc25
get rid of numeric prefixes on scenario files, use 00-ORDER.txt (#492)
Closes #463.
2022-06-25 22:33:55 +00:00
Ondřej Šebek
9b6eaef37b
Add generator for recipe dependencies (#476)
- add `generate` subparser to the executable
- create a generator for a Graphviz entity dependencies graph
- part of #344 

You can interactively test this with:
```bash
$ cabal run swarm:swarm -- generate recipes \
 | sed -n '/^digraph/,$p' > docs/recipes.dot
$ xdot docs/recipes.dot
```
2022-06-24 21:50:32 +00:00
Ondřej Šebek
bb8a31ec4d Test scenarios
- add winning solutions to scenarios
- test the winning solutions
  - fail if any robot has a `Fatal error` in its log
  - timeout in X seconds (default 1)
- add a Testing scenario collection hidden without the `--cheat` flag
  - add a test case for #394

- closes #388
2022-06-18 02:44:22 +02:00
Ondřej Šebek
05e4e08d10 Move test into separate folders
It makes IDE usage easier and allows us to split
main files once they get too big.
2022-06-18 02:44:22 +02:00
Ondřej Šebek
94c876a01a Add GHC 9.2.3 to CI 2022-06-09 01:29:05 +02:00
Brent Yorgey
69929f1b61 Bump dependency bounds
- bump upper bounds on dependencies
- remove special th-extras and depedent-sum deps
- fix problems with new opaque types in Aeson
2022-06-09 01:29:05 +02:00
Brent Yorgey
ee857a5d21
upgrade to brick-0.69 (#365)
Closes #340.
2022-06-04 22:59:18 -05:00
Ondřej Šebek
7ad65ad00a
Update Github Actions and fix Doctest (#352)
* Fix doctests

* Regenerate haskell-ci with config

- use latest haskell-ci
- configure haskell-ci to use doctest

* Update tested with compiler

- update cabal tested-with field
- update .mergify.yaml to new compiler
  - restore note about mergify in haskell-ci
2022-06-04 15:04:26 -05:00
Brent Yorgey
8961d03a1a
Generalize challenges + classic/creative modes to scenarios (#337)
Generalize challenges + various modes to all be "scenarios" which are described by `.yaml` files in `data/scenarios`.  

- Both challenges and classic/creative modes are now subsumed under the more general notion of "scenarios".
- A scenario describes how to set up the world etc. when starting a game; all scenarios are stored in a `.yaml` file in `data/scenarios`.
- "New game" menu item now lets the user choose a scenario.
- Some small improvements to the way seeds are handled.

See #296.  This will enable #35 and #25 .
2022-06-04 13:20:49 +00:00
Brent Yorgey
c8d0c4bd76
Add a main menu shown on startup (#326)
Lots of refining, adding more menu options, etc. that still needs to happen, but this adds a basic menu.  Quitting a game now quits to the menu rather than quitting the entire application.
2022-05-05 13:08:50 -05:00
Brent Yorgey
667f001c8b print git branch and hash in --help menu
Not super useful on its own.  This is mostly just to figure out the
`githash` library (which wasn't hard) in initial preparation for #66.
2022-04-27 08:01:45 -05:00
Brent Yorgey
4a600fa788 update URL repo references from byorgey/swarm to swarm-game/swarm 2022-03-14 14:09:47 -05:00
Brent Yorgey
b62d27e566
Use a new opaque type for robots instead of strings (#303)
The basic idea of this change is to create a new `robot` type and use it to identify robots instead of `string` names.  Internally, a `robot` value is just a (unique) `Int`. 

Closes #212 .

This ended up turning into a sort of constellation of related changes.

- Add the `robot` type and change the type of various built-in functions which used to take a robot name so they now take a `robot` (`give`, `install`, `reprogram`, `view`, `upload`) and change `build` so it returns a `robot`.
- All internal data structures that store robots are now keyed by a unique (`Int`) robot ID rather than by name.
- Add a `setname` command for setting a robot's display name (which no longer needs to uniquely identify a robot).
- Import a big list of words which we can use to randomly pick names for robots, just for fun.  This is why the diff says "+31,050  -265"; I did not write 31 thousand lines of code.
- Add constants `base`, `parent`, and `self` for getting a `robot` value referring to the base, one's parent, and one's self, respectively.
- Top-level binders like `r <- build {move}` now export a variable binding which can be used in later expressions entered at the REPL; additionally, unlike Haskell, a binder can now appear as the last statement in a block.
- Fix the pretty-printer for `Value` by doubling down on our current strategy of injecting `Value`s back into `Term`s and then pretty-printing the result.  I am now convinced this is the Right Way (tm) to do this; it only required adding a couple additional kinds of `Term` which represent internal results of evaluation and cannot show up in the surface language (`TRef`, `TRobot`).
- Update the tutorial.
- While updating the tutorial, I noticed that #294 had introduced a bug, where the inventory display no longer updated when 0 copies of an entity are added to the inventory (as with `scan` + `upload`), so I fixed that by changing the way inventory hashes are computed.

I tried running the benchmarks both before & after this change.  I was hoping that it might speed things up to be using `IntMap` and `IntSet` instead of looking things up by `Text` keys in a `Map` all the time.  However, if I'm interpreting the results correctly, it seems like it didn't really make all that much difference, at least for the particular benchmarks we have.
2022-03-02 03:00:44 +00:00
Brent Yorgey
b1f0e316fd
Challenge mode (#285)
Add a "challenge mode" where the player tries to achieve some specified goal from specific starting conditions.
2022-01-27 17:00:00 -06:00
Brent Yorgey
74ea395c83
homomorphic hashing for inventories (#294)
The hash for an inventory is now the sum of the hashes of its contents. As discussed in #229 , the point of this is that inventory hashes can now be maintained incrementally, which could be a big win if there are robots with big inventories. It is less "secure" but we don't really care about that.

Closes #229.
2022-01-24 17:43:34 -06:00
Ondřej Šebek
05dad31bff
Store history in XDG data directory (#253)
- fixes #136 
- changes the history file format to simple text line per `REPLEntry`
- refactors out a `REPLHistory` type and its pure functions
  - adds tests for REPL logic (move to different previous entry,...)
2021-11-04 14:59:17 +00:00
Brent Yorgey
f6a222092b
Add some simple property-based tests for arithmetic and comparison (#263) 2021-10-27 11:56:02 +00:00
Brent Yorgey
c982e81790
Delay type (#223)
Make explicit in the type system when evaluation of a computation should be delayed.  This gives the user fine-grained control over selective laziness (for example, once we have sum types and recursive types, one could use this to define lazy infinite data structures).  It also allows us to guarantee that certain commands such as `build` and `reprogram` delay evaluation of their arguments, and lets the user e.g. define their own modified versions of `build` without compromising those guarantees.

- Delay is indicated by curly braces both at the value and type levels, that is, if `t : ty` then `{t} : {ty}`.
- `force : {ty} -> ty` is now exposed in the surface language.
- Change from a CEK machine to a CESK machine. Recursive `let` and `def` delay via allocating a cell in the store.  For now, there is no other way to allocate anything in the store, but see discussion at #150 for some possible future directions.
- change the types of `build` and `reprogram` to require a delayed program, e.g. `build : string -> {cmd a} -> cmd string`
- `if` and `try` also require delayed arguments.
- don't elaborate Build and Reprogram with extra Delay wrappers since one is now required by the type
- Division by zero, negative exponents, and bad comparisons now throw exceptions.

Closes #150.  Closes #226.
2021-10-25 13:28:41 +00:00
Brent Yorgey
cdd3aff892 remove https://github.com/jtdaugherty/brick/issues/337 workaround
This issue is fixed in `brick-0.64.2`.
2021-10-22 11:55:32 -05:00
Paul Brauner
b72e09edb1
Use fused-effects for the game logic (#256)
Resolves #228.

I've redefined the missing lens operators in `Utils.hs` in order to keep the diff of the function bodies minimal. Hopefully that will make merges and rebases less painful. Most of the type signatures are modified though, we can't avoid this.
2021-10-21 22:44:56 +00:00
Ishan Bhanuka
150dc9b396
Test example .sw files to see if they type check (#233)
Closes #180 

Add `Integration.hs` which reads files from `example` folder and runs `processTerm` on the contents. The test passes if creating a term is successful.

Currently only one example i.e. `zigzag.sw` is failing.
2021-10-19 02:49:32 +00:00
Brent Yorgey
22a8de35b6
Add sum types (#224)
Adds sum types (e.g. `int + bool`) along with constants `inl : a -> a + b`, `inr : b -> a + b`, and `case : a + b -> (a -> c) -> (b -> c) -> c`.

I considered whether to automatically wrap the arguments to `case` in `delay`, like the arguments to `if`, but they are already functions anyway so we get a lot of laziness for free.  It would only make a difference if you wrote something like `case foo (let x = blah in \y. ...) (...)` in which case the `let x = blah` is going to be evaluated eagerly, *before* we know which branch we are going to take.  I don't think it's worth bothering about.  In the normal case that you write `case foo (\y. ...) (\z. ...)` then only one of the two functions gets run at all, without us having to do anything special with `delay`.

I also considered whether to make special syntax for case expressions, like `case foo of { inl x -> ... ; inr y -> ... }` but doing it as a simple built-in function is both easier to implement and feels like it fits better with the aesthetic of the language so far.

Closes #46 .
2021-10-16 23:17:42 +00:00
Ryan Yates
9edf01da7f
bug fix: byName out of sync with counts due to case insensitivity. (#157)
The `Inventory` `counts` and `byName` maps could get out of sync due to missing case insensitivity on deletion.  Perhaps a better fix would be to use something like [https://hackage.haskell.org/package/case-insensitive](https://hackage.haskell.org/package/case-insensitive).
2021-10-03 20:06:12 +00:00
Daniel Díaz Carrete
4d3f3aa12a
Compatibility with hashable-1.3.4 (#142)
The code has an orphan instance `Hashable (Map k v)` but, starting from [hashable-1.3.4.0](https://hackage.haskell.org/package/hashable-1.3.4.0/docs/Data-Hashable.html#t:Hashable), that instance already exists in hashable itself, making compilation fail.

I disabled it for that case using a CPP directive.
2021-10-02 15:34:38 +00:00
Tristan de Cacqueray
c7baf13efe
Add basic editor integration with LSP (#108)
This change improves the user experience when editing swarm code outside of the REPL with:

- CLI for a `format` command to quickly parse and type check a file.
- Basic LSP server to provide IDE feedback on save, e.g. visual squiggly for errors.
- Initial emacs mode.

Fixes #82 #110
2021-10-01 20:11:08 +00:00
Paul Brauner
678f1c0db3
Add some benchmark (#129)
Add a benchmark measuring the time it takes to run 1000 ticks of the growing 10, 20, or 30 trees.
2021-10-01 11:59:34 +00:00
Tristan de Cacqueray
0c12e0176e
Add parser test and fix missing semicolon between defs (#86) 2021-09-28 02:39:39 +00:00
Brent Yorgey
1a66a3c630 tmQ quasiquoter, now with bonus type checking!
The `tmQ` quasiquoter now runs the entire processing pipeline on a
term instead of only parsing.  This is 100% better since now the
typechecking will fail at compile time instead of runtime.  I'm very
glad I took the time to figure out how to make this work.  In the end
it wasn't that difficult, but it did require making a bunch more
`Data` instances for things, and adding cases for `TAntiString` in
more places (e.g. the typechecker and capability checker), since now
an antiquoted string variable has to go all the way through the
pipeline before finally getting a Haskell variable substituted for it
when the resulting `ProcessedTerm` is lifted into an AST.
2021-09-25 22:52:30 -05:00
Brent Yorgey
32d8e87905 add a quasiquoter for terms
Also modify the `seedProgram` so it will throw a Fatal exception in
case of an error instead of crashing.

Closes #16.
2021-09-25 18:03:18 -05:00
Brent Yorgey
a2aa581ca5 indent wrapped recipes by two spaces
Closes #48.
2021-09-25 16:49:15 -05:00
Tristan Cacqueray
5746fd432e Add ghc-options and ci flags to prevent compilation warnings 2021-09-25 14:10:21 +00:00
Brent Yorgey
7051835ec4 try allowing template-haskell-2.17 to build with GHC 9 2021-09-23 18:13:31 -05:00
Brent Yorgey
b0c7f92f79 add a quasiquoter for polytypes
This is a partial implementation of #16.  It might still be nice to
make a quasiquoter for terms as well.
2021-09-23 17:18:28 -05:00
Brent Yorgey
80cb5b74ad Generic borders with six possible label positions
Based on the code for `hBorderWithLabel` and `borderWithLabel` from
`brick`.  Closes #37.
2021-09-23 11:40:20 -05:00
Brent Yorgey
1a7495d9b5 relax upper bound on random again
See https://github.com/ekmett/linear/issues/166
2021-09-20 11:49:34 -05:00
Brent Yorgey
18867cf541 Disallow random-1.2.1 for now
See https://github.com/ekmett/linear/issues/166 .
2021-09-19 22:39:01 -05:00
Brent Yorgey
c3d058e28c refactor: move Swarm.TUI to Swarm.TUI.Controller
After splitting other stuff out, the only thing that was left was all
the event handling code.
2021-09-17 18:12:54 -05:00
Brent Yorgey
6ca1135cc0 refactor: split out Swarm.TUI.View 2021-09-17 17:55:14 -05:00
Brent Yorgey
28667fa108 refactor: split out Swarm.TUI.{List,Model} and add Haddock comments 2021-09-17 17:45:41 -05:00