Skip to content

Commit

Permalink
Add "widthNat" to SAWCore prelude, with evaluator support
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Huffman committed May 27, 2014
1 parent b53cc78 commit ecfa781
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
3 changes: 3 additions & 0 deletions prelude/Prelude.sawcore
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ maxNat Zero y = y;
maxNat (Succ x) Zero = Succ x;
maxNat (Succ x) (Succ y) = Succ (maxNat x y);

-- | Width(n) = 1 + floor(log_2(n))
widthNat :: Nat -> Nat;

-- | Axiom: equalNat implements *the* equality on type Nat.
eq_Nat :: Eq (Nat -> Nat -> Bool) (eq Nat) equalNat;

Expand Down
18 changes: 12 additions & 6 deletions src/Verifier/SAW/Prim.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Data.Vector ( Vector )
import qualified Data.Vector as V

------------------------------------------------------------
-- Primitive types
-- Natural numbers

-- | A natural number.
newtype Nat = Nat Integer
Expand Down Expand Up @@ -86,9 +86,14 @@ instance Bits Nat where
popCount (Nat x) = popCount x
#endif

-- data Fin :: (n :: Nat) -> sort 0 where {
-- FinVal :: (x r :: Nat) -> Fin (Succ (addNat r x));
-- }
-- | width(n) = 1 + floor(log_2(n))
widthNat :: Nat -> Nat
widthNat 0 = 0
widthNat n = 1 + widthNat (n `div` 2)

------------------------------------------------------------
-- Finite indices

data Fin = FinVal { finVal :: !Nat, finRem :: Nat }
deriving (Eq, Show)

Expand Down Expand Up @@ -141,8 +146,9 @@ instance Enum Fin where
-- data Vec :: (n :: Nat) -> sort 0 -> sort 0
data Vec t a = Vec t !(Vector a)

-- bitvector :: (n :: Nat) -> sort 0;
-- bitvector n = Vec n Bool;
------------------------------------------------------------
-- Unsigned, variable-width bit vectors

data BitVector = BV { width :: !Int, unsigned :: !Integer }
deriving Show
-- ^ Invariant: BV w x requires that 0 <= x < 2^w.
Expand Down

0 comments on commit ecfa781

Please sign in to comment.