@@ -11,6 +11,7 @@ import Core.Evaluate
11import Data.Bits
11import Data.Bits
12import Data.Word
12import Data.Word
13import Data.Int
13import Data.Int
14+import qualified Data.Vector.Unboxed as V
15data Prim = Prim { p_name :: Name,
16data Prim = Prim { p_name :: Name,
16 p_type :: Type,
17 p_type :: Type,
@@ -31,130 +32,130 @@ partial = Partial NotCovering
31primitives :: [Prim]
32primitives :: [Prim]
32primitives =
33primitives =
33 -- operators
34 -- operators
34− [Prim (UN "prim__eqChar") (ty [ChType, ChType] IType) 2 (bcBin (==))
35+ [Prim (UN "prim__eqChar") (ty [ChType, ChType] (AType (ATInt ITNative))) 2 (bcBin (==))
35− (2, LEq ITNative) total,
36+ (2, LEq (ATInt ITNative)) total,
36− Prim (UN "prim__ltChar") (ty [ChType, ChType] IType) 2 (bcBin (<))
37+ Prim (UN "prim__ltChar") (ty [ChType, ChType] (AType (ATInt ITNative))) 2 (bcBin (<))
37− (2, LLt ITNative) total,
38+ (2, LLt (ATInt ITNative)) total,
38− Prim (UN "prim__lteChar") (ty [ChType, ChType] IType) 2 (bcBin (<=))
39+ Prim (UN "prim__lteChar") (ty [ChType, ChType] (AType (ATInt ITNative))) 2 (bcBin (<=))
39− (2, LLe ITNative) total,
40+ (2, LLe (ATInt ITNative)) total,
40− Prim (UN "prim__gtChar") (ty [ChType, ChType] IType) 2 (bcBin (>))
41+ Prim (UN "prim__gtChar") (ty [ChType, ChType] (AType (ATInt ITNative))) 2 (bcBin (>))
41− (2, LGt ITNative) total,
42+ (2, LGt (ATInt ITNative)) total,
42− Prim (UN "prim__gteChar") (ty [ChType, ChType] IType) 2 (bcBin (>=))
43+ Prim (UN "prim__gteChar") (ty [ChType, ChType] (AType (ATInt ITNative))) 2 (bcBin (>=))
43− (2, LGe ITNative) total,
44+ (2, LGe (ATInt ITNative)) total,
45− iCoerce IT8 IT16 "zext" zext LZExt,
46+ iCoerce (ITFixed IT8) (ITFixed IT16) "zext" zext LZExt,
46− iCoerce IT8 IT32 "zext" zext LZExt,
47+ iCoerce (ITFixed IT8) (ITFixed IT32) "zext" zext LZExt,
47− iCoerce IT8 IT64 "zext" zext LZExt,
48+ iCoerce (ITFixed IT8) (ITFixed IT64) "zext" zext LZExt,
48− iCoerce IT8 ITBig "zext" zext LZExt,
49+ iCoerce (ITFixed IT8) ITBig "zext" zext LZExt,
49− iCoerce IT8 ITNative "zext" zext LZExt,
50+ iCoerce (ITFixed IT8) ITNative "zext" zext LZExt,
50− iCoerce IT16 IT32 "zext" zext LZExt,
51+ iCoerce (ITFixed IT16) (ITFixed IT32) "zext" zext LZExt,
51− iCoerce IT16 IT64 "zext" zext LZExt,
52+ iCoerce (ITFixed IT16) (ITFixed IT64) "zext" zext LZExt,
52− iCoerce IT16 ITBig "zext" zext LZExt,
53+ iCoerce (ITFixed IT16) ITBig "zext" zext LZExt,
53− iCoerce IT16 ITNative "zext" zext LZExt,
54+ iCoerce (ITFixed IT16) ITNative "zext" zext LZExt,
54− iCoerce IT32 IT64 "zext" zext LZExt,
55+ iCoerce (ITFixed IT32) (ITFixed IT64) "zext" zext LZExt,
55− iCoerce IT32 ITBig "zext" zext LZExt,
56+ iCoerce (ITFixed IT32) ITBig "zext" zext LZExt,
56− iCoerce IT32 ITNative "zext" zext LZExt,
57+ iCoerce (ITFixed IT32) ITNative "zext" zext LZExt,
57− iCoerce IT64 ITBig "zext" zext LZExt,
58+ iCoerce (ITFixed IT64) ITBig "zext" zext LZExt,
58 iCoerce ITNative ITBig "zext" zext LZExt,
59 iCoerce ITNative ITBig "zext" zext LZExt,
59− iCoerce ITNative IT64 "zext" zext LZExt,
60+ iCoerce ITNative (ITFixed IT64) "zext" zext LZExt,
60− iCoerce ITNative IT32 "zext" zext LZExt,
61+ iCoerce ITNative (ITFixed IT32) "zext" zext LZExt,
61− iCoerce ITNative IT16 "zext" zext LZExt,
62+ iCoerce ITNative (ITFixed IT16) "zext" zext LZExt,
63− iCoerce IT8 IT16 "sext" sext LSExt,
64+ iCoerce (ITFixed IT8) (ITFixed IT16) "sext" sext LSExt,
64− iCoerce IT8 IT32 "sext" sext LSExt,
65+ iCoerce (ITFixed IT8) (ITFixed IT32) "sext" sext LSExt,
65− iCoerce IT8 IT64 "sext" sext LSExt,
66+ iCoerce (ITFixed IT8) (ITFixed IT64) "sext" sext LSExt,
66− iCoerce IT8 ITBig "sext" sext LSExt,
67+ iCoerce (ITFixed IT8) ITBig "sext" sext LSExt,
67− iCoerce IT8 ITNative "sext" sext LSExt,
68+ iCoerce (ITFixed IT8) ITNative "sext" sext LSExt,
68− iCoerce IT16 IT32 "sext" sext LSExt,
69+ iCoerce (ITFixed IT16) (ITFixed IT32) "sext" sext LSExt,
69− iCoerce IT16 IT64 "sext" sext LSExt,
70+ iCoerce (ITFixed IT16) (ITFixed IT64) "sext" sext LSExt,
70− iCoerce IT16 ITBig "sext" sext LSExt,
71+ iCoerce (ITFixed IT16) ITBig "sext" sext LSExt,
71− iCoerce IT16 ITNative "sext" sext LSExt,
72+ iCoerce (ITFixed IT16) ITNative "sext" sext LSExt,
72− iCoerce IT32 IT64 "sext" sext LSExt,
73+ iCoerce (ITFixed IT32) (ITFixed IT64) "sext" sext LSExt,
73− iCoerce IT32 ITBig "sext" sext LSExt,
74+ iCoerce (ITFixed IT32) ITBig "sext" sext LSExt,
74− iCoerce IT32 ITNative "sext" sext LSExt,
75+ iCoerce (ITFixed IT32) ITNative "sext" sext LSExt,
75− iCoerce IT64 ITBig "sext" sext LSExt,
76+ iCoerce (ITFixed IT64) ITBig "sext" sext LSExt,
76 iCoerce ITNative ITBig "sext" sext LSExt,
77 iCoerce ITNative ITBig "sext" sext LSExt,
77 iCoerce ITNative ITBig "sext" sext LSExt,
78 iCoerce ITNative ITBig "sext" sext LSExt,
78− iCoerce ITNative IT64 "sext" sext LSExt,
79+ iCoerce ITNative (ITFixed IT64) "sext" sext LSExt,
79− iCoerce ITNative IT32 "sext" sext LSExt,
80+ iCoerce ITNative (ITFixed IT32) "sext" sext LSExt,
80− iCoerce ITNative IT16 "sext" sext LSExt,
81+ iCoerce ITNative (ITFixed IT16) "sext" sext LSExt,
82− iCoerce IT16 IT8 "trunc" trunc LTrunc,
83+ iCoerce (ITFixed IT16) (ITFixed IT8) "trunc" trunc LTrunc,
83− iCoerce IT32 IT8 "trunc" trunc LTrunc,
84+ iCoerce (ITFixed IT32) (ITFixed IT8) "trunc" trunc LTrunc,
84− iCoerce IT64 IT8 "trunc" trunc LTrunc,
85+ iCoerce (ITFixed IT64) (ITFixed IT8) "trunc" trunc LTrunc,
85− iCoerce ITBig IT8 "trunc" trunc LTrunc,
86+ iCoerce ITBig (ITFixed IT8) "trunc" trunc LTrunc,
86− iCoerce ITNative IT8 "trunc" trunc LTrunc,
87+ iCoerce ITNative (ITFixed IT8) "trunc" trunc LTrunc,
87− iCoerce IT32 IT16 "trunc" trunc LTrunc,
88+ iCoerce (ITFixed IT32) (ITFixed IT16) "trunc" trunc LTrunc,
88− iCoerce IT64 IT16 "trunc" trunc LTrunc,
89+ iCoerce (ITFixed IT64) (ITFixed IT16) "trunc" trunc LTrunc,
89− iCoerce ITBig IT16 "trunc" trunc LTrunc,
90+ iCoerce ITBig (ITFixed IT16) "trunc" trunc LTrunc,
90− iCoerce ITNative IT16 "trunc" trunc LTrunc,
91+ iCoerce ITNative (ITFixed IT16) "trunc" trunc LTrunc,
91− iCoerce IT64 IT32 "trunc" trunc LTrunc,
92+ iCoerce (ITFixed IT64) (ITFixed IT32) "trunc" trunc LTrunc,
92− iCoerce ITBig IT32 "trunc" trunc LTrunc,
93+ iCoerce ITBig (ITFixed IT32) "trunc" trunc LTrunc,
93− iCoerce ITNative IT32 "trunc" trunc LTrunc,
94+ iCoerce ITNative (ITFixed IT32) "trunc" trunc LTrunc,
94− iCoerce ITBig IT64 "trunc" trunc LTrunc,
95+ iCoerce ITBig (ITFixed IT64) "trunc" trunc LTrunc,
95− iCoerce IT16 ITNative "trunc" trunc LTrunc,
96+ iCoerce (ITFixed IT16) ITNative "trunc" trunc LTrunc,
96− iCoerce IT32 ITNative "trunc" trunc LTrunc,
97+ iCoerce (ITFixed IT32) ITNative "trunc" trunc LTrunc,
97− iCoerce IT64 ITNative "trunc" trunc LTrunc,
98+ iCoerce (ITFixed IT64) ITNative "trunc" trunc LTrunc,
98 iCoerce ITBig ITNative "trunc" trunc LTrunc,
99 iCoerce ITBig ITNative "trunc" trunc LTrunc,
99− iCoerce ITNative IT64 "trunc" trunc LTrunc,
100+ iCoerce ITNative (ITFixed IT64) "trunc" trunc LTrunc,
101− Prim (UN "prim__addFloat") (ty [FlType, FlType] FlType) 2 (fBin (+))
102+ Prim (UN "prim__addFloat") (ty [(AType ATFloat), (AType ATFloat)] (AType ATFloat)) 2 (fBin (+))
102− (2, LFPlus) total,
103+ (2, LPlus ATFloat) total,
103− Prim (UN "prim__subFloat") (ty [FlType, FlType] FlType) 2 (fBin (-))
104+ Prim (UN "prim__subFloat") (ty [(AType ATFloat), (AType ATFloat)] (AType ATFloat)) 2 (fBin (-))
104− (2, LFMinus) total,
105+ (2, LMinus ATFloat) total,
105− Prim (UN "prim__mulFloat") (ty [FlType, FlType] FlType) 2 (fBin (*))
106+ Prim (UN "prim__mulFloat") (ty [(AType ATFloat), (AType ATFloat)] (AType ATFloat)) 2 (fBin (*))
106− (2, LFTimes) total,
107+ (2, LTimes ATFloat) total,
107− Prim (UN "prim__divFloat") (ty [FlType, FlType] FlType) 2 (fBin (/))
108+ Prim (UN "prim__divFloat") (ty [(AType ATFloat), (AType ATFloat)] (AType ATFloat)) 2 (fBin (/))
108− (2, LFDiv) total,
109+ (2, LSDiv ATFloat) total,
109− Prim (UN "prim__eqFloat") (ty [FlType, FlType] IType) 2 (bfBin (==))
110+ Prim (UN "prim__eqFloat") (ty [(AType ATFloat), (AType ATFloat)] (AType (ATInt ITNative))) 2 (bfBin (==))
110− (2, LFEq) total,
111+ (2, LEq ATFloat) total,
111− Prim (UN "prim__ltFloat") (ty [FlType, FlType] IType) 2 (bfBin (<))
112+ Prim (UN "prim__ltFloat") (ty [(AType ATFloat), (AType ATFloat)] (AType (ATInt ITNative))) 2 (bfBin (<))
112− (2, LFLt) total,
113+ (2, LLt ATFloat) total,
113− Prim (UN "prim__lteFloat") (ty [FlType, FlType] IType) 2 (bfBin (<=))
114+ Prim (UN "prim__lteFloat") (ty [(AType ATFloat), (AType ATFloat)] (AType (ATInt ITNative))) 2 (bfBin (<=))
114− (2, LFLe) total,
115+ (2, LLe ATFloat) total,
115− Prim (UN "prim__gtFloat") (ty [FlType, FlType] IType) 2 (bfBin (>))
116+ Prim (UN "prim__gtFloat") (ty [(AType ATFloat), (AType ATFloat)] (AType (ATInt ITNative))) 2 (bfBin (>))
116− (2, LFGt) total,
117+ (2, LGt ATFloat) total,
117− Prim (UN "prim__gteFloat") (ty [FlType, FlType] IType) 2 (bfBin (>=))
118+ Prim (UN "prim__gteFloat") (ty [(AType ATFloat), (AType ATFloat)] (AType (ATInt ITNative))) 2 (bfBin (>=))
118− (2, LFGe) total,
119+ (2, LGe ATFloat) total,
119 Prim (UN "prim__concat") (ty [StrType, StrType] StrType) 2 (sBin (++))
120 Prim (UN "prim__concat") (ty [StrType, StrType] StrType) 2 (sBin (++))
120 (2, LStrConcat) total,
121 (2, LStrConcat) total,
121− Prim (UN "prim__eqString") (ty [StrType, StrType] IType) 2 (bsBin (==))
122+ Prim (UN "prim__eqString") (ty [StrType, StrType] (AType (ATInt ITNative))) 2 (bsBin (==))
122 (2, LStrEq) total,
123 (2, LStrEq) total,
123− Prim (UN "prim__ltString") (ty [StrType, StrType] IType) 2 (bsBin (<))
124+ Prim (UN "prim__ltString") (ty [StrType, StrType] (AType (ATInt ITNative))) 2 (bsBin (<))
124 (2, LStrLt) total,
125 (2, LStrLt) total,
125− Prim (UN "prim_lenString") (ty [StrType] IType) 1 (p_strLen)
126+ Prim (UN "prim_lenString") (ty [StrType] (AType (ATInt ITNative))) 1 (p_strLen)
126 (1, LStrLen) total,
127 (1, LStrLen) total,
127 -- Conversions
128 -- Conversions
128− Prim (UN "prim__charToInt") (ty [ChType] IType) 1 (c_charToInt)
129+ Prim (UN "prim__charToInt") (ty [ChType] (AType (ATInt ITNative))) 1 (c_charToInt)
129 (1, LChInt ITNative) total,
130 (1, LChInt ITNative) total,
130− Prim (UN "prim__intToChar") (ty [IType] ChType) 1 (c_intToChar)
131+ Prim (UN "prim__intToChar") (ty [(AType (ATInt ITNative))] ChType) 1 (c_intToChar)
131 (1, LIntCh ITNative) total,
132 (1, LIntCh ITNative) total,
132− Prim (UN "prim__strToFloat") (ty [StrType] FlType) 1 (c_strToFloat)
133+ Prim (UN "prim__strToFloat") (ty [StrType] (AType ATFloat)) 1 (c_strToFloat)
133 (1, LStrFloat) total,
134 (1, LStrFloat) total,
134− Prim (UN "prim__floatToStr") (ty [FlType] StrType) 1 (c_floatToStr)
135+ Prim (UN "prim__floatToStr") (ty [(AType ATFloat)] StrType) 1 (c_floatToStr)
135 (1, LFloatStr) total,
136 (1, LFloatStr) total,
137− Prim (UN "prim__floatExp") (ty [FlType] FlType) 1 (p_floatExp)
138+ Prim (UN "prim__floatExp") (ty [(AType ATFloat)] (AType ATFloat)) 1 (p_floatExp)
138− (1, LFExp) total,
139+ (1, LFExp) total,
139− Prim (UN "prim__floatLog") (ty [FlType] FlType) 1 (p_floatLog)
140+ Prim (UN "prim__floatLog") (ty [(AType ATFloat)] (AType ATFloat)) 1 (p_floatLog)
140 (1, LFLog) total,
141 (1, LFLog) total,
141− Prim (UN "prim__floatSin") (ty [FlType] FlType) 1 (p_floatSin)
142+ Prim (UN "prim__floatSin") (ty [(AType ATFloat)] (AType ATFloat)) 1 (p_floatSin)
142 (1, LFSin) total,
143 (1, LFSin) total,
143− Prim (UN "prim__floatCos") (ty [FlType] FlType) 1 (p_floatCos)
144+ Prim (UN "prim__floatCos") (ty [(AType ATFloat)] (AType ATFloat)) 1 (p_floatCos)
144 (1, LFCos) total,
145 (1, LFCos) total,
145− Prim (UN "prim__floatTan") (ty [FlType] FlType) 1 (p_floatTan)
146+ Prim (UN "prim__floatTan") (ty [(AType ATFloat)] (AType ATFloat)) 1 (p_floatTan)
146 (1, LFTan) total,
147 (1, LFTan) total,
147− Prim (UN "prim__floatASin") (ty [FlType] FlType) 1 (p_floatASin)
148+ Prim (UN "prim__floatASin") (ty [(AType ATFloat)] (AType ATFloat)) 1 (p_floatASin)
148 (1, LFASin) total,
149 (1, LFASin) total,
149− Prim (UN "prim__floatACos") (ty [FlType] FlType) 1 (p_floatACos)
150+ Prim (UN "prim__floatACos") (ty [(AType ATFloat)] (AType ATFloat)) 1 (p_floatACos)
150 (1, LFACos) total,
151 (1, LFACos) total,
151− Prim (UN "prim__floatATan") (ty [FlType] FlType) 1 (p_floatATan)
152+ Prim (UN "prim__floatATan") (ty [(AType ATFloat)] (AType ATFloat)) 1 (p_floatATan)
152 (1, LFATan) total,
153 (1, LFATan) total,
153− Prim (UN "prim__floatSqrt") (ty [FlType] FlType) 1 (p_floatSqrt)
154+ Prim (UN "prim__floatSqrt") (ty [(AType ATFloat)] (AType ATFloat)) 1 (p_floatSqrt)
154 (1, LFSqrt) total,
155 (1, LFSqrt) total,
155− Prim (UN "prim__floatFloor") (ty [FlType] FlType) 1 (p_floatFloor)
156+ Prim (UN "prim__floatFloor") (ty [(AType ATFloat)] (AType ATFloat)) 1 (p_floatFloor)
156 (1, LFFloor) total,
157 (1, LFFloor) total,
157− Prim (UN "prim__floatCeil") (ty [FlType] FlType) 1 (p_floatCeil)
158+ Prim (UN "prim__floatCeil") (ty [(AType ATFloat)] (AType ATFloat)) 1 (p_floatCeil)
158 (1, LFCeil) total,
159 (1, LFCeil) total,
160 Prim (UN "prim__strHead") (ty [StrType] ChType) 1 (p_strHead)
161 Prim (UN "prim__strHead") (ty [StrType] ChType) 1 (p_strHead)
@@ -163,7 +164,7 @@ primitives =
163 (1, LStrTail) partial,
164 (1, LStrTail) partial,
164 Prim (UN "prim__strCons") (ty [ChType, StrType] StrType) 2 (p_strCons)
165 Prim (UN "prim__strCons") (ty [ChType, StrType] StrType) 2 (p_strCons)
165 (2, LStrCons) total,
166 (2, LStrCons) total,
166− Prim (UN "prim__strIndex") (ty [StrType, IType] ChType) 2 (p_strIndex)
167+ Prim (UN "prim__strIndex") (ty [StrType, (AType (ATInt ITNative))] ChType) 2 (p_strIndex)
167 (2, LStrIndex) partial,
168 (2, LStrIndex) partial,
168 Prim (UN "prim__strRev") (ty [StrType] StrType) 1 (p_strRev)
169 Prim (UN "prim__strRev") (ty [StrType] StrType) 1 (p_strRev)
169 (1, LStrRev) total,
170 (1, LStrRev) total,
@@ -174,22 +175,30 @@ primitives =
174 -- Streams
175 -- Streams
175 Prim (UN "prim__stdin") (ty [] PtrType) 0 (p_cantreduce)
176 Prim (UN "prim__stdin") (ty [] PtrType) 0 (p_cantreduce)
176 (0, LStdIn) partial
177 (0, LStdIn) partial
177− ] ++ concatMap intOps [IT8, IT16, IT32, IT64, ITBig, ITNative]
178+ ] ++ concatMap intOps [ITFixed IT8, ITFixed IT16, ITFixed IT32, ITFixed IT64, ITBig, ITNative]
179+ ++ concatMap vecOps [ITVec IT8 16, ITVec IT16 8, ITVec IT32 4, ITVec IT64 2]
179intOps :: IntTy -> [Prim]
181intOps :: IntTy -> [Prim]
180−intOps ity =
182+intOps ity = intCmps ity ++ intArith ity ++ intConv ity
184+intCmps :: IntTy -> [Prim]
181− [ iCmp ity "lt" (bCmp ity (<)) LLt total
186+ [ iCmp ity "lt" False (bCmp ity (<)) (LLt . ATInt) total
182− , iCmp ity "lte" (bCmp ity (<=)) LLe total
187+ , iCmp ity "lte" False (bCmp ity (<=)) (LLe . ATInt) total
183− , iCmp ity "eq" (bCmp ity (==)) LEq total
188+ , iCmp ity "eq" False (bCmp ity (==)) (LEq . ATInt) total
184− , iCmp ity "gte" (bCmp ity (>=)) LGe total
189+ , iCmp ity "gte" False (bCmp ity (>=)) (LGe . ATInt) total
185− , iCmp ity "gt" (bCmp ity (>)) LGt total
190+ , iCmp ity "gt" False (bCmp ity (>)) (LGt . ATInt) total
193+intArith :: IntTy -> [Prim]
186− , iBinOp ity "add" (bitBin ity (+)) LPlus total
195+ [ iBinOp ity "add" (bitBin ity (+)) (LPlus . ATInt) total
187− , iBinOp ity "sub" (bitBin ity (-)) LMinus total
196+ , iBinOp ity "sub" (bitBin ity (-)) (LMinus . ATInt) total
188− , iBinOp ity "mul" (bitBin ity (*)) LTimes total
197+ , iBinOp ity "mul" (bitBin ity (*)) (LTimes . ATInt) total
189 , iBinOp ity "udiv" (bitBin ity div) LUDiv partial
198 , iBinOp ity "udiv" (bitBin ity div) LUDiv partial
190− , iBinOp ity "sdiv" (bsdiv ity) LSDiv partial
199+ , iBinOp ity "sdiv" (bsdiv ity) (LSDiv . ATInt) partial
191 , iBinOp ity "urem" (bitBin ity rem) LURem partial
200 , iBinOp ity "urem" (bitBin ity rem) LURem partial
192− , iBinOp ity "srem" (bsrem ity) LSRem partial
201+ , iBinOp ity "srem" (bsrem ity) (LSRem . ATInt) partial
193 , iBinOp ity "shl" (bitBin ity (\x y -> shiftL x (fromIntegral y))) LSHL total
202 , iBinOp ity "shl" (bitBin ity (\x y -> shiftL x (fromIntegral y))) LSHL total
194 , iBinOp ity "lshr" (bitBin ity (\x y -> shiftR x (fromIntegral y))) LLSHR total
203 , iBinOp ity "lshr" (bitBin ity (\x y -> shiftR x (fromIntegral y))) LLSHR total
195 , iBinOp ity "ashr" (bashr ity) LASHR total
204 , iBinOp ity "ashr" (bashr ity) LASHR total
@@ -197,52 +206,98 @@ intOps ity =
197 , iBinOp ity "or" (bitBin ity (.|.)) LOr total
206 , iBinOp ity "or" (bitBin ity (.|.)) LOr total
198 , iBinOp ity "xor" (bitBin ity (xor)) LXOr total
207 , iBinOp ity "xor" (bitBin ity (xor)) LXOr total
199 , iUnOp ity "compl" (bUn ity complement) LCompl total
208 , iUnOp ity "compl" (bUn ity complement) LCompl total
211+intConv :: IntTy -> [Prim]
200− , Prim (UN $ "prim__toStr" ++ intTyName ity) (ty [intTyToConst ity] StrType) 1 intToStr
213+ [ Prim (UN $ "prim__toStr" ++ intTyName ity) (ty [AType . ATInt $ ity] StrType) 1 intToStr
201 (1, LIntStr ity) total
214 (1, LIntStr ity) total
202− , Prim (UN $ "prim__fromStr" ++ intTyName ity) (ty [StrType] (intTyToConst ity)) 1 (strToInt ity)
215+ , Prim (UN $ "prim__fromStr" ++ intTyName ity) (ty [StrType] (AType . ATInt $ ity)) 1 (strToInt ity)
203 (1, LStrInt ity) total
216 (1, LStrInt ity) total
204− , Prim (UN $ "prim__toFloat" ++ intTyName ity) (ty [intTyToConst ity] FlType) 1 intToFloat
217+ , Prim (UN $ "prim__toFloat" ++ intTyName ity) (ty [AType . ATInt $ ity] (AType ATFloat)) 1 intToFloat
205 (1, LIntFloat ity) total
218 (1, LIntFloat ity) total
206− , Prim (UN $ "prim__fromFloat" ++ intTyName ity) (ty [FlType] (intTyToConst ity)) 1 (floatToInt ity)
219+ , Prim (UN $ "prim__fromFloat" ++ intTyName ity) (ty [AType ATFloat] (AType . ATInt $ ity)) 1 (floatToInt ity)
207 (1, LFloatInt ity) total
220 (1, LFloatInt ity) total
223+vecCmps :: IntTy -> [Prim]
225+ [ iCmp ity "lt" True (bCmp ity (<)) (LLt . ATInt) total
226+ , iCmp ity "lte" True (bCmp ity (<=)) (LLe . ATInt) total
227+ , iCmp ity "eq" True (bCmp ity (==)) (LEq . ATInt) total
228+ , iCmp ity "gte" True (bCmp ity (>=)) (LGe . ATInt) total
229+ , iCmp ity "gt" True (bCmp ity (>)) (LGt . ATInt) total
232+vecOps :: IntTy -> [Prim]
233+vecOps ity@(ITVec elem count) =
234+ [ Prim (UN $ "prim__mk" ++ intTyName ity)
235+ (ty (replicate count . AType . ATInt . ITFixed $ elem) (AType . ATInt $ ity))
236+ count (mkVecCon elem count) (count, LMkVec elem count) total
237+ , Prim (UN $ "prim__index" ++ intTyName ity)
238+ (ty [AType . ATInt $ ity, AType (ATInt (ITFixed IT32))] (AType . ATInt . ITFixed $ elem))
239+ 2 (mkVecIndex count) (2, LIdxVec elem count) partial -- TODO: Ensure this reduces
240+ , Prim (UN $ "prim__update" ++ intTyName ity)
241+ (ty [AType . ATInt $ ity, AType (ATInt (ITFixed IT32)), AType . ATInt . ITFixed $ elem]
242+ (AType . ATInt $ ity))
243+ 3 (mkVecUpdate elem count) (3, LUpdateVec elem count) partial -- TODO: Ensure this reduces
244+ ] ++ intArith ity ++ vecCmps ity
246+mkVecCon :: NativeTy -> Int -> [Const] -> Maybe Const
247+mkVecCon ity count args
248+ | length ints == count = Just (mkVec ity count ints)
249+ | otherwise = Nothing
252+ mkVec :: NativeTy -> Int -> [Integer] -> Const
253+ mkVec IT8 len values = B8V $ V.generate len (fromInteger . (values !!))
254+ mkVec IT16 len values = B16V $ V.generate len (fromInteger . (values !!))
255+ mkVec IT32 len values = B32V $ V.generate len (fromInteger . (values !!))
256+ mkVec IT64 len values = B64V $ V.generate len (fromInteger . (values !!))
258+mkVecIndex count [vec, B32 i] = Just (idxVec vec)
260+ idxVec :: Const -> Const
261+ idxVec (B8V v) = B8 $ V.unsafeIndex v (fromIntegral i)
262+ idxVec (B16V v) = B16 $ V.unsafeIndex v (fromIntegral i)
263+ idxVec (B32V v) = B32 $ V.unsafeIndex v (fromIntegral i)
264+ idxVec (B64V v) = B64 $ V.unsafeIndex v (fromIntegral i)
265+mkVecIndex _ _ = Nothing
267+mkVecUpdate ity count [vec, B32 i, newElem] = updateVec vec newElem
269+ updateVec :: Const -> Const -> Maybe Const
270+ updateVec (B8V v) (B8 e) = Just . B8V $ V.unsafeUpdate v (V.singleton (fromIntegral i, e))
271+ updateVec (B16V v) (B16 e) = Just . B16V $ V.unsafeUpdate v (V.singleton (fromIntegral i, e))
272+ updateVec (B32V v) (B32 e) = Just . B32V $ V.unsafeUpdate v (V.singleton (fromIntegral i, e))
273+ updateVec (B64V v) (B64 e) = Just . B64V $ V.unsafeUpdate v (V.singleton (fromIntegral i, e))
210intTyName :: IntTy -> String
275intTyName :: IntTy -> String
211intTyName ITNative = "Int"
276intTyName ITNative = "Int"
212intTyName ITBig = "BigInt"
277intTyName ITBig = "BigInt"
213−intTyName sized = "B" ++ show (intTyWidth sized)
278+intTyName (ITFixed sized) = "B" ++ show (nativeTyWidth sized)
214−
279+intTyName (ITVec ity count) = "B" ++ show (nativeTyWidth ity) ++ "x" ++ show count
215−iCmp, iBinOp, iUnOp :: IntTy -> String -> ([Const] -> Maybe Const) -> (IntTy -> PrimFn) -> Totality -> Prim
281+iCmp :: IntTy -> String -> Bool -> ([Const] -> Maybe Const) -> (IntTy -> PrimFn) -> Totality -> Prim
282+iCmp ity op self impl irop totality
216−iCmp ity op impl irop totality = Prim (UN $ "prim__" ++ op ++ intTyName ity) (ty (replicate 2 $ intTyToConst ity) IType) 2 impl (2, irop ity) totality
283+ = Prim (UN $ "prim__" ++ op ++ intTyName ity)
217−iBinOp ity op impl irop totality = Prim (UN $ "prim__" ++ op ++ intTyName ity) (ty (replicate 2 $ intTyToConst ity) (intTyToConst ity)) 2 impl (2, irop ity) totality
284+ (ty (replicate 2 . AType . ATInt $ ity) (AType (ATInt (if self then ity else ITNative))))
218−iUnOp ity op impl irop totality = Prim (UN $ "prim__" ++ op ++ intTyName ity) (ty [intTyToConst ity] (intTyToConst ity)) 1 impl (1, irop ity) totality
285+ 2 impl (2, irop ity) totality
287+iBinOp, iUnOp :: IntTy -> String -> ([Const] -> Maybe Const) -> (IntTy -> PrimFn) -> Totality -> Prim
288+iBinOp ity op impl irop totality
289+ = Prim (UN $ "prim__" ++ op ++ intTyName ity)
290+ (ty (replicate 2 . AType . ATInt $ ity) (AType . ATInt $ ity))
291+ 2 impl (2, irop ity) totality
292+iUnOp ity op impl irop totality
293+ = Prim (UN $ "prim__" ++ op ++ intTyName ity)
294+ (ty [AType . ATInt $ ity] (AType . ATInt $ ity))
295+ 1 impl (1, irop ity) totality
220iCoerce :: IntTy -> IntTy -> String -> (IntTy -> IntTy -> [Const] -> Maybe Const) -> (IntTy -> IntTy -> PrimFn) -> Prim
297iCoerce :: IntTy -> IntTy -> String -> (IntTy -> IntTy -> [Const] -> Maybe Const) -> (IntTy -> IntTy -> PrimFn) -> Prim
221iCoerce from to op impl irop =
298iCoerce from to op impl irop =
222 Prim (UN $ "prim__" ++ op ++ intTyName from ++ "_" ++ intTyName to)
299 Prim (UN $ "prim__" ++ op ++ intTyName from ++ "_" ++ intTyName to)
223− (ty [intTyToConst from] (intTyToConst to)) 1 (impl from to) (1, irop from to) total
300+ (ty [AType . ATInt $ from] (AType . ATInt $ to)) 1 (impl from to) (1, irop from to) total
225−iUn :: (Int -> Int) -> [Const] -> Maybe Const
226−iUn op [I x] = Just $ I (op x)
229−iBin :: (Int -> Int -> Int) -> [Const] -> Maybe Const
230−iBin op [I x, I y] = Just $ I (op x y)
233−bBin :: (Integer -> Integer -> Integer) -> [Const] -> Maybe Const
234−bBin op [BI x, BI y] = Just $ BI (op x y)
237−bBini :: (Integer -> Integer -> Int) -> [Const] -> Maybe Const
238−bBini op [BI x, BI y] = Just $ I (op x y)
241−biBin :: (Int -> Int -> Bool) -> [Const] -> Maybe Const
242−biBin op = iBin (\x y -> if (op x y) then 1 else 0)
244−bbBin :: (Integer -> Integer -> Bool) -> [Const] -> Maybe Const
245−bbBin op = bBini (\x y -> if (op x y) then 1 else 0)
247fBin :: (Double -> Double -> Double) -> [Const] -> Maybe Const
302fBin :: (Double -> Double -> Double) -> [Const] -> Maybe Const
248fBin op [Fl x, Fl y] = Just $ Fl (op x y)
303fBin op [Fl x, Fl y] = Just $ Fl (op x y)
@@ -269,81 +324,133 @@ sBin op [Str x, Str y] = Just $ Str (op x y)
269sBin _ _ = Nothing
324sBin _ _ = Nothing
271bsrem :: IntTy -> [Const] -> Maybe Const
326bsrem :: IntTy -> [Const] -> Maybe Const
272−bsrem IT8 [B8 x, B8 y]
327+bsrem (ITFixed IT8) [B8 x, B8 y]
273 = Just $ B8 (fromIntegral (fromIntegral x `rem` fromIntegral y :: Int8))
328 = Just $ B8 (fromIntegral (fromIntegral x `rem` fromIntegral y :: Int8))
274−bsrem IT16 [B16 x, B16 y]
329+bsrem (ITFixed IT16) [B16 x, B16 y]
275 = Just $ B16 (fromIntegral (fromIntegral x `rem` fromIntegral y :: Int16))
330 = Just $ B16 (fromIntegral (fromIntegral x `rem` fromIntegral y :: Int16))
276−bsrem IT32 [B32 x, B32 y]
331+bsrem (ITFixed IT32) [B32 x, B32 y]
277 = Just $ B32 (fromIntegral (fromIntegral x `rem` fromIntegral y :: Int32))
332 = Just $ B32 (fromIntegral (fromIntegral x `rem` fromIntegral y :: Int32))
278−bsrem IT64 [B64 x, B64 y]
333+bsrem (ITFixed IT64) [B64 x, B64 y]
279 = Just $ B64 (fromIntegral (fromIntegral x `rem` fromIntegral y :: Int64))
334 = Just $ B64 (fromIntegral (fromIntegral x `rem` fromIntegral y :: Int64))
280bsrem ITNative [I x, I y] = Just $ I (x `rem` y)
335bsrem ITNative [I x, I y] = Just $ I (x `rem` y)
336+bsrem (ITVec IT8 _) [B8V x, B8V y]
338+ V.zipWith (\n d -> (fromIntegral (fromIntegral n `rem` fromIntegral d :: Int8))) x y
339+bsrem (ITVec IT16 _) [B16V x, B16V y]
341+ V.zipWith (\n d -> (fromIntegral (fromIntegral n `rem` fromIntegral d :: Int16))) x y
342+bsrem (ITVec IT32 _) [B32V x, B32V y]
344+ V.zipWith (\n d -> (fromIntegral (fromIntegral n `rem` fromIntegral d :: Int64))) x y
345+bsrem (ITVec IT64 _) [B64V x, B64V y]
347+ V.zipWith (\n d -> (fromIntegral (fromIntegral n `rem` fromIntegral d :: Int64))) x y
281bsrem _ _ = Nothing
348bsrem _ _ = Nothing
283bsdiv :: IntTy -> [Const] -> Maybe Const
350bsdiv :: IntTy -> [Const] -> Maybe Const
284−bsdiv IT8 [B8 x, B8 y]
351+bsdiv (ITFixed IT8) [B8 x, B8 y]
285 = Just $ B8 (fromIntegral (fromIntegral x `div` fromIntegral y :: Int8))
352 = Just $ B8 (fromIntegral (fromIntegral x `div` fromIntegral y :: Int8))
286−bsdiv IT16 [B16 x, B16 y]
353+bsdiv (ITFixed IT16) [B16 x, B16 y]
287 = Just $ B16 (fromIntegral (fromIntegral x `div` fromIntegral y :: Int16))
354 = Just $ B16 (fromIntegral (fromIntegral x `div` fromIntegral y :: Int16))
288−bsdiv IT32 [B32 x, B32 y]
355+bsdiv (ITFixed IT32) [B32 x, B32 y]
289 = Just $ B32 (fromIntegral (fromIntegral x `div` fromIntegral y :: Int32))
356 = Just $ B32 (fromIntegral (fromIntegral x `div` fromIntegral y :: Int32))
290−bsdiv IT64 [B64 x, B64 y]
357+bsdiv (ITFixed IT64) [B64 x, B64 y]
291 = Just $ B64 (fromIntegral (fromIntegral x `div` fromIntegral y :: Int64))
358 = Just $ B64 (fromIntegral (fromIntegral x `div` fromIntegral y :: Int64))
292bsdiv ITNative [I x, I y] = Just $ I (x `div` y)
359bsdiv ITNative [I x, I y] = Just $ I (x `div` y)
360+bsdiv (ITVec IT8 _) [B8V x, B8V y]
362+ V.zipWith (\n d -> (fromIntegral (fromIntegral n `div` fromIntegral d :: Int8))) x y
363+bsdiv (ITVec IT16 _) [B16V x, B16V y]
365+ V.zipWith (\n d -> (fromIntegral (fromIntegral n `div` fromIntegral d :: Int16))) x y
366+bsdiv (ITVec IT32 _) [B32V x, B32V y]
368+ V.zipWith (\n d -> (fromIntegral (fromIntegral n `div` fromIntegral d :: Int64))) x y
369+bsdiv (ITVec IT64 _) [B64V x, B64V y]
371+ V.zipWith (\n d -> (fromIntegral (fromIntegral n `div` fromIntegral d :: Int64))) x y
293bsdiv _ _ = Nothing
372bsdiv _ _ = Nothing
295bashr :: IntTy -> [Const] -> Maybe Const
374bashr :: IntTy -> [Const] -> Maybe Const
296−bashr IT8 [B8 x, B8 y]
375+bashr (ITFixed IT8) [B8 x, B8 y]
297 = Just $ B8 (fromIntegral (fromIntegral x `shiftR` fromIntegral y :: Int8))
376 = Just $ B8 (fromIntegral (fromIntegral x `shiftR` fromIntegral y :: Int8))
298−bashr IT16 [B16 x, B16 y]
377+bashr (ITFixed IT16) [B16 x, B16 y]
299 = Just $ B16 (fromIntegral (fromIntegral x `shiftR` fromIntegral y :: Int16))
378 = Just $ B16 (fromIntegral (fromIntegral x `shiftR` fromIntegral y :: Int16))
300−bashr IT32 [B32 x, B32 y]
379+bashr (ITFixed IT32) [B32 x, B32 y]
301 = Just $ B32 (fromIntegral (fromIntegral x `shiftR` fromIntegral y :: Int32))
380 = Just $ B32 (fromIntegral (fromIntegral x `shiftR` fromIntegral y :: Int32))
302−bashr IT64 [B64 x, B64 y]
381+bashr (ITFixed IT64) [B64 x, B64 y]
303 = Just $ B64 (fromIntegral (fromIntegral x `shiftR` fromIntegral y :: Int64))
382 = Just $ B64 (fromIntegral (fromIntegral x `shiftR` fromIntegral y :: Int64))
304bashr ITNative [I x, I y] = Just $ I (x `shiftR` y)
383bashr ITNative [I x, I y] = Just $ I (x `shiftR` y)
384+bashr (ITVec IT8 _) [B8V x, B8V y]
386+ V.zipWith (\n d -> (fromIntegral (fromIntegral n `shiftR` fromIntegral d :: Int8))) x y
387+bashr (ITVec IT16 _) [B16V x, B16V y]
389+ V.zipWith (\n d -> (fromIntegral (fromIntegral n `shiftR` fromIntegral d :: Int16))) x y
390+bashr (ITVec IT32 _) [B32V x, B32V y]
392+ V.zipWith (\n d -> (fromIntegral (fromIntegral n `shiftR` fromIntegral d :: Int64))) x y
393+bashr (ITVec IT64 _) [B64V x, B64V y]
395+ V.zipWith (\n d -> (fromIntegral (fromIntegral n `shiftR` fromIntegral d :: Int64))) x y
305bashr _ _ = Nothing
396bashr _ _ = Nothing
307bUn :: IntTy -> (forall a. Bits a => a -> a) -> [Const] -> Maybe Const
398bUn :: IntTy -> (forall a. Bits a => a -> a) -> [Const] -> Maybe Const
308−bUn IT8 op [B8 x] = Just $ B8 (op x)
399+bUn (ITFixed IT8) op [B8 x] = Just $ B8 (op x)
309−bUn IT16 op [B16 x] = Just $ B16 (op x)
400+bUn (ITFixed IT16) op [B16 x] = Just $ B16 (op x)
310−bUn IT32 op [B32 x] = Just $ B32 (op x)
401+bUn (ITFixed IT32) op [B32 x] = Just $ B32 (op x)
311−bUn IT64 op [B64 x] = Just $ B64 (op x)
402+bUn (ITFixed IT64) op [B64 x] = Just $ B64 (op x)
312bUn ITBig op [BI x] = Just $ BI (op x)
403bUn ITBig op [BI x] = Just $ BI (op x)
313bUn ITNative op [I x] = Just $ I (op x)
404bUn ITNative op [I x] = Just $ I (op x)
405+bUn (ITVec IT8 _) op [B8V x] = Just . B8V $ V.map op x
406+bUn (ITVec IT16 _) op [B16V x] = Just . B16V $ V.map op x
407+bUn (ITVec IT32 _) op [B32V x] = Just . B32V $ V.map op x
408+bUn (ITVec IT64 _) op [B64V x] = Just . B64V $ V.map op x
314bUn _ _ _ = Nothing
409bUn _ _ _ = Nothing
316bitBin :: IntTy -> (forall a. (Bits a, Integral a) => a -> a -> a) -> [Const] -> Maybe Const
411bitBin :: IntTy -> (forall a. (Bits a, Integral a) => a -> a -> a) -> [Const] -> Maybe Const
317−bitBin IT8 op [B8 x, B8 y] = Just $ B8 (op x y)
412+bitBin (ITFixed IT8) op [B8 x, B8 y] = Just $ B8 (op x y)
318−bitBin IT16 op [B16 x, B16 y] = Just $ B16 (op x y)
413+bitBin (ITFixed IT16) op [B16 x, B16 y] = Just $ B16 (op x y)
319−bitBin IT32 op [B32 x, B32 y] = Just $ B32 (op x y)
414+bitBin (ITFixed IT32) op [B32 x, B32 y] = Just $ B32 (op x y)
320−bitBin IT64 op [B64 x, B64 y] = Just $ B64 (op x y)
415+bitBin (ITFixed IT64) op [B64 x, B64 y] = Just $ B64 (op x y)
321bitBin ITBig op [BI x, BI y] = Just $ BI (op x y)
416bitBin ITBig op [BI x, BI y] = Just $ BI (op x y)
322bitBin ITNative op [I x, I y] = Just $ I (op x y)
417bitBin ITNative op [I x, I y] = Just $ I (op x y)
418+bitBin (ITVec IT8 _) op [B8V x, B8V y] = Just . B8V $ V.zipWith op x y
419+bitBin (ITVec IT16 _) op [B16V x, B16V y] = Just . B16V $ V.zipWith op x y
420+bitBin (ITVec IT32 _) op [B32V x, B32V y] = Just . B32V $ V.zipWith op x y
421+bitBin (ITVec IT64 _) op [B64V x, B64V y] = Just . B64V $ V.zipWith op x y
323bitBin _ _ _ = Nothing
422bitBin _ _ _ = Nothing
325bCmp :: IntTy -> (forall a. Ord a => a -> a -> Bool) -> [Const] -> Maybe Const
424bCmp :: IntTy -> (forall a. Ord a => a -> a -> Bool) -> [Const] -> Maybe Const
326−bCmp IT8 op [B8 x, B8 y] = Just $ I (if (op x y) then 1 else 0)
425+bCmp (ITFixed IT8) op [B8 x, B8 y] = Just $ I (if (op x y) then 1 else 0)
327−bCmp IT16 op [B16 x, B16 y] = Just $ I (if (op x y) then 1 else 0)
426+bCmp (ITFixed IT16) op [B16 x, B16 y] = Just $ I (if (op x y) then 1 else 0)
328−bCmp IT32 op [B32 x, B32 y] = Just $ I (if (op x y) then 1 else 0)
427+bCmp (ITFixed IT32) op [B32 x, B32 y] = Just $ I (if (op x y) then 1 else 0)
329−bCmp IT64 op [B64 x, B64 y] = Just $ I (if (op x y) then 1 else 0)
428+bCmp (ITFixed IT64) op [B64 x, B64 y] = Just $ I (if (op x y) then 1 else 0)
330bCmp ITBig op [BI x, BI y] = Just $ I (if (op x y) then 1 else 0)
429bCmp ITBig op [BI x, BI y] = Just $ I (if (op x y) then 1 else 0)
331bCmp ITNative op [I x, I y] = Just $ I (if (op x y) then 1 else 0)
430bCmp ITNative op [I x, I y] = Just $ I (if (op x y) then 1 else 0)
431+bCmp (ITVec IT8 _) op [B8V x, B8V y]
432+ = Just . B8V . V.map (\b -> if b then -1 else 0) $ V.zipWith op x y
433+bCmp (ITVec IT16 _) op [B16V x, B16V y]
434+ = Just . B16V . V.map (\b -> if b then -1 else 0) $ V.zipWith op x y
435+bCmp (ITVec IT32 _) op [B32V x, B32V y]
436+ = Just . B32V . V.map (\b -> if b then -1 else 0) $ V.zipWith op x y
437+bCmp (ITVec IT64 _) op [B64V x, B64V y]
438+ = Just . B64V . V.map (\b -> if b then -1 else 0) $ V.zipWith op x y
332bCmp _ _ _ = Nothing
439bCmp _ _ _ = Nothing
334toInt :: Integral a => IntTy -> a -> Const
441toInt :: Integral a => IntTy -> a -> Const
335−toInt IT8 x = B8 (fromIntegral x)
442+toInt (ITFixed IT8) x = B8 (fromIntegral x)
336−toInt IT16 x = B16 (fromIntegral x)
443+toInt (ITFixed IT16) x = B16 (fromIntegral x)
337−toInt IT32 x = B32 (fromIntegral x)
444+toInt (ITFixed IT32) x = B32 (fromIntegral x)
338−toInt IT64 x = B64 (fromIntegral x)
445+toInt (ITFixed IT64) x = B64 (fromIntegral x)
339toInt ITBig x = BI (fromIntegral x)
446toInt ITBig x = BI (fromIntegral x)
340toInt ITNative x = I (fromIntegral x)
447toInt ITNative x = I (fromIntegral x)
342intToInt :: IntTy -> IntTy -> [Const] -> Maybe Const
449intToInt :: IntTy -> IntTy -> [Const] -> Maybe Const
343−intToInt IT8 out [B8 x] = Just $ toInt out x
450+intToInt (ITFixed IT8) out [B8 x] = Just $ toInt out x
344−intToInt IT16 out [B16 x] = Just $ toInt out x
451+intToInt (ITFixed IT16) out [B16 x] = Just $ toInt out x
345−intToInt IT32 out [B32 x] = Just $ toInt out x
452+intToInt (ITFixed IT32) out [B32 x] = Just $ toInt out x
346−intToInt IT64 out [B64 x] = Just $ toInt out x
453+intToInt (ITFixed IT64) out [B64 x] = Just $ toInt out x
347intToInt ITBig out [BI x] = Just $ toInt out x
454intToInt ITBig out [BI x] = Just $ toInt out x
348intToInt ITNative out [I x] = Just $ toInt out x
455intToInt ITNative out [I x] = Just $ toInt out x
349intToInt _ _ _ = Nothing
456intToInt _ _ _ = Nothing
@@ -356,10 +463,10 @@ zext from to val
356zext _ _ _ = Nothing
463zext _ _ _ = Nothing
358sext :: IntTy -> IntTy -> [Const] -> Maybe Const
465sext :: IntTy -> IntTy -> [Const] -> Maybe Const
359−sext IT8 out [B8 x] = Just $ toInt out (fromIntegral x :: Int8)
466+sext (ITFixed IT8) out [B8 x] = Just $ toInt out (fromIntegral x :: Int8)
360−sext IT16 out [B16 x] = Just $ toInt out (fromIntegral x :: Int16)
467+sext (ITFixed IT16) out [B16 x] = Just $ toInt out (fromIntegral x :: Int16)
361−sext IT32 out [B32 x] = Just $ toInt out (fromIntegral x :: Int32)
468+sext (ITFixed IT32) out [B32 x] = Just $ toInt out (fromIntegral x :: Int32)
362−sext IT64 out [B64 x] = Just $ toInt out (fromIntegral x :: Int64)
469+sext (ITFixed IT64) out [B64 x] = Just $ toInt out (fromIntegral x :: Int64)
363sext ITBig _ _ = Nothing
470sext ITBig _ _ = Nothing
364sext from to val = intToInt from to val
471sext from to val = intToInt from to val
@@ -369,19 +476,19 @@ trunc _ ITBig _ = Nothing
369trunc from to val | intTyWidth from > intTyWidth to = intToInt from to val
476trunc from to val | intTyWidth from > intTyWidth to = intToInt from to val
370trunc _ _ _ = Nothing
477trunc _ _ _ = Nothing
372−getInt :: [Const] -> Maybe Integer
373−getInt [B8 x] = Just . toInteger $ x
374−getInt [B16 x] = Just . toInteger $ x
375−getInt [B32 x] = Just . toInteger $ x
376−getInt [B64 x] = Just . toInteger $ x
377−getInt [I x] = Just . toInteger $ x
378−getInt [BI x] = Just x
381intToStr :: [Const] -> Maybe Const
479intToStr :: [Const] -> Maybe Const
382−intToStr val | Just i <- getInt val = Just $ Str (show i)
480+intToStr val | [i] <- getInt val = Just $ Str (show i)
383intToStr _ = Nothing
481intToStr _ = Nothing
483+getInt :: [Const] -> [Integer]
484+getInt (B8 x : xs) = toInteger x : getInt xs
485+getInt (B16 x : xs) = toInteger x : getInt xs
486+getInt (B32 x : xs) = toInteger x : getInt xs
487+getInt (B64 x : xs) = toInteger x : getInt xs
488+getInt (I x : xs) = toInteger x : getInt xs
489+getInt (BI x : xs) = x : getInt xs
385strToInt :: IntTy -> [Const] -> Maybe Const
492strToInt :: IntTy -> [Const] -> Maybe Const
386strToInt ity [Str x] = case reads x of
493strToInt ity [Str x] = case reads x of
387 [(n,"")] -> Just $ toInt ity (n :: Integer)
494 [(n,"")] -> Just $ toInt ity (n :: Integer)
@@ -389,7 +496,7 @@ strToInt ity [Str x] = case reads x of
389strToInt _ _ = Nothing
496strToInt _ _ = Nothing
391intToFloat :: [Const] -> Maybe Const
498intToFloat :: [Const] -> Maybe Const
392−intToFloat val | Just i <- getInt val = Just $ Fl (fromIntegral i)
499+intToFloat val | [i] <- getInt val = Just $ Fl (fromIntegral i)
393intToFloat _ = Nothing
500intToFloat _ = Nothing
395floatToInt :: IntTy -> [Const] -> Maybe Const
502floatToInt :: IntTy -> [Const] -> Maybe Const