Skip to content

Commit

Permalink
rename WExpMap to WorldMap
Browse files Browse the repository at this point in the history
  • Loading branch information
byorgey committed Jul 28, 2023
1 parent 26b3060 commit ee6e415
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 42 deletions.
24 changes: 12 additions & 12 deletions src/Swarm/Game/Scenario.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ import Swarm.Game.Scenario.Topography.Navigation.Portal
import Swarm.Game.Scenario.Topography.Structure qualified as Structure
import Swarm.Game.Scenario.Topography.WorldDescription
import Swarm.Game.Universe
import Swarm.Game.World.Typecheck (WExpMap)
import Swarm.Game.World.Typecheck (WorldMap)
import Swarm.Language.Pipeline (ProcessedTerm)
import Swarm.Util (binTuples, failT)
import Swarm.Util.Lens (makeLensesNoSigs)
Expand Down Expand Up @@ -113,7 +113,7 @@ data Scenario = Scenario

makeLensesNoSigs ''Scenario

instance FromJSONE (EntityMap, WExpMap) Scenario where
instance FromJSONE (EntityMap, WorldMap) Scenario where
parseJSONE = withObjectE "scenario" $ \v -> do
-- parse custom entities
emRaw <- liftE (v .:? "entities" .!= [])
Expand All @@ -122,10 +122,10 @@ instance FromJSONE (EntityMap, WExpMap) Scenario where
Left x -> failT [x]
-- extend ambient EntityMap with custom entities

-- Save the passed in WExpMap for later
wexpMap <- snd <$> getE
-- Save the passed in WorldMap for later
worldMap <- snd <$> getE

-- Get rid of WExpMap from context locally, and combine EntityMap
-- Get rid of WorldMap from context locally, and combine EntityMap
-- with any custom entities parsed above
localE fst $ withE em $ do
-- parse 'known' entity names and make sure they exist
Expand All @@ -143,7 +143,7 @@ instance FromJSONE (EntityMap, WExpMap) Scenario where
localE (,rsMap) $
v ..:? "structures" ..!= []

allWorlds <- localE (wexpMap,rootLevelSharedStructures,,rsMap) $ do
allWorlds <- localE (worldMap,rootLevelSharedStructures,,rsMap) $ do
rootWorld <- v ..: "world"
subworlds <- v ..:? "subworlds" ..!= []
return $ rootWorld :| subworlds
Expand Down Expand Up @@ -272,23 +272,23 @@ loadScenario ::
(MonadIO m) =>
String ->
EntityMap ->
WExpMap ->
WorldMap ->
ExceptT Text m (Scenario, FilePath)
loadScenario scenario em wexpMap = do
loadScenario scenario em worldMap = do
mfileName <- liftIO $ getScenarioPath scenario
fileName <- except $ maybeToEither ("Scenario not found: " <> from @String scenario) mfileName
s <- withExceptT prettyFailure $ loadScenarioFile em wexpMap fileName
s <- withExceptT prettyFailure $ loadScenarioFile em worldMap fileName
return (s, fileName)

-- | Load a scenario from a file.
loadScenarioFile ::
(MonadIO m) =>
EntityMap ->
WExpMap ->
WorldMap ->
FilePath ->
ExceptT SystemFailure m Scenario
loadScenarioFile em wexpMap fileName =
loadScenarioFile em worldMap fileName =
withExceptT (AssetNotLoaded (Data Scenarios) fileName . CanNotParseYaml)
. ExceptT
. liftIO
$ decodeFileEitherE (em, wexpMap) fileName
$ decodeFileEitherE (em, worldMap) fileName
6 changes: 3 additions & 3 deletions src/Swarm/Game/Scenario/Topography/WorldDescription.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ data PWorldDescription e = WorldDescription

type WorldDescription = PWorldDescription Entity

instance FromJSONE (WExpMap, InheritedStructureDefs, EntityMap, RobotMap) WorldDescription where
instance FromJSONE (WorldMap, InheritedStructureDefs, EntityMap, RobotMap) WorldDescription where
parseJSONE = withObjectE "world description" $ \v -> do
(wexpMap, scenarioLevelStructureDefs, em, rm) <- getE
(worldMap, scenarioLevelStructureDefs, em, rm) <- getE
(pal, rootWorldStructureDefs) <- localE (const (em, rm)) $ do
pal <- v ..:? "palette" ..!= WorldPalette mempty
rootWorldStructs <- v ..:? "structures" ..!= []
Expand Down Expand Up @@ -82,7 +82,7 @@ instance FromJSONE (WExpMap, InheritedStructureDefs, EntityMap, RobotMap) WorldD
mwexp <- liftE (v .:? "dsl")
dslTerm <- forM mwexp $ \wexp -> do
let checkResult =
run . runThrow @CheckErr . runReader wexpMap . runReader em $
run . runThrow @CheckErr . runReader worldMap . runReader em $
check CNil (TTyWorld TTyCell) wexp
either (fail . prettyString) return checkResult
WorldDescription
Expand Down
22 changes: 11 additions & 11 deletions src/Swarm/Game/ScenarioInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import Swarm.Game.ResourceLoading (getDataDirSafe, getSwarmSavePath)
import Swarm.Game.Scenario
import Swarm.Game.Scenario.Scoring.CodeSize
import Swarm.Game.Scenario.Status
import Swarm.Game.World.Typecheck (WExpMap)
import Swarm.Game.World.Typecheck (WorldMap)
import System.Directory (canonicalizePath, doesDirectoryExist, doesFileExist, listDirectory)
import System.FilePath (pathSeparator, splitDirectories, takeBaseName, takeExtensions, (-<.>), (</>))
import Witch (into)
Expand Down Expand Up @@ -129,13 +129,13 @@ flatten (SICollection _ c) = concatMap flatten $ scenarioCollectionToList c
-- | Load all the scenarios from the scenarios data directory.
loadScenariosWithWarnings ::
EntityMap ->
WExpMap ->
WorldMap ->
IO ([SystemFailure], ScenarioCollection)
loadScenariosWithWarnings em wexpMap = do
loadScenariosWithWarnings em worldMap = do
res <- getDataDirSafe Scenarios "scenarios"
case res of
Left err -> return ([err], SC mempty mempty)
Right dataDir -> loadScenarioDir em wexpMap dataDir
Right dataDir -> loadScenarioDir em worldMap dataDir

-- | The name of the special file which indicates the order of
-- scenarios in a folder.
Expand All @@ -151,10 +151,10 @@ readOrderFile orderFile =
loadScenarioDir ::
(MonadIO m) =>
EntityMap ->
WExpMap ->
WorldMap ->
FilePath ->
m ([SystemFailure], ScenarioCollection)
loadScenarioDir em wexpMap dir = do
loadScenarioDir em worldMap dir = do
let orderFile = dir </> orderFileName
dirName = takeBaseName dir
orderExists <- liftIO $ doesFileExist orderFile
Expand Down Expand Up @@ -198,7 +198,7 @@ loadScenarioDir em wexpMap dir = do
-- Only keep the files from 00-ORDER.txt that actually exist.
let morder' = filter (`elem` itemPaths) <$> morder
let loadItem filepath = do
(warnings, item) <- loadScenarioItem em wexpMap (dir </> filepath)
(warnings, item) <- loadScenarioItem em worldMap (dir </> filepath)
return (warnings, (filepath, item))
warningsAndScenarios <- mapM (runExceptT . loadItem) itemPaths
let (failures, successes) = partitionEithers warningsAndScenarios
Expand Down Expand Up @@ -258,18 +258,18 @@ saveScenarioInfo path si = do
loadScenarioItem ::
(MonadIO m) =>
EntityMap ->
WExpMap ->
WorldMap ->
FilePath ->
ExceptT [SystemFailure] m ([SystemFailure], ScenarioItem)
loadScenarioItem em wexpMap path = do
loadScenarioItem em worldMap path = do
isDir <- liftIO $ doesDirectoryExist path
let collectionName = into @Text . dropWhile isSpace . takeBaseName $ path
case isDir of
True -> do
(warnings, d) <- loadScenarioDir em wexpMap path
(warnings, d) <- loadScenarioDir em worldMap path
return (warnings, SICollection collectionName d)
False -> do
s <- withExceptT pure $ loadScenarioFile em wexpMap path
s <- withExceptT pure $ loadScenarioFile em worldMap path
eitherSi <- runExceptT $ loadScenarioInfo path
return $ case eitherSi of
Right si -> ([], SISingle (s, si))
Expand Down
4 changes: 2 additions & 2 deletions src/Swarm/Game/State.hs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ import Swarm.Game.World (Coords (..), WorldFun (..), locToCoords, worldFunFromAr
import Swarm.Game.World qualified as W
import Swarm.Game.World.Eval (runTTerm)
import Swarm.Game.World.Gen (Seed, findGoodOrigin)
import Swarm.Game.World.Typecheck (WExpMap)
import Swarm.Game.World.Typecheck (WorldMap)
import Swarm.Language.Capability (constCaps)
import Swarm.Language.Context qualified as Ctx
import Swarm.Language.Module (Module (Module))
Expand Down Expand Up @@ -1019,7 +1019,7 @@ data GameStateConfig = GameStateConfig
, initNameList :: Array Int Text
, initEntities :: EntityMap
, initRecipes :: [Recipe Entity]
, initWExpMap :: WExpMap
, initWorldMap :: WorldMap
}

-- | Create an initial, fresh game state record when starting a new scenario.
Expand Down
4 changes: 2 additions & 2 deletions src/Swarm/Game/World/Eval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ runTTerm t seed = convert . interpBTerm seed . bracket $ t
convert :: (Coords -> CellVal) -> WorldFun TerrainType Entity
convert f = WF ((\(CellVal t e _) -> (t, e)) . f)

loadWorldsWithWarnings :: EntityMap -> IO ([SystemFailure], WExpMap)
loadWorldsWithWarnings :: EntityMap -> IO ([SystemFailure], WorldMap)
loadWorldsWithWarnings em = do
res <- getDataDirSafe Worlds "worlds"
case res of
Expand All @@ -58,7 +58,7 @@ processWorldFile dir em (fp, src) = do
runParser parseWExp (into @Text src)
t <-
left (AssetNotLoaded (Data Worlds) fp . CustomMessage . prettyText) $
run . runThrow @CheckErr . runReader em . runReader @WExpMap M.empty $
run . runThrow @CheckErr . runReader em . runReader @WorldMap M.empty $
infer CNil wexp
return (into @Text (dropExtension (stripDir dir fp)), t)

Expand Down
16 changes: 8 additions & 8 deletions src/Swarm/Game/World/Typecheck.hs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ pattern SomeTy α = Some α (F.Const ())
------------------------------------------------------------
-- Type inference/checking + elaboration

type WExpMap = Map Text (Some (TTerm '[]))
type WorldMap = Map Text (Some (TTerm '[]))

-- | Type contexts, indexed by a type-level list of types of all the
-- variables in the context.
Expand All @@ -446,7 +446,7 @@ lookup x (CCons y ty ctx)
check ::
( Has (Throw CheckErr) sig m
, Has (Reader EntityMap) sig m
, Has (Reader WExpMap) sig m
, Has (Reader WorldMap) sig m
) =>
Ctx g ->
TTy t ->
Expand Down Expand Up @@ -560,7 +560,7 @@ typeArgsFor _ _ = []
applyOp ::
( Has (Throw CheckErr) sig m
, Has (Reader EntityMap) sig m
, Has (Reader WExpMap) sig m
, Has (Reader WorldMap) sig m
) =>
Ctx g ->
Op ->
Expand All @@ -575,7 +575,7 @@ infer ::
forall sig m g.
( Has (Throw CheckErr) sig m
, Has (Reader EntityMap) sig m
, Has (Reader WExpMap) sig m
, Has (Reader WorldMap) sig m
) =>
Ctx g ->
WExp ->
Expand All @@ -594,8 +594,8 @@ infer _ WHash = return $ Some (TTyWorld TTyInt) (embed CHash)
infer ctx (WLet defs body) = inferLet ctx defs body
infer ctx (WOverlay ts) = inferOverlay ctx ts
infer _ctx (WImport key) = do
wexpMap <- ask @WExpMap
case M.lookup key wexpMap of
worldMap <- ask @WorldMap
case M.lookup key worldMap of
Just (Some ty t) -> return (Some ty (weaken @g t))
Nothing -> throwError $ UnknownImport key

Expand Down Expand Up @@ -648,7 +648,7 @@ resolveCellItem (mCellTag, item) = case mCellTag of
inferLet ::
( Has (Throw CheckErr) sig m
, Has (Reader EntityMap) sig m
, Has (Reader WExpMap) sig m
, Has (Reader WorldMap) sig m
) =>
Ctx g ->
[(Var, WExp)] ->
Expand All @@ -665,7 +665,7 @@ inferLet ctx ((x, e) : xs) body = do
inferOverlay ::
( Has (Throw CheckErr) sig m
, Has (Reader EntityMap) sig m
, Has (Reader WExpMap) sig m
, Has (Reader WorldMap) sig m
) =>
Ctx g ->
NE.NonEmpty WExp ->
Expand Down
8 changes: 4 additions & 4 deletions src/Swarm/TUI/Model.hs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ import Swarm.Game.ScenarioInfo (
)
import Swarm.Game.State
import Swarm.Game.World.Eval (loadWorldsWithWarnings)
import Swarm.Game.World.Typecheck (WExpMap)
import Swarm.Game.World.Typecheck (WorldMap)
import Swarm.TUI.Inventory.Sorting
import Swarm.TUI.Model.Menu
import Swarm.TUI.Model.Name
Expand Down Expand Up @@ -194,7 +194,7 @@ data RuntimeState = RuntimeState
{ _webPort :: Maybe Port
, _upstreamRelease :: Either NewReleaseFailure String
, _eventLog :: Notifications LogEntry
, _worlds :: WExpMap
, _worlds :: WorldMap
, _scenarios :: ScenarioCollection
, _stdEntityMap :: EntityMap
, _stdRecipes :: [Recipe Entity]
Expand Down Expand Up @@ -252,7 +252,7 @@ eventLog :: Lens' RuntimeState (Notifications LogEntry)

-- | A collection of typechecked world DSL terms that are available to
-- be used in scenario definitions.
worlds :: Lens' RuntimeState WExpMap
worlds :: Lens' RuntimeState WorldMap

-- | The collection of scenarios that comes with the game.
scenarios :: Lens' RuntimeState ScenarioCollection
Expand Down Expand Up @@ -293,7 +293,7 @@ mkGameStateConfig rs =
, initNameList = rs ^. stdNameList
, initEntities = rs ^. stdEntityMap
, initRecipes = rs ^. stdRecipes
, initWExpMap = rs ^. worlds
, initWorldMap = rs ^. worlds
}

-- ----------------------------------------------------------------------------
Expand Down

0 comments on commit ee6e415

Please sign in to comment.