@@ -11,6 +11,8 @@ import IRTS.Lang
11import Core.TT
11import Core.TT
12import Core.Evaluate
12import Core.Evaluate
13import Data.Bits
13import Data.Bits
15data Prim = Prim { p_name :: Name,
17data Prim = Prim { p_name :: Name,
16 p_type :: Type,
18 p_type :: Type,
@@ -75,24 +77,90 @@ primitives =
75 Prim (UN "prim__gteChar") (ty [ChType, ChType] IType) 2 (bcBin (>=))
77 Prim (UN "prim__gteChar") (ty [ChType, ChType] IType) 2 (bcBin (>=))
76 (2, LGe) total,
78 (2, LGe) total,
78− Prim (UN "prim__addW8") (ty [W8Type, W8Type] W8Type) 2 (w8Bin (+))
80+ Prim (UN "prim__addB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (+))
82+ Prim (UN "prim__subB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (-))
84+ Prim (UN "prim__mulB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (*))
86+ Prim (UN "prim__udivB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin div)
88+ Prim (UN "prim__sdivB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin s8div)
90+ Prim (UN "prim__zextB8_16") (ty [B8Type] B16Type) 1 zext8_16
92+ Prim (UN "prim__zextB8_32") (ty [B8Type] B32Type) 1 zext8_32
94+ Prim (UN "prim__zextB8_64") (ty [B8Type] B64Type) 1 zext8_64
96+ Prim (UN "prim__sextB8_16") (ty [B8Type] B16Type) 1 sext8_16
98+ Prim (UN "prim__sextB8_32") (ty [B8Type] B32Type) 1 sext8_32
100+ Prim (UN "prim__sextB8_64") (ty [B8Type] B64Type) 1 sext8_64
103+ Prim (UN "prim__addB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin (+))
104+ (2, LB16Plus) total,
105+ Prim (UN "prim__subB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin (-))
106+ (2, LB16Minus) total,
107+ Prim (UN "prim__mulB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin (*))
108+ (2, LB16Times) total,
109+ Prim (UN "prim__udivB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin div)
110+ (2, LB16UDiv) total,
111+ Prim (UN "prim__sdivB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin s16div)
112+ (2, LB16SDiv) total,
113+ Prim (UN "prim__zextB16_32") (ty [B16Type] B32Type) 1 zext16_32
115+ Prim (UN "prim__zextB16_64") (ty [B16Type] B64Type) 1 zext16_64
117+ Prim (UN "prim__sextB16_32") (ty [B16Type] B32Type) 1 sext16_32
119+ Prim (UN "prim__sextB16_64") (ty [B16Type] B64Type) 1 sext16_64
121+ Prim (UN "prim__truncB16_8") (ty [B16Type] B8Type) 1 trunc16_8
124+ Prim (UN "prim__addB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin (+))
125+ (2, LB32Plus) total,
126+ Prim (UN "prim__subB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin (-))
127+ (2, LB32Minus) total,
128+ Prim (UN "prim__mulB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin (*))
129+ (2, LB32Times) total,
130+ Prim (UN "prim__udivB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin div)
131+ (2, LB32UDiv) total,
132+ Prim (UN "prim__sdivB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin s32div)
133+ (2, LB32SDiv) total,
134+ Prim (UN "prim__zextB32_64") (ty [B32Type] B64Type) 1 zext32_64
136+ Prim (UN "prim__sextB32_64") (ty [B32Type] B64Type) 1 sext32_64
138+ Prim (UN "prim__truncB32_8") (ty [B32Type] B8Type) 1 trunc32_8
140+ Prim (UN "prim__truncB32_16") (ty [B32Type] B16Type) 1 trunc32_16
143+ Prim (UN "prim__addB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin (+))
79− (2, LW8Plus) total,
144+ (2, LB64Plus) total,
80− Prim (UN "prim__subW8") (ty [W8Type, W8Type] W8Type) 2 (w8Bin (-))
145+ Prim (UN "prim__subB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin (-))
81− (2, LW8Minus) total,
146+ (2, LB64Minus) total,
82− Prim (UN "prim__mulW8") (ty [W8Type, W8Type] W8Type) 2 (w8Bin (*))
147+ Prim (UN "prim__mulB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin (*))
83− (2, LW8Times) total,
148+ (2, LB64Times) total,
84−
149+ Prim (UN "prim__udivB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin div)
85− Prim (UN "prim__addW16") (ty [W16Type, W16Type] W16Type) 2 (w16Bin (+))
86− (2, LW16Plus) total,
150+ (2, LB64UDiv) total,
87− Prim (UN "prim__subW16") (ty [W16Type, W16Type] W16Type) 2 (w16Bin (-))
151+ Prim (UN "prim__sdivB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin s64div)
88− (2, LW16Minus) total,
152+ (2, LB64SDiv) total,
89− Prim (UN "prim__mulW16") (ty [W16Type, W16Type] W16Type) 2 (w16Bin (*))
153+ Prim (UN "prim__truncB64_8") (ty [B64Type] B8Type) 1 trunc64_8
90− (2, LW16Times) total,
154+ (1, LB64T8) total,
91−
155+ Prim (UN "prim__truncB64_16") (ty [B64Type] B16Type) 1 trunc64_16
92− Prim (UN "prim__intToWord8") (ty [IType] W8Type) 1 intToWord8
156+ (1, LB64T16) total,
157+ Prim (UN "prim__truncB64_32") (ty [B64Type] B32Type) 1 trunc64_32
160+ Prim (UN "prim__intToBits8") (ty [IType] B8Type) 1 intToBits8
93− (1, LW8) total,
161+ (1, LB8) total,
94− Prim (UN "prim__intToWord16") (ty [IType] W16Type) 1 intToWord16
162+ Prim (UN "prim__intToBits16") (ty [IType] B16Type) 1 intToBits16
95− (1, LW16) total,
163+ (1, LB16) total,
97 Prim (UN "prim__addBigInt") (ty [BIType, BIType] BIType) 2 (bBin (+))
165 Prim (UN "prim__addBigInt") (ty [BIType, BIType] BIType) 2 (bBin (+))
98 (2, LBPlus) total,
166 (2, LBPlus) total,
@@ -245,19 +313,93 @@ bsBin _ _ = Nothing
245sBin op [VConstant (Str x), VConstant (Str y)] = Just $ VConstant (Str (op x y))
313sBin op [VConstant (Str x), VConstant (Str y)] = Just $ VConstant (Str (op x y))
246sBin _ _ = Nothing
314sBin _ _ = Nothing
248−w8Bin op [VConstant (W8 x), VConstant (W8 y)] = Just $ VConstant (W8 (op x y))
316+s8div :: Word8 -> Word8 -> Word8
249−w8Bin _ _ = Nothing
317+s8div x y = fromIntegral (fromIntegral x `div` fromIntegral y :: Int8)
251−w16Bin op [VConstant (W16 x), VConstant (W16 y)] = Just $ VConstant (W16 (op x y))
319+s16div :: Word16 -> Word16 -> Word16
252−w16Bin _ _ = Nothing
320+s16div x y = fromIntegral (fromIntegral x `div` fromIntegral y :: Int16)
254−-- w32Bin op [VConstant (W32 x), VConstant (W32 y)] = Just $ VConstant (W32 (op x y))
322+s32div :: Word32 -> Word32 -> Word32
255−-- w32Bin _ _ = Nothing
323+s32div x y = fromIntegral (fromIntegral x `div` fromIntegral y :: Int32)
325+s64div :: Word64 -> Word64 -> Word64
326+s64div x y = fromIntegral (fromIntegral x `div` fromIntegral y :: Int64)
328+b8Bin op [VConstant (B8 x), VConstant (B8 y)] = Just $ VConstant (B8 (op x y))
331+b16Bin op [VConstant (B16 x), VConstant (B16 y)] = Just $ VConstant (B16 (op x y))
334+b32Bin op [VConstant (B32 x), VConstant (B32 y)] = Just $ VConstant (B32 (op x y))
337+b64Bin op [VConstant (B64 x), VConstant (B64 y)] = Just $ VConstant (B64 (op x y))
340+toB8 x = VConstant (B8 (fromIntegral x))
341+toB16 x = VConstant (B16 (fromIntegral x))
342+toB32 x = VConstant (B32 (fromIntegral x))
343+toB64 x = VConstant (B64 (fromIntegral x))
345+zext8_16 [VConstant (B8 x)] = Just $ toB16 x
348+zext8_32 [VConstant (B8 x)] = Just $ toB32 x
351+zext8_64 [VConstant (B8 x)] = Just $ toB64 x
354+sext8_16 [VConstant (B8 x)] = Just $ toB16 (fromIntegral x :: Int8)
357+sext8_32 [VConstant (B8 x)] = Just $ toB32 (fromIntegral x :: Int8)
360+sext8_64 [VConstant (B8 x)] = Just $ toB64 (fromIntegral x :: Int8)
363+zext16_32 [VConstant (B16 x)] = Just $ toB32 x
364+zext16_32 _ = Nothing
366+zext16_64 [VConstant (B16 x)] = Just $ toB64 x
367+zext16_64 _ = Nothing
369+sext16_32 [VConstant (B16 x)] = Just $ toB32 (fromIntegral x :: Int16)
370+sext16_32 _ = Nothing
372+sext16_64 [VConstant (B16 x)] = Just $ toB64 (fromIntegral x :: Int16)
373+sext16_64 _ = Nothing
375+trunc16_8 [VConstant (B16 x)] = Just $ toB8 x
376+trunc16_8 _ = Nothing
378+zext32_64 [VConstant (B32 x)] = Just $ toB64 x
379+zext32_64 _ = Nothing
257−intToWord8 [VConstant (I x)] = Just $ VConstant (W8 $ fromIntegral x)
381+sext32_64 [VConstant (B32 x)] = Just $ toB64 (fromIntegral x :: Int32)
382+sext32_64 _ = Nothing
384+trunc32_8 [VConstant (B32 x)] = Just $ toB8 x
385+trunc32_8 _ = Nothing
387+trunc32_16 [VConstant (B32 x)] = Just $ toB16 x
388+trunc32_16 _ = Nothing
390+trunc64_8 [VConstant (B64 x)] = Just $ toB8 x
391+trunc64_8 _ = Nothing
393+trunc64_16 [VConstant (B64 x)] = Just $ toB16 x
258−intToWord8 _ = Nothing
394+trunc64_16 _ = Nothing
259−intToWord16 [VConstant (I x)] = Just $ VConstant (W16 $ fromIntegral x)
395+
396+trunc64_32 [VConstant (B64 x)] = Just $ toB32 x
397+trunc64_32 _ = Nothing
399+intToBits8 [VConstant (I x)] = Just $ toB8 x
400+intToBits8 _ = Nothing
401+intToBits16 [VConstant (I x)] = Just $ toB16 x
260−intToWord16 _ = Nothing
402+intToBits16 _ = Nothing
262c_intToStr [VConstant (I x)] = Just $ VConstant (Str (show x))
404c_intToStr [VConstant (I x)] = Just $ VConstant (Str (show x))
263c_intToStr _ = Nothing
405c_intToStr _ = Nothing