Skip to content

Commit db449e3

Browse files
committed
reinstate debug printing
1 parent c7bf582 commit db449e3

File tree

4 files changed

+54
-12
lines changed

4 files changed

+54
-12
lines changed

src/Agda2Lambox/Convert/Data.hs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ module Agda2Lambox.Convert.Data
55
) where
66

77
import Control.Monad.Reader ( ask, liftIO )
8-
import Control.Monad ( forM )
8+
import Control.Monad ( forM, when, unless )
99
import Data.List ( elemIndex )
10+
import Data.Maybe ( isJust )
1011

1112
import Utils
1213

@@ -31,10 +32,15 @@ import Agda.Utils.Monad (guardWithError)
3132

3233
-- | Convert a datatype definition to a Lambdabox declaration.
3334
convertDatatype :: Definition :~> GlobalDecl
34-
convertDatatype defn@Defn{defName, theDef} =
35+
convertDatatype defn@Defn{defName, theDef, defMutual} =
3536
withCurrentModule (qnameModule defName) do
3637
let Datatype{..} = theDef
3738

39+
let Just muts = dataMutual
40+
41+
unless (length muts < 2) $
42+
fail $ "mututal datatypes not supported" <> prettyShow dataMutual
43+
3844
ctors :: [ConstructorBody]
3945
<- forM dataCons \cname -> do
4046
DataCon arity <- getConstructorInfo cname

src/CoqGen.hs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,6 @@ instance Pretty (ToCoq t) => Pretty (ToCoq (Def t)) where
160160
, ("rarg", pcoq dArgs)
161161
]
162162

163-
-- | Generated module
164-
data CoqModule = CoqModule
165-
{ coqEnv :: [(KerName, GlobalDecl)]
166-
, coqPrograms :: [KerName]
167-
}
168-
169163
instance Pretty (ToCoq CoqModule) where
170164
pretty (ToCoq CoqModule{..}) = vsep
171165
[ vcat

src/LambdaBox.hs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ data GlobalDecl
186186

187187
type GlobalDecls = [(KerName, GlobalDecl)]
188188

189+
-- | Generated module
190+
data CoqModule = CoqModule
191+
{ coqEnv :: [(KerName, GlobalDecl)]
192+
, coqPrograms :: [KerName]
193+
}
194+
195+
189196
instance Pretty Term where
190197
prettyPrec p v =
191198
case v of
@@ -227,3 +234,32 @@ instance Pretty Name where
227234
prettyPrec _ = \case
228235
Anon -> text "_"
229236
Named s -> text s
237+
238+
239+
instance Pretty ConstructorBody where
240+
pretty Ctor{..} =
241+
pretty ctorName <+> parens (pretty ctorArgs <+> "arg(s)")
242+
243+
instance Pretty OneInductiveBody where
244+
pretty OneInductive{..} =
245+
vcat
246+
[ pretty indName
247+
, "constructors:" <+> pretty indCtors
248+
]
249+
250+
instance Pretty GlobalDecl where
251+
pretty = \case
252+
ConstantDecl (Just b) ->
253+
hang "constant:" 2 $ pretty b
254+
255+
ConstantDecl Nothing ->
256+
"primitive constant"
257+
258+
InductiveDecl MutualInductive{..} ->
259+
hang "mutual inductive(s):" 2 $
260+
vsep $ map pretty indBodies
261+
262+
instance Pretty CoqModule where
263+
pretty CoqModule{..} =
264+
vsep $ flip map (reverse coqEnv) \(kn, d) ->
265+
hang (pretty kn <> ":") 2 (pretty d)

src/Main.hs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import Agda2Lambox.Convert.Function ( convertFunction )
2424
import Agda2Lambox.Convert.Data ( convertDatatype )
2525
import Agda2Lambox.Convert.Record ( convertRecord )
2626
import Agda2Lambox.Monad ( runC0, inMutuals )
27-
import CoqGen ( ToCoq(ToCoq), CoqModule(..) )
28-
import LambdaBox ( KerName, GlobalDecl, qnameToKerName )
27+
import CoqGen ( ToCoq(ToCoq) )
28+
import LambdaBox ( KerName, GlobalDecl, qnameToKerName, CoqModule(CoqModule) )
2929

3030

3131
main :: IO ()
@@ -109,9 +109,15 @@ writeModule opts menv _ m (reverse . catMaybes -> cdefs) = do
109109

110110
liftIO $ createDirectoryIfMissing True outDir
111111

112+
let mod = CoqModule cdefs progs
113+
112114
unless (null cdefs) $ liftIO do
113-
putStrLn $ "Writing " <> fileName ".v"
115+
putStrLn $ "Writing " <> fileName ".{v,txt}"
116+
117+
writeFile (fileName ".txt")
118+
$ (<> "\n")
119+
$ pp $ mod
114120

115121
writeFile (fileName ".v")
116122
$ (<> "\n")
117-
$ pp $ ToCoq $ CoqModule cdefs progs
123+
$ pp $ ToCoq $ mod

0 commit comments

Comments
 (0)