@@ -5,7 +5,7 @@ module Main where
55import Control.Monad ( unless )
66import Control.Monad.IO.Class ( MonadIO (liftIO ) )
77import Control.DeepSeq ( NFData (.. ) )
8- import Data.Maybe ( fromMaybe , catMaybes , isJust )
8+ import Data.Maybe ( fromMaybe , catMaybes , isJust , isNothing )
99import Data.Version ( showVersion )
1010import GHC.Generics ( Generic )
1111import System.Console.GetOpt ( OptDescr (Option ), ArgDescr (ReqArg ) )
@@ -21,9 +21,11 @@ import LambdaBox
2121import qualified LambdaBox as L
2222import Agda2Lambox.Convert ( convert )
2323import Agda2Lambox.Convert.Function ( convertFunction )
24+ import Agda2Lambox.Convert.Data ( convertDatatype )
2425import Agda2Lambox.Monad ( runC0 , inMutuals )
2526import CoqGen ( ToCoq (ToCoq ) )
2627import Agda.Syntax.Common.Pretty ( (<?>) , pretty )
28+ import Agda.Syntax.Common (hasQuantityω )
2729
2830
2931main :: IO ()
@@ -90,30 +92,28 @@ moduleSetup _ _ m _ = do
9092 setScope . iInsideScope =<< curIF
9193 return $ Recompile ()
9294
93- -- | Which Agda definitions to ignore.
94- ignoreDef :: Definition -> Bool
95- ignoreDef d@ Defn {.. }
96- | hasQuantity0 d
97- = True
98- | Function {.. } <- theDef
99- = (theDef ^. funInline) -- inlined functions (from module application)
100- -- | | funErasure -- @0 functions
101- || isJust funExtLam -- pattern-lambdas
102- || isJust funWith -- with-generated
103- | otherwise
104- = True
105-
10695compile :: Options -> ModuleEnv -> IsMain -> Definition -> TCM (Maybe (KerName , GlobalDecl ))
107- compile _ _ _ defn | ignoreDef defn = return Nothing
108- compile opts tlm _ def@ Defn {.. } = do
109- body <- runC0 $ convertFunction def
110- return $ Just $ ( qnameToKerName defName
111- , ConstantDecl $ Just body)
96+ compile opts tlm _ def@ Defn {.. } =
97+ fmap (qnameToKerName defName,) <$> -- prepend kername
98+ case theDef of
99+
100+ -- TODO(flupe): offload the check to Convert.Function
101+ Function {.. }
102+ | not (theDef ^. funInline) -- not inlined (from module application)
103+ , isNothing funExtLam -- not a pattern-lambda-generated function NOTE(flupe): ?
104+ , isNothing funWith -- not a with-generated function NOTE(flupe): ?
105+ , hasQuantityω def -- non-erased
106+ -> Just <$> runC0 (convertFunction def)
107+
108+ Datatype {} -> Just <$> runC0 (convertDatatype def)
109+
110+ _ -> Nothing <$ (liftIO $ putStrLn $ " Skipping " <> prettyShow defName)
111+
112112
113113writeModule :: Options -> ModuleEnv -> IsMain -> TopLevelModuleName
114114 -> [Maybe (KerName , GlobalDecl )]
115115 -> TCM ModuleRes
116- writeModule opts _ _ m (catMaybes -> cdefs) = do
116+ writeModule opts _ _ m (reverse . catMaybes -> cdefs) = do
117117 compDir <- compileDir
118118
119119 let outDir = fromMaybe compDir (optOutDir opts)
@@ -134,7 +134,7 @@ writeModule opts _ _ m (catMaybes -> cdefs) = do
134134 where
135135 coqModuleTemplate :: [(KerName , GlobalDecl )] -> String
136136 coqModuleTemplate coqterms = unlines
137- [ " From MetaCoq.Common Require Import BasicAst Kernames."
137+ [ " From MetaCoq.Common Require Import BasicAst Kernames Universes ."
138138 , " From MetaCoq.Erasure Require Import EAst."
139139 , " From MetaCoq.Utils Require Import bytestring MCString."
140140 , " From Coq Require Import List."
0 commit comments