55 lines
1.5 KiB
Haskell
55 lines
1.5 KiB
Haskell
{-# LANGUAGE OverloadedLabels #-}
|
|
module Main
|
|
(main)
|
|
where
|
|
|
|
import qualified Gyehoek.ANF.Syntax as ANF
|
|
import Gyehoek.QBE (render)
|
|
import Gyehoek.Options
|
|
import qualified Data.Text.IO as TIO
|
|
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 = do
|
|
opts <- info (helper <*> parser) (fullDesc)
|
|
runEff . runFileSystem . driver $ 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
|
|
|