Commit 8cf8d131 authored by Sarah Müller's avatar Sarah Müller

wrote missing tests, no unaryInt, unaryBit funcs

parent eced0994
Pipeline #15292 failed with stages
in 13 minutes and 19 seconds
......@@ -153,13 +153,31 @@ instance (IsString err, ArrowFail err c, ArrowChoice c) => IsVal Val (ConcreteT
and = withBits (.&.)
or = withBits (.|.)
xor = withBits xor
complement = withUnBits complement --bitwise complement operator
complement = proc v -> case v of --bitwise complement operator
ByteVal b -> returnA -< ByteVal Bits.complement b
ShortVal s -> returnA -< ShortVal Bits.complement s
IntVal n -> returnA -< IntVal Bits.complement n
LongVal l -> returnA -< LongVal Data.Bits.complement l
CharVal c -> returnA -< CharVal Data.Bits.complement c -- TEST: do we need "data.bits" or simply "Bits"?
_ -> fail -< "Expected a number as argument for -"
-- rem = withInt mod <+> withFloat mod'
-- shl = withInt shiftL
-- shr = withInt shiftR
-- ushr = withInt shiftR -- WRONG: This should be an unsigned shift.
unplus = withUnInt (+)
unminus = withUnInt (-)
-- unplus = withUnaryInt (+)
-- unminus = withUnaryInt (-)
neg = proc v -> case v of
ByteVal b -> returnA -< ByteVal (-b)
ShortVal s -> returnA -< ShortVal (-s)
IntVal n -> returnA -< IntVal (-n)
LongVal l -> returnA -< LongVal (-l)
-- TODO: Char?
-- FloatVal f -> returnA -< FloatVal (-f)
-- DoubleVal d -> returnA -< DoubleVal (-d)
_ -> fail -< "Expected a number as argument for -"
plus = withInt (+)-- <+> withFloat (+) -- do something better.
minus = withInt (-)-- <+> withFloat (-)
mult = withInt (*)-- <+> withFloat (*)
......@@ -186,13 +204,7 @@ instance (IsString err, ArrowFail err c, ArrowChoice c) => IsVal Val (ConcreteT
-- lengthOf = deref >>> proc v -> case v of
-- ArrayVal xs -> returnA -< (IntVal (length xs))
-- _ -> fail -< "Expected an array variable for 'lengthOf'"
-- neg = proc v -> case v of
-- IntVal n -> returnA -< IntVal (-n)
-- LongVal l -> returnA -< LongVal (-l)
-- FloatVal f -> returnA -< FloatVal (-f)
-- DoubleVal d -> returnA -< DoubleVal (-d)
-- _ -> fail -< "Expected a number as argument for -"
-- newSimple = proc t -> case t of
-- RefType c -> do
-- fields <- getInitializedFields -< c
......@@ -392,16 +404,16 @@ withBits op =
_ -> fail -< "Expected integer variables for op"
withUnBits :: (IsString e, ArrowFail e c, ArrowChoice c) => (forall a. Bits a => a -> a) -> c (Val,Val) Val
withUnBits op =
proc v -> case v of
(ByteVal x) -> returnA -< ByteVal $ op x
(ShortVal x) -> returnA -< ShortVal $ op x
(IntVal x) -> returnA -< IntVal $ op x
(LongVal x) -> returnA -< LongVal $ op x
(CharVal x) -> returnA -< CharVal $ op x
_ -> fail -< "Expected integer variables for op"
--withUnaryBits :: (IsString e, ArrowFail e c, ArrowChoice c) => (forall a. Bits a => a -> a) -> c (Val,Val) Val
--withUnaryBits op =
-- proc v -> case v of
-- (ByteVal x) -> returnA -< ByteVal $ op x
-- (ShortVal x) -> returnA -< ShortVal $ op x
-- (IntVal x) -> returnA -< IntVal $ op x
-- (LongVal x) -> returnA -< LongVal $ op x
-- (CharVal x) -> returnA -< CharVal $ op x
--
-- _ -> fail -< "Expected integer variables for op"
withInt :: (IsString e, ArrowFail e c, ArrowChoice c) => (Int -> Int -> Int) -> c (Val,Val) Val
withInt op =
......@@ -423,14 +435,14 @@ withInt op =
(ByteVal x1,CharVal x2) -> returnA -< IntVal $ op x1 x2
_ -> fail -< "Expected integer variables for op"
withUnInt :: (IsString e, ArrowFail e c, ArrowChoice c) => (Int -> Int) -> c (Val,Val) Val
withUnInt = op =
proc v -> case v of
ByteVal x -> returnA -< ByteVal $ op x
ShortVal x -> returnA -< ShortVal $ op x
IntVal x -> returnA -< IntVal $ op x
LongVal x -> returnA -< LongVal $ op x
CharVal x -> returnA -< CharVal $ op x --what does unary minus do here?
--withUnaryInt :: (IsString e, ArrowFail e c, ArrowChoice c) => (Int -> Int) -> c (Val,Val) Val
--withUnaryInt = op =
-- proc v -> case v of
-- ByteVal x -> returnA -< ByteVal $ op x
-- ShortVal x -> returnA -< ShortVal $ op x
-- IntVal x -> returnA -< IntVal $ op x
-- LongVal x -> returnA -< LongVal $ op x
-- CharVal x -> returnA -< CharVal $ op x --what does unary minus do here?
-- withFloat :: (IsString e, ArrowFail e c) => (Float -> Float -> Float) -> c (Val,Val) Val
-- withFloat op = proc (v1,v2) -> case (v1,v2) of
-- (FloatVal x1,FloatVal x2) -> returnA -< FloatVal $ op x1 x2
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment