Skip to content

Commit

Permalink
Use cue to read compiled nockma files in nockma run and repl
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcadman committed Oct 4, 2024
1 parent b3f2933 commit e4b1a1f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
10 changes: 5 additions & 5 deletions app/Commands/Dev/Nockma/Repl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,15 @@ replAction =
banner
}

runCommand :: forall r. (Members '[EmbedIO, App] r) => NockmaReplOptions -> Sem r ()
runCommand :: forall r. (Members '[Files, EmbedIO, App] r) => NockmaReplOptions -> Sem r ()
runCommand opts = do
mt :: Maybe (Term Natural) <- mapM iniStack (opts ^. nockmaReplOptionsStackFile)
liftIO . (`State.evalStateT` (iniState mt)) $ replAction
where
iniStack :: AppPath File -> Sem r (Term Natural)
iniStack af = do
afile <- fromAppPathFile af
parsedTerm <- Nockma.parseTermFile afile
case parsedTerm of
Left err -> exitJuvixError (JuvixError err)
Right t -> return t
checkCued (Nockma.cueJammedFile afile)

iniState :: Maybe (Term Natural) -> ReplState
iniState mt =
Expand All @@ -202,3 +199,6 @@ runCommand opts = do
_replStateLoadedFile = Nothing,
_replStateLastResult = nockNilTagged "repl-result"
}

checkCued :: Sem (Error JuvixError ': r) a -> Sem r a
checkCued = runErrorNoCallStackWith exitJuvixError
5 changes: 4 additions & 1 deletion app/Commands/Dev/Nockma/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ runCommand opts = do
afile <- fromAppPathFile inputFile
argsFile <- mapM fromAppPathFile (opts ^. nockmaRunArgs)
parsedArgs <- mapM (Nockma.parseTermFile >=> checkParsed) argsFile
parsedTerm <- Nockma.parseJammedFile afile
parsedTerm <- checkCued (Nockma.cueJammedFile afile)
case parsedTerm of
t@(TermCell {}) -> do
let formula = anomaCallTuple parsedArgs
Expand All @@ -35,3 +35,6 @@ runCommand opts = do
checkParsed = \case
Left err -> exitJuvixError (JuvixError err)
Right tm -> return tm

checkCued :: Sem (Error JuvixError ': r) a -> Sem r a
checkCued = runErrorNoCallStackWith exitJuvixError
7 changes: 3 additions & 4 deletions src/Juvix/Compiler/Nockma/Translation/FromSource/Base.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Juvix.Compiler.Nockma.Translation.FromSource.Base where

import Data.ByteString qualified as BS
import Data.HashMap.Internal.Strict qualified as HashMap
import Data.List.NonEmpty qualified as NonEmpty
import Data.Text qualified as Text
Expand All @@ -25,9 +24,9 @@ parseText = runParser noFile
parseReplText :: Text -> Either MegaparsecError (ReplTerm Natural)
parseReplText = runParserFor replTerm noFile

parseJammedFile :: (MonadIO m) => Prelude.Path Abs File -> m (Term Natural)
parseJammedFile fp = do
bs <- liftIO (BS.readFile (toFilePath fp))
cueJammedFile :: (Members '[Files, Error JuvixError] r) => Prelude.Path Abs File -> Sem r (Term Natural)
cueJammedFile fp = do
bs <- readFileBS' fp
case Cue.cueFromByteString'' @Natural bs of
Left _ -> error "nock natural error"
Right (Left _) -> error "cue decoding error"
Expand Down

0 comments on commit e4b1a1f

Please sign in to comment.