on master help sign in
Add bitwise &/| primitives for Int (prim__andInt / prim__orInt)
0136305Edwin Brady
src/IRTS/CodegenC.hs+2
@@ -213,6 +213,8 @@ doOp v LMinus [l, r] = v ++ "INTOP(-," ++ creg l ++ ", " ++ creg r ++ ")"
213doOp v LTimes [l, r] = v ++ "MULT(" ++ creg l ++ ", " ++ creg r ++ ")"
213doOp v LTimes [l, r] = v ++ "MULT(" ++ creg l ++ ", " ++ creg r ++ ")"
214doOp v LDiv [l, r] = v ++ "INTOP(/," ++ creg l ++ ", " ++ creg r ++ ")"
214doOp 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 ++ ")"
216+doOp v LAnd [l, r] = v ++ "INTOP(&," ++ creg l ++ ", " ++ creg r ++ ")"
217+doOp v LOr [l, r] = v ++ "INTOP(|," ++ creg l ++ ", " ++ creg r ++ ")"
216doOp v LEq [l, r] = v ++ "INTOP(==," ++ creg l ++ ", " ++ creg r ++ ")"
218doOp v LEq [l, r] = v ++ "INTOP(==," ++ creg l ++ ", " ++ creg r ++ ")"
217doOp v LLt [l, r] = v ++ "INTOP(<," ++ creg l ++ ", " ++ creg r ++ ")"
219doOp v LLt [l, r] = v ++ "INTOP(<," ++ creg l ++ ", " ++ creg r ++ ")"
218doOp v LLe [l, r] = v ++ "INTOP(<=," ++ creg l ++ ", " ++ creg r ++ ")"
220doOp v LLe [l, r] = v ++ "INTOP(<=," ++ creg l ++ ", " ++ creg r ++ ")"
src/IRTS/Lang.hs+1−1
@@ -28,7 +28,7 @@ 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
31+data PrimFn = LPlus | LMinus | LTimes | LDiv | LMod | LAnd | LOr
32 | LEq | LLt | LLe | LGt | LGe
32 | LEq | LLt | LLe | LGt | LGe
33 | LFPlus | LFMinus | LFTimes | LFDiv
33 | LFPlus | LFMinus | LFTimes | LFDiv
34 | LFEq | LFLt | LFLe | LFGt | LFGe
34 | LFEq | LFLt | LFLe | LFGt | LFGe
src/Idris/Primitives.hs+5
@@ -10,6 +10,7 @@ import IRTS.Lang
10
10
11import Core.TT
11import Core.TT
12import Core.Evaluate
12import Core.Evaluate
13+import Data.Bits
13
14
14data Prim = Prim { p_name :: Name,
15data Prim = Prim { p_name :: Name,
15 p_type :: Type,
16 p_type :: Type,
@@ -41,6 +42,10 @@ primitives =
41 (2, LDiv) partial,
42 (2, LDiv) partial,
42 Prim (UN "prim__modInt") (ty [IType, IType] IType) 2 (iBin (mod))
43 Prim (UN "prim__modInt") (ty [IType, IType] IType) 2 (iBin (mod))
43 (2, LMod) partial,
44 (2, LMod) partial,
45+ Prim (UN "prim__andInt") (ty [IType, IType] IType) 2 (iBin (.&.))
46+ (2, LAnd) partial,
47+ Prim (UN "prim__orInt") (ty [IType, IType] IType) 2 (iBin (.|.))
48+ (2, LOr) partial,
44 Prim (UN "prim__eqInt") (ty [IType, IType] IType) 2 (biBin (==))
49 Prim (UN "prim__eqInt") (ty [IType, IType] IType) 2 (biBin (==))
45 (2, LEq) total,
50 (2, LEq) total,
46 Prim (UN "prim__ltInt") (ty [IType, IType] IType) 2 (biBin (<))
51 Prim (UN "prim__ltInt") (ty [IType, IType] IType) 2 (biBin (<))