packages feed

Paraiso 0.3.0.0 → 0.3.1.0

raw patch · 7 files changed

+128/−72 lines, 7 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Language.Paraiso.OM.Arithmetic: instance Read Operator
+ Language.Paraiso.Name: isNameOf :: Text -> a -> Named a
+ Language.Paraiso.OM.Arithmetic: Cast :: TypeRep -> Operator
+ Language.Paraiso.OM.Builder: cast :: (TRealm r, Typeable c1, Typeable c2) => c2 -> (Builder v g a (Value r c1)) -> (Builder v g a (Value r c2))
+ Language.Paraiso.OM.Builder.Internal: cast :: (TRealm r, Typeable c1, Typeable c2) => c2 -> (Builder v g a (Value r c1)) -> (Builder v g a (Value r c2))
+ Language.Paraiso.OM.DynValue: class ToDynable a
+ Language.Paraiso.OM.DynValue: f2d :: (Functor f, ToDynable x) => f x -> f DynValue
+ Language.Paraiso.OM.DynValue: instance (TRealm r, Typeable c) => ToDynable (StaticValue r c)
+ Language.Paraiso.OM.DynValue: instance (TRealm r, Typeable c) => ToDynable (Value r c)
+ Language.Paraiso.OM.Value: StaticValue :: rea -> con -> StaticValue rea con
+ Language.Paraiso.OM.Value: data StaticValue rea con
+ Language.Paraiso.OM.Value: instance (Eq rea, Eq con) => Eq (StaticValue rea con)
+ Language.Paraiso.OM.Value: instance (Show rea, Show con) => Show (StaticValue rea con)
- Language.Paraiso.OM.Builder: load :: (TRealm r, Typeable c) => r -> c -> Name -> B (Value r c)
+ Language.Paraiso.OM.Builder: load :: (TRealm r, Typeable c) => Named (StaticValue r c) -> B (Value r c)
- Language.Paraiso.OM.Builder: loadIndex :: Typeable c => c -> Axis v -> Builder v g a (Value TArray c)
+ Language.Paraiso.OM.Builder: loadIndex :: Typeable g => Axis v -> Builder v g a (Value TArray g)
- Language.Paraiso.OM.Builder: loadSize :: (TRealm r, Typeable c) => r -> c -> Axis v -> Builder v g a (Value r c)
+ Language.Paraiso.OM.Builder: loadSize :: Typeable g => Axis v -> Builder v g a (Value TScalar g)
- Language.Paraiso.OM.Builder: store :: (TRealm r, Typeable c) => Name -> Builder v g a (Value r c) -> Builder v g a ()
+ Language.Paraiso.OM.Builder: store :: (TRealm r, Typeable c) => Named (StaticValue r c) -> Builder v g a (Value r c) -> Builder v g a ()
- Language.Paraiso.OM.Builder.Internal: load :: (TRealm r, Typeable c) => r -> c -> Name -> B (Value r c)
+ Language.Paraiso.OM.Builder.Internal: load :: (TRealm r, Typeable c) => Named (StaticValue r c) -> B (Value r c)
- Language.Paraiso.OM.Builder.Internal: loadIndex :: Typeable c => c -> Axis v -> Builder v g a (Value TArray c)
+ Language.Paraiso.OM.Builder.Internal: loadIndex :: Typeable g => Axis v -> Builder v g a (Value TArray g)
- Language.Paraiso.OM.Builder.Internal: loadSize :: (TRealm r, Typeable c) => r -> c -> Axis v -> Builder v g a (Value r c)
+ Language.Paraiso.OM.Builder.Internal: loadSize :: Typeable g => Axis v -> Builder v g a (Value TScalar g)
- Language.Paraiso.OM.Builder.Internal: store :: (TRealm r, Typeable c) => Name -> Builder v g a (Value r c) -> Builder v g a ()
+ Language.Paraiso.OM.Builder.Internal: store :: (TRealm r, Typeable c) => Named (StaticValue r c) -> Builder v g a (Value r c) -> Builder v g a ()
- Language.Paraiso.OM.DynValue: toDyn :: (TRealm r, Typeable c) => Value r c -> DynValue
+ Language.Paraiso.OM.DynValue: toDyn :: ToDynable a => a -> DynValue

Files

Language/Paraiso/Name.hs view
@@ -4,8 +4,9 @@ -- | name identifier. module Language.Paraiso.Name    (-   Name, Named(..), mkName,-   Nameable(..), namee+    Nameable(..),+    Name, mkName, isNameOf,  +    Named(..), namee,   ) where import Control.Monad import Data.Text (Text, unpack)@@ -36,10 +37,15 @@ -- | Convert some type to a named type. data Named a = Named Name a +-- | create Named object in an instance.+isNameOf ::  Text -> a -> Named a+isNameOf n a = Named (mkName n) a+ instance Nameable (Named a) where   name (Named n _) = n instance Functor Named where   fmap f (Named n a) = Named n $ f a+   -- | The thing the name points to.
Language/Paraiso/OM/Arithmetic.hs view
@@ -6,7 +6,8 @@      Operator(..)     ) where -import NumericPrelude hiding (Ordering(..), Eq(..), Ord(..))+import qualified Data.Dynamic as Dynamic+import           NumericPrelude hiding (Ordering(..), Eq(..), Ord(..)) import qualified NumericPrelude as P  class Arity a where@@ -60,8 +61,9 @@   Acos |   Atan |   Atan2 |  -  Sincos -  deriving (P.Eq, P.Ord, P.Show, P.Read)+  Sincos |+  Cast Dynamic.TypeRep+  deriving (P.Eq, P.Ord, P.Show)  instance Arity Operator where   arity a = case a of@@ -105,4 +107,4 @@     Atan -> (1,1)     Atan2 -> (2,1)     Sincos -> (1,2)-+    Cast _ -> (1,1)
Language/Paraiso/OM/Builder.hs view
@@ -14,7 +14,7 @@      bind,      load, store, imm,      reduce, broadcast, shift, -     loadIndex, loadSize,+     loadIndex, loadSize, cast,      annotate, (<?>),      withAnnotation     ) where
Language/Paraiso/OM/Builder/Internal.hs view
@@ -17,7 +17,7 @@      load, store,      reduce, broadcast,      shift, loadIndex,loadSize,-     imm, mkOp1, mkOp2,+     imm, mkOp1, mkOp2, cast,      annotate, (<?>),      withAnnotation     ) where@@ -166,14 +166,12 @@  -- | Load from a static value. load :: (TRealm r, Typeable c) => -        r             -- ^The 'TRealm' type.-     -> c             -- ^The 'Val.content' type.-     -> Name          -- ^The 'Name' of the static value to load.-     -> B (Value r c) -- ^The loaded 'TArray' 'Value' as a result.-load r0 c0 name0 = do+        Named (Val.StaticValue r c) -- ^ the named static value to be loaded from.+     -> B (Value r c)               -- ^ The loaded 'Value' as a result.+load (Named name0 (Val.StaticValue r0 c0))= do   let -      type0 = mkDyn r0 c0-      nv = Named name0 type0+    type0 = mkDyn r0 c0+    nv = Named name0 type0   idx <- lookUpStatic nv   n0 <- addNodeE []   $ NInst  (Load idx)   n1 <- addNodeE [n0] $ NValue type0 @@ -181,10 +179,10 @@  -- | Store to a static value. store :: (TRealm r, Typeable c) => -         Name                    -- ^The 'Name' of the static value to store.-      -> Builder v g a (Value r c) -- ^The 'Value' to be stored.-      -> Builder v g a ()          -- ^The result.-store name0 builder0 = do+         Named (Val.StaticValue r c) -- ^ the named static value to be stored on.+      -> Builder v g a (Value r c)   -- ^ The 'Value' to be stored.+      -> Builder v g a ()            -- ^ The result.+store (Named name0 _) builder0 = do   val0 <- builder0   let        type0 = toDyn val0@@ -243,27 +241,30 @@   return (FromNode TArray c1 n3)  -- | Load the 'Axis' component of the mesh address, to a 'TArray' 'Value'.-loadIndex :: (Typeable c) => -             c                            -- ^The 'Val.content' type.-          -> Axis v                       -- ^ The axis for which index is required-          -> Builder v g a (Value TArray c) -- ^ The 'TArray' 'Value' that contains the address as a result.-loadIndex c0 axis = do-  let type0 = mkDyn TArray c0+loadIndex :: (Typeable g) +          => Axis v                         -- ^ The axis for which index is required+          -> Builder v g a (Value TArray g) -- ^ The 'TArray' 'Value' that contains the address as a result.+loadIndex axis = do+  -- create a phantom object of type g+  c0 <- (return undefined) `asTypeOf` (fmap Val.content $ loadIndex axis)+  let +    type0 = mkDyn TArray c0   n0 <- addNodeE []   $ NInst (LoadIndex axis)   n1 <- addNodeE [n0] $ NValue type0    return (FromNode TArray c0 n1)  -- | Load the 'Axis' component of the mesh size, to either a  'TScalar' 'Value' or  'TArray' 'Value'..-loadSize :: (TRealm r, Typeable c)-            => r                            -- ^ The 'TRealm'-            -> c                            -- ^The 'Val.content' type.-            -> Axis v                       -- ^ The axis for which the size is required-            -> Builder v g a (Value r c) -- ^ The 'TScalar' 'Value' that contains the size of the mesh in that direction.-loadSize r0 c0 axis = do-  let type0 = mkDyn r0 c0+loadSize :: (Typeable g) +         => Axis v                          -- ^ The axis for which the size is required+         -> Builder v g a (Value TScalar g) -- ^ The 'TScalar' 'Value' that contains the size of the mesh in that direction.+loadSize axis = do+  -- create a phantom object of type g+  c0 <- (return undefined) `asTypeOf` (fmap Val.content $ loadSize axis)+  let +    type0 = mkDyn TScalar c0   n0 <- addNodeE []   $ NInst (LoadSize axis)   n1 <- addNodeE [n0] $ NValue type0 -  return (FromNode r0 c0 n1)+  return (FromNode TScalar c0 n1)   -- | Create an immediate 'Value' from a Haskell concrete value. @@ -273,6 +274,13 @@     -> B (Value r c) -- ^'TArray' 'Value' with the @c@ stored. imm c0 = return (FromImm unitTRealm c0) +++----------------------------------------------------------------+-- Here comes the Arith instruction emitters.+----------------------------------------------------------------++ -- | Make a unary operator mkOp1 :: (TRealm r, Typeable c) =>           A.Operator                -- ^The operator symbol@@ -307,41 +315,7 @@   return $ FromNode r1 c1 n01  --- | Execute the builder under modifed annotation.-withAnnotation :: (a -> a) -> Builder v g a ret ->  Builder v g a ret-withAnnotation f builder1 = do-  stat0 <- State.get-  let curAnot0 = currentAnnotation (context stat0)-      curAnot1 = f curAnot0-  State.put $ stat0{ context = (context stat0){ currentAnnotation = curAnot1 } }-  ret <- builder1-  stat1 <- State.get-  State.put $ stat1{ context = (context stat1){ currentAnnotation = curAnot0} }-  return ret ---- | Execute the builder, and annotate the very result with the givin function. -annotate :: (TRealm r, Typeable c) => (a -> a) -> Builder v g a (Value r c) ->  Builder v g a (Value r c)-annotate f builder1 = do-  v1 <- builder1-  n1 <- valueToNode v1-  let -    r1 = Val.realm v1-    c1 = Val.content v1-    annotator con@(ins, n2, node2, outs)-      | n1 /= n2  = con-      | otherwise = (ins, n2, fmap f node2, outs)-  stat0 <- State.get-  State.put $ stat0 {    -    target = FGL.gmap annotator (target stat0)-    }-  return $ FromNode r1 c1 n1 ---- | (<?>) = annotate-infixr 0 <?>-(<?>) :: (TRealm r, Typeable c) => (a -> a) -> Builder v g a (Value r c) ->  Builder v g a (Value r c)-(<?>) = annotate- -- | Builder is Additive 'Additive.C'. -- You can use 'Additive.zero', 'Additive.+', 'Additive.-', 'Additive.negate'. instance (TRealm r, Typeable c, Additive.C c) => Additive.C (Builder v g a (Value r c)) where@@ -370,6 +344,8 @@            bx_n3 <- fmap return $ f x n3            modify $ bx_n3*bx_n3 +-- Here comes the Arith node creaters.+ -- | Builder is Ring 'IntegralDomain.C'. -- You can use div and mod. instance (TRealm r, Typeable c, IntegralDomain.C c) => IntegralDomain.C (Builder v g a (Value r c)) where@@ -438,3 +414,56 @@         asin = mkOp1 A.Asin         acos = mkOp1 A.Acos         atan = mkOp1 A.Atan++-- | take a phantom object 'c2', and perform the cast that keeps the realm while+--   change the content type from 'c1' to 'c2'.+cast :: (TRealm r, Typeable c1,Typeable c2) => c2 -> (Builder v g a (Value r c1)) -> (Builder v g a (Value r c2))+cast c2 builder1 = do+  v1 <- builder1+  let +      r1 = Val.realm v1+      c1 = Val.content v1+  n1 <- valueToNode v1+  n0 <-  addNodeE [n1] $ NInst (Arith $ A.Cast $ Dynamic.typeOf c2) +  n01 <- addNodeE [n0] $ NValue (toDyn v1) +  return $ FromNode r1 c2 n01++++++-- | Execute the builder under modifed annotation.+withAnnotation :: (a -> a) -> Builder v g a ret ->  Builder v g a ret+withAnnotation f builder1 = do+  stat0 <- State.get+  let curAnot0 = currentAnnotation (context stat0)+      curAnot1 = f curAnot0+  State.put $ stat0{ context = (context stat0){ currentAnnotation = curAnot1 } }+  ret <- builder1+  stat1 <- State.get+  State.put $ stat1{ context = (context stat1){ currentAnnotation = curAnot0} }+  return ret+++-- | Execute the builder, and annotate the very result with the givin function. +annotate :: (TRealm r, Typeable c) => (a -> a) -> Builder v g a (Value r c) ->  Builder v g a (Value r c)+annotate f builder1 = do+  v1 <- builder1+  n1 <- valueToNode v1+  let +    r1 = Val.realm v1+    c1 = Val.content v1+    annotator con@(ins, n2, node2, outs)+      | n1 /= n2  = con+      | otherwise = (ins, n2, fmap f node2, outs)+  stat0 <- State.get+  State.put $ stat0 {    +    target = FGL.gmap annotator (target stat0)+    }+  return $ FromNode r1 c1 n1 ++-- | (<?>) = annotate+infixr 0 <?>+(<?>) :: (TRealm r, Typeable c) => (a -> a) -> Builder v g a (Value r c) ->  Builder v g a (Value r c)+(<?>) = annotate+
Language/Paraiso/OM/DynValue.hs view
@@ -6,7 +6,7 @@  module Language.Paraiso.OM.DynValue   (-   DynValue(..), mkDyn, toDyn+   DynValue(..), mkDyn, toDyn, f2d,  ToDynable    ) where  import Data.Typeable@@ -20,9 +20,25 @@ mkDyn :: (R.TRealm r, Typeable c) => r -> c -> DynValue mkDyn r0 c0 = DynValue (R.tRealm r0) (typeOf c0) ++-- | Something that can be converted to 'DynValue'+class ToDynable a where+  toDyn :: a -> DynValue+ -- | Convert 'Val.Value' to 'DynValue'-toDyn :: (R.TRealm r, Typeable c) => Val.Value r c -> DynValue-toDyn x = mkDyn (Val.realm x) (Val.content x)+instance (R.TRealm r, Typeable c) => ToDynable (Val.Value r c) where+  toDyn x = mkDyn (Val.realm x) (Val.content x)++-- | Convert 'Val.StaticValue' to 'DynValue'+instance (R.TRealm r, Typeable c) => ToDynable (Val.StaticValue r c) where+  toDyn (Val.StaticValue r c) = mkDyn r c++-- | map 'toDyn' over functors.+--   an idiom used in collecting OM static variables.+f2d :: (Functor f, ToDynable x) => f x -> f DynValue+f2d = fmap toDyn++  instance R.Realmable DynValue where   realm = realm
Language/Paraiso/OM/Value.hs view
@@ -6,7 +6,7 @@  module Language.Paraiso.OM.Value   (-   Value(..)+   Value(..), StaticValue(..)   ) where  import Data.Typeable@@ -27,6 +27,9 @@   -- 'content' is the immediate value to be stored.   FromImm {realm :: rea, content :: con} deriving (Eq, Show)                        +-- | static value type.+data StaticValue rea con = StaticValue rea con deriving (Eq, Show)+  instance  (R.TRealm rea, Typeable con) => R.Realmable (Value rea con) where   realm (FromNode r _ _) = R.tRealm r
Paraiso.cabal view
@@ -15,7 +15,7 @@ -- The package version. See the Haskell package versioning policy
 -- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for
 -- standards guiding when and how versions should be incremented.
-Version:             0.3.0.0
+Version:             0.3.1.0
 Tested-With:         GHC==7.4.1
 
 -- A short (one-line) description of the package.