diff --git a/app/Gyehoek/Options.hs b/app/Gyehoek/Options.hs new file mode 100644 index 0000000..d1e0c3e --- /dev/null +++ b/app/Gyehoek/Options.hs @@ -0,0 +1,44 @@ +{-# LANGUAGE NoFieldSelectors #-} +module Gyehoek.Options + ( Options(..) + , parser + ) + where + +import System.IO (Handle) +import Data.HashSet (HashSet) +import Options.Applicative +import qualified Data.HashSet as HS + + +data Options = MkOptions + { -- dumpANF :: Maybe FilePath + -- , dumpQBE :: Maybe FilePath + output :: Maybe FilePath + , sourceFiles :: HashSet FilePath + } + deriving (Show) + +-- parseDumpQBE = +-- optional $ strOption +-- ( long "dump-qbe" +-- <> metavar "FILE" +-- ) + +-- parseDumpANF = +-- optional $ strOption +-- ( long "dump-anf" +-- <> metavar "FILE" +-- ) + +parseOutput = + optional $ strOption + ( long "output" + <> short 'o' + <> metavar "FILE" + ) + +parser :: Parser Options +parser = MkOptions + <$> parseOutput + <*> (HS.fromList <$> some (argument str (metavar "FILES"))) diff --git a/app/Main.hs b/app/Main.hs index 590b6c1..4042ea0 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,17 +1,25 @@ -{-# LANGUAGE PatternSynonyms #-} -{-# LANGUAGE ViewPatterns #-} -{-# LANGUAGE BlockArguments #-} -{-# LANGUAGE OverloadedLists #-} 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 Prelude hiding ((.),id) import Control.Category +import Options.Applicative main :: IO () -main = TIO.putStrLn . render $ ANF.expr +main = driver =<< execParser opts + where + opts = info (helper <*> parser) + ( fullDesc + ) + + + +driver :: Options -> IO () +driver opts = do + print opts diff --git a/gyehoek.cabal b/gyehoek.cabal index 0393842..2939555 100644 --- a/gyehoek.cabal +++ b/gyehoek.cabal @@ -22,7 +22,7 @@ common ghcstuffs -Wall -fdefer-type-errors -fno-show-valid-hole-fits -fdefer-out-of-scope-variables -fplugin=Effectful.Plugin - other-extensions: + default-extensions: BlockArguments DeriveGeneric OverloadedStrings @@ -37,14 +37,15 @@ executable gyehoek other-modules: Gyehoek.ANF.Syntax Gyehoek.GenSym + Gyehoek.Options Gyehoek.QBE Gyehoek.QBE.Parse Gyehoek.Scheme.Syntax Gyehoek.Sexp - -- other-extensions: build-depends: , base ^>=4.21.2.0 + , containers , effectful , effectful-core , effectful-plugin @@ -60,6 +61,7 @@ executable gyehoek , sexp-grammar , template-haskell , text + , unordered-containers , vector hs-source-dirs: app diff --git a/play/a.out b/play/a.out deleted file mode 100755 index e0e7218..0000000 Binary files a/play/a.out and /dev/null differ diff --git a/play/t.ssa b/play/t.ssa deleted file mode 100644 index cd2e7f5..0000000 --- a/play/t.ssa +++ /dev/null @@ -1,15 +0,0 @@ -type :scm = {l 2} -export -function w $main () { -@start - %x0 =l call $GC_malloc (l 16) - %.4 =l add %x0, 8 - storel 10, %x0 - storel 14, %.4 - %x1 =l call $scm_write (l %x0) - %.5 =l mul 22, 18 - %.6 =l and %.5, 18446744073709551613 - %x2 =l or %.6, 2 - %x3 =l call $scm_write (l %x2) - ret %x3 -} \ No newline at end of file diff --git a/runtime/gyehoek.c b/runtime/gyehoek.c index 3c3e48c..6643a11 100644 --- a/runtime/gyehoek.c +++ b/runtime/gyehoek.c @@ -5,7 +5,7 @@ SCM scm_write (SCM x) { if (SCM_IMP (x)) { printf ("#\n", SCM_UNPACK (x) >> 2); } else { - printf ("#\n", SCM_UNPACK(x)); + printf ("#\n", SCM_UNPACK(x)); } return SCM_PACK(NULL); }