-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9d045e
commit a92f9fb
Showing
12 changed files
with
169 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,107 +1,24 @@ | ||
{-# LANGUAGE UndecidableInstances #-} | ||
{-# LANGUAGE QuantifiedConstraints #-} | ||
|
||
module Commands.Dev.Anoma.Prove.Options where | ||
module Commands.Dev.Anoma.Prove.Options | ||
( module Commands.Dev.Anoma.Prove.Options, | ||
module Commands.Dev.Anoma.Prove.Options.ProveArg, | ||
) | ||
where | ||
|
||
import Commands.Dev.Anoma.Prove.Options.ProveArg | ||
import CommonOptions | ||
import Juvix.Data.IntegerWithBase | ||
import Juvix.Parser.Lexer | ||
import Juvix.Prelude.Parsing hiding (option, many) | ||
import Prelude qualified | ||
|
||
data ProveArgTag | ||
= ProveArgNat | ||
| ProveArgBase64 | ||
| ProveArgBytes | ||
deriving stock (Eq, Bounded, Enum, Data) | ||
|
||
instance Show ProveArgTag where | ||
show = \case | ||
ProveArgNat -> "nat" | ||
ProveArgBase64 -> "base64" | ||
ProveArgBytes -> "bytes" | ||
|
||
type ProveArgType :: ProveArgTag -> GHCType | ||
type family ProveArgType s = res where | ||
ProveArgType 'ProveArgNat = Natural | ||
ProveArgType 'ProveArgBase64 = AppPath File | ||
ProveArgType 'ProveArgBytes = AppPath File | ||
|
||
$(genDefunSymbols [''ProveArgType]) | ||
|
||
data ProveOptions = ProveOptions | ||
{ _proveFile :: AppPath File, | ||
_proveArgs :: Maybe (AppPath File), | ||
_proveArgs2 :: [ProveArg], | ||
_proveArgs :: [ProveArg], | ||
_proveOutputFile :: Maybe (AppPath File) | ||
} | ||
deriving stock (Data) | ||
|
||
newtype ProveArg = ProveArg | ||
{ _proveArg :: Sigma ProveArgTag ProveArgTypeSym0 | ||
} | ||
|
||
$(genSingletons [''ProveArgTag]) | ||
|
||
makeLenses ''ProveOptions | ||
makeLenses ''ProveArg | ||
|
||
type Parse = Parsec Void Text | ||
|
||
parseProveArg :: Parser ProveArg | ||
parseProveArg = | ||
option | ||
pp | ||
( long "arg" | ||
<> completer (enumCompleter (Proxy @ProveArgTag)) | ||
<> metavar "ARG_TYPE:ARG" | ||
) | ||
where | ||
pProveArgTag :: Parse ProveArgTag | ||
pProveArgTag = | ||
choice | ||
[ chunk (show a) $> a | ||
| a :: ProveArgTag <- allElements | ||
] | ||
|
||
pAppPath :: Parse (AppPath File) | ||
pAppPath = do | ||
i <- mkPrepath . unpack <$> takeRest | ||
return | ||
AppPath | ||
{ _pathIsInput = True, | ||
_pathPath = i | ||
} | ||
|
||
pProveArg :: Parse ProveArg | ||
pProveArg = do | ||
dty <- pProveArgTag | ||
withSomeSing dty $ \ty -> do | ||
chunk ":" | ||
a <- pProveArgType ty | ||
return (ProveArg (ty :&: a)) | ||
|
||
pProveArgType :: SProveArgTag t -> Parse (ProveArgType t) | ||
pProveArgType p = do | ||
ret <- case p of | ||
SProveArgBytes -> pAppPath | ||
SProveArgBase64 -> pAppPath | ||
SProveArgNat -> do | ||
off <- getOffset | ||
i <- (^. withLocParam . integerWithBaseValue) <$> integerWithBase' | ||
if | ||
| i < 0 -> parseFailure off "Expected a non-negative integer" | ||
| otherwise -> return (fromIntegral i) | ||
eof | ||
return ret | ||
|
||
pp :: ReadM ProveArg | ||
pp = eitherReader $ \strInput -> parseHelper pProveArg (pack strInput) | ||
|
||
parseProveOptions :: Parser ProveOptions | ||
parseProveOptions = do | ||
_proveFile <- parseInputFile FileExtNockma | ||
_proveArgs <- optional anomaArgsOpt | ||
_proveArgs2 <- many parseProveArg | ||
_proveArgs <- many parseProveArg | ||
_proveOutputFile <- optional parseGenericOutputFile | ||
pure ProveOptions {..} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
module Commands.Dev.Anoma.Prove.Options.ProveArg | ||
( ProveArg (..), | ||
parseProveArg, | ||
) | ||
where | ||
|
||
import Commands.Dev.Anoma.Prove.Options.ProveArgTag | ||
import CommonOptions | ||
import Juvix.Data.IntegerWithBase | ||
import Juvix.Parser.Lexer | ||
import Juvix.Prelude.Parsing hiding (many, option) | ||
|
||
type Parse = Parsec Void Text | ||
|
||
newtype ProveArg' = ProveArg' | ||
{ _proveArg :: Sigma ProveArgTag ProveArgTypeSym0 | ||
} | ||
|
||
data ProveArg | ||
= ProveArgNat Natural | ||
| ProveArgBase64 (AppPath File) | ||
| ProveArgBytes (AppPath File) | ||
deriving stock (Data) | ||
|
||
parseProveArg :: Parser ProveArg | ||
parseProveArg = fromProveArg' <$> parseProveArg' | ||
where | ||
fromProveArg' :: ProveArg' -> ProveArg | ||
fromProveArg' (ProveArg' (ty :&: a)) = case ty of | ||
SProveArgTagNat -> ProveArgNat a | ||
SProveArgTagBase64 -> ProveArgBase64 a | ||
SProveArgTagBytes -> ProveArgBytes a | ||
|
||
parseProveArg' :: Parser ProveArg' | ||
parseProveArg' = | ||
option | ||
pp | ||
( long "arg" | ||
<> completer (enumCompleter (Proxy @ProveArgTag)) | ||
<> metavar "ARG_TYPE:ARG" | ||
) | ||
where | ||
pProveArgTag :: Parse ProveArgTag | ||
pProveArgTag = | ||
choice | ||
[ chunk (show a) $> a | ||
| a :: ProveArgTag <- allElements | ||
] | ||
|
||
pAppPath :: Parse (AppPath File) | ||
pAppPath = do | ||
i <- mkPrepath . unpack <$> takeRest | ||
return | ||
AppPath | ||
{ _pathIsInput = True, | ||
_pathPath = i | ||
} | ||
|
||
pProveArg' :: Parse ProveArg' | ||
pProveArg' = do | ||
dty <- pProveArgTag | ||
withSomeSing dty $ \ty -> do | ||
chunk ":" | ||
a <- pProveArgType ty | ||
return (ProveArg' (ty :&: a)) | ||
|
||
pProveArgType :: SProveArgTag t -> Parse (ProveArgType t) | ||
pProveArgType p = do | ||
ret <- case p of | ||
SProveArgTagBytes -> pAppPath | ||
SProveArgTagBase64 -> pAppPath | ||
SProveArgTagNat -> do | ||
off <- getOffset | ||
i <- (^. withLocParam . integerWithBaseValue) <$> integerWithBase' | ||
if | ||
| i < 0 -> parseFailure off "Expected a non-negative integer" | ||
| otherwise -> return (fromIntegral i) | ||
eof | ||
return ret | ||
|
||
pp :: ReadM ProveArg' | ||
pp = eitherReader $ \strInput -> parseHelper pProveArg' (pack strInput) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{-# LANGUAGE UndecidableInstances #-} | ||
|
||
module Commands.Dev.Anoma.Prove.Options.ProveArgTag where | ||
|
||
import CommonOptions | ||
import Prelude qualified | ||
|
||
data ProveArgTag | ||
= ProveArgTagNat | ||
| ProveArgTagBase64 | ||
| ProveArgTagBytes | ||
deriving stock (Eq, Bounded, Enum, Data) | ||
|
||
instance Show ProveArgTag where | ||
show = \case | ||
ProveArgTagNat -> "nat" | ||
ProveArgTagBase64 -> "base64" | ||
ProveArgTagBytes -> "bytes" | ||
|
||
type ProveArgType :: ProveArgTag -> GHCType | ||
type family ProveArgType s = res where | ||
ProveArgType 'ProveArgTagNat = Natural | ||
ProveArgType 'ProveArgTagBase64 = AppPath File | ||
ProveArgType 'ProveArgTagBytes = AppPath File | ||
|
||
$(genDefunSymbols [''ProveArgType]) | ||
$(genSingletons [''ProveArgTag]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.