Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The args file to the prove CLI must now be textual nock term #3253

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions app/Commands/Dev/Anoma/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,28 @@ cellOrFail term f = case term of
TermAtom {} -> exitFailMsg "Expected nockma input to be a cell"
t@(TermCell {}) -> inject (f t)

data ParsedArgsMode
= -- | The args file is a pretty nockma term
ParsedArgsModePretty
| -- | The args file is either a pretty nockma term or a jammed nockma term
ParsedArgsModeJammedOrPretty

-- | Calls Anoma.Protobuf.NockService.Prove
runNock ::
forall r.
(Members '[Error SimpleError, Anoma] r, Members AppEffects r) =>
ParsedArgsMode ->
AppPath File ->
Maybe (AppPath File) ->
Sem r Anoma.RunNockmaResult
runNock programFile margsFile = do
runNock argsMode programFile margsFile = do
afile <- fromAppPathFile programFile
argsFile <- mapM fromAppPathFile margsFile
parsedArgs <- runAppError @JuvixError (mapM Nockma.cueJammedFileOrPretty argsFile)
parsedArgs <- runAppError @JuvixError $ do
let argsParser = case argsMode of
ParsedArgsModeJammedOrPretty -> Nockma.cueJammedFileOrPretty
ParsedArgsModePretty -> Nockma.parsePrettyTerm
mapM argsParser argsFile
parsedTerm <- runAppError @JuvixError (Nockma.cueJammedFileOrPretty afile)
cellOrFail parsedTerm (go (maybe [] unfoldList parsedArgs))
where
Expand Down
2 changes: 1 addition & 1 deletion app/Commands/Dev/Anoma/Prove.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Juvix.Compiler.Nockma.Pretty hiding (Path)

runCommand :: forall r. (Members (Anoma ': Error SimpleError ': AppEffects) r) => ProveOptions -> Sem r ()
runCommand opts = do
res <- runNock (opts ^. proveFile) (opts ^. proveArgs)
res <- runNock ParsedArgsModePretty (opts ^. proveFile) (opts ^. proveArgs)
let traces = res ^. runNockmaTraces
forM_ traces (renderStdOutLn . ppOutDefault)
let provedCode = Encoding.jamToByteString (res ^. runNockmaResult)
Expand Down
2 changes: 1 addition & 1 deletion app/Commands/Dev/Nockma/Run/Anoma.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ makeLenses ''RunCommandArgs

runInAnoma :: forall r. (Members '[Error SimpleError, Anoma] r, Members AppEffects r) => RunCommandArgs -> Sem r ()
runInAnoma runArgs = do
res <- runNock (runArgs ^. runCommandProgramFile) (runArgs ^. runCommandArgsFile)
res <- runNock ParsedArgsModeJammedOrPretty (runArgs ^. runCommandProgramFile) (runArgs ^. runCommandArgsFile)
let traces = res ^. runNockmaTraces
renderStdOutLn (annotate AnnImportant $ "Traces (" <> show (length traces) <> "):")
forM_ traces $ \tr ->
Expand Down
10 changes: 9 additions & 1 deletion src/Juvix/Compiler/Nockma/Translation/FromSource/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ parseText = runParser noFile
parseReplText :: Text -> Either MegaparsecError (ReplTerm Natural)
parseReplText = runParserFor replTerm noFile

-- | Parse the file as an annotated unjammed term.
parsePrettyTerm ::
forall r.
(Members '[Files, Error JuvixError] r) =>
Prelude.Path Abs File ->
Sem r (Term Natural)
parsePrettyTerm f = evalHighlightBuilder (parseTermFile f)

-- | If the file ends in .debug.nockma it parses an annotated unjammed term. Otherwise
-- it is equivalent to cueJammedFile
cueJammedFileOrPretty ::
Expand All @@ -40,7 +48,7 @@ cueJammedFileOrPretty ::
Prelude.Path Abs File ->
Sem r (Term Natural)
cueJammedFileOrPretty f
| f `hasExtensions` nockmaDebugFileExts = evalHighlightBuilder (parseTermFile f)
| f `hasExtensions` nockmaDebugFileExts = parsePrettyTerm f
| otherwise = cueJammedFile f

-- | If the file ends in .debug.nockma it parses an annotated unjammed program. Otherwise
Expand Down
Loading