on master help sign in
Add bitwise &/| primitives for Int (prim__andInt / prim__orInt)
commit01363057f35c1bd8eaddef598ec107f539d52d4a authorEdwin Brady <ecb10@st-andrews.ac.uk> dateThu 29 Nov 2012, 10:29 (14 years ago) parent7fe382d
3 files changed+8−1
src/IRTS/CodegenC.hs+2 src/IRTS/Lang.hs+1−1 src/Idris/Primitives.hs+5
src/IRTS/CodegenC.hs+2
@@ -213,6 +213,8 @@ doOp v LMinus [l, r] = v ++ "INTOP(-," ++ creg l ++ ", " ++ creg r ++ ")"
213213doOp v LTimes [l, r] = v ++ "MULT(" ++ creg l ++ ", " ++ creg r ++ ")"
214214doOp v LDiv [l, r] = v ++ "INTOP(/," ++ creg l ++ ", " ++ creg r ++ ")"
215215doOp 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 ++ ")"
216218doOp v LEq [l, r] = v ++ "INTOP(==," ++ creg l ++ ", " ++ creg r ++ ")"
217219doOp v LLt [l, r] = v ++ "INTOP(<," ++ creg l ++ ", " ++ creg r ++ ")"
218220doOp v LLe [l, r] = v ++ "INTOP(<=," ++ creg l ++ ", " ++ creg r ++ ")"
src/IRTS/Lang.hs+1−1
@@ -28,7 +28,7 @@ data LExp = LV LVar
2828-- Primitive operators. Backends are not *required* to implement all
2929-- of these, but should report an error if they are unable
3030
31−data PrimFn = LPlus | LMinus | LTimes | LDiv | LMod
31+data PrimFn = LPlus | LMinus | LTimes | LDiv | LMod | LAnd | LOr
3232 | LEq | LLt | LLe | LGt | LGe
3333 | LFPlus | LFMinus | LFTimes | LFDiv
3434 | LFEq | LFLt | LFLe | LFGt | LFGe
src/Idris/Primitives.hs+5
@@ -10,6 +10,7 @@ import IRTS.Lang
1010
1111import Core.TT
1212import Core.Evaluate
13+import Data.Bits
1314
1415data Prim = Prim { p_name :: Name,
1516 p_type :: Type,
@@ -41,6 +42,10 @@ primitives =
4142 (2, LDiv) partial,
4243 Prim (UN "prim__modInt") (ty [IType, IType] IType) 2 (iBin (mod))
4344 (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,
4449 Prim (UN "prim__eqInt") (ty [IType, IType] IType) 2 (biBin (==))
4550 (2, LEq) total,
4651 Prim (UN "prim__ltInt") (ty [IType, IType] IType) 2 (biBin (<))