Skip to content

Commit 7a1f95f

Browse files
committed
Adapt saw-core-coq to changed tuple representation.
1 parent 1e00330 commit 7a1f95f

File tree

1 file changed

+19
-15
lines changed
  • saw-core-coq/src/Verifier/SAW/Translation/Coq

1 file changed

+19
-15
lines changed

saw-core-coq/src/Verifier/SAW/Translation/Coq/Term.hs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -218,24 +218,30 @@ translateIdentToIdent i =
218218
translateSort :: Sort -> Coq.Sort
219219
translateSort s = if s == propSort then Coq.Prop else Coq.Type
220220

221+
translateTuple :: [Coq.Term] -> Coq.Term
222+
translateTuple [] = Coq.Var "tt"
223+
translateTuple (x : xs) = Coq.App (Coq.Var "pair") [x, translateTuple xs]
224+
225+
translateTupleType :: [Coq.Term] -> Coq.Term
226+
translateTupleType [] = Coq.Ascription (Coq.Var "unit") (Coq.Sort Coq.Type)
227+
-- We need to explicitly tell Coq that we want unit to be a Type, since
228+
-- all SAW core sorts are translated to Types
229+
translateTupleType (x : xs) = Coq.App (Coq.Var "prod") [x, translateTupleType xs]
230+
231+
translateTupleSelector :: Int -> Coq.Term -> Coq.Term
232+
translateTupleSelector i x
233+
| i == 0 = Coq.App (Coq.Var "SAWCoreScaffolding.fst") [x]
234+
| otherwise = translateTupleSelector (i - 1) (Coq.App (Coq.Var "SAWCoreScaffolding.snd") [x])
235+
221236
flatTermFToExpr ::
222237
TermTranslationMonad m =>
223238
FlatTermF Term ->
224239
m Coq.Term
225240
flatTermFToExpr tf = -- traceFTermF "flatTermFToExpr" tf $
226241
case tf of
227242
Primitive pn -> translateIdent (primName pn)
228-
UnitValue -> pure (Coq.Var "tt")
229-
UnitType ->
230-
-- We need to explicitly tell Coq that we want unit to be a Type, since
231-
-- all SAW core sorts are translated to Types
232-
pure (Coq.Ascription (Coq.Var "unit") (Coq.Sort Coq.Type))
233-
PairValue x y -> Coq.App (Coq.Var "pair") <$> traverse translateTerm [x, y]
234-
PairType x y -> Coq.App (Coq.Var "prod") <$> traverse translateTerm [x, y]
235-
PairLeft t ->
236-
Coq.App <$> pure (Coq.Var "SAWCoreScaffolding.fst") <*> traverse translateTerm [t]
237-
PairRight t ->
238-
Coq.App <$> pure (Coq.Var "SAWCoreScaffolding.snd") <*> traverse translateTerm [t]
243+
TupleValue xs -> translateTuple <$> traverse translateTerm (Vector.toList xs)
244+
TupleSelector x i -> translateTupleSelector i <$> translateTerm x
239245
-- TODO: maybe have more customizable translation of data types
240246
DataTypeApp n is as -> translateIdentWithArgs (primName n) (is ++ as)
241247
CtorApp n is as -> translateIdentWithArgs (primName n) (is ++ as)
@@ -644,10 +650,8 @@ defaultTermForType typ = do
644650
defaultT <- defaultTermForType typ'
645651
return $ Coq.App seqConst [ nT, typ'T, defaultT ]
646652

647-
(asPairType -> Just (x,y)) -> do
648-
x' <- defaultTermForType x
649-
y' <- defaultTermForType y
650-
return $ Coq.App (Coq.Var "pair") [x',y']
653+
(asTupleType -> Just xs) ->
654+
translateTuple <$> traverse defaultTermForType xs
651655

652656
(asPiList -> (bs,body))
653657
| not (null bs)

0 commit comments

Comments
 (0)