Commit Graph

35 Commits

Author SHA1 Message Date
Tristan de Cacqueray
04e143d51b
Destroy robot when needed (#429)
This change fixes #428
2022-06-19 01:26:20 +00:00
Tristan de Cacqueray
1eb714db38
Crafting tutorial (#423)
This change adds a new crafting tutorial.
2022-06-18 22:48:10 +00:00
Ondřej Šebek
6838dfa1aa Add portal challenge to tests 2022-06-18 02:44:22 +02:00
Ondřej Šebek
820f1b067e Recurse integration test discovery 2022-06-18 02:44:22 +02: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
bda16b79ac
Iron (#373)
- add iron ore, iron mine and iron vein (closes #93)
  - split gear into iron/wooden gear
  - add metal drill
  - add faster recipes with the metal drill
- add compass (closes #341)
- handle multiple entities providing the same capability
  - try to find if the robot has at least one entity providing the capability
  - when no entity could provide the capability rejects it too
- list required devices in the `Incapable` error (closes #342)
2022-06-14 16:13:27 +00:00
Ondřej Šebek
b67a0f3ef4
Enable HLint in CI (#371)
- uncomment HLint configuration in Haskell-CI config
- remove unused pragmas
- remove some unnecessary parens
2022-06-08 22:40:29 +00:00
Ondřej Šebek
9a72bc52a5
Reformat codebase with Fourmolu (#370)
Run
```bash
fourmolu -i $(find . -name '*.hs')
```
2022-06-08 22:32:12 +00: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
noahyor
1cf4abd7d3
Add boolean operations like && and || (#307)
Closes #189.
2022-03-11 19:32:54 +00:00
Brent Yorgey
008d4000a5
Add a --run flag to run the contents of a program on startup (#312)
Fixes #82.

Right now it only works in classic mode.  It wouldn't be too hard to
make it work with challenge mode as well, but that would require some
more careful thinking about whether every challenge is required to
have a 'base' and how we identify which robot that is, so that we run
the given file on the right robot.
2022-03-07 05:56:15 -06: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
Brent Yorgey
f6a1931b23 parse and pretty-print tuples properly
Tuples are now parsed as parens containing terms separated by commas,
instead of just treating the comma as a binary infix operator.  This
fixes #225 --- we now properly parse tuples containing lambdas.
Tuples bigger than pairs are treated as syntax sugar for right-nested
pairs, e.g. (1,2,3) is (1,(2,3)) (and also pretty-prints as the former).
2021-12-15 17:06:59 -06:00
Brent Yorgey
b1366b7c2a
add format function and string concatenation operator ++ (#293)
Adds a new function `format : a -> string` and an operator `++ : string -> string -> string`.

Closes #248.
2021-12-04 23:19:19 +00:00
Brent Yorgey
cbad51911c
allow only whitespace when reading a term (#291)
- The user can now enter only whitespace (including comments) at the
  REPL.
- A new file which is blank / only comments is no longer invalid from
  the perspective of LSP.

Closes #275.
2021-12-02 22:07:09 +00:00
Ondřej Šebek
fb79910c20
Add location to type matching errors (#270)
- closes #268 
- computes the location for `SBind` and operators
2021-11-04 17:09:24 +00: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
Alexander Block
8deb10f3b7
allow ' in variable names (#273)
Closes #269 

- The parser now accepts  `'` in a variable name as long as it does not start with `'` (to rule out potentially problematic variable names like `'a'`).
- Unit tests for this are added.
2021-10-30 22:50:57 +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
4f33b22611 remove redundant import 2021-10-22 11:58:10 -05:00
Ondřej Šebek
400d101736
Add ($) operator (#239)
- add `$` operator to avoid multiple parentheses
2021-10-20 06:54:08 +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
Ondřej Šebek
c30b710a84
Fix operator parsing (#237)
- add check that operator is not followed by another "operator"

Fixes #236
2021-10-16 14:39:49 +00:00
Brent Yorgey
01391288fd
leave discovered entities in the inventory forever (#164)
Once an entity has been discovered, it stays in the inventory, even if its count becomes 0.

I think I just deleted the code @fryguybob carefully fixed in #157... =)

Fixes #163.
2021-10-09 15:43:26 +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
Brent Yorgey
d0ff1a15e7
Implicitly quantify over free type variables (#149)
Also, if an explicit `forall` is given, require all type variables to be bound.

Fixes #148.

We might want to wait until merging #137 and then rebase this on top, since some changes might be required.
2021-10-03 02:27:58 +00:00
Tristan de Cacqueray
ef5d628608
Annotate the AST with source location to improve error message (#137)
This change modifies the `Swarm.Language.Syntax.Term` data type to include the source location so that we can include a line number/column to type errors
2021-10-02 23:44:27 +00:00
Tristan de Cacqueray
a23212ae9d
Reformat the haskell code with fourmolu (#146)
This PR was generated using `find src/ app/ test/ -name "*.hs" | xargs fourmolu --mode=inplace`.

Fixes #103
2021-10-02 18:40:24 +00:00
Ondřej Šebek
09e03f4ba4
Pretty print operators (#118)
- moves info about constants to `Syntax.hs`
  - adds `infoConst`&friends functions on `Const`
  - lot of noise - needs to be simplified
- changes the pretty-printing logic for `Term` application
- creates parsers for `Const` automatically
- ~~adds a heavy dependency to get [something like `Enum`](https://hackage.haskell.org/package/finitary)~~

Closes #8:
- #8
2021-10-01 17:00:05 +00:00
Tristan de Cacqueray
0c12e0176e
Add parser test and fix missing semicolon between defs (#86) 2021-09-28 02:39:39 +00:00