1{-# LANGUAGE RankNTypes, ScopedTypeVariables #-}
3module Idris.Primitives(elabPrims) where
17data Prim = Prim { p_name :: Name,
20 p_def :: [Value] -> Maybe Value,
21 p_lexp :: (Int, PrimFn),
26ty (t:ts) x = Bind (MN 0 "T") (Pi (Constant t)) (ty ts x)
28believeTy = Bind (UN "a") (Pi (TType (UVar (-2))))
29 (Bind (UN "b") (Pi (TType (UVar (-2))))
30 (Bind (UN "x") (Pi (V 1)) (V 1)))
33partial = Partial NotCovering
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 (==))
71 Prim (UN "prim__ltChar") (ty [ChType, ChType] IType) 2 (bcBin (<))
73 Prim (UN "prim__lteChar") (ty [ChType, ChType] IType) 2 (bcBin (<=))
75 Prim (UN "prim__gtChar") (ty [ChType, ChType] IType) 2 (bcBin (>))
77 Prim (UN "prim__gteChar") (ty [ChType, ChType] IType) 2 (bcBin (>=))
80 Prim (UN "prim__ltB8") (ty [B8Type, B8Type] IType) 2 (b8Cmp (<))
82 Prim (UN "prim__lteB8") (ty [B8Type, B8Type] IType) 2 (b8Cmp (<=))
84 Prim (UN "prim__eqB8") (ty [B8Type, B8Type] IType) 2 (b8Cmp (==))
86 Prim (UN "prim__gteB8") (ty [B8Type, B8Type] IType) 2 (b8Cmp (>))
88 Prim (UN "prim__gtB8") (ty [B8Type, B8Type] IType) 2 (b8Cmp (>=))
90 Prim (UN "prim__addB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (+))
92 Prim (UN "prim__subB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (-))
94 Prim (UN "prim__mulB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (*))
96 Prim (UN "prim__udivB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin div)
98 Prim (UN "prim__sdivB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin s8div)
100 Prim (UN "prim__uremB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin rem)
101 (2, LB8URem) partial,
102 Prim (UN "prim__sremB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin s8rem)
103 (2, LB8SRem) partial,
104 Prim (UN "prim__shlB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (\x y -> shiftL x (fromIntegral y)))
106 Prim (UN "prim__lshrB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (\x y -> shiftR x (fromIntegral y)))
108 Prim (UN "prim__ashrB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (\x y -> fromIntegral $
109 shiftR (fromIntegral x :: Int8)
112 Prim (UN "prim__andB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (.&.))
114 Prim (UN "prim__orB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin (.|.))
116 Prim (UN "prim__xorB8") (ty [B8Type, B8Type] B8Type) 2 (b8Bin xor)
118 Prim (UN "prim__complB8") (ty [B8Type] B8Type) 1 (b8Un complement)
120 Prim (UN "prim__zextB8_16") (ty [B8Type] B16Type) 1 zext8_16
122 Prim (UN "prim__zextB8_32") (ty [B8Type] B32Type) 1 zext8_32
124 Prim (UN "prim__zextB8_64") (ty [B8Type] B64Type) 1 zext8_64
126 Prim (UN "prim__sextB8_16") (ty [B8Type] B16Type) 1 sext8_16
128 Prim (UN "prim__sextB8_32") (ty [B8Type] B32Type) 1 sext8_32
130 Prim (UN "prim__sextB8_64") (ty [B8Type] B64Type) 1 sext8_64
133 Prim (UN "prim__ltB16") (ty [B16Type, B16Type] IType) 2 (b16Cmp (<))
135 Prim (UN "prim__lteB16") (ty [B16Type, B16Type] IType) 2 (b16Cmp (<=))
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 (+))
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)))
161 Prim (UN "prim__ashrB16") (ty [B16Type, B16Type] B16Type) 2 (b16Bin (\x y -> fromIntegral $
162 shiftR (fromIntegral x :: Int16)
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 (+))
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)))
212 Prim (UN "prim__ashrB32") (ty [B32Type, B32Type] B32Type) 2 (b32Bin (\x y -> fromIntegral $
213 shiftR (fromIntegral x :: Int32)
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 (+))
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)))
261 Prim (UN "prim__ashrB64") (ty [B64Type, B64Type] B64Type) 2 (b64Bin (\x y -> fromIntegral $
262 shiftR (fromIntegral x :: Int64)
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 (+))
313 Prim (UN "prim__subFloat") (ty [FlType, FlType] FlType) 2 (fBin (-))
315 Prim (UN "prim__mulFloat") (ty [FlType, FlType] FlType) 2 (fBin (*))
317 Prim (UN "prim__divFloat") (ty [FlType, FlType] FlType) 2 (fBin (/))
319 Prim (UN "prim__eqFloat") (ty [FlType, FlType] IType) 2 (bfBin (==))
321 Prim (UN "prim__ltFloat") (ty [FlType, FlType] IType) 2 (bfBin (<))
323 Prim (UN "prim__lteFloat") (ty [FlType, FlType] IType) 2 (bfBin (<=))
325 Prim (UN "prim__gtFloat") (ty [FlType, FlType] IType) 2 (bfBin (>))
327 Prim (UN "prim__gteFloat") (ty [FlType, FlType] IType) 2 (bfBin (>=))
329 Prim (UN "prim__concat") (ty [StrType, StrType] StrType) 2 (sBin (++))
330 (2, LStrConcat) total,
331 Prim (UN "prim__eqString") (ty [StrType, StrType] IType) 2 (bsBin (==))
333 Prim (UN "prim__ltString") (ty [StrType, StrType] IType) 2 (bsBin (<))
335 Prim (UN "prim_lenString") (ty [StrType] IType) 1 (p_strLen)
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)
344 Prim (UN "prim__intToChar") (ty [IType] ChType) 1 (c_intToChar)
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)
355 (1, LStrFloat) total,
356 Prim (UN "prim__floatToStr") (ty [FlType] StrType) 1 (c_floatToStr)
357 (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)
365 Prim (UN "prim__floatLog") (ty [FlType] FlType) 1 (p_floatLog)
367 Prim (UN "prim__floatSin") (ty [FlType] FlType) 1 (p_floatSin)
369 Prim (UN "prim__floatCos") (ty [FlType] FlType) 1 (p_floatCos)
371 Prim (UN "prim__floatTan") (ty [FlType] FlType) 1 (p_floatTan)
373 Prim (UN "prim__floatASin") (ty [FlType] FlType) 1 (p_floatASin)
375 Prim (UN "prim__floatACos") (ty [FlType] FlType) 1 (p_floatACos)
377 Prim (UN "prim__floatATan") (ty [FlType] FlType) 1 (p_floatATan)
379 Prim (UN "prim__floatSqrt") (ty [FlType] FlType) 1 (p_floatSqrt)
381 Prim (UN "prim__floatFloor") (ty [FlType] FlType) 1 (p_floatFloor)
383 Prim (UN "prim__floatCeil") (ty [FlType] FlType) 1 (p_floatCeil)
386 Prim (UN "prim__strHead") (ty [StrType] ChType) 1 (p_strHead)
387 (1, LStrHead) partial,
388 Prim (UN "prim__strTail") (ty [StrType] StrType) 1 (p_strTail)
389 (1, LStrTail) partial,
390 Prim (UN "prim__strCons") (ty [ChType, StrType] StrType) 2 (p_strCons)
392 Prim (UN "prim__strIndex") (ty [StrType, IType] ChType) 2 (p_strIndex)
393 (2, LStrIndex) partial,
394 Prim (UN "prim__strRev") (ty [StrType] StrType) 1 (p_strRev)
396 Prim (UN "prim__readString") (ty [PtrType] StrType) 1 (p_cantreduce)
397 (1, LReadStr) partial,
398 Prim (UN "prim__vm") (ty [] PtrType) 0 (p_cantreduce)
401 Prim (UN "prim__stdin") (ty [] PtrType) 0 (p_cantreduce)
403 Prim (UN "prim__believe_me") believeTy 3 (p_believeMe)
404 (3, LNoOp) partial -- ahem
407p_believeMe [_,_,x] = Just x
408p_believeMe _ = Nothing
410iUn op [VConstant (I x)] = Just $ VConstant (I (op x))
413iBin op [VConstant (I x), VConstant (I y)] = Just $ VConstant (I (op x y))
416bBin op [VConstant (BI x), VConstant (BI y)] = Just $ VConstant (BI (op x y))
419bBini op [VConstant (BI x), VConstant (BI y)] = Just $ VConstant (I (op x y))
422biBin op = iBin (\x y -> if (op x y) then 1 else 0)
423bbBin op = bBini (\x y -> if (op x y) then 1 else 0)
425fBin op [VConstant (Fl x), VConstant (Fl y)] = Just $ VConstant (Fl (op x y))
428bfBin op [VConstant (Fl x), VConstant (Fl y)] = let i = (if op x y then 1 else 0) in
429 Just $ VConstant (I i)
432bcBin op [VConstant (Ch x), VConstant (Ch y)] = let i = (if op x y then 1 else 0) in
433 Just $ VConstant (I i)
436bsBin op [VConstant (Str x), VConstant (Str y)]
437 = let i = (if op x y then 1 else 0) in
438 Just $ VConstant (I i)
441sBin op [VConstant (Str x), VConstant (Str y)] = Just $ VConstant (Str (op x y))
444s8div :: Word8 -> Word8 -> Word8
445s8div x y = fromIntegral (fromIntegral x `div` fromIntegral y :: Int8)
447s16div :: Word16 -> Word16 -> Word16
448s16div x y = fromIntegral (fromIntegral x `div` fromIntegral y :: Int16)
450s32div :: Word32 -> Word32 -> Word32
451s32div x y = fromIntegral (fromIntegral x `div` fromIntegral y :: Int32)
453s64div :: Word64 -> Word64 -> Word64
454s64div x y = fromIntegral (fromIntegral x `div` fromIntegral y :: Int64)
456s8rem :: Word8 -> Word8 -> Word8
457s8rem x y = fromIntegral (fromIntegral x `rem` fromIntegral y :: Int8)
459s16rem :: Word16 -> Word16 -> Word16
460s16rem x y = fromIntegral (fromIntegral x `rem` fromIntegral y :: Int16)
462s32rem :: Word32 -> Word32 -> Word32
463s32rem x y = fromIntegral (fromIntegral x `rem` fromIntegral y :: Int32)
465s64rem :: Word64 -> Word64 -> Word64
466s64rem x y = fromIntegral (fromIntegral x `rem` fromIntegral y :: Int64)
468b8Bin op [VConstant (B8 x), VConstant (B8 y)] = Just $ VConstant (B8 (op x y))
471b8Un op [VConstant (B8 x)] = Just $ VConstant (B8 (op x))
474b16Bin op [VConstant (B16 x), VConstant (B16 y)] = Just $ VConstant (B16 (op x y))
477b16Un op [VConstant (B16 x)] = Just $ VConstant (B16 (op x))
480b32Bin op [VConstant (B32 x), VConstant (B32 y)] = Just $ VConstant (B32 (op x y))
483b32Un op [VConstant (B32 x)] = Just $ VConstant (B32 (op x))
486b64Bin op [VConstant (B64 x), VConstant (B64 y)] = Just $ VConstant (B64 (op x y))
489b64Un op [VConstant (B64 x)] = Just $ VConstant (B64 (op x))
492b8Cmp op [VConstant (B8 x), VConstant (B8 y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
495b16Cmp op [VConstant (B16 x), VConstant (B16 y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
498b32Cmp op [VConstant (B32 x), VConstant (B32 y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
501b64Cmp op [VConstant (B64 x), VConstant (B64 y)] = Just $ VConstant (I (if (op x y) then 1 else 0))
504toB8 x = VConstant (B8 (fromIntegral x))
505toB16 x = VConstant (B16 (fromIntegral x))
506toB32 x = VConstant (B32 (fromIntegral x))
507toB64 x = VConstant (B64 (fromIntegral x))
509zext8_16 [VConstant (B8 x)] = Just $ toB16 x
512zext8_32 [VConstant (B8 x)] = Just $ toB32 x
515zext8_64 [VConstant (B8 x)] = Just $ toB64 x
518sext8_16 [VConstant (B8 x)] = Just $ toB16 (fromIntegral x :: Int8)
521sext8_32 [VConstant (B8 x)] = Just $ toB32 (fromIntegral x :: Int8)
524sext8_64 [VConstant (B8 x)] = Just $ toB64 (fromIntegral x :: Int8)
527zext16_32 [VConstant (B16 x)] = Just $ toB32 x
530zext16_64 [VConstant (B16 x)] = Just $ toB64 x
533sext16_32 [VConstant (B16 x)] = Just $ toB32 (fromIntegral x :: Int16)
536sext16_64 [VConstant (B16 x)] = Just $ toB64 (fromIntegral x :: Int16)
539trunc16_8 [VConstant (B16 x)] = Just $ toB8 x
542zext32_64 [VConstant (B32 x)] = Just $ toB64 x
545sext32_64 [VConstant (B32 x)] = Just $ toB64 (fromIntegral x :: Int32)
548trunc32_8 [VConstant (B32 x)] = Just $ toB8 x
551trunc32_16 [VConstant (B32 x)] = Just $ toB16 x
552trunc32_16 _ = Nothing
554trunc64_8 [VConstant (B64 x)] = Just $ toB8 x
557trunc64_16 [VConstant (B64 x)] = Just $ toB16 x
558trunc64_16 _ = Nothing
560trunc64_32 [VConstant (B64 x)] = Just $ toB32 x
561trunc64_32 _ = Nothing
563intToBits8 [VConstant (I x)] = Just $ toB8 x
564intToBits8 _ = Nothing
565intToBits16 [VConstant (I x)] = Just $ toB16 x
566intToBits16 _ = Nothing
567intToBits32 [VConstant (I x)] = Just $ toB32 x
568intToBits32 _ = Nothing
569intToBits64 [VConstant (I x)] = Just $ toB64 x
570intToBits64 _ = Nothing
572bits32ToInt [VConstant (B32 x)] = Just $ VConstant (I (fromIntegral x))
573bits32ToInt _ = Nothing
575c_intToStr [VConstant (I x)] = Just $ VConstant (Str (show x))
576c_intToStr _ = Nothing
577c_strToInt [VConstant (Str x)] = case reads x of
578 [(n,"")] -> Just $ VConstant (I n)
579 _ -> Just $ VConstant (I 0)
580c_strToInt _ = Nothing
582c_intToChar [VConstant (I x)] = Just $ VConstant (Ch (toEnum x))
583c_intToChar _ = Nothing
584c_charToInt [VConstant (Ch x)] = Just $ VConstant (I (fromEnum x))
585c_charToInt _ = Nothing
587c_intToBigInt [VConstant (I x)] = Just $ VConstant (BI (fromIntegral x))
588c_intToBigInt _ = Nothing
589c_bigIntToInt [VConstant (BI x)] = Just $ VConstant (I (fromInteger x))
590c_bigIntToInt _ = Nothing
592c_bigIntToStr [VConstant (BI x)] = Just $ VConstant (Str (show x))
593c_bigIntToStr _ = Nothing
594c_strToBigInt [VConstant (Str x)] = case reads x of
595 [(n,"")] -> Just $ VConstant (BI n)
596 _ -> Just $ VConstant (BI 0)
597c_strToBigInt _ = Nothing
599c_floatToStr [VConstant (Fl x)] = Just $ VConstant (Str (show x))
600c_floatToStr _ = Nothing
601c_strToFloat [VConstant (Str x)] = case reads x of
602 [(n,"")] -> Just $ VConstant (Fl n)
603 _ -> Just $ VConstant (Fl 0)
604c_strToFloat _ = Nothing
606c_floatToInt [VConstant (Fl x)] = Just $ VConstant (I (truncate x))
607c_floatToInt _ = Nothing
609c_intToFloat [VConstant (I x)] = Just $ VConstant (Fl (fromIntegral x))
610c_intToFloat _ = Nothing
612p_fPrim f [VConstant (Fl x)] = Just $ VConstant (Fl (f x))
615p_floatExp = p_fPrim exp
616p_floatLog = p_fPrim log
617p_floatSin = p_fPrim sin
618p_floatCos = p_fPrim cos
619p_floatTan = p_fPrim tan
620p_floatASin = p_fPrim asin
621p_floatACos = p_fPrim acos
622p_floatATan = p_fPrim atan
623p_floatSqrt = p_fPrim sqrt
624p_floatFloor = p_fPrim (fromInteger . floor)
625p_floatCeil = p_fPrim (fromInteger . ceiling)
627p_strLen [VConstant (Str xs)] = Just $ VConstant (I (length xs))
628p_strHead [VConstant (Str (x:xs))] = Just $ VConstant (Ch x)
630p_strTail [VConstant (Str (x:xs))] = Just $ VConstant (Str xs)
632p_strIndex [VConstant (Str xs), VConstant (I i)]
633 | i < length xs = Just $ VConstant (Ch (xs!!i))
634p_strIndex _ = Nothing
635p_strCons [VConstant (Ch x), VConstant (Str xs)] = Just $ VConstant (Str (x:xs))
637p_strRev [VConstant (Str xs)] = Just $ VConstant (Str (reverse xs))
640p_cantreduce _ = Nothing
642elabPrim :: Prim -> Idris ()
643elabPrim (Prim n ty i def sc tot)
644 = do updateContext (addOperator n ty i def)
647 putIState i { idris_scprims = (n, sc) : idris_scprims i }
650elabPrims = do mapM_ (elabDecl EAll toplevel)
651 (map (PData "" defaultSyntax (FC "builtin" 0) False)
652 [inferDecl, unitDecl, falseDecl, pairDecl, eqDecl])
653 mapM_ elabPrim primitives
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list