never executed always true always false
1 {-# LANGUAGE DeriveGeneric, DeriveDataTypeable, DeriveFunctor, DeriveTraversable, DeriveFoldable #-}
2
3 module Conjure.Language.Expression.Op.Negate where
4
5 import Conjure.Prelude
6 import Conjure.Language.Expression.Op.Internal.Common
7
8 import qualified Data.Aeson as JSON -- aeson
9 import qualified Data.Aeson.KeyMap as KM
10
11 import qualified Data.Vector as V -- vector
12
13
14 data OpNegate x = OpNegate x
15 deriving (Eq, Ord, Show, Data, Functor, Traversable, Foldable, Typeable, Generic)
16
17 instance Serialize x => Serialize (OpNegate x)
18 instance Hashable x => Hashable (OpNegate x)
19 instance ToJSON x => ToJSON (OpNegate x) where toJSON = genericToJSON jsonOptions
20 instance FromJSON x => FromJSON (OpNegate x) where parseJSON = genericParseJSON jsonOptions
21
22 instance (TypeOf x, Pretty x) => TypeOf (OpNegate x) where
23 typeOf p@(OpNegate a) = do
24 TypeInt t <- typeOf a
25 case t of
26 TagInt -> return ()
27 _ -> raiseTypeError p
28 return (TypeInt t)
29
30 instance SimplifyOp OpNegate x where
31 simplifyOp _ = na "simplifyOp{OpNegate}"
32
33 instance Pretty x => Pretty (OpNegate x) where
34 prettyPrec prec (OpNegate a) = parensIf (prec > 2000) ("-" <> prettyPrec 2000 a)
35
36 instance VarSymBreakingDescription x => VarSymBreakingDescription (OpNegate x) where
37 varSymBreakingDescription (OpNegate a) = JSON.Object $ KM.fromList
38 [ ("type", JSON.String "OpNegate")
39 , ("children", JSON.Array $ V.fromList
40 [ varSymBreakingDescription a
41 ])
42 ]