aboutsummaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2020-06-10 19:59:03 +0200
committerTom Smeding <tom.smeding@gmail.com>2020-06-10 19:59:13 +0200
commitbc52411ae2ed26cab1d5086ae6df68f23ebbd052 (patch)
tree365e7bab678bb46981befe5b2a1c0c967a9a9c57 /main
Initial state I found the code in
Diffstat (limited to 'main')
-rw-r--r--main/Main.hs33
1 files changed, 33 insertions, 0 deletions
diff --git a/main/Main.hs b/main/Main.hs
new file mode 100644
index 0000000..58e475c
--- /dev/null
+++ b/main/Main.hs
@@ -0,0 +1,33 @@
+module Main where
+
+import System.Exit
+
+import qualified CC.Parser
+import qualified CC.Typecheck
+import CC.Types
+
+
+-- Put the passes in a type-level list to be able to run subsequences of
+-- passes.
+
+
+type Pass a b = Context -> a -> Either String b
+
+pass :: (Read a, Show b, Show e) => (Context -> a -> Either e b) -> Pass a b
+pass f ctx a = either (Left . show) Right (f ctx a)
+
+passJoin :: (Read a, Show b, Read b, Show c) => Pass a b -> Pass b c -> Pass a c
+passJoin f1 f2 ctx a = f1 ctx a >>= f2 ctx
+
+main :: IO ()
+main = do
+ let parse = pass CC.Parser.runPass
+ typecheck = pass CC.Typecheck.runPass
+
+ let combined = parse `passJoin` typecheck
+
+ source <- getContents
+ let context = Context "<stdin>"
+ case combined context (read source) of
+ Right prog -> print prog
+ Left err -> die (show err)