@@ -115,24 +115,24 @@ data InputText = InputText
115
115
116
116
--------------------------------------------------------------------------------
117
117
118
- -- | Should a given import result in all symbols being visible (as they
119
- -- are for focused modules in the Cryptol REPL) or only public symbols?
120
- -- Making all symbols visible is useful for verification and code
121
- -- generation.
118
+ -- | 'ImportVisibility' - Should a given import (see 'importModule')
119
+ -- result in all symbols being visible (as they are for focused
120
+ -- modules in the Cryptol REPL) or only public symbols? Making all
121
+ -- symbols visible is useful for verification and code generation.
122
+ --
123
+ -- NOTE: this notion of public vs. private symbols is specific to
124
+ -- SAWScript and distinct from Cryptol's notion of private
125
+ -- definitions.
122
126
--
123
- -- NOTE: PublicAndPrivate is specific to SAWScript (Cryptol cannot do such).
124
127
data ImportVisibility
125
- = OnlyPublic
126
- | PublicAndPrivate
128
+ = OnlyPublic -- ^ behaves like a normal Cryptol "import"
129
+ | PublicAndPrivate -- ^ allows viewing of both "private" sections and (arbitrarily nested) submodules.
127
130
deriving (Eq , Show )
128
131
129
132
130
133
-- | The environment for capturing the Cryptol interpreter state as well as the
131
134
-- SAWCore translations and associated state.
132
135
--
133
- -- FIXME[D]: The differences in function between this and the similar
134
- -- C.Env?
135
-
136
136
data CryptolEnv = CryptolEnv
137
137
{ eImports :: [(ImportVisibility , P. Import )]
138
138
-- ^ Declarations of imported Cryptol modules
@@ -185,6 +185,14 @@ nameMatcher xs =
185
185
186
186
-- Initialize ------------------------------------------------------------------
187
187
188
+ -- | initCryptolEnv - Create initial CryptolEnv, this involves loading the built-in modules
189
+ -- (preludeName, arrayName, preludeReferenceName) and translating them into SAWCore, and
190
+ -- putting them into scope.
191
+ --
192
+ -- NOTE: submodules in these built-in modules would be suppported here.
193
+ --
194
+ -- FIXME: There is some code duplication between this and `loadCryptolModule` and `importModule`.
195
+
188
196
initCryptolEnv ::
189
197
(? fileReader :: FilePath -> IO ByteString ) =>
190
198
SharedContext -> IO CryptolEnv
@@ -226,7 +234,6 @@ initCryptolEnv sc = do
226
234
let refDecls = T. mDecls refMod
227
235
let nms = Set. toList (MI. ifsPublic (TIface. genIfaceNames refMod))
228
236
229
- -- FIXME: assuming we have same "bug" were we to have submodules in prelude. ?
230
237
let refPrims = Map. fromList
231
238
[ (prelPrim (identText (MN. nameIdent nm)), T. EWhere (T. EVar nm) refDecls)
232
239
| nm <- nms ]
@@ -285,8 +292,7 @@ ioParseResult res = case res of
285
292
286
293
-- NamingEnv and Related -------------------------------------------------------
287
294
288
- -- | getNamingEnv env - get the full MR.NamingEnv based on all the `eImports`
289
- --
295
+ -- | @'getNamingEnv' env@ - get the full 'MR.NamingEnv' based on all the 'eImports'
290
296
291
297
getNamingEnv :: CryptolEnv -> MR. NamingEnv
292
298
getNamingEnv env =
@@ -504,9 +510,6 @@ loadCryptolModule sc env path = do
504
510
-- user binds the `cryptolModule` returned here at the saw
505
511
-- command line.
506
512
507
- -- FIXME: A better CLI API could simplify both this code and the SAWScript
508
- -- semantics.
509
-
510
513
return ( cryptolModule
511
514
, updateFFITypes m
512
515
env { eModuleEnv = modEnv''
@@ -544,7 +547,7 @@ mkCryptolModule m types newTermEnv =
544
547
(\ k _ -> Set. member k (MEx. exported C. NSType (T. mExports m)))
545
548
(T. mTySyns m)
546
549
)
547
- -- FIXME: ensure type synonym in submodule is included.
550
+ -- FIXME: TODO: ensure type synonym in submodule is included.
548
551
549
552
-- create the map of symbols:
550
553
( Map. filterWithKey (\ k _ -> Set. member k names)
@@ -576,34 +579,32 @@ updateFFITypes m env = env { eFFITypes = eFFITypes' }
576
579
" Cannot find foreign function in term environment: " <> Text. pack (show nm)
577
580
]
578
581
579
- -- | bindCryptolModule - ad hoc function called when we do `D <-cryptol_load`
582
+ -- | bindCryptolModule - ad hoc function called when `D <-cryptol_load` is seen
580
583
-- on the command line.
581
584
--
582
585
-- FIXME:
583
586
-- - submodules are not handled correctly below.
584
- -- - the code is duplicating functionality that we have with imports.
587
+ -- - the code is duplicating functionality that we have with `importModule`
585
588
--
586
589
bindCryptolModule :: (P. ModName , CryptolModule ) -> CryptolEnv -> CryptolEnv
587
590
bindCryptolModule (modName, CryptolModule sm tm) env =
588
591
env { eExtraNames = flip (foldr addName) (Map. keys tm') $
589
592
flip (foldr addTSyn) (Map. keys sm) $
590
593
flip (foldr addSubModule) (Map. keys tm') $
591
- -- FIXME: This added function doesn't really
592
- -- fix the submodule support bugs.
593
594
eExtraNames env
594
595
, eExtraTSyns = Map. union sm (eExtraTSyns env)
595
596
, eExtraTypes = Map. union (fmap fst tm') (eExtraTypes env)
596
597
, eTermEnv = Map. union (fmap snd tm') (eTermEnv env)
597
598
}
598
599
where
599
- -- select out those typed terms from `tm' that have Cryptol schemas
600
+ -- | `tm'` is the typed terms from `tm` that have Cryptol schemas
600
601
tm' = Map. mapMaybe f tm
601
602
where
602
603
f (TypedTerm (TypedTermSchema s) x) = Just (s,x)
603
604
f _ = Nothing
604
605
605
606
addName name = MN. shadowing (MN. singletonNS C. NSValue (P. mkQual modName (MN. nameIdent name)) name)
606
- -- FIXME: suspicious. (we need to do any C.NSModule?)
607
+ -- FIXME: suspicious. (Do we need to do any C.NSModule?)
607
608
608
609
addSubModule name = MN. shadowing (MN. singletonNS C. NSModule (P. mkQual modName (MN. nameIdent name)) name)
609
610
@@ -623,6 +624,13 @@ extractDefFromCryptolModule (CryptolModule _ tm) name =
623
624
624
625
--------------------------------------------------------------------------------
625
626
627
+ -- | @'importModule' sc env src as vis imps@ - extend the Cryptol
628
+ -- environment with a module. Closely mirrors the sawscript command "import".
629
+ --
630
+ -- NOTE:
631
+ -- - the module can be qualified or not (per 'as' argument).
632
+ -- - per 'vis' we can import public definitions or *all* (i.e., kinternal and public) definitions.
633
+
626
634
importModule ::
627
635
(? fileReader :: FilePath -> IO ByteString ) =>
628
636
SharedContext {- ^ Shared context for creating terms -} ->
@@ -793,7 +801,7 @@ pExprToTypedTerm sc env pexpr = do
793
801
let nameEnv = getNamingEnv env
794
802
let npe' = MR. rename npe
795
803
re <- MM. interactive (MB. rename interactiveName nameEnv npe')
796
- -- NOTE: if a Value not in scope, reported here.
804
+ -- NOTE: if a name is not in scope, it is reported here.
797
805
798
806
-- Infer types
799
807
let ifDecls = getAllIfaceDecls modEnv
0 commit comments