[project @ 1996-07-25 21:02:03 by partain]
[nofib.git] / GHC_ONLY / bugs / jtod_circint / Bit.hs
1 module Bit where
2 import LogFun
3 import Signal
4
5 data Bit = Bot | WeakZero | WeakOne | Zero | One | Top
6 deriving (Eq,Show{-was:Text-})
7
8 instance Static Bit where
9 intToSig = intToSigBit
10 sigToInt = sigToIntBit
11 showStaticSig = showBit
12
13 instance Lattice Bit where
14 bot = Bot
15 top = Top
16 weakZero = WeakZero
17 weakOne = WeakOne
18 lub = lubBit
19 pass = passBit
20
21 instance Signal Bit where
22 showSig = showBit
23 initial = Zero
24 zerO = Zero
25 one = One
26 tt1 = tt1Bit
27 tt2 = tt2Bit
28
29 instance Log Bit where
30 dumLog = Zero
31
32 tt1Bit :: TT1 -> Bit -> Bit
33 tt1Bit (a,b) =
34 let p = intBit a
35 q = intBit b
36 f x = case x of
37 Bot -> Bot
38 Zero -> p
39 One -> q
40 Top -> Top
41 in f
42
43 tt2Bit :: TT2 -> Bit -> Bit -> Bit
44 tt2Bit (a,b,c,d) = f
45 where p = intBit a
46 q = intBit b
47 r = intBit c
48 s = intBit d
49 f x y = case x of
50 Bot -> case y of
51 Bot -> Bot
52 WeakZero -> Bot
53 WeakOne -> Bot
54 Zero -> Bot
55 One -> Bot
56 Top -> Top
57 WeakZero -> case y of
58 Bot -> Bot
59 WeakZero -> p
60 WeakOne -> q
61 Zero -> p
62 One -> q
63 Top -> Top
64 WeakOne -> case y of
65 Bot -> Bot
66 WeakZero -> r
67 WeakOne -> s
68 Zero -> r
69 One -> s
70 Top -> Top
71 Zero -> case y of
72 Bot -> Bot
73 WeakZero -> p
74 WeakOne -> q
75 Zero -> p
76 One -> q
77 Top -> Top
78 One -> case y of
79 Bot -> Bot
80 WeakZero -> r
81 WeakOne -> s
82 Zero -> r
83 One -> s
84 Top -> Top
85 Top -> case y of
86 Bot -> Top
87 WeakZero -> Top
88 WeakOne -> Top
89 Zero -> Top
90 One -> Top
91 Top -> Top
92
93 lubBit :: Bit -> Bit -> Bit
94 lubBit a b =
95 case a of
96 Bot -> case b of
97 Bot -> Bot
98 WeakZero -> WeakZero
99 WeakOne -> WeakOne
100 Zero -> Zero
101 One -> One
102 Top -> Top
103 WeakZero -> case b of
104 Bot -> Zero
105 WeakZero -> WeakZero
106 WeakOne -> Top
107 Zero -> Zero
108 One -> One
109 Top -> Top
110 WeakOne -> case b of
111 Bot -> WeakOne
112 WeakZero -> Top
113 WeakOne -> WeakOne
114 Zero -> Zero
115 One -> One
116 Top -> Top
117 Zero -> case b of
118 Bot -> Zero
119 WeakZero -> Zero
120 WeakOne -> Zero
121 Zero -> Zero
122 One -> Top
123 Top -> Top
124 One -> case b of
125 Bot -> One
126 WeakZero -> One
127 WeakOne -> One
128 Zero -> Top
129 One -> One
130 Top -> Top
131 Top -> case b of
132 Bot -> Top
133 WeakZero -> Top
134 WeakOne -> Top
135 Zero -> Top
136 One -> Top
137 Top -> Top
138
139 showBit :: Bit -> String
140 showBit Bot = "v"
141 showBit WeakZero = "z"
142 showBit WeakOne = "o"
143 showBit Zero = "0"
144 showBit One = "1"
145 showBit Top = "^"
146
147
148 intBit :: Int -> Bit
149 intBit 0 = Zero
150 intBit 1 = One
151 intBit x =
152 error ("\nintBit received bad Int " ++ show x ++ ".\n")
153
154 intToSigBit :: Int -> Bit
155 intToSigBit i
156 | i==0 = Zero
157 | i==1 = One
158 | i==8 = Bot
159 | i==9 = Top
160
161 sigToIntBit :: Bit -> Int
162 sigToIntBit Zero = 0
163 sigToIntBit One = 1
164 sigToIntBit Bot = 8
165 sigToIntBit Top = 9
166
167 passBit :: Bit -> Bit -> Bit
168 passBit c a =
169 case c of
170 Bot -> Bot
171 Zero -> Bot
172 One -> a
173 Top -> Top
174
175 instance Num Bit where
176 (+) = or2
177 (*) = and2
178 a - b = xor a b
179 negate = inv
180 abs = error "abs not defined for Signals"
181 signum = error "signum not defined for Signals"
182 fromInteger = error "fromInteger not defined for Signals"
183