Skip to content

Commit a1b4088

Browse files
committed
basic reading of COMPILE info
1 parent 01be55b commit a1b4088

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/Agda/Utils.hs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ module Agda.Utils where
55

66
import Control.Applicative ( liftA2 )
77
import Data.Bifunctor ( second )
8+
import Data.Functor ( (<&>) )
89
import Data.Maybe ( isJust, isNothing, catMaybes )
10+
import Data.Text ( Text )
911

1012
import Agda.Compiler.Backend ( getUniqueCompilerPragma, PureTCM, HasConstInfo (getConstInfo) )
1113
import Agda.Syntax.Abstract.Name
@@ -31,11 +33,22 @@ import Agda.TypeChecking.Reduce (reduceDefCopy)
3133

3234
-- * Miscellaneous
3335

36+
-- | Pragma string for the agda2lambox backend.
37+
agda2lamboxP :: Text
38+
agda2lamboxP = "AGDA2LAMBOX"
39+
3440
pp :: Pretty a => a -> String
3541
pp = prettyShow
3642

3743
hasPragma :: QName -> TCM Bool
38-
hasPragma qn = isJust <$> getUniqueCompilerPragma "AGDA2LAMBOX" qn
44+
hasPragma qn = isJust <$> getUniqueCompilerPragma agda2lamboxP qn
45+
46+
-- | Retrieve the additional info to a COMPILE pragma, if any
47+
getPragmaInfo :: QName -> TCM (Maybe String)
48+
getPragmaInfo qn =
49+
getUniqueCompilerPragma agda2lamboxP qn <&> \case
50+
Nothing -> Nothing
51+
Just (CompilerPragma _ info) -> Just info
3952

4053
isDataDef, isRecDef, isFunDef, isDataOrRecDef :: Defn -> Bool
4154
isDataDef = \case

src/Agda2Lambox/Compile.hs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Agda.TypeChecking.Pretty
1717
import Agda.Utils.Monad ( ifM, ifNotM, orM )
1818
import Agda.Utils.SmallSet qualified as SmallSet
1919

20-
import Agda.Utils ( hasPragma, isDataOrRecDef, treeless, isArity )
20+
import Agda.Utils ( isDataOrRecDef, isArity, getPragmaInfo )
2121

2222
import Agda2Lambox.Compile.Monad
2323
import Agda2Lambox.Compile.Target
@@ -47,7 +47,13 @@ compile t qs = do
4747

4848
compileDefinition :: Target t -> Definition -> CompileM (Maybe (GlobalDecl t))
4949
compileDefinition target defn@Defn{..} = setCurrentRange defName do
50-
reportSDoc "agda2lambox.compile" 1 $ "Compiling definition: " <+> prettyTCM defName
50+
reportSDoc "agda2lambox.compile" 1 $ "Compiling definition:" <+> prettyTCM defName
51+
52+
-- retrieve compile annotation written in COMPILE pragma
53+
annotation <- liftTCM $ getPragmaInfo defName
54+
55+
reportSDoc "agda2lambox.compile" 1 $
56+
"Definition is annotated as such:" <+> prettyTCM annotation
5157

5258
-- we skip definitions introduced by module application
5359

0 commit comments

Comments
 (0)