|
1 | 1 | {-# LANGUAGE DeriveGeneric, DeriveAnyClass, NamedFieldPuns, OverloadedStrings #-} |
2 | | -{-# LANGUAGE GADTs #-} |
| 2 | +{-# LANGUAGE GADTs, BangPatterns #-} |
3 | 3 | -- | The agda2lambox Agda backend |
4 | 4 | module Main (main) where |
5 | 5 |
|
@@ -41,7 +41,7 @@ main :: IO () |
41 | 41 | main = runAgda [agda2lambox] |
42 | 42 |
|
43 | 43 | data Output = RocqOutput | AstOutput |
44 | | - deriving (Generic, NFData) |
| 44 | + deriving (Eq, Show, Generic, NFData) |
45 | 45 |
|
46 | 46 | -- | Backend options. |
47 | 47 | data Options = forall t. Options |
@@ -91,7 +91,7 @@ agda2lambox = Backend backend |
91 | 91 | "Write output files to DIR. (default: project root)" |
92 | 92 | , Option ['t'] ["typed"] (NoArg typedOpt) |
93 | 93 | "Compile to typed λ□ environments." |
94 | | - , Option ['c'] ["rocq"] (NoArg typedOpt) |
| 94 | + , Option ['c'] ["rocq"] (NoArg rocqOpt) |
95 | 95 | "Output a Rocq file." |
96 | 96 | ] |
97 | 97 | , isEnabled = \ _ -> True |
@@ -120,31 +120,28 @@ writeModule |
120 | 120 | -> TCM ModuleRes |
121 | 121 | writeModule opts menv NotMain _ _ = pure () |
122 | 122 | writeModule Options{..} menv IsMain m defs = do |
123 | | - programs <- filterM hasPragma defs |
124 | 123 | outDir <- flip fromMaybe optOutDir <$> compileDir |
125 | | - |
126 | | - defs' <- filterOutWhere defs |
127 | | - |
128 | | - env <- compile optTarget $ reverse defs' |
| 124 | + defs' <- filterOutWhere defs |
| 125 | + env <- compile optTarget $ reverse defs' |
| 126 | + programs <- filterM hasPragma defs' |
129 | 127 |
|
130 | 128 | liftIO $ createDirectoryIfMissing True outDir |
131 | 129 |
|
132 | 130 | let fileName = (outDir </>) . moduleNameToFileName m |
133 | 131 | coqMod = CoqModule env (map qnameToKName programs) |
134 | 132 |
|
| 133 | + |
135 | 134 | liftIO do |
136 | 135 | putStrLn $ "Writing " <> fileName ".txt" |
137 | | - |
138 | | - pp coqMod <> "\n" |
139 | | - & writeFile (fileName ".txt") |
140 | | - |
141 | | - case optOutput of |
142 | | - RocqOutput -> do |
143 | | - putStrLn $ "Writing " <> fileName ".v" |
144 | | - prettyCoq optTarget coqMod <> "\n" |
145 | | - & writeFile (fileName ".v") |
146 | | - |
147 | | - AstOutput -> do |
148 | | - putStrLn $ "Writing " <> fileName ".ast" |
149 | | - prettySexp optTarget coqMod <> "\n" |
150 | | - & LText.writeFile (fileName ".ast") |
| 136 | + pp coqMod <> "\n" & writeFile (fileName ".txt") |
| 137 | + |
| 138 | + liftIO $ case optOutput of |
| 139 | + RocqOutput -> do |
| 140 | + putStrLn $ "Writing " <> fileName ".v" |
| 141 | + prettyCoq optTarget coqMod <> "\n" |
| 142 | + & writeFile (fileName ".v") |
| 143 | + |
| 144 | + AstOutput -> do |
| 145 | + putStrLn $ "Writing " <> fileName ".ast" |
| 146 | + prettySexp optTarget coqMod <> "\n" |
| 147 | + & LText.writeFile (fileName ".ast") |
0 commit comments