Skip to content

Commit

Permalink
Drop exec
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdone committed Aug 23, 2024
1 parent 7f82766 commit 7eabe72
Showing 1 changed file with 1 addition and 24 deletions.
25 changes: 1 addition & 24 deletions Hell.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ data Command
= Run FilePath
| Check FilePath
| Version
| Exec String

main :: IO ()
main = dispatch =<< Options.execParser opts
Expand All @@ -99,8 +98,7 @@ commandParser =
Options.asum [
Run <$> Options.strArgument (Options.metavar "FILE" <> Options.help "Run the given .hell file"),
Check <$> Options.strOption (Options.long "check" <> Options.metavar "FILE" <> Options.help "Typecheck the given .hell file"),
Version <$ Options.flag () () (Options.long "version" <> Options.help "Print the version"),
Exec <$> Options.strOption (Options.long "exec" <> Options.help "Execute the given expression" <> Options.metavar "EXPR")
Version <$ Options.flag () () (Options.long "version" <> Options.help "Print the version")
]

dispatch :: Command -> IO ()
Expand Down Expand Up @@ -157,27 +155,6 @@ dispatch (Check filePath) = do
case Type.eqTypeRep t (typeRep @(IO ())) of
Just Type.HRefl -> pure ()
Nothing -> error $ "Type isn't IO (), but: " ++ prettyString t
dispatch (Exec string) = do
case HSE.parseExpWithMode HSE.defaultParseMode { HSE.extensions = HSE.extensions HSE.defaultParseMode ++ [HSE.EnableExtension HSE.PatternSignatures, HSE.EnableExtension HSE.BlockArguments, HSE.EnableExtension HSE.TypeApplications] } string of
HSE.ParseFailed _ e -> error $ e
HSE.ParseOk e ->
case desugarExp mempty e of
Left err -> error $ prettyString err
Right uterm ->
case inferExp mempty uterm of
Left err -> error $ prettyString err
Right iterm ->
case check iterm Nil of
Left err -> error $ prettyString err
Right (Typed t ex) ->
case Type.eqTypeRep (typeRepKind t) (typeRep @Type) of
Nothing -> error $ "Kind error, that's nowhere near an IO ()!"
Just Type.HRefl ->
case Type.eqTypeRep t (typeRep @(IO ())) of
Just Type.HRefl ->
let action :: IO () = eval () ex
in action
Nothing -> error $ "Type isn't IO (), but: " ++ prettyString t

--------------------------------------------------------------------------------
-- Get declarations from the module
Expand Down

0 comments on commit 7eabe72

Please sign in to comment.