-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JuvixReg parser and pretty printer (#2617)
* Closes #2578 * Implements JuvixReg parser and pretty printer. * Adds the `juvix dev reg read file.jvr` command. * Adds the `reg` target to the `compile` commands. * Adds tests for the JuvixReg parser.
- Loading branch information
Showing
128 changed files
with
5,433 additions
and
387 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Commands.Dev.Reg where | ||
|
||
import Commands.Base | ||
import Commands.Dev.Reg.Options | ||
import Commands.Dev.Reg.Read as Read | ||
|
||
runCommand :: forall r. (Members '[Embed IO, App, TaggedLock] r) => RegCommand -> Sem r () | ||
runCommand = \case | ||
Read opts -> Read.runCommand opts |
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,24 @@ | ||
module Commands.Dev.Reg.Options where | ||
|
||
import Commands.Dev.Reg.Read.Options | ||
import CommonOptions | ||
|
||
newtype RegCommand | ||
= Read RegReadOptions | ||
deriving stock (Data) | ||
|
||
parseRegCommand :: Parser RegCommand | ||
parseRegCommand = | ||
hsubparser $ | ||
mconcat | ||
[ commandRead | ||
] | ||
where | ||
commandRead :: Mod CommandFields RegCommand | ||
commandRead = command "read" readInfo | ||
|
||
readInfo :: ParserInfo RegCommand | ||
readInfo = | ||
info | ||
(Read <$> parseRegReadOptions) | ||
(progDesc "Parse a JuvixReg file and pretty print it") |
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,19 @@ | ||
module Commands.Dev.Reg.Read where | ||
|
||
import Commands.Base | ||
import Commands.Dev.Reg.Read.Options | ||
import Juvix.Compiler.Reg.Pretty qualified as Reg | ||
import Juvix.Compiler.Reg.Translation.FromSource qualified as Reg | ||
|
||
runCommand :: forall r. (Members '[Embed IO, App] r) => RegReadOptions -> Sem r () | ||
runCommand opts = do | ||
afile :: Path Abs File <- fromAppPathFile file | ||
s <- readFile (toFilePath afile) | ||
case Reg.runParser (toFilePath afile) s of | ||
Left err -> | ||
exitJuvixError (JuvixError err) | ||
Right tab -> | ||
renderStdOut (Reg.ppOutDefault tab tab) | ||
where | ||
file :: AppPath File | ||
file = opts ^. regReadInputFile |
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,15 @@ | ||
module Commands.Dev.Reg.Read.Options where | ||
|
||
import CommonOptions | ||
|
||
newtype RegReadOptions = RegReadOptions | ||
{ _regReadInputFile :: AppPath File | ||
} | ||
deriving stock (Data) | ||
|
||
makeLenses ''RegReadOptions | ||
|
||
parseRegReadOptions :: Parser RegReadOptions | ||
parseRegReadOptions = do | ||
_regReadInputFile <- parseInputFile FileExtJuvixAsm | ||
pure RegReadOptions {..} |
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ treeSupportedTargets = | |
[ TargetWasm32Wasi, | ||
TargetNative64, | ||
TargetAsm, | ||
TargetReg, | ||
TargetNockma | ||
] | ||
|
||
|
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.