on master help sign in
String primitives
348cf91Benjamin Saunders
lib/Prelude/Bits.idr+7
@@ -56,3 +56,10 @@ bitsUDiv {n=m} x y with (Bits m)
56 | Bits16 = prim__udivB16 x y
56 | Bits16 = prim__udivB16 x y
57 | Bits32 = prim__udivB32 x y
57 | Bits32 = prim__udivB32 x y
58 | Bits64 = prim__udivB64 x y
58 | Bits64 = prim__udivB64 x y
59+
60+bitsToStr : {n : Nat} -> Bits n -> String
61+bitsToStr {n=m} x with (Bits m)
62+ | Bits8 = prim__b8ToStr x
63+ | Bits16 = prim__b16ToStr x
64+ | Bits32 = prim__b32ToStr x
65+ | Bits64 = prim__b64ToStr x
src/IRTS/Lang.hs+1
@@ -49,6 +49,7 @@ data PrimFn = LPlus | LMinus | LTimes | LDiv | LMod
49 | LB64Plus | LB64Minus | LB64Times | LB64UDiv | LB64SDiv
49 | LB64Plus | LB64Minus | LB64Times | LB64UDiv | LB64SDiv
50 | LB64T8 | LB64T16 | LB64T32
50 | LB64T8 | LB64T16 | LB64T32
51 | LIntB8 | LIntB16 | LIntB32 | LIntB64 | LB32Int
51 | LIntB8 | LIntB16 | LIntB32 | LIntB64 | LB32Int
52+ | LB8Str | LB16Str | LB32Str | LB64Str
52
53
53 | LFExp | LFLog | LFSin | LFCos | LFTan | LFASin | LFACos | LFATan
54 | LFExp | LFLog | LFSin | LFCos | LFTan | LFASin | LFACos | LFATan
54 | LFSqrt | LFFloor | LFCeil
55 | LFSqrt | LFFloor | LFCeil
src/Idris/Primitives.hs+20
@@ -77,6 +77,8 @@ primitives =
77 Prim (UN "prim__gteChar") (ty [ChType, ChType] IType) 2 (bcBin (>=))
77 Prim (UN "prim__gteChar") (ty [ChType, ChType] IType) 2 (bcBin (>=))
78 (2, LGe) total,
78 (2, LGe) total,
79
79
80+ Prim (UN "prim__b8ToStr") (ty [B8Type] StrType) 1 (b8ToStr)
81+ (1, LB8Str) total,
80 Prim (UN "prim__addB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (+))
82 Prim (UN "prim__addB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (+))
81 (2, LB8Plus) total,
83 (2, LB8Plus) total,
82 Prim (UN "prim__subB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (-))
84 Prim (UN "prim__subB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (-))
@@ -100,6 +102,8 @@ primitives =
100 Prim (UN "prim__sextB8_64") (ty [B8Type] B64Type) 1 sext8_64
102 Prim (UN "prim__sextB8_64") (ty [B8Type] B64Type) 1 sext8_64
101 (1, LB8Z64) total,
103 (1, LB8Z64) total,
102
104
105+ Prim (UN "prim__b16ToStr") (ty [B16Type] StrType) 1 (b16ToStr)
106+ (1, LB16Str) total,
103 Prim (UN "prim__addB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin (+))
107 Prim (UN "prim__addB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin (+))
104 (2, LB16Plus) total,
108 (2, LB16Plus) total,
105 Prim (UN "prim__subB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin (-))
109 Prim (UN "prim__subB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin (-))
@@ -121,6 +125,8 @@ primitives =
121 Prim (UN "prim__truncB16_8") (ty [B16Type] B8Type) 1 trunc16_8
125 Prim (UN "prim__truncB16_8") (ty [B16Type] B8Type) 1 trunc16_8
122 (1, LB16T8) total,
126 (1, LB16T8) total,
123
127
128+ Prim (UN "prim__b32ToStr") (ty [B32Type] StrType) 1 (b32ToStr)
129+ (1, LB32Str) total,
124 Prim (UN "prim__addB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin (+))
130 Prim (UN "prim__addB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin (+))
125 (2, LB32Plus) total,
131 (2, LB32Plus) total,
126 Prim (UN "prim__subB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin (-))
132 Prim (UN "prim__subB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin (-))
@@ -140,6 +146,8 @@ primitives =
140 Prim (UN "prim__truncB32_16") (ty [B32Type] B16Type) 1 trunc32_16
146 Prim (UN "prim__truncB32_16") (ty [B32Type] B16Type) 1 trunc32_16
141 (1, LB32T16) total,
147 (1, LB32T16) total,
142
148
149+ Prim (UN "prim__b64ToStr") (ty [B64Type] StrType) 1 (b64ToStr)
150+ (1, LB64Str) total,
143 Prim (UN "prim__addB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin (+))
151 Prim (UN "prim__addB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin (+))
144 (2, LB64Plus) total,
152 (2, LB64Plus) total,
145 Prim (UN "prim__subB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin (-))
153 Prim (UN "prim__subB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin (-))
@@ -331,6 +339,18 @@ s32div x y = fromIntegral (fromIntegral x `div` fromIntegral y :: Int32)
331s64div :: Word64 -> Word64 -> Word64
339s64div :: Word64 -> Word64 -> Word64
332s64div x y = fromIntegral (fromIntegral x `div` fromIntegral y :: Int64)
340s64div x y = fromIntegral (fromIntegral x `div` fromIntegral y :: Int64)
333
341
342+b8ToStr [VConstant (B8 x)] = Just $ VConstant (Str (show x))
343+b8ToStr _ = Nothing
344+
345+b16ToStr [VConstant (B16 x)] = Just $ VConstant (Str (show x))
346+b16ToStr _ = Nothing
347+
348+b32ToStr [VConstant (B32 x)] = Just $ VConstant (Str (show x))
349+b32ToStr _ = Nothing
350+
351+b64ToStr [VConstant (B64 x)] = Just $ VConstant (Str (show x))
352+b64ToStr _ = Nothing
353+
334b8Bin op [VConstant (B8 x), VConstant (B8 y)] = Just $ VConstant (B8 (op x y))
354b8Bin op [VConstant (B8 x), VConstant (B8 y)] = Just $ VConstant (B8 (op x y))
335b8Bin _ _ = Nothing
355b8Bin _ _ = Nothing
336
356