Merge branch 'cλash' of http://git.stderr.nl/matthijs/projects/master-project
[matthijs/master-project/cλash.git] / Bits.hs
1 {-# LANGUAGE FlexibleContexts,GADTs,ExistentialQuantification,LiberalTypeSynonyms,TemplateHaskell #-}
2
3 module Bits where
4
5 import qualified Data.Param.TFVec as TFVec
6 import qualified Types
7 import Language.Haskell.TH.Lift
8
9 --class Signal a where
10 --      hwand :: a -> a -> a
11 --      hwor  :: a -> a -> a
12 --      hwxor :: a -> a -> a
13 --      hwnot :: a -> a
14 --
15 --      -- Prettyprint a signal. We're not extending Show here, since show must
16 --      -- return a valid haskell syntax
17 --      displaysig :: a -> String
18
19 hwand :: Bit -> Bit -> Bit
20 hwor  :: Bit -> Bit -> Bit
21 hwxor :: Bit -> Bit -> Bit
22 hwnot :: Bit -> Bit
23
24 -- Prettyprint Bit signal. We're not extending Show here, since show must
25 -- return Bit valid haskell syntax
26 displaysig :: Bit -> String
27
28 --instance Signal Bit where
29 High `hwand` High = High
30 _ `hwand` _ = Low
31
32 High `hwor` _  = High
33 _ `hwor` High  = High
34 Low `hwor` Low = Low
35
36 High `hwxor` Low = High
37 Low `hwxor` High = High
38 _ `hwxor` _      = Low
39
40 hwnot High = Low
41 hwnot Low  = High
42
43 displaysig High = "1" 
44 displaysig Low  = "0"
45
46 -- The plain Bit type
47 data Bit = High | Low
48   deriving (Show, Eq, Read)
49
50 $(deriveLift1 ''Bit)
51
52 -- A function to prettyprint a bitvector
53
54 --displaysigs :: (Signal s) => [s] -> String
55 displaysigs :: [Bit] -> String
56 displaysigs = (foldl (++) "") . (map displaysig)
57
58 type Stream a = [a]
59
60 -- An infinite streams of highs or lows
61 lows  = Low : lows
62 highs = High : highs
63
64 type BitVec len = TFVec.TFVec len Bit
65
66 -- vim: set ts=8 sw=2 sts=2 expandtab: