Skip to content

Commit

Permalink
subworld-aware location command
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo committed Oct 20, 2024
1 parent 0262f66 commit 4961274
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions editors/emacs/swarm-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"time"
"scout"
"whereami"
"locateme"
"waypoint"
"structure"
"floorplan"
Expand Down
2 changes: 1 addition & 1 deletion editors/vim/swarm.vim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
syn keyword Keyword def tydef rec end let in require
syn keyword Builtins self parent base if inl inr case fst snd force undefined fail not format chars split charat tochar key
syn keyword Command noop wait selfdestruct move backup volume path push stride turn grab harvest sow ignite place ping give equip unequip make has equipped count drill use build salvage reprogram say listen log view appear create halt time scout whereami waypoint structure floorplan hastag tagmembers detect resonate density sniff chirp watch surveil heading blocked scan upload ishere isempty meet meetall whoami setname random run return try swap atomic instant installkeyhandler teleport as robotnamed robotnumbered knows
syn keyword Command noop wait selfdestruct move backup volume path push stride turn grab harvest sow ignite place ping give equip unequip make has equipped count drill use build salvage reprogram say listen log view appear create halt time scout whereami locateme waypoint structure floorplan hastag tagmembers detect resonate density sniff chirp watch surveil heading blocked scan upload ishere isempty meet meetall whoami setname random run return try swap atomic instant installkeyhandler teleport as robotnamed robotnumbered knows
syn keyword Direction east north west south down forward left back right
syn match Type "\<[A-Z][a-zA-Z_]*\>"
syn match Operators "[-=!<>|&+*/^$:]"
Expand Down
3 changes: 3 additions & 0 deletions src/swarm-engine/Swarm/Game/Step/Const.hs
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,9 @@ execConst runChildProg c vs s k = do
Whereami -> do
loc <- use robotLocation
return $ mkReturn $ loc ^. planar
LocateMe -> do
loc <- use robotLocation
return $ mkReturn $ (loc ^. subworld, loc ^. planar)

Check warning on line 562 in src/swarm-engine/Swarm/Game/Step/Const.hs

View workflow job for this annotation

GitHub Actions / HLint

Warning in execConst in module Swarm.Game.Step.Const: Redundant $ ▫︎ Found: "mkReturn $ (loc ^. subworld, loc ^. planar)" ▫︎ Perhaps: "mkReturn (loc ^. subworld, loc ^. planar)"
Waypoint -> case vs of
[VText name, VInt idx] -> do
lm <- use $ landscape . worldNavigation
Expand Down
7 changes: 7 additions & 0 deletions src/swarm-lang/Swarm/Language/Syntax/Constants.hs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ data Const
Scout
| -- | Get the current x, y coordinates
Whereami
| -- | Get the current subworld and x, y coordinates
LocateMe
| -- | Get the x, y coordinates of a named waypoint, by index
Waypoint
| -- | Get the x, y coordinates of southwest corner of a constructed structure, by index
Expand Down Expand Up @@ -678,6 +680,11 @@ constInfo c = case c of
shortDoc
(Set.singleton $ Query $ Sensing RobotSensing)
"Get the current x and y coordinates."
LocateMe ->
command 0 Intangible $
shortDoc
(Set.singleton $ Query $ Sensing RobotSensing)
"Get the current subworld and x, y coordinates."
Waypoint ->
command 2 Intangible . doc (Set.singleton $ Query APriori) "Get the x, y coordinates of a named waypoint, by index" $
[ "Return only the waypoints in the same subworld as the calling robot."
Expand Down
1 change: 1 addition & 0 deletions src/swarm-lang/Swarm/Language/Typecheck.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,7 @@ inferConst c = run . runReader @TVCtx Ctx.empty . quantify $ case c of
Time -> [tyQ| Cmd Int |]
Scout -> [tyQ| Dir -> Cmd Bool |]
Whereami -> [tyQ| Cmd (Int * Int) |]
LocateMe -> [tyQ| Cmd (Text, (Int * Int)) |]

Check failure on line 1039 in src/swarm-lang/Swarm/Language/Typecheck.hs

View workflow job for this annotation

GitHub Actions / Haskell-CI - windows-latest - ghc-9.8.2

• src/swarm-lang\Swarm\Language\Typecheck.hs:1039:30:
Waypoint -> [tyQ| Text -> Int -> Cmd (Int * (Int * Int)) |]
Structure -> [tyQ| Text -> Int -> Cmd (Unit + (Int * (Int * Int))) |]
Floorplan -> [tyQ| Text -> Cmd (Int * Int) |]
Expand Down

0 comments on commit 4961274

Please sign in to comment.