on master help sign in
Merge pull request #112 from raichoo/master
0c8d6e7Edwin Brady
lib/Data/Bits.idrnew file+25
@@ -0,0 +1,25 @@
1+module Data.Bits
2+
3+%access public
4+%default partial
5+
6+infixl 5 .|.
7+infixl 7 .&.
8+
9+class Num a => Bits a where
10+ (.|.) : a -> a -> a
11+ (.&.) : a -> a -> a
12+
13+ xor : a -> a -> a
14+ complement : a -> a
15+ shiftL : a -> Int -> a
16+ shiftR : a -> Int -> a
17+
18+instance Bits Int where
19+ (.|.) = prim__orInt
20+ (.&.) = prim__andInt
21+
22+ xor = prim__xorInt
23+ complement = prim__complInt
24+ shiftL = prim__shLInt
25+ shiftR = prim__shRInt
lib/base.ipkg+1−1
@@ -14,7 +14,7 @@ modules = Builtins, Prelude, IO, System,
14
14
15 Language.Reflection,
15 Language.Reflection,
16
16
17− Data.Morphisms,
17+ Data.Morphisms, Data.Bits,
18
18
19 Control.Monad.Identity, Control.Monad.State, Control.Category,
19 Control.Monad.Identity, Control.Monad.State, Control.Category,
20 Control.Arrow
20 Control.Arrow
src/IRTS/CodegenC.hs+4
@@ -215,6 +215,10 @@ doOp v LDiv [l, r] = v ++ "INTOP(/," ++ creg l ++ ", " ++ creg r ++ ")"
215doOp v LMod [l, r] = v ++ "INTOP(%," ++ creg l ++ ", " ++ creg r ++ ")"
215doOp v LMod [l, r] = v ++ "INTOP(%," ++ creg l ++ ", " ++ creg r ++ ")"
216doOp v LAnd [l, r] = v ++ "INTOP(&," ++ creg l ++ ", " ++ creg r ++ ")"
216doOp v LAnd [l, r] = v ++ "INTOP(&," ++ creg l ++ ", " ++ creg r ++ ")"
217doOp v LOr [l, r] = v ++ "INTOP(|," ++ creg l ++ ", " ++ creg r ++ ")"
217doOp v LOr [l, r] = v ++ "INTOP(|," ++ creg l ++ ", " ++ creg r ++ ")"
218+doOp v LXOr [l, r] = v ++ "INTOP(^," ++ creg l ++ ", " ++ creg r ++ ")"
219+doOp v LSHL [l, r] = v ++ "INTOP(<<," ++ creg l ++ ", " ++ creg r ++ ")"
220+doOp v LSHR [l, r] = v ++ "INTOP(>>," ++ creg l ++ ", " ++ creg r ++ ")"
221+doOp v LCompl [x] = v ++ "INTOP(~," ++ creg x ++ ")"
218doOp v LEq [l, r] = v ++ "INTOP(==," ++ creg l ++ ", " ++ creg r ++ ")"
222doOp v LEq [l, r] = v ++ "INTOP(==," ++ creg l ++ ", " ++ creg r ++ ")"
219doOp v LLt [l, r] = v ++ "INTOP(<," ++ creg l ++ ", " ++ creg r ++ ")"
223doOp v LLt [l, r] = v ++ "INTOP(<," ++ creg l ++ ", " ++ creg r ++ ")"
220doOp v LLe [l, r] = v ++ "INTOP(<=," ++ creg l ++ ", " ++ creg r ++ ")"
224doOp v LLe [l, r] = v ++ "INTOP(<=," ++ creg l ++ ", " ++ creg r ++ ")"
src/IRTS/Lang.hs+2−1
@@ -28,7 +28,8 @@ data LExp = LV LVar
28-- Primitive operators. Backends are not *required* to implement all
28-- Primitive operators. Backends are not *required* to implement all
29-- of these, but should report an error if they are unable
29-- of these, but should report an error if they are unable
30
30
31−data PrimFn = LPlus | LMinus | LTimes | LDiv | LMod | LAnd | LOr
31+data PrimFn = LPlus | LMinus | LTimes | LDiv | LMod
32+ | LAnd | LOr | LXOr | LCompl | LSHL| LSHR
32 | LEq | LLt | LLe | LGt | LGe
33 | LEq | LLt | LLe | LGt | LGe
33 | LFPlus | LFMinus | LFTimes | LFDiv
34 | LFPlus | LFMinus | LFTimes | LFDiv
34 | LFEq | LFLt | LFLe | LFGt | LFGe
35 | LFEq | LFLt | LFLe | LFGt | LFGe
src/Idris/Primitives.hs+15−4
@@ -38,14 +38,22 @@ primitives =
38 (2, LMinus) total,
38 (2, LMinus) total,
39 Prim (UN "prim__mulInt") (ty [IType, IType] IType) 2 (iBin (*))
39 Prim (UN "prim__mulInt") (ty [IType, IType] IType) 2 (iBin (*))
40 (2, LTimes) total,
40 (2, LTimes) total,
41− Prim (UN "prim__divInt") (ty [IType, IType] IType) 2 (iBin (div))
41+ Prim (UN "prim__divInt") (ty [IType, IType] IType) 2 (iBin div)
42 (2, LDiv) partial,
42 (2, LDiv) partial,
43− Prim (UN "prim__modInt") (ty [IType, IType] IType) 2 (iBin (mod))
43+ Prim (UN "prim__modInt") (ty [IType, IType] IType) 2 (iBin mod)
44 (2, LMod) partial,
44 (2, LMod) partial,
45 Prim (UN "prim__andInt") (ty [IType, IType] IType) 2 (iBin (.&.))
45 Prim (UN "prim__andInt") (ty [IType, IType] IType) 2 (iBin (.&.))
46 (2, LAnd) partial,
46 (2, LAnd) partial,
47 Prim (UN "prim__orInt") (ty [IType, IType] IType) 2 (iBin (.|.))
47 Prim (UN "prim__orInt") (ty [IType, IType] IType) 2 (iBin (.|.))
48 (2, LOr) partial,
48 (2, LOr) partial,
49+ Prim (UN "prim__xorInt") (ty [IType, IType] IType) 2 (iBin xor)
50+ (2, LXOr) partial,
51+ Prim (UN "prim__shLInt") (ty [IType, IType] IType) 2 (iBin shiftL)
52+ (2, LSHL) partial,
53+ Prim (UN "prim__shRInt") (ty [IType, IType] IType) 2 (iBin shiftR)
54+ (2, LSHR) partial,
55+ Prim (UN "prim__complInt") (ty [IType] IType) 1 (iUn complement)
56+ (1, LCompl) partial,
49 Prim (UN "prim__eqInt") (ty [IType, IType] IType) 2 (biBin (==))
57 Prim (UN "prim__eqInt") (ty [IType, IType] IType) 2 (biBin (==))
50 (2, LEq) total,
58 (2, LEq) total,
51 Prim (UN "prim__ltInt") (ty [IType, IType] IType) 2 (biBin (<))
59 Prim (UN "prim__ltInt") (ty [IType, IType] IType) 2 (biBin (<))
@@ -73,9 +81,9 @@ primitives =
73 (2, LBMinus) total,
81 (2, LBMinus) total,
74 Prim (UN "prim__mulBigInt") (ty [BIType, BIType] BIType) 2 (bBin (*))
82 Prim (UN "prim__mulBigInt") (ty [BIType, BIType] BIType) 2 (bBin (*))
75 (2, LBTimes) total,
83 (2, LBTimes) total,
76− Prim (UN "prim__divBigInt") (ty [BIType, BIType] BIType) 2 (bBin (div))
84+ Prim (UN "prim__divBigInt") (ty [BIType, BIType] BIType) 2 (bBin div)
77 (2, LBDiv) partial,
85 (2, LBDiv) partial,
78− Prim (UN "prim__modBigInt") (ty [BIType, BIType] BIType) 2 (bBin (mod))
86+ Prim (UN "prim__modBigInt") (ty [BIType, BIType] BIType) 2 (bBin mod)
79 (2, LBMod) partial,
87 (2, LBMod) partial,
80 Prim (UN "prim__eqBigInt") (ty [BIType, BIType] IType) 2 (bbBin (==))
88 Prim (UN "prim__eqBigInt") (ty [BIType, BIType] IType) 2 (bbBin (==))
81 (2, LBEq) total,
89 (2, LBEq) total,
@@ -184,6 +192,9 @@ primitives =
184p_believeMe [_,_,x] = Just x
192p_believeMe [_,_,x] = Just x
185p_believeMe _ = Nothing
193p_believeMe _ = Nothing
186
194
195+iUn op [VConstant (I x)] = Just $ VConstant (I (op x))
196+iUn _ _ = Nothing
197+
187iBin op [VConstant (I x), VConstant (I y)] = Just $ VConstant (I (op x y))
198iBin op [VConstant (I x), VConstant (I y)] = Just $ VConstant (I (op x y))
188iBin _ _ = Nothing
199iBin _ _ = Nothing
189
200