@@ -1,4 +1,4 @@
1−{-# LANGUAGE RankNTypes, ScopedTypeVariables #-}
1+{-# LANGUAGE RankNTypes, ScopedTypeVariables, PatternGuards #-}
3module Idris.Primitives(elabPrims) where
3module Idris.Primitives(elabPrims) where
@@ -34,280 +34,73 @@ partial = Partial NotCovering
35primitives =
35primitives =
36 -- operators
36 -- operators
37− [Prim (UN "prim__addInt") (ty [IType, IType] IType) 2 (iBin (+))
39− Prim (UN "prim__subInt") (ty [IType, IType] IType) 2 (iBin (-))
41− Prim (UN "prim__mulInt") (ty [IType, IType] IType) 2 (iBin (*))
43− Prim (UN "prim__divInt") (ty [IType, IType] IType) 2 (iBin div)
45− Prim (UN "prim__modInt") (ty [IType, IType] IType) 2 (iBin mod)
47− Prim (UN "prim__andInt") (ty [IType, IType] IType) 2 (iBin (.&.))
49− Prim (UN "prim__orInt") (ty [IType, IType] IType) 2 (iBin (.|.))
51− Prim (UN "prim__xorInt") (ty [IType, IType] IType) 2 (iBin xor)
53− Prim (UN "prim__shLInt") (ty [IType, IType] IType) 2 (iBin shiftL)
55− Prim (UN "prim__shRInt") (ty [IType, IType] IType) 2 (iBin shiftR)
57− Prim (UN "prim__complInt") (ty [IType] IType) 1 (iUn complement)
59− Prim (UN "prim__eqInt") (ty [IType, IType] IType) 2 (biBin (==))
61− Prim (UN "prim__ltInt") (ty [IType, IType] IType) 2 (biBin (<))
63− Prim (UN "prim__lteInt") (ty [IType, IType] IType) 2 (biBin (<=))
65− Prim (UN "prim__gtInt") (ty [IType, IType] IType) 2 (biBin (>))
67− Prim (UN "prim__gteInt") (ty [IType, IType] IType) 2 (biBin (>=))
69− Prim (UN "prim__eqChar") (ty [ChType, ChType] IType) 2 (bcBin (==))
37+ [Prim (UN "prim__eqChar") (ty [ChType, ChType] IType) 2 (bcBin (==))
70− (2, LEq) total,
38+ (2, LEq ITNative) total,
71 Prim (UN "prim__ltChar") (ty [ChType, ChType] IType) 2 (bcBin (<))
39 Prim (UN "prim__ltChar") (ty [ChType, ChType] IType) 2 (bcBin (<))
72− (2, LLt) total,
40+ (2, LLt ITNative) total,
73 Prim (UN "prim__lteChar") (ty [ChType, ChType] IType) 2 (bcBin (<=))
41 Prim (UN "prim__lteChar") (ty [ChType, ChType] IType) 2 (bcBin (<=))
74− (2, LLe) total,
42+ (2, LLe ITNative) total,
75 Prim (UN "prim__gtChar") (ty [ChType, ChType] IType) 2 (bcBin (>))
43 Prim (UN "prim__gtChar") (ty [ChType, ChType] IType) 2 (bcBin (>))
76− (2, LGt) total,
44+ (2, LGt ITNative) total,
77 Prim (UN "prim__gteChar") (ty [ChType, ChType] IType) 2 (bcBin (>=))
45 Prim (UN "prim__gteChar") (ty [ChType, ChType] IType) 2 (bcBin (>=))
78− (2, LGe) total,
46+ (2, LGe ITNative) total,
80− Prim (UN "prim__ltB8") (ty [B8Type, B8Type] IType) 2 (b8Cmp (<))
48+ iCoerce IT8 IT16 "zext" zext LZExt,
81− (2, LB8Lt) total,
49+ iCoerce IT8 IT32 "zext" zext LZExt,
82− Prim (UN "prim__lteB8") (ty [B8Type, B8Type] IType) 2 (b8Cmp (<=))
50+ iCoerce IT8 IT64 "zext" zext LZExt,
83− (2, LB8Lte) total,
51+ iCoerce IT8 ITBig "zext" zext LZExt,
84− Prim (UN "prim__eqB8") (ty [B8Type, B8Type] IType) 2 (b8Cmp (==))
52+ iCoerce IT8 ITNative "zext" zext LZExt,
85− (2, LB8Eq) total,
53+ iCoerce IT16 IT32 "zext" zext LZExt,
86− Prim (UN "prim__gteB8") (ty [B8Type, B8Type] IType) 2 (b8Cmp (>))
54+ iCoerce IT16 IT64 "zext" zext LZExt,
87− (2, LB8Gte) total,
55+ iCoerce IT16 ITBig "zext" zext LZExt,
88− Prim (UN "prim__gtB8") (ty [B8Type, B8Type] IType) 2 (b8Cmp (>=))
56+ iCoerce IT16 ITNative "zext" zext LZExt,
89− (2, LB8Gt) total,
57+ iCoerce IT32 IT64 "zext" zext LZExt,
90− Prim (UN "prim__addB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (+))
58+ iCoerce IT32 ITBig "zext" zext LZExt,
91− (2, LB8Plus) total,
59+ iCoerce IT32 ITNative "zext" zext LZExt,
92− Prim (UN "prim__subB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (-))
60+ iCoerce IT64 ITBig "zext" zext LZExt,
93− (2, LB8Minus) total,
61+ iCoerce ITNative ITBig "zext" zext LZExt,
94− Prim (UN "prim__mulB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (*))
62+ iCoerce ITNative IT64 "zext" zext LZExt,
95− (2, LB8Times) total,
63+ iCoerce ITNative IT32 "zext" zext LZExt,
96− Prim (UN "prim__udivB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin div)
64+ iCoerce ITNative IT16 "zext" zext LZExt,
97− (2, LB8UDiv) partial,
65+
98− Prim (UN "prim__sdivB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin s8div)
66+ iCoerce IT8 IT16 "sext" sext LSExt,
99− (2, LB8SDiv) partial,
67+ iCoerce IT8 IT32 "sext" sext LSExt,
100− Prim (UN "prim__uremB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin rem)
68+ iCoerce IT8 IT64 "sext" sext LSExt,
101− (2, LB8URem) partial,
69+ iCoerce IT8 ITBig "sext" sext LSExt,
102− Prim (UN "prim__sremB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin s8rem)
70+ iCoerce IT8 ITNative "sext" sext LSExt,
103− (2, LB8SRem) partial,
71+ iCoerce IT16 IT32 "sext" sext LSExt,
104− Prim (UN "prim__shlB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (\x y -> shiftL x (fromIntegral y)))
72+ iCoerce IT16 IT64 "sext" sext LSExt,
105− (2, LB8Shl) total,
73+ iCoerce IT16 ITBig "sext" sext LSExt,
106− Prim (UN "prim__lshrB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (\x y -> shiftR x (fromIntegral y)))
74+ iCoerce IT16 ITNative "sext" sext LSExt,
107− (2, LB8AShr) total,
75+ iCoerce IT32 IT64 "sext" sext LSExt,
108− Prim (UN "prim__ashrB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (\x y -> fromIntegral $
76+ iCoerce IT32 ITBig "sext" sext LSExt,
109− shiftR (fromIntegral x :: Int8)
77+ iCoerce IT32 ITNative "sext" sext LSExt,
110− (fromIntegral y)))
78+ iCoerce IT64 ITBig "sext" sext LSExt,
111− (2, LB8LShr) total,
79+ iCoerce ITNative ITBig "sext" sext LSExt,
112− Prim (UN "prim__andB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (.&.))
80+ iCoerce ITNative ITBig "sext" sext LSExt,
113− (2, LB8And) total,
81+ iCoerce ITNative IT64 "sext" sext LSExt,
114− Prim (UN "prim__orB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (.|.))
82+ iCoerce ITNative IT32 "sext" sext LSExt,
115− (2, LB8Or) total,
83+ iCoerce ITNative IT16 "sext" sext LSExt,
116− Prim (UN "prim__xorB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin xor)
84+
117− (2, LB8Xor) total,
85+ iCoerce IT16 IT8 "trunc" trunc LTrunc,
118− Prim (UN "prim__complB8") (ty [B8Type] B8Type) 1 (b8Un complement)
86+ iCoerce IT32 IT8 "trunc" trunc LTrunc,
119− (1, LB8Compl) total,
87+ iCoerce IT64 IT8 "trunc" trunc LTrunc,
120− Prim (UN "prim__zextB8_16") (ty [B8Type] B16Type) 1 zext8_16
88+ iCoerce ITBig IT8 "trunc" trunc LTrunc,
121− (1, LB8Z16) total,
89+ iCoerce ITNative IT8 "trunc" trunc LTrunc,
122− Prim (UN "prim__zextB8_32") (ty [B8Type] B32Type) 1 zext8_32
90+ iCoerce IT32 IT16 "trunc" trunc LTrunc,
123− (1, LB8Z32) total,
91+ iCoerce IT64 IT16 "trunc" trunc LTrunc,
124− Prim (UN "prim__zextB8_64") (ty [B8Type] B64Type) 1 zext8_64
92+ iCoerce ITBig IT16 "trunc" trunc LTrunc,
125− (1, LB8Z64) total,
93+ iCoerce ITNative IT16 "trunc" trunc LTrunc,
126− Prim (UN "prim__sextB8_16") (ty [B8Type] B16Type) 1 sext8_16
94+ iCoerce IT64 IT32 "trunc" trunc LTrunc,
127− (1, LB8Z16) total,
95+ iCoerce ITBig IT32 "trunc" trunc LTrunc,
128− Prim (UN "prim__sextB8_32") (ty [B8Type] B32Type) 1 sext8_32
96+ iCoerce ITNative IT32 "trunc" trunc LTrunc,
129− (1, LB8Z32) total,
97+ iCoerce ITBig IT64 "trunc" trunc LTrunc,
130− Prim (UN "prim__sextB8_64") (ty [B8Type] B64Type) 1 sext8_64
98+ iCoerce IT16 ITNative "trunc" trunc LTrunc,
131− (1, LB8Z64) total,
99+ iCoerce IT32 ITNative "trunc" trunc LTrunc,
132−
100+ iCoerce IT64 ITNative "trunc" trunc LTrunc,
133− Prim (UN "prim__ltB16") (ty [B16Type, B16Type] IType) 2 (b16Cmp (<))
101+ iCoerce ITBig ITNative "trunc" trunc LTrunc,
134− (2, LB16Lt) total,
102+ iCoerce ITNative IT64 "trunc" trunc LTrunc,
135− Prim (UN "prim__lteB16") (ty [B16Type, B16Type] IType) 2 (b16Cmp (<=))
103+
137− Prim (UN "prim__eqB16") (ty [B16Type, B16Type] IType) 2 (b16Cmp (==))
139− Prim (UN "prim__gteB16") (ty [B16Type, B16Type] IType) 2 (b16Cmp (>))
141− Prim (UN "prim__gtB16") (ty [B16Type, B16Type] IType) 2 (b16Cmp (>=))
143− Prim (UN "prim__addB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin (+))
144− (2, LB16Plus) total,
145− Prim (UN "prim__subB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin (-))
146− (2, LB16Minus) total,
147− Prim (UN "prim__mulB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin (*))
148− (2, LB16Times) total,
149− Prim (UN "prim__udivB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin div)
150− (2, LB16UDiv) partial,
151− Prim (UN "prim__sdivB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin s16div)
152− (2, LB16SDiv) partial,
153− Prim (UN "prim__uremB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin rem)
154− (2, LB16URem) partial,
155− Prim (UN "prim__sremB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin s16rem)
156− (2, LB16SRem) partial,
157− Prim (UN "prim__shlB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin (\x y -> shiftL x (fromIntegral y)))
159− Prim (UN "prim__lshrB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin (\x y -> shiftR x (fromIntegral y)))
160− (2, LB16AShr) total,
161− Prim (UN "prim__ashrB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin (\x y -> fromIntegral $
162− shiftR (fromIntegral x :: Int16)
164− (2, LB16LShr) total,
165− Prim (UN "prim__andB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin (.&.))
167− Prim (UN "prim__orB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin (.|.))
169− Prim (UN "prim__xorB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin xor)
171− Prim (UN "prim__complB16") (ty [B16Type] B16Type) 1 (b16Un complement)
172− (1, LB16Compl) total,
173− Prim (UN "prim__zextB16_32") (ty [B16Type] B32Type) 1 zext16_32
175− Prim (UN "prim__zextB16_64") (ty [B16Type] B64Type) 1 zext16_64
177− Prim (UN "prim__sextB16_32") (ty [B16Type] B32Type) 1 sext16_32
179− Prim (UN "prim__sextB16_64") (ty [B16Type] B64Type) 1 sext16_64
181− Prim (UN "prim__truncB16_8") (ty [B16Type] B8Type) 1 trunc16_8
184− Prim (UN "prim__ltB32") (ty [B32Type, B32Type] IType) 2 (b32Cmp (<))
186− Prim (UN "prim__lteB32") (ty [B32Type, B32Type] IType) 2 (b32Cmp (<=))
188− Prim (UN "prim__eqB32") (ty [B32Type, B32Type] IType) 2 (b32Cmp (==))
190− Prim (UN "prim__gteB32") (ty [B32Type, B32Type] IType) 2 (b32Cmp (>))
192− Prim (UN "prim__gtB32") (ty [B32Type, B32Type] IType) 2 (b32Cmp (>=))
194− Prim (UN "prim__addB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin (+))
195− (2, LB32Plus) total,
196− Prim (UN "prim__subB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin (-))
197− (2, LB32Minus) total,
198− Prim (UN "prim__mulB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin (*))
199− (2, LB32Times) total,
200− Prim (UN "prim__udivB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin div)
201− (2, LB32UDiv) partial,
202− Prim (UN "prim__sdivB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin s32div)
203− (2, LB32SDiv) partial,
204− Prim (UN "prim__uremB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin rem)
205− (2, LB32URem) partial,
206− Prim (UN "prim__sremB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin s32rem)
207− (2, LB32SRem) partial,
208− Prim (UN "prim__shlB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin (\x y -> shiftL x (fromIntegral y)))
210− Prim (UN "prim__lshrB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin (\x y -> shiftR x (fromIntegral y)))
211− (2, LB32AShr) total,
212− Prim (UN "prim__ashrB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin (\x y -> fromIntegral $
213− shiftR (fromIntegral x :: Int32)
215− (2, LB32LShr) total,
216− Prim (UN "prim__andB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin (.&.))
218− Prim (UN "prim__orB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin (.|.))
220− Prim (UN "prim__xorB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin xor)
222− Prim (UN "prim__complB32") (ty [B32Type] B32Type) 1 (b32Un complement)
223− (1, LB32Compl) total,
224− Prim (UN "prim__zextB32_64") (ty [B32Type] B64Type) 1 zext32_64
226− Prim (UN "prim__sextB32_64") (ty [B32Type] B64Type) 1 sext32_64
228− Prim (UN "prim__truncB32_8") (ty [B32Type] B8Type) 1 trunc32_8
230− Prim (UN "prim__truncB32_16") (ty [B32Type] B16Type) 1 trunc32_16
233− Prim (UN "prim__ltB64") (ty [B64Type, B64Type] IType) 2 (b64Cmp (<))
235− Prim (UN "prim__lteB64") (ty [B64Type, B64Type] IType) 2 (b64Cmp (<=))
237− Prim (UN "prim__eqB64") (ty [B64Type, B64Type] IType) 2 (b64Cmp (==))
239− Prim (UN "prim__gteB64") (ty [B64Type, B64Type] IType) 2 (b64Cmp (>))
241− Prim (UN "prim__gtB64") (ty [B64Type, B64Type] IType) 2 (b64Cmp (>=))
243− Prim (UN "prim__addB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin (+))
244− (2, LB64Plus) total,
245− Prim (UN "prim__subB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin (-))
246− (2, LB64Minus) total,
247− Prim (UN "prim__mulB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin (*))
248− (2, LB64Times) total,
249− Prim (UN "prim__udivB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin div)
250− (2, LB64UDiv) partial,
251− Prim (UN "prim__sdivB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin s64div)
252− (2, LB64SDiv) partial,
253− Prim (UN "prim__uremB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin rem)
254− (2, LB64URem) partial,
255− Prim (UN "prim__sremB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin s64rem)
256− (2, LB64SRem) partial,
257− Prim (UN "prim__shlB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin (\x y -> shiftL x (fromIntegral y)))
259− Prim (UN "prim__lshrB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin (\x y -> shiftR x (fromIntegral y)))
260− (2, LB64AShr) total,
261− Prim (UN "prim__ashrB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin (\x y -> fromIntegral $
262− shiftR (fromIntegral x :: Int64)
264− (2, LB64LShr) total,
265− Prim (UN "prim__andB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin (.&.))
267− Prim (UN "prim__orB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin (.|.))
269− Prim (UN "prim__xorB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin xor)
271− Prim (UN "prim__complB64") (ty [B64Type] B64Type) 1 (b64Un complement)
272− (1, LB64Compl) total,
273− Prim (UN "prim__truncB64_8") (ty [B64Type] B8Type) 1 trunc64_8
275− Prim (UN "prim__truncB64_16") (ty [B64Type] B16Type) 1 trunc64_16
277− Prim (UN "prim__truncB64_32") (ty [B64Type] B32Type) 1 trunc64_32
280− Prim (UN "prim__intToB8") (ty [IType] B8Type) 1 intToBits8
282− Prim (UN "prim__intToB16") (ty [IType] B16Type) 1 intToBits16
284− Prim (UN "prim__intToB32") (ty [IType] B32Type) 1 intToBits32
286− Prim (UN "prim__intToB64") (ty [IType] B64Type) 1 intToBits64
288− Prim (UN "prim__B32ToInt") (ty [B32Type] IType) 1 bits32ToInt
291− Prim (UN "prim__addBigInt") (ty [BIType, BIType] BIType) 2 (bBin (+))
293− Prim (UN "prim__subBigInt") (ty [BIType, BIType] BIType) 2 (bBin (-))
295− Prim (UN "prim__mulBigInt") (ty [BIType, BIType] BIType) 2 (bBin (*))
297− Prim (UN "prim__divBigInt") (ty [BIType, BIType] BIType) 2 (bBin div)
299− Prim (UN "prim__modBigInt") (ty [BIType, BIType] BIType) 2 (bBin mod)
301− Prim (UN "prim__eqBigInt") (ty [BIType, BIType] IType) 2 (bbBin (==))
303− Prim (UN "prim__ltBigInt") (ty [BIType, BIType] IType) 2 (bbBin (<))
305− Prim (UN "prim__lteBigInt") (ty [BIType, BIType] IType) 2 (bbBin (<=))
307− Prim (UN "prim__gtBigInt") (ty [BIType, BIType] IType) 2 (bbBin (>))
309− Prim (UN "prim__gtBigInt") (ty [BIType, BIType] IType) 2 (bbBin (>=))
311 Prim (UN "prim__addFloat") (ty [FlType, FlType] FlType) 2 (fBin (+))
104 Prim (UN "prim__addFloat") (ty [FlType, FlType] FlType) 2 (fBin (+))
312 (2, LFPlus) total,
105 (2, LFPlus) total,
313 Prim (UN "prim__subFloat") (ty [FlType, FlType] FlType) 2 (fBin (-))
106 Prim (UN "prim__subFloat") (ty [FlType, FlType] FlType) 2 (fBin (-))
@@ -335,30 +128,14 @@ primitives =
335 Prim (UN "prim_lenString") (ty [StrType] IType) 1 (p_strLen)
128 Prim (UN "prim_lenString") (ty [StrType] IType) 1 (p_strLen)
336 (1, LStrLen) total,
129 (1, LStrLen) total,
337 -- Conversions
130 -- Conversions
338− Prim (UN "prim__strToInt") (ty [StrType] IType) 1 (c_strToInt)
340− Prim (UN "prim__intToStr") (ty [IType] StrType) 1 (c_intToStr)
342 Prim (UN "prim__charToInt") (ty [ChType] IType) 1 (c_charToInt)
131 Prim (UN "prim__charToInt") (ty [ChType] IType) 1 (c_charToInt)
343− (1, LChInt) total,
132+ (1, LChInt ITNative) total,
344 Prim (UN "prim__intToChar") (ty [IType] ChType) 1 (c_intToChar)
133 Prim (UN "prim__intToChar") (ty [IType] ChType) 1 (c_intToChar)
345− (1, LIntCh) total,
134+ (1, LIntCh ITNative) total,
346− Prim (UN "prim__intToBigInt") (ty [IType] BIType) 1 (c_intToBigInt)
348− Prim (UN "prim__bigIntToInt") (ty [BIType] IType) 1 (c_bigIntToInt)
350− Prim (UN "prim__strToBigInt") (ty [StrType] BIType) 1 (c_strToBigInt)
352− Prim (UN "prim__bigIntToStr") (ty [BIType] StrType) 1 (c_bigIntToStr)
354 Prim (UN "prim__strToFloat") (ty [StrType] FlType) 1 (c_strToFloat)
135 Prim (UN "prim__strToFloat") (ty [StrType] FlType) 1 (c_strToFloat)
355 (1, LStrFloat) total,
136 (1, LStrFloat) total,
356 Prim (UN "prim__floatToStr") (ty [FlType] StrType) 1 (c_floatToStr)
137 Prim (UN "prim__floatToStr") (ty [FlType] StrType) 1 (c_floatToStr)
357 (1, LFloatStr) total,
138 (1, LFloatStr) total,
358− Prim (UN "prim__intToFloat") (ty [IType] FlType) 1 (c_intToFloat)
359− (1, LIntFloat) total,
360− Prim (UN "prim__floatToInt") (ty [FlType] IType) 1 (c_floatToInt)
361− (1, LFloatInt) total,
363 Prim (UN "prim__floatExp") (ty [FlType] FlType) 1 (p_floatExp)
140 Prim (UN "prim__floatExp") (ty [FlType] FlType) 1 (p_floatExp)
364 (1, LFExp) total,
141 (1, LFExp) total,
@@ -402,7 +179,49 @@ primitives =
402 (0, LStdIn) partial,
179 (0, LStdIn) partial,
403 Prim (UN "prim__believe_me") believeTy 3 (p_believeMe)
180 Prim (UN "prim__believe_me") believeTy 3 (p_believeMe)
404 (3, LNoOp) partial -- ahem
181 (3, LNoOp) partial -- ahem
405− ]
182+ ] ++ concatMap intOps [IT8, IT16, IT32, IT64, ITBig, ITNative]
185+ [ iCmp ity "lt" (bCmp ity (<)) LLt total
186+ , iCmp ity "lte" (bCmp ity (<=)) LLe total
187+ , iCmp ity "eq" (bCmp ity (==)) LEq total
188+ , iCmp ity "gte" (bCmp ity (>=)) LGe total
189+ , iCmp ity "gt" (bCmp ity (>)) LGt total
190+ , iBinOp ity "add" (bitBin ity (+)) LPlus total
191+ , iBinOp ity "sub" (bitBin ity (-)) LMinus total
192+ , iBinOp ity "mul" (bitBin ity (*)) LTimes total
193+ , iBinOp ity "udiv" (bitBin ity div) LUDiv partial
194+ , iBinOp ity "sdiv" (bsdiv ity) LSDiv partial
195+ , iBinOp ity "urem" (bitBin ity rem) LURem partial
196+ , iBinOp ity "srem" (bsrem ity) LSRem partial
197+ , iBinOp ity "shl" (bitBin ity (\x y -> shiftL x (fromIntegral y))) LSHL total
198+ , iBinOp ity "lshr" (bitBin ity (\x y -> shiftR x (fromIntegral y))) LLSHR total
199+ , iBinOp ity "ashr" (bashr ity) LASHR total
200+ , iBinOp ity "and" (bitBin ity (.&.)) LAnd total
201+ , iBinOp ity "or" (bitBin ity (.|.)) LOr total
202+ , iBinOp ity "xor" (bitBin ity (xor)) LXOr total
203+ , iUnOp ity "compl" (bUn ity complement) LCompl total
204+ , Prim (UN $ "prim__toStr" ++ intTyName ity) (ty [intTyToConst ity] StrType) 1 intToStr
205+ (1, LIntStr ity) total
206+ , Prim (UN $ "prim__fromStr" ++ intTyName ity) (ty [StrType] (intTyToConst ity)) 1 (strToInt ity)
207+ (1, LStrInt ity) total
208+ , Prim (UN $ "prim__toFloat" ++ intTyName ity) (ty [intTyToConst ity] FlType) 1 intToFloat
209+ (1, LIntFloat ity) total
210+ , Prim (UN $ "prim__fromFloat" ++ intTyName ity) (ty [FlType] (intTyToConst ity)) 1 (floatToInt ity)
211+ (1, LFloatInt ity) total
214+intTyName :: IntTy -> String
215+intTyName ITNative = "Int"
216+intTyName ITBig = "BigInt"
217+intTyName sized = "B" ++ show (intTyWidth sized)
219+iCmp ity op impl irop totality = Prim (UN $ "prim__" ++ op ++ intTyName ity) (ty (replicate 2 $ intTyToConst ity) IType) 2 impl (2, irop ity) totality
220+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
221+iUnOp ity op impl irop totality = Prim (UN $ "prim__" ++ op ++ intTyName ity) (ty [intTyToConst ity] (intTyToConst ity)) 1 impl (1, irop ity) totality
222+iCoerce from to op impl irop =
223+ Prim (UN $ "prim__" ++ op ++ intTyName from ++ "_" ++ intTyName to)
224+ (ty [intTyToConst from] (intTyToConst to)) 1 (impl from to) (1, irop from to) total
407p_believeMe [_,_,x] = Just x
226p_believeMe [_,_,x] = Just x
408p_believeMe _ = Nothing
227p_believeMe _ = Nothing
@@ -441,161 +260,127 @@ bsBin _ _ = Nothing
441sBin op [VConstant (Str x), VConstant (Str y)] = Just $ VConstant (Str (op x y))
260sBin op [VConstant (Str x), VConstant (Str y)] = Just $ VConstant (Str (op x y))
442sBin _ _ = Nothing
261sBin _ _ = Nothing
444−s8div :: Word8 -> Word8 -> Word8
263+bsrem IT8 [VConstant (B8 x), VConstant (B8 y)]
445−s8div x y = fromIntegral (fromIntegral x `div` fromIntegral y :: Int8)
264+ = Just $ VConstant (B8 (fromIntegral (fromIntegral x `rem` fromIntegral y :: Int8)))
446−
265+bsrem IT16 [VConstant (B16 x), VConstant (B16 y)]
447−s16div :: Word16 -> Word16 -> Word16
266+ = Just $ VConstant (B16 (fromIntegral (fromIntegral x `rem` fromIntegral y :: Int16)))
448−s16div x y = fromIntegral (fromIntegral x `div` fromIntegral y :: Int16)
267+bsrem IT32 [VConstant (B32 x), VConstant (B32 y)]
449−
268+ = Just $ VConstant (B32 (fromIntegral (fromIntegral x `rem` fromIntegral y :: Int32)))
450−s32div :: Word32 -> Word32 -> Word32
269+bsrem IT64 [VConstant (B64 x), VConstant (B64 y)]
451−s32div x y = fromIntegral (fromIntegral x `div` fromIntegral y :: Int32)
270+ = Just $ VConstant (B64 (fromIntegral (fromIntegral x `rem` fromIntegral y :: Int64)))
452−
271+bsrem ITNative [VConstant (I x), VConstant (I y)] = Just $ VConstant (I (x `rem` y))
453−s64div :: Word64 -> Word64 -> Word64
272+bsrem _ _ = Nothing
454−s64div x y = fromIntegral (fromIntegral x `div` fromIntegral y :: Int64)
273+
455−
274+bsdiv IT8 [VConstant (B8 x), VConstant (B8 y)]
456−s8rem :: Word8 -> Word8 -> Word8
275+ = Just $ VConstant (B8 (fromIntegral (fromIntegral x `div` fromIntegral y :: Int8)))
457−s8rem x y = fromIntegral (fromIntegral x `rem` fromIntegral y :: Int8)
276+bsdiv IT16 [VConstant (B16 x), VConstant (B16 y)]
458−
277+ = Just $ VConstant (B16 (fromIntegral (fromIntegral x `div` fromIntegral y :: Int16)))
459−s16rem :: Word16 -> Word16 -> Word16
278+bsdiv IT32 [VConstant (B32 x), VConstant (B32 y)]
460−s16rem x y = fromIntegral (fromIntegral x `rem` fromIntegral y :: Int16)
279+ = Just $ VConstant (B32 (fromIntegral (fromIntegral x `div` fromIntegral y :: Int32)))
461−
280+bsdiv IT64 [VConstant (B64 x), VConstant (B64 y)]
462−s32rem :: Word32 -> Word32 -> Word32
281+ = Just $ VConstant (B64 (fromIntegral (fromIntegral x `div` fromIntegral y :: Int64)))
463−s32rem x y = fromIntegral (fromIntegral x `rem` fromIntegral y :: Int32)
282+bsdiv ITNative [VConstant (I x), VConstant (I y)] = Just $ VConstant (I (x `div` y))
464−
283+bsdiv _ _ = Nothing
465−s64rem :: Word64 -> Word64 -> Word64
284+
466−s64rem x y = fromIntegral (fromIntegral x `rem` fromIntegral y :: Int64)
285+bashr IT8 [VConstant (B8 x), VConstant (B8 y)]
467−
286+ = Just $ VConstant (B8 (fromIntegral (fromIntegral x `shiftR` fromIntegral y :: Int8)))
468−b8Bin op [VConstant (B8 x), VConstant (B8 y)] = Just $ VConstant (B8 (op x y))
287+bashr IT16 [VConstant (B16 x), VConstant (B16 y)]
469−b8Bin _ _ = Nothing
288+ = Just $ VConstant (B16 (fromIntegral (fromIntegral x `shiftR` fromIntegral y :: Int16)))
470−
289+bashr IT32 [VConstant (B32 x), VConstant (B32 y)]
471−b8Un op [VConstant (B8 x)] = Just $ VConstant (B8 (op x))
290+ = Just $ VConstant (B32 (fromIntegral (fromIntegral x `shiftR` fromIntegral y :: Int32)))
472−b8Un _ _ = Nothing
291+bashr IT64 [VConstant (B64 x), VConstant (B64 y)]
473−
292+ = Just $ VConstant (B64 (fromIntegral (fromIntegral x `shiftR` fromIntegral y :: Int64)))
474−b16Bin op [VConstant (B16 x), VConstant (B16 y)] = Just $ VConstant (B16 (op x y))
293+bashr ITNative [VConstant (I x), VConstant (I y)] = Just $ VConstant (I (x `shiftR` y))
475−b16Bin _ _ = Nothing
294+bashr _ _ = Nothing
477−b16Un op [VConstant (B16 x)] = Just $ VConstant (B16 (op x))
296+bUn :: IntTy -> (forall a. Bits a => a -> a) -> [Value] -> Maybe Value
478−b16Un _ _ = Nothing
297+bUn IT8 op [VConstant (B8 x)] = Just $ VConstant (B8 (op x))
479−
298+bUn IT16 op [VConstant (B16 x)] = Just $ VConstant (B16 (op x))
480−b32Bin op [VConstant (B32 x), VConstant (B32 y)] = Just $ VConstant (B32 (op x y))
299+bUn IT32 op [VConstant (B32 x)] = Just $ VConstant (B32 (op x))
481−b32Bin _ _ = Nothing
300+bUn IT64 op [VConstant (B64 x)] = Just $ VConstant (B64 (op x))
482−
301+bUn ITBig op [VConstant (BI x)] = Just $ VConstant (BI (op x))
483−b32Un op [VConstant (B32 x)] = Just $ VConstant (B32 (op x))
302+bUn ITNative op [VConstant (I x)] = Just $ VConstant (I (op x))
484−b32Un _ _ = Nothing
303+bUn _ _ _ = Nothing
486−b64Bin op [VConstant (B64 x), VConstant (B64 y)] = Just $ VConstant (B64 (op x y))
305+bitBin :: IntTy -> (forall a. (Bits a, Integral a) => a -> a -> a) -> [Value] -> Maybe Value
487−b64Bin _ _ = Nothing
306+bitBin IT8 op [VConstant (B8 x), VConstant (B8 y)] = Just $ VConstant (B8 (op x y))
488−
307+bitBin IT16 op [VConstant (B16 x), VConstant (B16 y)] = Just $ VConstant (B16 (op x y))
489−b64Un op [VConstant (B64 x)] = Just $ VConstant (B64 (op x))
308+bitBin IT32 op [VConstant (B32 x), VConstant (B32 y)] = Just $ VConstant (B32 (op x y))
490−b64Un _ _ = Nothing
309+bitBin IT64 op [VConstant (B64 x), VConstant (B64 y)] = Just $ VConstant (B64 (op x y))
491−
310+bitBin ITBig op [VConstant (BI x), VConstant (BI y)] = Just $ VConstant (BI (op x y))
492−b8Cmp op [VConstant (B8 x), VConstant (B8 y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
311+bitBin ITNative op [VConstant (I x), VConstant (I y)] = Just $ VConstant (I (op x y))
493−b8Cmp _ _ = Nothing
312+bitBin _ _ _ = Nothing
495−b16Cmp op [VConstant (B16 x), VConstant (B16 y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
314+bCmp :: IntTy -> (forall a. Ord a => a -> a -> Bool) -> [Value] -> Maybe Value
496−b16Cmp _ _ = Nothing
315+bCmp IT8 op [VConstant (B8 x), VConstant (B8 y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
497−
316+bCmp IT16 op [VConstant (B16 x), VConstant (B16 y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
498−b32Cmp op [VConstant (B32 x), VConstant (B32 y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
317+bCmp IT32 op [VConstant (B32 x), VConstant (B32 y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
499−b32Cmp _ _ = Nothing
318+bCmp IT64 op [VConstant (B64 x), VConstant (B64 y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
500−
319+bCmp ITBig op [VConstant (BI x), VConstant (BI y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
501−b64Cmp op [VConstant (B64 x), VConstant (B64 y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
320+bCmp ITNative op [VConstant (I x), VConstant (I y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
502−b64Cmp _ _ = Nothing
321+bCmp _ _ _ = Nothing
504−toB8 x = VConstant (B8 (fromIntegral x))
323+toInt IT8 x = VConstant (B8 (fromIntegral x))
505−toB16 x = VConstant (B16 (fromIntegral x))
324+toInt IT16 x = VConstant (B16 (fromIntegral x))
506−toB32 x = VConstant (B32 (fromIntegral x))
325+toInt IT32 x = VConstant (B32 (fromIntegral x))
507−toB64 x = VConstant (B64 (fromIntegral x))
326+toInt IT64 x = VConstant (B64 (fromIntegral x))
508−
327+toInt ITBig x = VConstant (BI (fromIntegral x))
509−zext8_16 [VConstant (B8 x)] = Just $ toB16 x
328+toInt ITNative x = VConstant (I (fromIntegral x))
510−zext8_16 _ = Nothing
329+
511−
330+intToInt IT8 out [VConstant (B8 x)] = Just $ toInt out x
512−zext8_32 [VConstant (B8 x)] = Just $ toB32 x
331+intToInt IT16 out [VConstant (B16 x)] = Just $ toInt out x
513−zext8_32 _ = Nothing
332+intToInt IT32 out [VConstant (B32 x)] = Just $ toInt out x
514−
333+intToInt IT64 out [VConstant (B64 x)] = Just $ toInt out x
515−zext8_64 [VConstant (B8 x)] = Just $ toB64 x
334+intToInt ITBig out [VConstant (BI x)] = Just $ toInt out x
516−zext8_64 _ = Nothing
335+intToInt ITNative out [VConstant (I x)] = Just $ toInt out x
517−
336+intToInt _ _ _ = Nothing
518−sext8_16 [VConstant (B8 x)] = Just $ toB16 (fromIntegral x :: Int8)
337+
519−sext8_16 _ = Nothing
338+zext from ITBig val = intToInt from ITBig val
520−
339+zext ITBig _ _ = Nothing
521−sext8_32 [VConstant (B8 x)] = Just $ toB32 (fromIntegral x :: Int8)
340+zext from to val
522−sext8_32 _ = Nothing
341+ | intTyWidth from < intTyWidth to = intToInt from to val
523−
342+zext _ _ _ = Nothing
524−sext8_64 [VConstant (B8 x)] = Just $ toB64 (fromIntegral x :: Int8)
343+
525−sext8_64 _ = Nothing
344+sext IT8 out [VConstant (B8 x)] = Just $ toInt out (fromIntegral x :: Int8)
526−
345+sext IT16 out [VConstant (B16 x)] = Just $ toInt out (fromIntegral x :: Int16)
527−zext16_32 [VConstant (B16 x)] = Just $ toB32 x
346+sext IT32 out [VConstant (B32 x)] = Just $ toInt out (fromIntegral x :: Int32)
528−zext16_32 _ = Nothing
347+sext IT64 out [VConstant (B64 x)] = Just $ toInt out (fromIntegral x :: Int64)
529−
348+sext ITBig _ _ = Nothing
530−zext16_64 [VConstant (B16 x)] = Just $ toB64 x
349+sext from to val = intToInt from to val
531−zext16_64 _ = Nothing
350+
532−
351+trunc ITBig to val = intToInt ITBig to val
533−sext16_32 [VConstant (B16 x)] = Just $ toB32 (fromIntegral x :: Int16)
352+trunc _ ITBig _ = Nothing
534−sext16_32 _ = Nothing
353+trunc from to val | intTyWidth from > intTyWidth to = intToInt from to val
535−
354+trunc _ _ _ = Nothing
536−sext16_64 [VConstant (B16 x)] = Just $ toB64 (fromIntegral x :: Int16)
355+
537−sext16_64 _ = Nothing
356+getInt :: [Value] -> Maybe Integer
538−
357+getInt [VConstant (B8 x)] = Just . toInteger $ x
539−trunc16_8 [VConstant (B16 x)] = Just $ toB8 x
358+getInt [VConstant (B16 x)] = Just . toInteger $ x
540−trunc16_8 _ = Nothing
359+getInt [VConstant (B32 x)] = Just . toInteger $ x
541−
360+getInt [VConstant (B64 x)] = Just . toInteger $ x
542−zext32_64 [VConstant (B32 x)] = Just $ toB64 x
361+getInt [VConstant (I x)] = Just . toInteger $ x
543−zext32_64 _ = Nothing
362+getInt [VConstant (BI x)] = Just x
544−
363+getInt _ = Nothing
545−sext32_64 [VConstant (B32 x)] = Just $ toB64 (fromIntegral x :: Int32)
364+
546−sext32_64 _ = Nothing
365+intToStr val | Just i <- getInt val = Just $ VConstant (Str (show i))
547−
366+intToStr _ = Nothing
548−trunc32_8 [VConstant (B32 x)] = Just $ toB8 x
367+
549−trunc32_8 _ = Nothing
368+strToInt ity [VConstant (Str x)] = case reads x of
550−
369+ [(n,"")] -> Just $ toInt ity (n :: Integer)
551−trunc32_16 [VConstant (B32 x)] = Just $ toB16 x
370+ _ -> Just $ VConstant (I 0)
552−trunc32_16 _ = Nothing
371+strToInt _ _ = Nothing
554−trunc64_8 [VConstant (B64 x)] = Just $ toB8 x
373+intToFloat val | Just i <- getInt val = Just $ VConstant (Fl (fromIntegral i))
555−trunc64_8 _ = Nothing
374+intToFloat _ = Nothing
557−trunc64_16 [VConstant (B64 x)] = Just $ toB16 x
376+floatToInt ity [VConstant (Fl x)] = Just $ toInt ity (truncate x :: Integer)
558−trunc64_16 _ = Nothing
377+floatToInt _ _ = Nothing
560−trunc64_32 [VConstant (B64 x)] = Just $ toB32 x
561−trunc64_32 _ = Nothing
563−intToBits8 [VConstant (I x)] = Just $ toB8 x
564−intToBits8 _ = Nothing
565−intToBits16 [VConstant (I x)] = Just $ toB16 x
566−intToBits16 _ = Nothing
567−intToBits32 [VConstant (I x)] = Just $ toB32 x
568−intToBits32 _ = Nothing
569−intToBits64 [VConstant (I x)] = Just $ toB64 x
570−intToBits64 _ = Nothing
572−bits32ToInt [VConstant (B32 x)] = Just $ VConstant (I (fromIntegral x))
573−bits32ToInt _ = Nothing
575−c_intToStr [VConstant (I x)] = Just $ VConstant (Str (show x))
576−c_intToStr _ = Nothing
577−c_strToInt [VConstant (Str x)] = case reads x of
578− [(n,"")] -> Just $ VConstant (I n)
579− _ -> Just $ VConstant (I 0)
580−c_strToInt _ = Nothing
582c_intToChar [VConstant (I x)] = Just $ VConstant (Ch (toEnum x))
379c_intToChar [VConstant (I x)] = Just $ VConstant (Ch (toEnum x))
583c_intToChar _ = Nothing
380c_intToChar _ = Nothing
584c_charToInt [VConstant (Ch x)] = Just $ VConstant (I (fromEnum x))
381c_charToInt [VConstant (Ch x)] = Just $ VConstant (I (fromEnum x))
585c_charToInt _ = Nothing
382c_charToInt _ = Nothing
587−c_intToBigInt [VConstant (I x)] = Just $ VConstant (BI (fromIntegral x))
588−c_intToBigInt _ = Nothing
589−c_bigIntToInt [VConstant (BI x)] = Just $ VConstant (I (fromInteger x))
590−c_bigIntToInt _ = Nothing
592−c_bigIntToStr [VConstant (BI x)] = Just $ VConstant (Str (show x))
593−c_bigIntToStr _ = Nothing
594−c_strToBigInt [VConstant (Str x)] = case reads x of
595− [(n,"")] -> Just $ VConstant (BI n)
596− _ -> Just $ VConstant (BI 0)
597−c_strToBigInt _ = Nothing
599c_floatToStr [VConstant (Fl x)] = Just $ VConstant (Str (show x))
384c_floatToStr [VConstant (Fl x)] = Just $ VConstant (Str (show x))
600c_floatToStr _ = Nothing
385c_floatToStr _ = Nothing
601c_strToFloat [VConstant (Str x)] = case reads x of
386c_strToFloat [VConstant (Str x)] = case reads x of
@@ -603,12 +388,6 @@ c_strToFloat [VConstant (Str x)] = case reads x of
603 _ -> Just $ VConstant (Fl 0)
388 _ -> Just $ VConstant (Fl 0)
604c_strToFloat _ = Nothing
389c_strToFloat _ = Nothing
606−c_floatToInt [VConstant (Fl x)] = Just $ VConstant (I (truncate x))
607−c_floatToInt _ = Nothing
609−c_intToFloat [VConstant (I x)] = Just $ VConstant (Fl (fromIntegral x))
610−c_intToFloat _ = Nothing
612p_fPrim f [VConstant (Fl x)] = Just $ VConstant (Fl (f x))
391p_fPrim f [VConstant (Fl x)] = Just $ VConstant (Fl (f x))
613p_fPrim f _ = Nothing
392p_fPrim f _ = Nothing
@@ -625,6 +404,7 @@ p_floatFloor = p_fPrim (fromInteger . floor)
625p_floatCeil = p_fPrim (fromInteger . ceiling)
404p_floatCeil = p_fPrim (fromInteger . ceiling)
627p_strLen [VConstant (Str xs)] = Just $ VConstant (I (length xs))
406p_strLen [VConstant (Str xs)] = Just $ VConstant (I (length xs))
628p_strHead [VConstant (Str (x:xs))] = Just $ VConstant (Ch x)
408p_strHead [VConstant (Str (x:xs))] = Just $ VConstant (Ch x)
629p_strHead _ = Nothing
409p_strHead _ = Nothing
630p_strTail [VConstant (Str (x:xs))] = Just $ VConstant (Str xs)
410p_strTail [VConstant (Str (x:xs))] = Just $ VConstant (Str xs)