mirror of
https://github.com/GaloisInc/cryptol.git
synced 2024-09-11 14:06:13 +03:00
Add SMT Array primitives. (#732)
* Add SMT Array primitives. * Move SMT Array primitives in Array.cry. * Minor.
This commit is contained in:
parent
63bfdb2c06
commit
c1bdd77ff0
15
lib/Array.cry
Normal file
15
lib/Array.cry
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Galois, Inc.
|
||||||
|
* Distributed under the terms of the BSD3 license (see LICENSE file)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** The type and operations of the theory of arrays. */
|
||||||
|
|
||||||
|
module Array where
|
||||||
|
|
||||||
|
primitive type Array : * -> * -> *
|
||||||
|
|
||||||
|
primitive arrayConstant : {a, b} b -> (Array a b)
|
||||||
|
primitive arrayLookup : {a, b} (Array a b) -> a -> b
|
||||||
|
primitive arrayUpdate : {a, b} (Array a b) -> a -> b -> (Array a b)
|
||||||
|
|
@ -426,6 +426,7 @@ etaDelay sym msg env0 Forall{ sVars = vs0, sType = tp0 } = goTpVars env0 vs0
|
|||||||
TVBit -> v
|
TVBit -> v
|
||||||
TVInteger -> v
|
TVInteger -> v
|
||||||
TVIntMod _ -> v
|
TVIntMod _ -> v
|
||||||
|
TVArray{} -> v
|
||||||
|
|
||||||
TVSeq n TVBit ->
|
TVSeq n TVBit ->
|
||||||
do w <- sDelayFill sym (fromWordVal "during eta-expansion" =<< v) (etaWord sym n v)
|
do w <- sDelayFill sym (fromWordVal "during eta-expansion" =<< v) (etaWord sym n v)
|
||||||
|
@ -164,6 +164,9 @@ arithBinary sym opw opi opz = loop
|
|||||||
TVIntMod n ->
|
TVIntMod n ->
|
||||||
VInteger <$> opz n (fromVInteger l) (fromVInteger r)
|
VInteger <$> opz n (fromVInteger l) (fromVInteger r)
|
||||||
|
|
||||||
|
TVArray{} ->
|
||||||
|
evalPanic "arithBinary" ["Array not in class Arith"]
|
||||||
|
|
||||||
TVSeq w a
|
TVSeq w a
|
||||||
-- words and finite sequences
|
-- words and finite sequences
|
||||||
| isTBit a -> do
|
| isTBit a -> do
|
||||||
@ -235,6 +238,9 @@ arithUnary sym opw opi opz = loop
|
|||||||
TVIntMod n ->
|
TVIntMod n ->
|
||||||
VInteger <$> opz n (fromVInteger v)
|
VInteger <$> opz n (fromVInteger v)
|
||||||
|
|
||||||
|
TVArray{} ->
|
||||||
|
evalPanic "arithUnary" ["Array not in class Arith"]
|
||||||
|
|
||||||
TVSeq w a
|
TVSeq w a
|
||||||
-- words and finite sequences
|
-- words and finite sequences
|
||||||
| isTBit a -> do
|
| isTBit a -> do
|
||||||
@ -292,6 +298,8 @@ arithNullary sym opw opi opz = loop
|
|||||||
|
|
||||||
TVIntMod n -> VInteger <$> opz n
|
TVIntMod n -> VInteger <$> opz n
|
||||||
|
|
||||||
|
TVArray{} -> evalPanic "arithNullary" ["Array not in class Arith"]
|
||||||
|
|
||||||
TVSeq w a
|
TVSeq w a
|
||||||
-- words and finite sequences
|
-- words and finite sequences
|
||||||
| isTBit a -> pure $ VWord w $ (WordVal <$> opw w)
|
| isTBit a -> pure $ VWord w $ (WordVal <$> opw w)
|
||||||
@ -445,6 +453,8 @@ cmpValue sym fb fw fi fz = cmp
|
|||||||
TVBit -> fb (fromVBit v1) (fromVBit v2) k
|
TVBit -> fb (fromVBit v1) (fromVBit v2) k
|
||||||
TVInteger -> fi (fromVInteger v1) (fromVInteger v2) k
|
TVInteger -> fi (fromVInteger v1) (fromVInteger v2) k
|
||||||
TVIntMod n -> fz n (fromVInteger v1) (fromVInteger v2) k
|
TVIntMod n -> fz n (fromVInteger v1) (fromVInteger v2) k
|
||||||
|
TVArray{} -> panic "Cryptol.Prims.Value.cmpValue"
|
||||||
|
[ "Arrays are not comparable" ]
|
||||||
TVSeq n t
|
TVSeq n t
|
||||||
| isTBit t -> do w1 <- fromVWord sym "cmpValue" v1
|
| isTBit t -> do w1 <- fromVWord sym "cmpValue" v1
|
||||||
w2 <- fromVWord sym "cmpValue" v2
|
w2 <- fromVWord sym "cmpValue" v2
|
||||||
@ -608,6 +618,8 @@ zeroV sym ty = case ty of
|
|||||||
TVIntMod _ ->
|
TVIntMod _ ->
|
||||||
VInteger <$> integerLit sym 0
|
VInteger <$> integerLit sym 0
|
||||||
|
|
||||||
|
TVArray{} -> evalPanic "zeroV" ["Array not in class Zero"]
|
||||||
|
|
||||||
-- sequences
|
-- sequences
|
||||||
TVSeq w ety
|
TVSeq w ety
|
||||||
| isTBit ety -> pure $ word sym w 0
|
| isTBit ety -> pure $ word sym w 0
|
||||||
@ -1010,6 +1022,7 @@ logicBinary sym opb opw = loop
|
|||||||
TVBit -> VBit <$> (opb (fromVBit l) (fromVBit r))
|
TVBit -> VBit <$> (opb (fromVBit l) (fromVBit r))
|
||||||
TVInteger -> evalPanic "logicBinary" ["Integer not in class Logic"]
|
TVInteger -> evalPanic "logicBinary" ["Integer not in class Logic"]
|
||||||
TVIntMod _ -> evalPanic "logicBinary" ["Z not in class Logic"]
|
TVIntMod _ -> evalPanic "logicBinary" ["Z not in class Logic"]
|
||||||
|
TVArray{} -> evalPanic "logicBinary" ["Array not in class Logic"]
|
||||||
TVSeq w aty
|
TVSeq w aty
|
||||||
-- words
|
-- words
|
||||||
| isTBit aty
|
| isTBit aty
|
||||||
@ -1085,6 +1098,7 @@ logicUnary sym opb opw = loop
|
|||||||
|
|
||||||
TVInteger -> evalPanic "logicUnary" ["Integer not in class Logic"]
|
TVInteger -> evalPanic "logicUnary" ["Integer not in class Logic"]
|
||||||
TVIntMod _ -> evalPanic "logicUnary" ["Z not in class Logic"]
|
TVIntMod _ -> evalPanic "logicUnary" ["Z not in class Logic"]
|
||||||
|
TVArray{} -> evalPanic "logicUnary" ["Array not in class Logic"]
|
||||||
|
|
||||||
TVSeq w ety
|
TVSeq w ety
|
||||||
-- words
|
-- words
|
||||||
@ -1420,6 +1434,7 @@ errorV sym ty msg = case ty of
|
|||||||
TVBit -> cryUserError sym msg
|
TVBit -> cryUserError sym msg
|
||||||
TVInteger -> cryUserError sym msg
|
TVInteger -> cryUserError sym msg
|
||||||
TVIntMod _ -> cryUserError sym msg
|
TVIntMod _ -> cryUserError sym msg
|
||||||
|
TVArray{} -> cryUserError sym msg
|
||||||
|
|
||||||
-- sequences
|
-- sequences
|
||||||
TVSeq w ety
|
TVSeq w ety
|
||||||
|
@ -66,6 +66,7 @@ are as follows:
|
|||||||
|:----------------- |:-------------- |:--------------------------- |
|
|:----------------- |:-------------- |:--------------------------- |
|
||||||
| `Bit` | booleans | `TVBit` |
|
| `Bit` | booleans | `TVBit` |
|
||||||
| `Integer` | integers | `TVInteger` |
|
| `Integer` | integers | `TVInteger` |
|
||||||
|
| `Array` | arrays | `TVArray` |
|
||||||
| `[n]a` | finite lists | `TVSeq n a` |
|
| `[n]a` | finite lists | `TVSeq n a` |
|
||||||
| `[inf]a` | infinite lists | `TVStream a` |
|
| `[inf]a` | infinite lists | `TVStream a` |
|
||||||
| `(a, b, c)` | tuples | `TVTuple [a,b,c]` |
|
| `(a, b, c)` | tuples | `TVTuple [a,b,c]` |
|
||||||
@ -171,6 +172,7 @@ cpo that represents any given schema.
|
|||||||
> TVBit -> VBit (fromVBit val)
|
> TVBit -> VBit (fromVBit val)
|
||||||
> TVInteger -> VInteger (fromVInteger val)
|
> TVInteger -> VInteger (fromVInteger val)
|
||||||
> TVIntMod _ -> VInteger (fromVInteger val)
|
> TVIntMod _ -> VInteger (fromVInteger val)
|
||||||
|
> TVArray{} -> evalPanic "copyByTValue" ["Unsupported Array type"]
|
||||||
> TVSeq w ety -> VList (Nat w) (map (go ety) (copyList w (fromVList val)))
|
> TVSeq w ety -> VList (Nat w) (map (go ety) (copyList w (fromVList val)))
|
||||||
> TVStream ety -> VList Inf (map (go ety) (copyStream (fromVList val)))
|
> TVStream ety -> VList Inf (map (go ety) (copyStream (fromVList val)))
|
||||||
> TVTuple etys -> VTuple (zipWith go etys (copyList (genericLength etys) (fromVTuple val)))
|
> TVTuple etys -> VTuple (zipWith go etys (copyList (genericLength etys) (fromVTuple val)))
|
||||||
@ -751,6 +753,7 @@ at the same positions.
|
|||||||
> go TVBit = VBit b
|
> go TVBit = VBit b
|
||||||
> go TVInteger = VInteger (fmap (\c -> if c then -1 else 0) b)
|
> go TVInteger = VInteger (fmap (\c -> if c then -1 else 0) b)
|
||||||
> go (TVIntMod _) = VInteger (fmap (const 0) b)
|
> go (TVIntMod _) = VInteger (fmap (const 0) b)
|
||||||
|
> go (TVArray{}) = evalPanic "logicNullary" ["Array not in class Logic"]
|
||||||
> go (TVSeq n ety) = VList (Nat n) (genericReplicate n (go ety))
|
> go (TVSeq n ety) = VList (Nat n) (genericReplicate n (go ety))
|
||||||
> go (TVStream ety) = VList Inf (repeat (go ety))
|
> go (TVStream ety) = VList Inf (repeat (go ety))
|
||||||
> go (TVTuple tys) = VTuple (map go tys)
|
> go (TVTuple tys) = VTuple (map go tys)
|
||||||
@ -768,6 +771,7 @@ at the same positions.
|
|||||||
> TVBit -> VBit (fmap op (fromVBit val))
|
> TVBit -> VBit (fmap op (fromVBit val))
|
||||||
> TVInteger -> evalPanic "logicUnary" ["Integer not in class Logic"]
|
> TVInteger -> evalPanic "logicUnary" ["Integer not in class Logic"]
|
||||||
> TVIntMod _ -> evalPanic "logicUnary" ["Z not in class Logic"]
|
> TVIntMod _ -> evalPanic "logicUnary" ["Z not in class Logic"]
|
||||||
|
> TVArray{} -> evalPanic "logicUnary" ["Array not in class Logic"]
|
||||||
> TVSeq w ety -> VList (Nat w) (map (go ety) (fromVList val))
|
> TVSeq w ety -> VList (Nat w) (map (go ety) (fromVList val))
|
||||||
> TVStream ety -> VList Inf (map (go ety) (fromVList val))
|
> TVStream ety -> VList Inf (map (go ety) (fromVList val))
|
||||||
> TVTuple etys -> VTuple (zipWith go etys (fromVTuple val))
|
> TVTuple etys -> VTuple (zipWith go etys (fromVTuple val))
|
||||||
@ -785,6 +789,7 @@ at the same positions.
|
|||||||
> TVBit -> VBit (liftA2 op (fromVBit l) (fromVBit r))
|
> TVBit -> VBit (liftA2 op (fromVBit l) (fromVBit r))
|
||||||
> TVInteger -> evalPanic "logicBinary" ["Integer not in class Logic"]
|
> TVInteger -> evalPanic "logicBinary" ["Integer not in class Logic"]
|
||||||
> TVIntMod _ -> evalPanic "logicBinary" ["Z not in class Logic"]
|
> TVIntMod _ -> evalPanic "logicBinary" ["Z not in class Logic"]
|
||||||
|
> TVArray{} -> evalPanic "logicBinary" ["Array not in class Logic"]
|
||||||
> TVSeq w ety -> VList (Nat w) (zipWith (go ety) (fromVList l) (fromVList r))
|
> TVSeq w ety -> VList (Nat w) (zipWith (go ety) (fromVList l) (fromVList r))
|
||||||
> TVStream ety -> VList Inf (zipWith (go ety) (fromVList l) (fromVList r))
|
> TVStream ety -> VList Inf (zipWith (go ety) (fromVList l) (fromVList r))
|
||||||
> TVTuple etys -> VTuple (zipWith3 go etys (fromVTuple l) (fromVTuple r))
|
> TVTuple etys -> VTuple (zipWith3 go etys (fromVTuple l) (fromVTuple r))
|
||||||
@ -819,6 +824,8 @@ up of non-empty finite bitvectors.
|
|||||||
> VInteger i
|
> VInteger i
|
||||||
> TVIntMod n ->
|
> TVIntMod n ->
|
||||||
> VInteger (flip mod n <$> i)
|
> VInteger (flip mod n <$> i)
|
||||||
|
> TVArray{} ->
|
||||||
|
> evalPanic "arithNullary" ["Array not in class Arith"]
|
||||||
> TVSeq w a
|
> TVSeq w a
|
||||||
> | isTBit a -> vWord w i
|
> | isTBit a -> vWord w i
|
||||||
> | otherwise -> VList (Nat w) (genericReplicate w (go a))
|
> | otherwise -> VList (Nat w) (genericReplicate w (go a))
|
||||||
@ -852,6 +859,8 @@ up of non-empty finite bitvectors.
|
|||||||
> case fromVInteger val of
|
> case fromVInteger val of
|
||||||
> Left e -> Left e
|
> Left e -> Left e
|
||||||
> Right i -> flip mod n <$> op i
|
> Right i -> flip mod n <$> op i
|
||||||
|
> TVArray{} ->
|
||||||
|
> evalPanic "arithUnary" ["Array not in class Arith"]
|
||||||
> TVSeq w a
|
> TVSeq w a
|
||||||
> | isTBit a -> vWord w (op =<< fromVWord val)
|
> | isTBit a -> vWord w (op =<< fromVWord val)
|
||||||
> | otherwise -> VList (Nat w) (map (go a) (fromVList val))
|
> | otherwise -> VList (Nat w) (map (go a) (fromVList val))
|
||||||
@ -900,6 +909,8 @@ up of non-empty finite bitvectors.
|
|||||||
> case fromVInteger r of
|
> case fromVInteger r of
|
||||||
> Left e -> Left e
|
> Left e -> Left e
|
||||||
> Right j -> flip mod n <$> op i j
|
> Right j -> flip mod n <$> op i j
|
||||||
|
> TVArray{} ->
|
||||||
|
> evalPanic "arithBinary" ["Array not in class Arith"]
|
||||||
> TVSeq w a
|
> TVSeq w a
|
||||||
> | isTBit a -> vWord w $
|
> | isTBit a -> vWord w $
|
||||||
> case fromWord l of
|
> case fromWord l of
|
||||||
@ -968,6 +979,8 @@ bits to the *left* of that position are equal.
|
|||||||
> compare <$> fromVInteger l <*> fromVInteger r
|
> compare <$> fromVInteger l <*> fromVInteger r
|
||||||
> TVIntMod _ ->
|
> TVIntMod _ ->
|
||||||
> compare <$> fromVInteger l <*> fromVInteger r
|
> compare <$> fromVInteger l <*> fromVInteger r
|
||||||
|
> TVArray{} ->
|
||||||
|
> evalPanic "lexCompare" ["invalid type"]
|
||||||
> TVSeq _w ety ->
|
> TVSeq _w ety ->
|
||||||
> lexList (zipWith (lexCompare ety) (fromVList l) (fromVList r))
|
> lexList (zipWith (lexCompare ety) (fromVList l) (fromVList r))
|
||||||
> TVStream _ ->
|
> TVStream _ ->
|
||||||
@ -1011,6 +1024,8 @@ fields are compared in alphabetical order.
|
|||||||
> evalPanic "lexSignedCompare" ["invalid type"]
|
> evalPanic "lexSignedCompare" ["invalid type"]
|
||||||
> TVIntMod _ ->
|
> TVIntMod _ ->
|
||||||
> evalPanic "lexSignedCompare" ["invalid type"]
|
> evalPanic "lexSignedCompare" ["invalid type"]
|
||||||
|
> TVArray{} ->
|
||||||
|
> evalPanic "lexSignedCompare" ["invalid type"]
|
||||||
> TVSeq _w ety
|
> TVSeq _w ety
|
||||||
> | isTBit ety ->
|
> | isTBit ety ->
|
||||||
> case fromSignedVWord l of
|
> case fromSignedVWord l of
|
||||||
|
@ -30,6 +30,7 @@ data TValue
|
|||||||
= TVBit -- ^ @ Bit @
|
= TVBit -- ^ @ Bit @
|
||||||
| TVInteger -- ^ @ Integer @
|
| TVInteger -- ^ @ Integer @
|
||||||
| TVIntMod Integer -- ^ @ Z n @
|
| TVIntMod Integer -- ^ @ Z n @
|
||||||
|
| TVArray TValue TValue -- ^ @ Array a b @
|
||||||
| TVSeq Integer TValue -- ^ @ [n]a @
|
| TVSeq Integer TValue -- ^ @ [n]a @
|
||||||
| TVStream TValue -- ^ @ [inf]t @
|
| TVStream TValue -- ^ @ [inf]t @
|
||||||
| TVTuple [TValue] -- ^ @ (a, b, c )@
|
| TVTuple [TValue] -- ^ @ (a, b, c )@
|
||||||
@ -45,6 +46,7 @@ tValTy tv =
|
|||||||
TVBit -> tBit
|
TVBit -> tBit
|
||||||
TVInteger -> tInteger
|
TVInteger -> tInteger
|
||||||
TVIntMod n -> tIntMod (tNum n)
|
TVIntMod n -> tIntMod (tNum n)
|
||||||
|
TVArray a b -> tArray (tValTy a) (tValTy b)
|
||||||
TVSeq n t -> tSeq (tNum n) (tValTy t)
|
TVSeq n t -> tSeq (tNum n) (tValTy t)
|
||||||
TVStream t -> tSeq tInf (tValTy t)
|
TVStream t -> tSeq tInf (tValTy t)
|
||||||
TVTuple ts -> tTuple (map tValTy ts)
|
TVTuple ts -> tTuple (map tValTy ts)
|
||||||
@ -105,6 +107,7 @@ evalType env ty =
|
|||||||
(TCIntMod, [n]) -> case num n of
|
(TCIntMod, [n]) -> case num n of
|
||||||
Inf -> evalPanic "evalType" ["invalid type Z inf"]
|
Inf -> evalPanic "evalType" ["invalid type Z inf"]
|
||||||
Nat m -> Right $ TVIntMod m
|
Nat m -> Right $ TVIntMod m
|
||||||
|
(TCArray, [a, b]) -> Right $ TVArray (val a) (val b)
|
||||||
(TCSeq, [n, t]) -> Right $ tvSeq (num n) (val t)
|
(TCSeq, [n, t]) -> Right $ tvSeq (num n) (val t)
|
||||||
(TCFun, [a, b]) -> Right $ TVFun (val a) (val b)
|
(TCFun, [a, b]) -> Right $ TVFun (val a) (val b)
|
||||||
(TCTuple _, _) -> Right $ TVTuple (map val ts)
|
(TCTuple _, _) -> Right $ TVTuple (map val ts)
|
||||||
|
@ -42,14 +42,14 @@ import qualified Cryptol.TypeCheck.AST as T
|
|||||||
import qualified Cryptol.TypeCheck.PP as T
|
import qualified Cryptol.TypeCheck.PP as T
|
||||||
import qualified Cryptol.TypeCheck.Sanity as TcSanity
|
import qualified Cryptol.TypeCheck.Sanity as TcSanity
|
||||||
import Cryptol.Transform.AddModParams (addModParams)
|
import Cryptol.Transform.AddModParams (addModParams)
|
||||||
import Cryptol.Utils.Ident (preludeName, interactiveName
|
import Cryptol.Utils.Ident (preludeName, arrayName, interactiveName
|
||||||
, modNameChunks, notParamInstModName
|
, modNameChunks, notParamInstModName
|
||||||
, isParamInstModName )
|
, isParamInstModName )
|
||||||
import Cryptol.Utils.PP (pretty)
|
import Cryptol.Utils.PP (pretty)
|
||||||
import Cryptol.Utils.Panic (panic)
|
import Cryptol.Utils.Panic (panic)
|
||||||
import Cryptol.Utils.Logger(logPutStrLn, logPrint)
|
import Cryptol.Utils.Logger(logPutStrLn, logPrint)
|
||||||
|
|
||||||
import Cryptol.Prelude (preludeContents)
|
import Cryptol.Prelude (preludeContents, arrayContents)
|
||||||
|
|
||||||
import Cryptol.Transform.MonoValues (rewModule)
|
import Cryptol.Transform.MonoValues (rewModule)
|
||||||
|
|
||||||
@ -259,6 +259,7 @@ findModule n = do
|
|||||||
handleNotFound =
|
handleNotFound =
|
||||||
case n of
|
case n of
|
||||||
m | m == preludeName -> pure (InMem "Cryptol" preludeContents)
|
m | m == preludeName -> pure (InMem "Cryptol" preludeContents)
|
||||||
|
| m == arrayName -> pure (InMem "Array" arrayContents)
|
||||||
_ -> moduleNotFound n =<< getSearchPath
|
_ -> moduleNotFound n =<< getSearchPath
|
||||||
|
|
||||||
-- generate all possible search paths
|
-- generate all possible search paths
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
{-# LANGUAGE FlexibleInstances #-}
|
{-# LANGUAGE FlexibleInstances #-}
|
||||||
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
|
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
|
||||||
{-# LANGUAGE MultiParamTypeClasses #-}
|
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# LANGUAGE RecordWildCards #-}
|
{-# LANGUAGE RecordWildCards #-}
|
||||||
-- for the instances of RunM and BaseM
|
-- for the instances of RunM and BaseM
|
||||||
{-# LANGUAGE UndecidableInstances #-}
|
{-# LANGUAGE UndecidableInstances #-}
|
||||||
@ -221,7 +222,10 @@ nameFixity = nFixity
|
|||||||
asPrim :: Name -> Maybe Ident
|
asPrim :: Name -> Maybe Ident
|
||||||
asPrim Name { .. } =
|
asPrim Name { .. } =
|
||||||
case nInfo of
|
case nInfo of
|
||||||
Declared p _ | p == preludeName -> Just nIdent
|
Declared p _
|
||||||
|
| p == preludeName -> Just nIdent
|
||||||
|
| p == arrayName ->
|
||||||
|
Just $ mkIdent $ modNameToText p <> "::" <> identText nIdent
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
|
|
||||||
toParamInstName :: Name -> Name
|
toParamInstName :: Name -> Name
|
||||||
|
@ -13,7 +13,11 @@
|
|||||||
{-# LANGUAGE QuasiQuotes #-}
|
{-# LANGUAGE QuasiQuotes #-}
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
|
||||||
module Cryptol.Prelude (preludeContents,cryptolTcContents) where
|
module Cryptol.Prelude
|
||||||
|
( preludeContents
|
||||||
|
, arrayContents
|
||||||
|
, cryptolTcContents
|
||||||
|
) where
|
||||||
|
|
||||||
|
|
||||||
import Data.ByteString(ByteString)
|
import Data.ByteString(ByteString)
|
||||||
@ -23,6 +27,9 @@ import Text.Heredoc (there)
|
|||||||
preludeContents :: ByteString
|
preludeContents :: ByteString
|
||||||
preludeContents = B.pack [there|lib/Cryptol.cry|]
|
preludeContents = B.pack [there|lib/Cryptol.cry|]
|
||||||
|
|
||||||
|
arrayContents :: ByteString
|
||||||
|
arrayContents = B.pack [there|lib/Array.cry|]
|
||||||
|
|
||||||
cryptolTcContents :: String
|
cryptolTcContents :: String
|
||||||
cryptolTcContents = [there|lib/CryptolTC.z3|]
|
cryptolTcContents = [there|lib/CryptolTC.z3|]
|
||||||
|
|
||||||
|
@ -348,6 +348,7 @@ typeSize ty =
|
|||||||
TCon (TC (TCNum n)) _ -> Just n
|
TCon (TC (TCNum n)) _ -> Just n
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
(TCIntMod, _) -> Nothing
|
(TCIntMod, _) -> Nothing
|
||||||
|
(TCArray, _) -> Nothing
|
||||||
(TCSeq, [sz,el]) -> case tNoUser sz of
|
(TCSeq, [sz,el]) -> case tNoUser sz of
|
||||||
TCon (TC (TCNum n)) _ -> (^ n) <$> typeSize el
|
TCon (TC (TCNum n)) _ -> (^ n) <$> typeSize el
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
@ -381,6 +382,7 @@ typeValues ty =
|
|||||||
[ TCon (TC (TCNum n)) _ ] | 0 < n ->
|
[ TCon (TC (TCNum n)) _ ] | 0 < n ->
|
||||||
[ VInteger x | x <- [ 0 .. n - 1 ] ]
|
[ VInteger x | x <- [ 0 .. n - 1 ] ]
|
||||||
_ -> []
|
_ -> []
|
||||||
|
TCArray -> []
|
||||||
TCSeq ->
|
TCSeq ->
|
||||||
case map tNoUser ts of
|
case map tNoUser ts of
|
||||||
[ TCon (TC (TCNum n)) _, TCon (TC TCBit) [] ] ->
|
[ TCon (TC (TCNum n)) _, TCon (TC TCBit) [] ] ->
|
||||||
|
@ -42,6 +42,7 @@ builtInType nm =
|
|||||||
case M.nameInfo nm of
|
case M.nameInfo nm of
|
||||||
M.Declared m _
|
M.Declared m _
|
||||||
| m == preludeName -> Map.lookup (M.nameIdent nm) builtInTypes
|
| m == preludeName -> Map.lookup (M.nameIdent nm) builtInTypes
|
||||||
|
| m == arrayName -> Map.lookup (M.nameIdent nm) builtInArray
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
|
|
||||||
where
|
where
|
||||||
@ -81,6 +82,11 @@ builtInType nm =
|
|||||||
, "lengthFromThenTo" ~> TF TCLenFromThenTo
|
, "lengthFromThenTo" ~> TF TCLenFromThenTo
|
||||||
]
|
]
|
||||||
|
|
||||||
|
-- Built-in types from Array.cry
|
||||||
|
builtInArray = Map.fromList
|
||||||
|
[ "Array" ~> TC TCArray
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -115,6 +121,7 @@ instance HasKind TC where
|
|||||||
TCBit -> KType
|
TCBit -> KType
|
||||||
TCInteger -> KType
|
TCInteger -> KType
|
||||||
TCIntMod -> KNum :-> KType
|
TCIntMod -> KNum :-> KType
|
||||||
|
TCArray -> KType :-> KType :-> KType
|
||||||
TCSeq -> KNum :-> KType :-> KType
|
TCSeq -> KNum :-> KType :-> KType
|
||||||
TCFun -> KType :-> KType :-> KType
|
TCFun -> KType :-> KType :-> KType
|
||||||
TCTuple n -> foldr (:->) KType (replicate n KType)
|
TCTuple n -> foldr (:->) KType (replicate n KType)
|
||||||
@ -190,6 +197,7 @@ data TC = TCNum Integer -- ^ Numbers
|
|||||||
| TCBit -- ^ Bit
|
| TCBit -- ^ Bit
|
||||||
| TCInteger -- ^ Integer
|
| TCInteger -- ^ Integer
|
||||||
| TCIntMod -- ^ @Z _@
|
| TCIntMod -- ^ @Z _@
|
||||||
|
| TCArray -- ^ @Array _ _@
|
||||||
| TCSeq -- ^ @[_] _@
|
| TCSeq -- ^ @[_] _@
|
||||||
| TCFun -- ^ @_ -> _@
|
| TCFun -- ^ @_ -> _@
|
||||||
| TCTuple Int -- ^ @(_, _, _)@
|
| TCTuple Int -- ^ @(_, _, _)@
|
||||||
@ -286,6 +294,7 @@ instance PP TC where
|
|||||||
TCBit -> text "Bit"
|
TCBit -> text "Bit"
|
||||||
TCInteger -> text "Integer"
|
TCInteger -> text "Integer"
|
||||||
TCIntMod -> text "Z"
|
TCIntMod -> text "Z"
|
||||||
|
TCArray -> text "Array"
|
||||||
TCSeq -> text "[]"
|
TCSeq -> text "[]"
|
||||||
TCFun -> text "(->)"
|
TCFun -> text "(->)"
|
||||||
TCTuple 0 -> text "()"
|
TCTuple 0 -> text "()"
|
||||||
|
@ -489,6 +489,9 @@ tInteger = TCon (TC TCInteger) []
|
|||||||
tIntMod :: Type -> Type
|
tIntMod :: Type -> Type
|
||||||
tIntMod n = TCon (TC TCIntMod) [n]
|
tIntMod n = TCon (TC TCIntMod) [n]
|
||||||
|
|
||||||
|
tArray :: Type -> Type -> Type
|
||||||
|
tArray a b = TCon (TC TCArray) [a, b]
|
||||||
|
|
||||||
tWord :: Type -> Type
|
tWord :: Type -> Type
|
||||||
tWord a = tSeq a tBit
|
tWord a = tSeq a tBit
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ module Cryptol.Utils.Ident
|
|||||||
, modNameChunks
|
, modNameChunks
|
||||||
, packModName
|
, packModName
|
||||||
, preludeName
|
, preludeName
|
||||||
|
, arrayName
|
||||||
, interactiveName
|
, interactiveName
|
||||||
, noModuleName
|
, noModuleName
|
||||||
, exprModName
|
, exprModName
|
||||||
@ -100,6 +101,9 @@ modInstPref = "`"
|
|||||||
preludeName :: ModName
|
preludeName :: ModName
|
||||||
preludeName = packModName ["Cryptol"]
|
preludeName = packModName ["Cryptol"]
|
||||||
|
|
||||||
|
arrayName :: ModName
|
||||||
|
arrayName = packModName ["Array"]
|
||||||
|
|
||||||
interactiveName :: ModName
|
interactiveName :: ModName
|
||||||
interactiveName = packModName ["<interactive>"]
|
interactiveName = packModName ["<interactive>"]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user