diff options
author | Marvin Borner | 2024-02-15 13:53:41 +0100 |
---|---|---|
committer | Marvin Borner | 2024-02-15 13:53:41 +0100 |
commit | c7801f7c1e5e9ca1dee061f011492ba37e0e1c73 (patch) | |
tree | 33c955277d774cb91b6131ad1815d30ec40fde56 /src/Optimizer.hs | |
parent | faf61ef00caa6ffe4e54c5a98232dafb905b9b26 (diff) |
Added number conversion utility functions
Diffstat (limited to 'src/Optimizer.hs')
-rw-r--r-- | src/Optimizer.hs | 71 |
1 files changed, 36 insertions, 35 deletions
diff --git a/src/Optimizer.hs b/src/Optimizer.hs index 4f464ab..2744b8f 100644 --- a/src/Optimizer.hs +++ b/src/Optimizer.hs @@ -19,43 +19,45 @@ import System.Process tryIO :: IO a -> IO (Either IOException a) tryIO = try -toBloc :: Expression -> IO (Failable Handle) -toBloc e = do - let binary = toBinary e - tryBloc <- tryIO $ createProcess (proc "bloc" ["-i", "-", "--from-blc"]) - { std_in = CreatePipe - , std_out = CreatePipe - } - let bloc = case tryBloc of - Right (Just i, Just o, _, _) -> Just (i, o) - _ -> Nothing - case bloc of - Just (inH, outH) -> do - hPutStrLn inH binary - return $ Right outH - Nothing -> return $ Left $ OptimizerError "can't read/write to bloc" +-- toBloc :: Expression -> IO (Failable Handle) +-- toBloc e = do +-- let binary = toBinary e +-- tryBloc <- tryIO $ createProcess (proc "bloc" ["-i", "-", "--from-blc"]) +-- { std_in = CreatePipe +-- , std_out = CreatePipe +-- } +-- let bloc = case tryBloc of +-- Right (Just i, Just o, _, _) -> Just (i, o) +-- _ -> Nothing +-- case bloc of +-- Just (inH, outH) -> do +-- hPutStrLn inH binary +-- return $ Right outH +-- Nothing -> return $ Left $ OptimizerError "can't read/write to bloc" toTarget :: Expression -> String -> IO (Failable String) toTarget e target = do - maybeBloc <- toBloc e - case maybeBloc of - Left err -> return $ Left err - Right bloc -> do - res <- tryIO $ createProcess (proc "blocade" ["-i", "-", "-t", target]) - { std_in = UseHandle bloc - , std_out = CreatePipe - } - let out = case res of - Left _ -> Nothing - Right (_, o, _, _) -> o - case out of - Just h -> do - hSetBinaryMode h True - content <- hGetContents h - return $ case content of - "" -> Left $ OptimizerError "blocade returned empty string" - _ -> Right content - Nothing -> return $ Left $ OptimizerError "can't read from blocade" + res <- tryIO $ createProcess_ + "" + (shell $ "bloc -v -i - --from-blc | blocade -v -i - -t " <> target) + { std_in = CreatePipe + , std_out = CreatePipe + } + case res of + Right (Just inH, Just outH, _, _) -> do + let binary = toBinary e + hSetBuffering inH NoBuffering + hSetBuffering outH NoBuffering + hSetBinaryMode outH True + hIsOpen inH >>= print + hIsWritable inH >>= print + hPutStrLn inH binary + hFlush inH + content <- hGetContents' outH + return $ case content of + "" -> Left $ OptimizerError "blocade returned empty string" + _ -> Right content + _ -> return $ Left $ OptimizerError "can't read from blocade" -- TODO: add more targets (including other PL compilation) toExpression :: String -> String -> Expression @@ -82,4 +84,3 @@ optimizeToTarget conf e = do optimizedReduce :: EvalConf -> Expression -> IO Expression optimizedReduce conf e = optimizeToTarget conf e >>= reduce - |