destVecTypedTerm :: SharedContext -> TypedTerm -> IO (Maybe (Cryptol.Type, [TypedTerm]))
destVecTypedTerm sc (TypedTerm ttp t) =
  case asVec of
    Nothing -> pure Nothing
    Just (len, ety) ->
      do len_tm <- scNat sc (fromInteger len)
         ty_tm <- Cryptol.importType sc Cryptol.emptyEnv ety
         idxs <- traverse (scNat sc) (map fromInteger [0 .. len-1])
         ts <- traverse (scAt sc len_tm ty_tm t) idxs
         pure $ Just (ety, map (TypedTerm (TypedTermSchema (Cryptol.tMono ety))) ts)
  where
    asVec =
      do ty <- ttIsMono ttp
         (n, a) <- Cryptol.tIsSeq ty
         n' <- Cryptol.tIsNum n
         Just (n', a)

------------------------------------------------------------------------


-- | Process a "crucible_equal" statement from the postcondition
-- section of the CrucibleSetup block.
destVecTypedTerm :: SharedContext -> TypedTerm -> IO (Maybe (Cryptol.Type, [TypedTerm]))
destVecTypedTerm sc (TypedTerm ttp t) =
  case asVec of
    Nothing -> pure Nothing
    Just (len, ety) ->
      do len_tm <- scNat sc (fromInteger len)
         ty_tm <- Cryptol.importType sc Cryptol.emptyEnv ety
         idxs <- traverse (scNat sc) (map fromInteger [0 .. len-1])
         ts <- traverse (scAt sc len_tm ty_tm t) idxs
         pure $ Just (ety, map (TypedTerm (TypedTermSchema (Cryptol.tMono ety))) ts)
  where
    asVec =
      do ty <- ttIsMono ttp
         (n, a) <- Cryptol.tIsSeq ty
         n' <- Cryptol.tIsNum n
         Just (n', a)

------------------------------------------------------------------------


-- | Process a "crucible_equal" statement from the postcondition
-- section of the CrucibleSetup block.
destVecTypedTerm sc (TypedTerm ttp t) =
  case asVec of
    Nothing -> pure Nothing
    Just (len, ety) ->
      do len_tm <- scNat sc (fromInteger len)
         ty_tm <- Cryptol.importType sc Cryptol.emptyEnv ety
         idxs <- traverse (scNat sc) (map fromInteger [0 .. len-1])
         ts <- traverse (scAt sc len_tm ty_tm t) idxs
         pure $ Just (ety, map (TypedTerm (TypedTermSchema (Cryptol.tMono ety))) ts)
  where
    asVec =
      do ty <- ttIsMono ttp
         (n, a) <- Cryptol.tIsSeq ty
         n' <- Cryptol.tIsNum n
         Just (n', a)

------------------------------------------------------------------------


-- | Process a "crucible_equal" statement from the postcondition
-- section of the CrucibleSetup block.