@@ -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,23 @@ 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]
180intOps ity =
182intOps ity =
181− [ iCmp ity "lt" (bCmp ity (<)) LLt total
183+ [ iCmp ity "lt" (bCmp ity (<)) (LLt . ATInt) total
182− , iCmp ity "lte" (bCmp ity (<=)) LLe total
184+ , iCmp ity "lte" (bCmp ity (<=)) (LLe . ATInt) total
183− , iCmp ity "eq" (bCmp ity (==)) LEq total
185+ , iCmp ity "eq" (bCmp ity (==)) (LEq . ATInt) total
184− , iCmp ity "gte" (bCmp ity (>=)) LGe total
186+ , iCmp ity "gte" (bCmp ity (>=)) (LGe . ATInt) total
185− , iCmp ity "gt" (bCmp ity (>)) LGt total
187+ , iCmp ity "gt" (bCmp ity (>)) (LGt . ATInt) total
186− , iBinOp ity "add" (bitBin ity (+)) LPlus total
188+ , iBinOp ity "add" (bitBin ity (+)) (LPlus . ATInt) total
187− , iBinOp ity "sub" (bitBin ity (-)) LMinus total
189+ , iBinOp ity "sub" (bitBin ity (-)) (LMinus . ATInt) total
188− , iBinOp ity "mul" (bitBin ity (*)) LTimes total
190+ , iBinOp ity "mul" (bitBin ity (*)) (LTimes . ATInt) total
189 , iBinOp ity "udiv" (bitBin ity div) LUDiv partial
191 , iBinOp ity "udiv" (bitBin ity div) LUDiv partial
190− , iBinOp ity "sdiv" (bsdiv ity) LSDiv partial
192+ , iBinOp ity "sdiv" (bsdiv ity) (LSDiv . ATInt) partial
191 , iBinOp ity "urem" (bitBin ity rem) LURem partial
193 , iBinOp ity "urem" (bitBin ity rem) LURem partial
192− , iBinOp ity "srem" (bsrem ity) LSRem partial
194+ , iBinOp ity "srem" (bsrem ity) (LSRem . ATInt) partial
193 , iBinOp ity "shl" (bitBin ity (\x y -> shiftL x (fromIntegral y))) LSHL total
195 , 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
196 , iBinOp ity "lshr" (bitBin ity (\x y -> shiftR x (fromIntegral y))) LLSHR total
195 , iBinOp ity "ashr" (bashr ity) LASHR total
197 , iBinOp ity "ashr" (bashr ity) LASHR total
@@ -197,30 +199,57 @@ intOps ity =
197 , iBinOp ity "or" (bitBin ity (.|.)) LOr total
199 , iBinOp ity "or" (bitBin ity (.|.)) LOr total
198 , iBinOp ity "xor" (bitBin ity (xor)) LXOr total
200 , iBinOp ity "xor" (bitBin ity (xor)) LXOr total
199 , iUnOp ity "compl" (bUn ity complement) LCompl total
201 , iUnOp ity "compl" (bUn ity complement) LCompl total
200− , Prim (UN $ "prim__toStr" ++ intTyName ity) (ty [intTyToConst ity] StrType) 1 intToStr
202+ , Prim (UN $ "prim__toStr" ++ intTyName ity) (ty [AType . ATInt $ ity] StrType) 1 intToStr
201 (1, LIntStr ity) total
203 (1, LIntStr ity) total
202− , Prim (UN $ "prim__fromStr" ++ intTyName ity) (ty [StrType] (intTyToConst ity)) 1 (strToInt ity)
204+ , Prim (UN $ "prim__fromStr" ++ intTyName ity) (ty [StrType] (AType . ATInt $ ity)) 1 (strToInt ity)
203 (1, LStrInt ity) total
205 (1, LStrInt ity) total
204− , Prim (UN $ "prim__toFloat" ++ intTyName ity) (ty [intTyToConst ity] FlType) 1 intToFloat
206+ , Prim (UN $ "prim__toFloat" ++ intTyName ity) (ty [AType . ATInt $ ity] (AType ATFloat)) 1 intToFloat
205 (1, LIntFloat ity) total
207 (1, LIntFloat ity) total
206− , Prim (UN $ "prim__fromFloat" ++ intTyName ity) (ty [FlType] (intTyToConst ity)) 1 (floatToInt ity)
208+ , Prim (UN $ "prim__fromFloat" ++ intTyName ity) (ty [AType ATFloat] (AType . ATInt $ ity)) 1 (floatToInt ity)
207 (1, LFloatInt ity) total
209 (1, LFloatInt ity) total
212+vecOps ity@(ITVec elem count) =
213+ [ Prim (UN $ "prim__mk" ++ intTyName ity)
214+ (ty (replicate count . AType . ATInt . ITFixed $ elem) (AType . ATInt $ ity))
215+ count (mkVecCon elem count) (count, LMkVec elem count) total
218+mkVecCon ity count args = if length ints == count
219+ then Just (mkVec ity count ints)
220+ else error $ "Got: " ++ show args ++ " when expecting " ++ show count ++ " x " ++ show ity
223+ mkVec :: NativeTy -> Int -> [Integer] -> Const
224+ mkVec IT8 len values = B8V $ V.generate len (fromInteger . (values !!))
225+ mkVec IT16 len values = B16V $ V.generate len (fromInteger . (values !!))
226+ mkVec IT32 len values = B32V $ V.generate len (fromInteger . (values !!))
227+ mkVec IT64 len values = B64V $ V.generate len (fromInteger . (values !!))
210intTyName :: IntTy -> String
229intTyName :: IntTy -> String
211intTyName ITNative = "Int"
230intTyName ITNative = "Int"
212intTyName ITBig = "BigInt"
231intTyName ITBig = "BigInt"
213−intTyName sized = "B" ++ show (intTyWidth sized)
232+intTyName (ITFixed sized) = "B" ++ show (nativeTyWidth sized)
233+intTyName (ITVec ity count) = "B" ++ show (nativeTyWidth ity) ++ "x" ++ show count
215iCmp, iBinOp, iUnOp :: IntTy -> String -> ([Const] -> Maybe Const) -> (IntTy -> PrimFn) -> Totality -> Prim
235iCmp, iBinOp, iUnOp :: IntTy -> String -> ([Const] -> Maybe Const) -> (IntTy -> PrimFn) -> Totality -> Prim
236+iCmp ity op 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
237+ = 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
238+ (ty (replicate 2 . AType . ATInt $ ity) (AType (ATInt 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
239+ 2 impl (2, irop ity) totality
240+iBinOp ity op impl irop totality
241+ = Prim (UN $ "prim__" ++ op ++ intTyName ity)
242+ (ty (replicate 2 . AType . ATInt $ ity) (AType . ATInt $ ity))
243+ 2 impl (2, irop ity) totality
244+iUnOp ity op impl irop totality
245+ = Prim (UN $ "prim__" ++ op ++ intTyName ity)
246+ (ty [AType . ATInt $ ity] (AType . ATInt $ ity))
247+ 1 impl (1, irop ity) totality
220iCoerce :: IntTy -> IntTy -> String -> (IntTy -> IntTy -> [Const] -> Maybe Const) -> (IntTy -> IntTy -> PrimFn) -> Prim
249iCoerce :: IntTy -> IntTy -> String -> (IntTy -> IntTy -> [Const] -> Maybe Const) -> (IntTy -> IntTy -> PrimFn) -> Prim
221iCoerce from to op impl irop =
250iCoerce from to op impl irop =
222 Prim (UN $ "prim__" ++ op ++ intTyName from ++ "_" ++ intTyName to)
251 Prim (UN $ "prim__" ++ op ++ intTyName from ++ "_" ++ intTyName to)
223− (ty [intTyToConst from] (intTyToConst to)) 1 (impl from to) (1, irop from to) total
252+ (ty [AType . ATInt $ from] (AType . ATInt $ to)) 1 (impl from to) (1, irop from to) total
225iUn :: (Int -> Int) -> [Const] -> Maybe Const
254iUn :: (Int -> Int) -> [Const] -> Maybe Const
226iUn op [I x] = Just $ I (op x)
255iUn op [I x] = Just $ I (op x)
@@ -269,81 +298,81 @@ sBin op [Str x, Str y] = Just $ Str (op x y)
269sBin _ _ = Nothing
298sBin _ _ = Nothing
271bsrem :: IntTy -> [Const] -> Maybe Const
300bsrem :: IntTy -> [Const] -> Maybe Const
272−bsrem IT8 [B8 x, B8 y]
301+bsrem (ITFixed IT8) [B8 x, B8 y]
273 = Just $ B8 (fromIntegral (fromIntegral x `rem` fromIntegral y :: Int8))
302 = Just $ B8 (fromIntegral (fromIntegral x `rem` fromIntegral y :: Int8))
274−bsrem IT16 [B16 x, B16 y]
303+bsrem (ITFixed IT16) [B16 x, B16 y]
275 = Just $ B16 (fromIntegral (fromIntegral x `rem` fromIntegral y :: Int16))
304 = Just $ B16 (fromIntegral (fromIntegral x `rem` fromIntegral y :: Int16))
276−bsrem IT32 [B32 x, B32 y]
305+bsrem (ITFixed IT32) [B32 x, B32 y]
277 = Just $ B32 (fromIntegral (fromIntegral x `rem` fromIntegral y :: Int32))
306 = Just $ B32 (fromIntegral (fromIntegral x `rem` fromIntegral y :: Int32))
278−bsrem IT64 [B64 x, B64 y]
307+bsrem (ITFixed IT64) [B64 x, B64 y]
279 = Just $ B64 (fromIntegral (fromIntegral x `rem` fromIntegral y :: Int64))
308 = Just $ B64 (fromIntegral (fromIntegral x `rem` fromIntegral y :: Int64))
280bsrem ITNative [I x, I y] = Just $ I (x `rem` y)
309bsrem ITNative [I x, I y] = Just $ I (x `rem` y)
281bsrem _ _ = Nothing
310bsrem _ _ = Nothing
283bsdiv :: IntTy -> [Const] -> Maybe Const
312bsdiv :: IntTy -> [Const] -> Maybe Const
284−bsdiv IT8 [B8 x, B8 y]
313+bsdiv (ITFixed IT8) [B8 x, B8 y]
285 = Just $ B8 (fromIntegral (fromIntegral x `div` fromIntegral y :: Int8))
314 = Just $ B8 (fromIntegral (fromIntegral x `div` fromIntegral y :: Int8))
286−bsdiv IT16 [B16 x, B16 y]
315+bsdiv (ITFixed IT16) [B16 x, B16 y]
287 = Just $ B16 (fromIntegral (fromIntegral x `div` fromIntegral y :: Int16))
316 = Just $ B16 (fromIntegral (fromIntegral x `div` fromIntegral y :: Int16))
288−bsdiv IT32 [B32 x, B32 y]
317+bsdiv (ITFixed IT32) [B32 x, B32 y]
289 = Just $ B32 (fromIntegral (fromIntegral x `div` fromIntegral y :: Int32))
318 = Just $ B32 (fromIntegral (fromIntegral x `div` fromIntegral y :: Int32))
290−bsdiv IT64 [B64 x, B64 y]
319+bsdiv (ITFixed IT64) [B64 x, B64 y]
291 = Just $ B64 (fromIntegral (fromIntegral x `div` fromIntegral y :: Int64))
320 = Just $ B64 (fromIntegral (fromIntegral x `div` fromIntegral y :: Int64))
292bsdiv ITNative [I x, I y] = Just $ I (x `div` y)
321bsdiv ITNative [I x, I y] = Just $ I (x `div` y)
293bsdiv _ _ = Nothing
322bsdiv _ _ = Nothing
295bashr :: IntTy -> [Const] -> Maybe Const
324bashr :: IntTy -> [Const] -> Maybe Const
296−bashr IT8 [B8 x, B8 y]
325+bashr (ITFixed IT8) [B8 x, B8 y]
297 = Just $ B8 (fromIntegral (fromIntegral x `shiftR` fromIntegral y :: Int8))
326 = Just $ B8 (fromIntegral (fromIntegral x `shiftR` fromIntegral y :: Int8))
298−bashr IT16 [B16 x, B16 y]
327+bashr (ITFixed IT16) [B16 x, B16 y]
299 = Just $ B16 (fromIntegral (fromIntegral x `shiftR` fromIntegral y :: Int16))
328 = Just $ B16 (fromIntegral (fromIntegral x `shiftR` fromIntegral y :: Int16))
300−bashr IT32 [B32 x, B32 y]
329+bashr (ITFixed IT32) [B32 x, B32 y]
301 = Just $ B32 (fromIntegral (fromIntegral x `shiftR` fromIntegral y :: Int32))
330 = Just $ B32 (fromIntegral (fromIntegral x `shiftR` fromIntegral y :: Int32))
302−bashr IT64 [B64 x, B64 y]
331+bashr (ITFixed IT64) [B64 x, B64 y]
303 = Just $ B64 (fromIntegral (fromIntegral x `shiftR` fromIntegral y :: Int64))
332 = Just $ B64 (fromIntegral (fromIntegral x `shiftR` fromIntegral y :: Int64))
304bashr ITNative [I x, I y] = Just $ I (x `shiftR` y)
333bashr ITNative [I x, I y] = Just $ I (x `shiftR` y)
305bashr _ _ = Nothing
334bashr _ _ = Nothing
307bUn :: IntTy -> (forall a. Bits a => a -> a) -> [Const] -> Maybe Const
336bUn :: IntTy -> (forall a. Bits a => a -> a) -> [Const] -> Maybe Const
308−bUn IT8 op [B8 x] = Just $ B8 (op x)
337+bUn (ITFixed IT8) op [B8 x] = Just $ B8 (op x)
309−bUn IT16 op [B16 x] = Just $ B16 (op x)
338+bUn (ITFixed IT16) op [B16 x] = Just $ B16 (op x)
310−bUn IT32 op [B32 x] = Just $ B32 (op x)
339+bUn (ITFixed IT32) op [B32 x] = Just $ B32 (op x)
311−bUn IT64 op [B64 x] = Just $ B64 (op x)
340+bUn (ITFixed IT64) op [B64 x] = Just $ B64 (op x)
312bUn ITBig op [BI x] = Just $ BI (op x)
341bUn ITBig op [BI x] = Just $ BI (op x)
313bUn ITNative op [I x] = Just $ I (op x)
342bUn ITNative op [I x] = Just $ I (op x)
314bUn _ _ _ = Nothing
343bUn _ _ _ = Nothing
316bitBin :: IntTy -> (forall a. (Bits a, Integral a) => a -> a -> a) -> [Const] -> Maybe Const
345bitBin :: 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)
346+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)
347+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)
348+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)
349+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)
350bitBin ITBig op [BI x, BI y] = Just $ BI (op x y)
322bitBin ITNative op [I x, I y] = Just $ I (op x y)
351bitBin ITNative op [I x, I y] = Just $ I (op x y)
323bitBin _ _ _ = Nothing
352bitBin _ _ _ = Nothing
325bCmp :: IntTy -> (forall a. Ord a => a -> a -> Bool) -> [Const] -> Maybe Const
354bCmp :: 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)
355+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)
356+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)
357+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)
358+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)
359bCmp 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)
360bCmp ITNative op [I x, I y] = Just $ I (if (op x y) then 1 else 0)
332bCmp _ _ _ = Nothing
361bCmp _ _ _ = Nothing
334toInt :: Integral a => IntTy -> a -> Const
363toInt :: Integral a => IntTy -> a -> Const
335−toInt IT8 x = B8 (fromIntegral x)
364+toInt (ITFixed IT8) x = B8 (fromIntegral x)
336−toInt IT16 x = B16 (fromIntegral x)
365+toInt (ITFixed IT16) x = B16 (fromIntegral x)
337−toInt IT32 x = B32 (fromIntegral x)
366+toInt (ITFixed IT32) x = B32 (fromIntegral x)
338−toInt IT64 x = B64 (fromIntegral x)
367+toInt (ITFixed IT64) x = B64 (fromIntegral x)
339toInt ITBig x = BI (fromIntegral x)
368toInt ITBig x = BI (fromIntegral x)
340toInt ITNative x = I (fromIntegral x)
369toInt ITNative x = I (fromIntegral x)
342intToInt :: IntTy -> IntTy -> [Const] -> Maybe Const
371intToInt :: IntTy -> IntTy -> [Const] -> Maybe Const
343−intToInt IT8 out [B8 x] = Just $ toInt out x
372+intToInt (ITFixed IT8) out [B8 x] = Just $ toInt out x
344−intToInt IT16 out [B16 x] = Just $ toInt out x
373+intToInt (ITFixed IT16) out [B16 x] = Just $ toInt out x
345−intToInt IT32 out [B32 x] = Just $ toInt out x
374+intToInt (ITFixed IT32) out [B32 x] = Just $ toInt out x
346−intToInt IT64 out [B64 x] = Just $ toInt out x
375+intToInt (ITFixed IT64) out [B64 x] = Just $ toInt out x
347intToInt ITBig out [BI x] = Just $ toInt out x
376intToInt ITBig out [BI x] = Just $ toInt out x
348intToInt ITNative out [I x] = Just $ toInt out x
377intToInt ITNative out [I x] = Just $ toInt out x
349intToInt _ _ _ = Nothing
378intToInt _ _ _ = Nothing
@@ -356,10 +385,10 @@ zext from to val
356zext _ _ _ = Nothing
385zext _ _ _ = Nothing
358sext :: IntTy -> IntTy -> [Const] -> Maybe Const
387sext :: IntTy -> IntTy -> [Const] -> Maybe Const
359−sext IT8 out [B8 x] = Just $ toInt out (fromIntegral x :: Int8)
388+sext (ITFixed IT8) out [B8 x] = Just $ toInt out (fromIntegral x :: Int8)
360−sext IT16 out [B16 x] = Just $ toInt out (fromIntegral x :: Int16)
389+sext (ITFixed IT16) out [B16 x] = Just $ toInt out (fromIntegral x :: Int16)
361−sext IT32 out [B32 x] = Just $ toInt out (fromIntegral x :: Int32)
390+sext (ITFixed IT32) out [B32 x] = Just $ toInt out (fromIntegral x :: Int32)
362−sext IT64 out [B64 x] = Just $ toInt out (fromIntegral x :: Int64)
391+sext (ITFixed IT64) out [B64 x] = Just $ toInt out (fromIntegral x :: Int64)
363sext ITBig _ _ = Nothing
392sext ITBig _ _ = Nothing
364sext from to val = intToInt from to val
393sext from to val = intToInt from to val
@@ -369,19 +398,19 @@ trunc _ ITBig _ = Nothing
369trunc from to val | intTyWidth from > intTyWidth to = intToInt from to val
398trunc from to val | intTyWidth from > intTyWidth to = intToInt from to val
370trunc _ _ _ = Nothing
399trunc _ _ _ = 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
401intToStr :: [Const] -> Maybe Const
382−intToStr val | Just i <- getInt val = Just $ Str (show i)
402+intToStr val | [i] <- getInt val = Just $ Str (show i)
383intToStr _ = Nothing
403intToStr _ = Nothing
405+getInt :: [Const] -> [Integer]
406+getInt (B8 x : xs) = toInteger x : getInt xs
407+getInt (B16 x : xs) = toInteger x : getInt xs
408+getInt (B32 x : xs) = toInteger x : getInt xs
409+getInt (B64 x : xs) = toInteger x : getInt xs
410+getInt (I x : xs) = toInteger x : getInt xs
411+getInt (BI x : xs) = x : getInt xs
385strToInt :: IntTy -> [Const] -> Maybe Const
414strToInt :: IntTy -> [Const] -> Maybe Const
386strToInt ity [Str x] = case reads x of
415strToInt ity [Str x] = case reads x of
387 [(n,"")] -> Just $ toInt ity (n :: Integer)
416 [(n,"")] -> Just $ toInt ity (n :: Integer)
@@ -389,7 +418,7 @@ strToInt ity [Str x] = case reads x of
389strToInt _ _ = Nothing
418strToInt _ _ = Nothing
391intToFloat :: [Const] -> Maybe Const
420intToFloat :: [Const] -> Maybe Const
392−intToFloat val | Just i <- getInt val = Just $ Fl (fromIntegral i)
421+intToFloat val | [i] <- getInt val = Just $ Fl (fromIntegral i)
393intToFloat _ = Nothing
422intToFloat _ = Nothing
395floatToInt :: IntTy -> [Const] -> Maybe Const
424floatToInt :: IntTy -> [Const] -> Maybe Const