Skip to content

Commit

Permalink
fix run command
Browse files Browse the repository at this point in the history
  • Loading branch information
byorgey committed Jun 15, 2024
1 parent 8e2a87e commit 11b1aa7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion data/scenarios/Tutorials/farming.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ objectives:
n <- count "lambda";
return (n >= 256)
}
} { return false }
} {return false}
- goal:
- Congratulations! You have completed the most difficult simulated exercise and are ready to begin exploring the new planet in earnest. Of course there is much more remaining to explore in the world, and many additional programming language features to unlock.
- |
Expand Down
2 changes: 1 addition & 1 deletion env.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Ctx {unCtx = fromList [("mp",Requirements {capReqs = fromList [CPower,CMove,CPlace], devReqs = fromList [], invReqs = fromList []}),("rr",Requirements {capReqs = fromList [CPower,CMove,CTurn,CPlace,CLambda], devReqs = fromList [], invReqs = fromList []}),("x4",Requirements {capReqs = fromList [CPower,CLambda], devReqs = fromList [], invReqs = fromList []})]}
Ctx {unCtx = fromList []}
23 changes: 21 additions & 2 deletions src/swarm-engine/Swarm/Game/CESK.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ module Swarm.Game.CESK (
continue,
cancel,
resetBlackholes,
prepareTerm,

-- ** Extracting information
finalValue,
suspendedEnv,
store,
cont,
) where

import Control.Lens (Lens', Traversal', lens, traversal, (^.))
Expand Down Expand Up @@ -322,6 +324,23 @@ store = lens get set
Waiting t c -> Waiting t (set c s)
Suspended v e _ k -> Suspended v e s k

-- | Lens focusing on the continuation of a CESK machine.
cont :: Lens' CESK Cont
cont = lens get set
where
get = \case
In _ _ _ k -> k
Out _ _ k -> k
Up _ _ k -> k
Waiting _ c -> get c
Suspended _ _ _ k -> k
set cesk k = case cesk of
In t e s _ -> In t e s k
Out v s _ -> Out v s k
Up x s _ -> Up x s k
Waiting t c -> Waiting t (set c k)
Suspended v e s _ -> Suspended v e s k

-- | Create a brand new CESK machine, with empty environment and
-- store, to evaluate a given term. We always initialize the
-- machine with a single FExec frame as the continuation; if the
Expand All @@ -331,14 +350,14 @@ initMachine t = In (prepareTerm mempty t) mempty emptyStore [FExec]

-- | Load a program into an existing robot CESK machine: either
-- continue from a suspended state, or, as a fallback, start from
-- scratch with an empty environment.
-- scratch with an empty environment but the same store.
--
-- Also insert a @suspend@ primitive at the end, so the resulting
-- term is suitable for execution by the base (REPL) robot.
continue :: TSyntax -> CESK -> CESK
continue t = \case
Suspended _ e s k -> In (insertSuspend $ prepareTerm e t) e s (FExec : k)
_ -> In (insertSuspend $ prepareTerm mempty t) mempty emptyStore [FExec]
cesk -> In (insertSuspend $ prepareTerm mempty t) mempty (cesk ^. store) [FExec]

-- | Prepare a term for evaluation by a CESK machine in the given
-- environment: erase all type annotations, and optionally wrap it
Expand Down
8 changes: 6 additions & 2 deletions src/swarm-engine/Swarm/Game/Step/Const.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ import Swarm.Game.Tick
import Swarm.Game.Universe
import Swarm.Game.Value
import Swarm.Language.Capability
import Swarm.Language.Elaborate (insertSuspend)
import Swarm.Language.Key (parseKeyComboFull)
import Swarm.Language.Pipeline
import Swarm.Language.Pretty (prettyText)
Expand Down Expand Up @@ -1227,8 +1228,11 @@ execConst runChildProg c vs s k = do
Nothing -> return $ mkReturn ()
Just pt -> do
void $ traceLog CmdStatus Info "run: OK."
cesk <- use machine
return $ continue pt cesk
case k of
[] -> return $ In (insertSuspend (prepareTerm mempty pt)) mempty s [FExec]
_ -> return $ In (prepareTerm mempty pt) mempty s (FExec : k)
-- mempty above means we will wipe out all our current definitions every time
-- we execute 'run'...
_ -> badConst
Not -> case vs of
[VBool b] -> return $ Out (VBool (not b)) s k
Expand Down

0 comments on commit 11b1aa7

Please sign in to comment.