Skip to content

Commit

Permalink
parse nockma arguments as a list
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira authored and paulcadman committed Nov 5, 2024
1 parent 663cd85 commit 660813f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/Commands/Dev/Nockma/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ runCommand opts = do
t@(TermCell {}) -> case opts ^. nockmaRunAnomaDir of
Just path -> do
anomaDir <- AnomaPath <$> fromAppPathDir path
runInAnoma anomaDir t (unfoldTuple parsedArgs)
runInAnoma anomaDir t (fromMaybe [] (unfoldList <$> parsedArgs))
Nothing -> do
let formula = anomaCallTuple parsedArgs
(counts, res) <-
Expand Down
2 changes: 1 addition & 1 deletion app/Commands/Dev/Nockma/Run/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ parseNockmaRunOptions = do
somePreFileOpt
( long "args"
<> metavar "ARGS_FILE"
<> help "Path to file containing args"
<> help "Path to file containing args. When run on anoma, the args file should contain a list (i.e. to pass 2 and [1 4] as args, the contents should be [2 [1 4] 0])."
<> action "file"
)
pure AppPath {_pathIsInput = True, ..}
Expand Down
18 changes: 16 additions & 2 deletions src/Juvix/Compiler/Nockma/Language.hs
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,22 @@ instance (NockmaEq a) => NockmaEq (Term a) where
instance (NockmaEq a) => NockmaEq (Cell a) where
nockmaEq (Cell l r) (Cell l' r') = nockmaEq l l' && nockmaEq r r'

unfoldTuple :: Maybe (Term Natural) -> [Term Natural]
unfoldTuple = maybe [] (toList . unfoldTuple1)
unfoldList :: Term Natural -> [Term Natural]
unfoldList = ensureNockmList . nonEmpty . unfoldTuple
where
ensureNockmList :: Maybe (NonEmpty (Term Natural)) -> [Term Natural]
ensureNockmList = \case
Nothing -> err
Just l -> case l ^. _unsnoc1 of
(ini, lst)
| lst == nockNilTagged "unfoldList" -> ini
| otherwise -> err
where
err :: x
err = error "Nockma lists must have the form [x1 .. xn 0]"

unfoldTuple :: Term Natural -> [Term Natural]
unfoldTuple = toList . unfoldTuple1

unfoldTuple1 :: Term Natural -> NonEmpty (Term Natural)
unfoldTuple1 = nonEmpty' . run . execOutputList . go
Expand Down

0 comments on commit 660813f

Please sign in to comment.