This commit is contained in:
2026-05-15 16:52:07 -06:00
parent 5dcf44222f
commit 6dda8c4268
5 changed files with 81 additions and 10 deletions

View File

@@ -1,3 +1,4 @@
{-# LANGUAGE OverloadedLabels #-}
module Main
(main)
where
@@ -6,20 +7,48 @@ import qualified Gyehoek.ANF.Syntax as ANF
import Gyehoek.QBE (render)
import Gyehoek.Options
import qualified Data.Text.IO as TIO
import Prelude hiding ((.),id)
import Data.Text (Text)
import Prelude hiding (readFile, (.),id)
import Control.Category
import Options.Applicative
import Control.Lens
import Data.Generics.Labels
import System.OsPath (OsPath)
import System.FilePath ((-<.>))
import Effectful.FileSystem
import Effectful
import Effectful.FileSystem.IO
import Gyehoek.GenSym (runGenSym)
import qualified Gyehoek.Sexp as Sexp
import Data.Text.Lens
import Data.List (List)
import qualified Gyehoek.Scheme.Syntax as Scm
import Effectful.Exception
main :: IO ()
main = driver =<< execParser opts
where
opts = info (helper <*> parser)
( fullDesc
)
main = do
opts <- info (helper <*> parser) (fullDesc)
runEff . runFileSystem . driver $ opts
driver :: Options -> IO ()
driver opts = do
print opts
hPutStr :: IOE :> es => Handle -> Text -> Eff es ()
hPutStr h = liftIO . TIO.hPutStr h
readFile :: IOE :> es => FilePath -> Eff es Text
readFile = liftIO . TIO.readFile
readScm :: FileSystem :> es => FilePath -> Eff es (List Scm.Exp)
readScm f = (Sexp.parseSexps f <$> readFile f) >>= either error pure
driver :: FileSystem :> es => Options -> Eff es ()
driver = runGenSym . traverseOf_ (#sourceFiles . folded) \f ->
withFile f ReadMode \h_scm ->
(Sexp.encode <$> ANF.toANF _) >>= \case
Left e -> hPutStr stderr (view packed e)
Right s ->
withFile (f -<.> "anf") WriteMode \h_anf -> do
hPutStr h_anf ";;; -*- mode:scheme -*-\n\n"
hPutStr h_anf s