fluid-idl 0.0.4 → 0.0.5
raw patch · 11 files changed
+118/−752 lines, 11 filesdep +fluid-idldep −fluiddep −tuplePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: fluid-idl
Dependencies removed: fluid, tuple
API changes (from Hackage documentation)
- Fluid.Ast: instance Fluid.Ast.ToAst GHC.Int.Int16
- Fluid.Ast: instance Fluid.Ast.ToAst GHC.Int.Int32
- Fluid.Ast: instance Fluid.Ast.ToAst GHC.Int.Int64
- Fluid.Ast: instance Fluid.Ast.ToAst GHC.Int.Int8
- Fluid.Ast: instance Fluid.Ast.ToAst GHC.Types.Float
- Fluid.Ast: instance Fluid.Ast.ToAst GHC.Word.Word16
- Fluid.Ast: instance Fluid.Ast.ToAst GHC.Word.Word32
- Fluid.Ast: instance Fluid.Ast.ToAst GHC.Word.Word64
- Fluid.Ast: instance Fluid.Ast.ToAst GHC.Word.Word8
- Fluid.Client.Expr: addI16 :: Expr Int16 -> Expr Int16 -> Expr Int16
- Fluid.Client.Expr: addI32 :: Expr Int32 -> Expr Int32 -> Expr Int32
- Fluid.Client.Expr: addI64 :: Expr Int64 -> Expr Int64 -> Expr Int64
- Fluid.Client.Expr: addI8 :: Expr Int8 -> Expr Int8 -> Expr Int8
- Fluid.Client.Expr: addU16 :: Expr Word16 -> Expr Word16 -> Expr Word16
- Fluid.Client.Expr: addU32 :: Expr Word32 -> Expr Word32 -> Expr Word32
- Fluid.Client.Expr: addU64 :: Expr Word64 -> Expr Word64 -> Expr Word64
- Fluid.Client.Expr: addU8 :: Expr Word8 -> Expr Word8 -> Expr Word8
- Fluid.Client.Expr: divI16 :: Expr Int16 -> Expr Int16 -> Expr Int16
- Fluid.Client.Expr: divI32 :: Expr Int32 -> Expr Int32 -> Expr Int32
- Fluid.Client.Expr: divI64 :: Expr Int64 -> Expr Int64 -> Expr Int64
- Fluid.Client.Expr: divI8 :: Expr Int8 -> Expr Int8 -> Expr Int8
- Fluid.Client.Expr: divU16 :: Expr Word16 -> Expr Word16 -> Expr Word16
- Fluid.Client.Expr: divU32 :: Expr Word32 -> Expr Word32 -> Expr Word32
- Fluid.Client.Expr: divU64 :: Expr Word64 -> Expr Word64 -> Expr Word64
- Fluid.Client.Expr: divU8 :: Expr Word8 -> Expr Word8 -> Expr Word8
- Fluid.Client.Expr: f32 :: Float -> Expr Float
- Fluid.Client.Expr: f64 :: Double -> Expr Double
- Fluid.Client.Expr: i16 :: Int16 -> Expr Int16
- Fluid.Client.Expr: i32 :: Int32 -> Expr Int32
- Fluid.Client.Expr: i64 :: Int64 -> Expr Int64
- Fluid.Client.Expr: i8 :: Int8 -> Expr Int8
- Fluid.Client.Expr: instance Fluid.Client.Expr.ToExpr GHC.Int.Int16
- Fluid.Client.Expr: instance Fluid.Client.Expr.ToExpr GHC.Int.Int32
- Fluid.Client.Expr: instance Fluid.Client.Expr.ToExpr GHC.Int.Int64
- Fluid.Client.Expr: instance Fluid.Client.Expr.ToExpr GHC.Int.Int8
- Fluid.Client.Expr: instance Fluid.Client.Expr.ToExpr GHC.Types.Float
- Fluid.Client.Expr: instance Fluid.Client.Expr.ToExpr GHC.Word.Word16
- Fluid.Client.Expr: instance Fluid.Client.Expr.ToExpr GHC.Word.Word32
- Fluid.Client.Expr: instance Fluid.Client.Expr.ToExpr GHC.Word.Word64
- Fluid.Client.Expr: instance Fluid.Client.Expr.ToExpr GHC.Word.Word8
- Fluid.Client.Expr: mulI16 :: Expr Int16 -> Expr Int16 -> Expr Int16
- Fluid.Client.Expr: mulI32 :: Expr Int32 -> Expr Int32 -> Expr Int32
- Fluid.Client.Expr: mulI64 :: Expr Int64 -> Expr Int64 -> Expr Int64
- Fluid.Client.Expr: mulI8 :: Expr Int8 -> Expr Int8 -> Expr Int8
- Fluid.Client.Expr: mulU16 :: Expr Word16 -> Expr Word16 -> Expr Word16
- Fluid.Client.Expr: mulU32 :: Expr Word32 -> Expr Word32 -> Expr Word32
- Fluid.Client.Expr: mulU64 :: Expr Word64 -> Expr Word64 -> Expr Word64
- Fluid.Client.Expr: mulU8 :: Expr Word8 -> Expr Word8 -> Expr Word8
- Fluid.Client.Expr: subI16 :: Expr Int16 -> Expr Int16 -> Expr Int16
- Fluid.Client.Expr: subI32 :: Expr Int32 -> Expr Int32 -> Expr Int32
- Fluid.Client.Expr: subI64 :: Expr Int64 -> Expr Int64 -> Expr Int64
- Fluid.Client.Expr: subI8 :: Expr Int8 -> Expr Int8 -> Expr Int8
- Fluid.Client.Expr: subU16 :: Expr Word16 -> Expr Word16 -> Expr Word16
- Fluid.Client.Expr: subU32 :: Expr Word32 -> Expr Word32 -> Expr Word32
- Fluid.Client.Expr: subU64 :: Expr Word64 -> Expr Word64 -> Expr Word64
- Fluid.Client.Expr: subU8 :: Expr Word8 -> Expr Word8 -> Expr Word8
- Fluid.Client.Expr: u16 :: Word16 -> Expr Word16
- Fluid.Client.Expr: u32 :: Word32 -> Expr Word32
- Fluid.Client.Expr: u64 :: Word64 -> Expr Word64
- Fluid.Client.Expr: u8 :: Word8 -> Expr Word8
- Fluid.Prim: Prim'F32 :: Float -> Prim
- Fluid.Prim: Prim'F64 :: Double -> Prim
- Fluid.Prim: Prim'I16 :: Int16 -> Prim
- Fluid.Prim: Prim'I32 :: Int32 -> Prim
- Fluid.Prim: Prim'I64 :: Int64 -> Prim
- Fluid.Prim: Prim'I8 :: Int8 -> Prim
- Fluid.Prim: Prim'U16 :: Word16 -> Prim
- Fluid.Prim: Prim'U32 :: Word32 -> Prim
- Fluid.Prim: Prim'U64 :: Word64 -> Prim
- Fluid.Prim: Prim'U8 :: Word8 -> Prim
- Fluid.Types: instance Fluid.Types.HasType GHC.Int.Int16
- Fluid.Types: instance Fluid.Types.HasType GHC.Int.Int32
- Fluid.Types: instance Fluid.Types.HasType GHC.Int.Int64
- Fluid.Types: instance Fluid.Types.HasType GHC.Int.Int8
- Fluid.Types: instance Fluid.Types.HasType GHC.Types.Float
- Fluid.Types: instance Fluid.Types.HasType GHC.Word.Word16
- Fluid.Types: instance Fluid.Types.HasType GHC.Word.Word32
- Fluid.Types: instance Fluid.Types.HasType GHC.Word.Word64
- Fluid.Types: instance Fluid.Types.HasType GHC.Word.Word8
- Fluid.Val: instance Fluid.Val.FromVal GHC.Int.Int16
- Fluid.Val: instance Fluid.Val.FromVal GHC.Int.Int32
- Fluid.Val: instance Fluid.Val.FromVal GHC.Int.Int64
- Fluid.Val: instance Fluid.Val.FromVal GHC.Int.Int8
- Fluid.Val: instance Fluid.Val.FromVal GHC.Types.Float
- Fluid.Val: instance Fluid.Val.FromVal GHC.Word.Word16
- Fluid.Val: instance Fluid.Val.FromVal GHC.Word.Word32
- Fluid.Val: instance Fluid.Val.FromVal GHC.Word.Word64
- Fluid.Val: instance Fluid.Val.FromVal GHC.Word.Word8
- Fluid.Val: instance Fluid.Val.ToVal GHC.Int.Int16
- Fluid.Val: instance Fluid.Val.ToVal GHC.Int.Int32
- Fluid.Val: instance Fluid.Val.ToVal GHC.Int.Int64
- Fluid.Val: instance Fluid.Val.ToVal GHC.Int.Int8
- Fluid.Val: instance Fluid.Val.ToVal GHC.Types.Float
- Fluid.Val: instance Fluid.Val.ToVal GHC.Word.Word16
- Fluid.Val: instance Fluid.Val.ToVal GHC.Word.Word32
- Fluid.Val: instance Fluid.Val.ToVal GHC.Word.Word64
- Fluid.Val: instance Fluid.Val.ToVal GHC.Word.Word8
+ Fluid.Ast: instance Fluid.Ast.ToAst GHC.Types.Int
+ Fluid.Client.Expr: addFloat :: Expr Double -> Expr Double -> Expr Double
+ Fluid.Client.Expr: addInt :: Expr Int -> Expr Int -> Expr Int
+ Fluid.Client.Expr: divFloat :: Expr Double -> Expr Double -> Expr Double
+ Fluid.Client.Expr: divInt :: Expr Int -> Expr Int -> Expr Int
+ Fluid.Client.Expr: float :: Double -> Expr Double
+ Fluid.Client.Expr: instance Fluid.Client.Expr.ToExpr GHC.Types.Int
+ Fluid.Client.Expr: int :: Int -> Expr Int
+ Fluid.Client.Expr: mulFloat :: Expr Double -> Expr Double -> Expr Double
+ Fluid.Client.Expr: mulInt :: Expr Int -> Expr Int -> Expr Int
+ Fluid.Client.Expr: subFloat :: Expr Double -> Expr Double -> Expr Double
+ Fluid.Client.Expr: subInt :: Expr Int -> Expr Int -> Expr Int
+ Fluid.Prim: Prim'Float :: Double -> Prim
+ Fluid.Prim: Prim'Int :: Int -> Prim
+ Fluid.Types: instance Fluid.Types.HasType GHC.Types.Int
+ Fluid.Val: instance Fluid.Val.FromVal GHC.Types.Int
+ Fluid.Val: instance Fluid.Val.ToVal GHC.Types.Int
Files
- fluid-idl.cabal +2/−3
- library/Fluid/Ast.hs +1/−27
- library/Fluid/Client/Expr.hs +31/−177
- library/Fluid/Prim.hs +4/−22
- library/Fluid/Server/Expr.hs +56/−399
- library/Fluid/Types.hs +3/−29
- library/Fluid/Val.hs +6/−79
- package.yaml +2/−3
- tests/AstSpec.hs +5/−5
- tests/ClientSpec.hs +4/−5
- tests/ValSpec.hs +4/−3
fluid-idl.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack name: fluid-idl-version: 0.0.4+version: 0.0.5 synopsis: Fluid | The Programmatic IDL description: Fluid | The Programmatic IDL category: Web@@ -67,12 +67,11 @@ build-depends: aeson , base >= 4.7 && < 5- , fluid+ , fluid-idl , containers , hspec , scientific , text- , tuple , vector other-modules: AstSpec
library/Fluid/Ast.hs view
@@ -33,8 +33,6 @@ import Data.Text (Text) import Data.Aeson import Data.Map (Map)-import Data.Int-import Data.Word import GHC.Generics (Generic) import Fluid.Types@@ -74,31 +72,7 @@ instance ToAst Text where toAst s = Ast'Const (Const'String s) -instance ToAst Int8 where- toAst = num--instance ToAst Int16 where- toAst = num--instance ToAst Int32 where- toAst = num--instance ToAst Int64 where- toAst = num--instance ToAst Word8 where- toAst = num--instance ToAst Word16 where- toAst = num--instance ToAst Word32 where- toAst = num--instance ToAst Word64 where- toAst = num--instance ToAst Float where+instance ToAst Int where toAst = num instance ToAst Double where
library/Fluid/Client/Expr.hs view
@@ -26,53 +26,21 @@ , noT , eq , neq- , addI8- , addI16- , addI32- , addI64- , addU8- , addU16- , addU32- , addU64- , subI8- , subI16- , subI32- , subI64- , subU8- , subU16- , subU32- , subU64- , mulI8- , mulI16- , mulI32- , mulI64- , mulU8- , mulU16- , mulU32- , mulU64- , divI8- , divI16- , divI32- , divI64- , divU8- , divU16- , divU32- , divU64+ , addInt+ , addFloat+ , subInt+ , subFloat+ , mulInt+ , mulFloat+ , divInt+ , divFloat , concaT -- , unit , bool , string- , i8- , i16- , i32- , i64- , u8- , u16- , u32- , u64- , f32- , f64+ , int+ , float -- , option , list@@ -198,8 +166,6 @@ import qualified Data.Map as Map import Data.Aeson (toJSON, Value) import Data.Proxy-import Data.Word-import Data.Int import Data.Map (Map) import qualified Fluid.Ast as Ast@@ -356,101 +322,29 @@ neq :: (HasType a) => Expr a -> Expr a -> Expr Bool neq x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "neq") [toAst x, toAst y]) -addI8 :: Expr Int8 -> Expr Int8 -> Expr Int8-addI8 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "addI8") [toAst x, toAst y])--addI16 :: Expr Int16 -> Expr Int16 -> Expr Int16-addI16 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "addI16") [toAst x, toAst y])--addI32 :: Expr Int32 -> Expr Int32 -> Expr Int32-addI32 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "addI32") [toAst x, toAst y])--addI64 :: Expr Int64 -> Expr Int64 -> Expr Int64-addI64 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "addI64") [toAst x, toAst y])--addU8 :: Expr Word8 -> Expr Word8 -> Expr Word8-addU8 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "addU8") [toAst x, toAst y])--addU16 :: Expr Word16 -> Expr Word16 -> Expr Word16-addU16 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "addU16") [toAst x, toAst y])--addU32 :: Expr Word32 -> Expr Word32 -> Expr Word32-addU32 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "addU32") [toAst x, toAst y])--addU64 :: Expr Word64 -> Expr Word64 -> Expr Word64-addU64 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "addU64") [toAst x, toAst y])--subI8 :: Expr Int8 -> Expr Int8 -> Expr Int8-subI8 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "subI8") [toAst x, toAst y])--subI16 :: Expr Int16 -> Expr Int16 -> Expr Int16-subI16 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "subI16") [toAst x, toAst y])--subI32 :: Expr Int32 -> Expr Int32 -> Expr Int32-subI32 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "subI32") [toAst x, toAst y])--subI64 :: Expr Int64 -> Expr Int64 -> Expr Int64-subI64 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "subI64") [toAst x, toAst y])--subU8 :: Expr Word8 -> Expr Word8 -> Expr Word8-subU8 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "subU8") [toAst x, toAst y])--subU16 :: Expr Word16 -> Expr Word16 -> Expr Word16-subU16 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "subU16") [toAst x, toAst y])--subU32 :: Expr Word32 -> Expr Word32 -> Expr Word32-subU32 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "subU32") [toAst x, toAst y])--subU64 :: Expr Word64 -> Expr Word64 -> Expr Word64-subU64 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "subU64") [toAst x, toAst y])--mulI8 :: Expr Int8 -> Expr Int8 -> Expr Int8-mulI8 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "mulI8") [toAst x, toAst y])--mulI16 :: Expr Int16 -> Expr Int16 -> Expr Int16-mulI16 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "mulI16") [toAst x, toAst y])--mulI32 :: Expr Int32 -> Expr Int32 -> Expr Int32-mulI32 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "mulI32") [toAst x, toAst y])--mulI64 :: Expr Int64 -> Expr Int64 -> Expr Int64-mulI64 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "mulI64") [toAst x, toAst y])--mulU8 :: Expr Word8 -> Expr Word8 -> Expr Word8-mulU8 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "mulU8") [toAst x, toAst y])--mulU16 :: Expr Word16 -> Expr Word16 -> Expr Word16-mulU16 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "mulU16") [toAst x, toAst y])--mulU32 :: Expr Word32 -> Expr Word32 -> Expr Word32-mulU32 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "mulU32") [toAst x, toAst y])--mulU64 :: Expr Word64 -> Expr Word64 -> Expr Word64-mulU64 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "mulU64") [toAst x, toAst y])--divI8 :: Expr Int8 -> Expr Int8 -> Expr Int8-divI8 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "divI8") [toAst x, toAst y])+addInt :: Expr Int-> Expr Int -> Expr Int+addInt x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "addInt") [toAst x, toAst y]) -divI16 :: Expr Int16 -> Expr Int16 -> Expr Int16-divI16 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "divI16") [toAst x, toAst y])+addFloat :: Expr Double -> Expr Double -> Expr Double+addFloat x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "addFloat") [toAst x, toAst y]) -divI32 :: Expr Int32 -> Expr Int32 -> Expr Int32-divI32 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "divI32") [toAst x, toAst y])+subInt :: Expr Int -> Expr Int -> Expr Int+subInt x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "subInt") [toAst x, toAst y]) -divI64 :: Expr Int64 -> Expr Int64 -> Expr Int64-divI64 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "divI64") [toAst x, toAst y])+subFloat :: Expr Double -> Expr Double -> Expr Double+subFloat x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "subFloat") [toAst x, toAst y]) -divU8 :: Expr Word8 -> Expr Word8 -> Expr Word8-divU8 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "divU8") [toAst x, toAst y])+mulInt :: Expr Int -> Expr Int -> Expr Int+mulInt x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "mulInt") [toAst x, toAst y]) -divU16 :: Expr Word16 -> Expr Word16 -> Expr Word16-divU16 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "divU16") [toAst x, toAst y])+mulFloat :: Expr Double -> Expr Double -> Expr Double+mulFloat x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "mulFloat") [toAst x, toAst y]) -divU32 :: Expr Word32 -> Expr Word32 -> Expr Word32-divU32 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "divU32") [toAst x, toAst y])+divInt :: Expr Int -> Expr Int -> Expr Int+divInt x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "divInt") [toAst x, toAst y]) -divU64 :: Expr Word64 -> Expr Word64 -> Expr Word64-divU64 x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "divU64") [toAst x, toAst y])+divFloat :: Expr Double -> Expr Double -> Expr Double+divFloat x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "divFloat") [toAst x, toAst y]) concaT :: Expr T.Text -> Expr T.Text -> Expr T.Text concaT x y = Expr (Ast'FnCall $ Ast.FnCall (Ast'Ref $ Ast.Ref "concat") [toAst x, toAst y])@@ -469,23 +363,7 @@ instance ToExpr T.Text -instance ToExpr Int8--instance ToExpr Int16--instance ToExpr Int32--instance ToExpr Int64--instance ToExpr Word8--instance ToExpr Word16--instance ToExpr Word32--instance ToExpr Word64--instance ToExpr Float+instance ToExpr Int instance ToExpr Double @@ -500,35 +378,11 @@ string :: T.Text -> Expr T.Text string = ex -i8 :: Int8 -> Expr Int8-i8 = ex--i16 :: Int16 -> Expr Int16-i16 = ex--i32 :: Int32 -> Expr Int32-i32 = ex--i64 :: Int64 -> Expr Int64-i64 = ex--u8 :: Word8 -> Expr Word8-u8 = ex--u16 :: Word16 -> Expr Word16-u16 = ex--u32 :: Word32 -> Expr Word32-u32 = ex--u64 :: Word64 -> Expr Word64-u64 = ex--f32 :: Float -> Expr Float-f32 = ex+int :: Int -> Expr Int+int = ex -f64 :: Double -> Expr Double-f64 = ex+float :: Double -> Expr Double+float = ex --
library/Fluid/Prim.hs view
@@ -3,36 +3,18 @@ ) where import Data.Aeson-import Data.Word-import Data.Int import Data.Text (Text) data Prim = Prim'Bool Bool- | Prim'I8 Int8- | Prim'I16 Int16- | Prim'I32 Int32- | Prim'I64 Int64- | Prim'U8 Word8- | Prim'U16 Word16- | Prim'U32 Word32- | Prim'U64 Word64- | Prim'F32 Float- | Prim'F64 Double+ | Prim'Int Int+ | Prim'Float Double | Prim'String Text deriving (Show, Eq) instance ToJSON Prim where toJSON = \case Prim'Bool b -> toJSON b- Prim'I8 i -> toJSON i- Prim'I16 i -> toJSON i- Prim'I32 i -> toJSON i- Prim'I64 i -> toJSON i- Prim'U8 u -> toJSON u- Prim'U16 u -> toJSON u- Prim'U32 u -> toJSON u- Prim'U64 u -> toJSON u- Prim'F32 f -> toJSON f- Prim'F64 f -> toJSON f+ Prim'Int i -> toJSON i+ Prim'Float f -> toJSON f Prim'String s -> toJSON s
library/Fluid/Server/Expr.hs view
@@ -49,12 +49,10 @@ import Control.Monad.Reader (MonadReader(..), ReaderT(..), asks, lift) import Data.Map (Map) import Data.Foldable (foldlM)-import Data.Int-import Data.Word import Data.Aeson (parseJSON, Value) import Data.Aeson.Types (parseMaybe) import Data.IORef (IORef, readIORef, newIORef, writeIORef)-import Data.Scientific (toBoundedInteger, toBoundedRealFloat, Scientific)+import Data.Scientific (toBoundedInteger, toRealFloat, Scientific) import Data.Text (Text) import qualified Fluid.Ast as Ast@@ -601,49 +599,14 @@ gte <- newIORef gteExpr concat' <- newIORef concatExpr - addI8 <- newIORef $ i8Expr (+)- addI16 <- newIORef $ i16Expr (+)- addI32 <- newIORef $ i32Expr (+)- addI64 <- newIORef $ i64Expr (+)- addU8 <- newIORef $ u8Expr (+)- addU16 <- newIORef $ u16Expr (+)- addU32 <- newIORef $ u32Expr (+)- addU64 <- newIORef $ u64Expr (+)- addF32 <- newIORef $ f32Expr (+)- addF64 <- newIORef $ f64Expr (+)-- subI8 <- newIORef $ i8Expr (-)- subI16 <- newIORef $ i16Expr (-)- subI32 <- newIORef $ i32Expr (-)- subI64 <- newIORef $ i64Expr (-)- subU8 <- newIORef $ u8Expr (-)- subU16 <- newIORef $ u16Expr (-)- subU32 <- newIORef $ u32Expr (-)- subU64 <- newIORef $ u64Expr (-)- subF32 <- newIORef $ f32Expr (-)- subF64 <- newIORef $ f64Expr (-)-- mulI8 <- newIORef $ i8Expr (*)- mulI16 <- newIORef $ i16Expr (*)- mulI32 <- newIORef $ i32Expr (*)- mulI64 <- newIORef $ i64Expr (*)- mulU8 <- newIORef $ u8Expr (*)- mulU16 <- newIORef $ u16Expr (*)- mulU32 <- newIORef $ u32Expr (*)- mulU64 <- newIORef $ u64Expr (*)- mulF32 <- newIORef $ f32Expr (*)- mulF64 <- newIORef $ f64Expr (*)-- divI8 <- newIORef $ i8Expr (div)- divI16 <- newIORef $ i16Expr (div)- divI32 <- newIORef $ i32Expr (div)- divI64 <- newIORef $ i64Expr (div)- divU8 <- newIORef $ u8Expr (div)- divU16 <- newIORef $ u16Expr (div)- divU32 <- newIORef $ u32Expr (div)- divU64 <- newIORef $ u64Expr (div)- divF32 <- newIORef $ f32Expr (/)- divF64 <- newIORef $ f64Expr (/)+ addInt <- newIORef $ intExpr (+)+ addFloat <- newIORef $ floatExpr (+)+ subInt <- newIORef $ intExpr (-)+ subFloat <- newIORef $ floatExpr (-)+ mulInt <- newIORef $ intExpr (*)+ mulFloat <- newIORef $ floatExpr (*)+ divInt <- newIORef $ intExpr (div)+ divFloat <- newIORef $ floatExpr (/) tuple <- newIORef tupleExpr @@ -666,49 +629,14 @@ , ("gt", gt) , ("gte", gte) - , ("addI8", addI8)- , ("addI16", addI16)- , ("addI32", addI32)- , ("addI64", addI64)- , ("addU8", addU8)- , ("addU16", addU16)- , ("addU32", addU32)- , ("addU64", addU64)- , ("addF32", addF32)- , ("addF64", addF64)-- , ("subI8", subI8)- , ("subI16", subI16)- , ("subI32", subI32)- , ("subI64", subI64)- , ("subU8", subU8)- , ("subU16", subU16)- , ("subU32", subU32)- , ("subU64", subU64)- , ("subF32", subF32)- , ("subF64", subF64)-- , ("mulI8", mulI8)- , ("mulI16", mulI16)- , ("mulI32", mulI32)- , ("mulI64", mulI64)- , ("mulU8", mulU8)- , ("mulU16", mulU16)- , ("mulU32", mulU32)- , ("mulU64", mulU64)- , ("mulF32", mulF32)- , ("mulF64", mulF64)-- , ("divI8", divI8)- , ("divI16", divI16)- , ("divI32", divI32)- , ("divI64", divI64)- , ("divU8", divU8)- , ("divU16", divU16)- , ("divU32", divU32)- , ("divU64", divU64)- , ("divF32", divF32)- , ("divF64", divF64)+ , ("addInt", addInt)+ , ("addFloat", addFloat)+ , ("subInt", subInt)+ , ("subFloat", subFloat)+ , ("mulInt", mulInt)+ , ("mulFloat", mulFloat)+ , ("divInt", divInt)+ , ("divFloat", divFloat) , ("concat", concat') , ("tuple", tuple)@@ -806,148 +734,15 @@ where go f a list = foldlM (\x y -> f [x, y]) a list -i8Expr :: RuntimeThrower m => (Int8 -> Int8 -> Int8) -> Expr m-i8Expr op = Expr'Fn . Fn $ \args ->- case args of- (_:[]) -> runtimeThrow RuntimeError'TooFewArguments- [Expr'Val (Val'Prim (Prim'I8 x)), Expr'Val (Val'Prim (Prim'I8 y))] -> toExpr $ x `op` y- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'I8 y))] -> case toBoundedInteger x of- Just x' -> toExpr $ x' `op` y- Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Prim (Prim'I8 x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedInteger y of- Just y' -> toExpr $ x `op` y'- Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Infer (Infer'Number y))] -> case (toBoundedInteger x, toBoundedInteger y) of- (Just x', Just y') -> toExpr $ x' `op` y'- _ -> runtimeThrow RuntimeError'IncompatibleType- (_:_:[]) -> runtimeThrow RuntimeError'IncompatibleType- _ -> runtimeThrow RuntimeError'TooManyArguments- where- toExpr v = return $ Expr'Val (toVal v)--i16Expr :: RuntimeThrower m => (Int16 -> Int16 -> Int16) -> Expr m-i16Expr op = Expr'Fn . Fn $ \args ->- case args of- (_:[]) -> runtimeThrow RuntimeError'TooFewArguments- [Expr'Val (Val'Prim (Prim'I16 x)), Expr'Val (Val'Prim (Prim'I16 y))] -> toExpr $ x `op` y- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'I16 y))] -> case toBoundedInteger x of- Just x' -> toExpr $ x' `op` y- Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Prim (Prim'I16 x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedInteger y of- Just y' -> toExpr $ x `op` y'- Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Infer (Infer'Number y))] -> case (toBoundedInteger x, toBoundedInteger y) of- (Just x', Just y') -> toExpr $ x' `op` y'- _ -> runtimeThrow RuntimeError'IncompatibleType- (_:_:[]) -> runtimeThrow RuntimeError'IncompatibleType- _ -> runtimeThrow RuntimeError'TooManyArguments- where- toExpr v = return $ Expr'Val (toVal v)--i32Expr :: RuntimeThrower m => (Int32 -> Int32 -> Int32) -> Expr m-i32Expr op = Expr'Fn . Fn $ \args ->- case args of- (_:[]) -> runtimeThrow RuntimeError'TooFewArguments- [Expr'Val (Val'Prim (Prim'I32 x)), Expr'Val (Val'Prim (Prim'I32 y))] -> toExpr $ x `op` y- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'I32 y))] -> case toBoundedInteger x of- Just x' -> toExpr $ x' `op` y- Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Prim (Prim'I32 x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedInteger y of- Just y' -> toExpr $ x `op` y'- Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Infer (Infer'Number y))] -> case (toBoundedInteger x, toBoundedInteger y) of- (Just x', Just y') -> toExpr $ x' `op` y'- _ -> runtimeThrow RuntimeError'IncompatibleType- (_:_:[]) -> runtimeThrow RuntimeError'IncompatibleType- _ -> runtimeThrow RuntimeError'TooManyArguments- where- toExpr v = return $ Expr'Val (toVal v)--i64Expr :: RuntimeThrower m => (Int64 -> Int64 -> Int64) -> Expr m-i64Expr op = Expr'Fn . Fn $ \args ->- case args of- (_:[]) -> runtimeThrow RuntimeError'TooFewArguments- [Expr'Val (Val'Prim (Prim'I64 x)), Expr'Val (Val'Prim (Prim'I64 y))] -> toExpr $ x `op` y- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'I64 y))] -> case toBoundedInteger x of- Just x' -> toExpr $ x' `op` y- Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Prim (Prim'I64 x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedInteger y of- Just y' -> toExpr $ x `op` y'- Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Infer (Infer'Number y))] -> case (toBoundedInteger x, toBoundedInteger y) of- (Just x', Just y') -> toExpr $ x' `op` y'- _ -> runtimeThrow RuntimeError'IncompatibleType- (_:_:[]) -> runtimeThrow RuntimeError'IncompatibleType- _ -> runtimeThrow RuntimeError'TooManyArguments- where- toExpr v = return $ Expr'Val (toVal v)--u8Expr :: RuntimeThrower m => (Word8 -> Word8 -> Word8) -> Expr m-u8Expr op = Expr'Fn . Fn $ \args ->- case args of- (_:[]) -> runtimeThrow RuntimeError'TooFewArguments- [Expr'Val (Val'Prim (Prim'U8 x)), Expr'Val (Val'Prim (Prim'U8 y))] -> toExpr $ x `op` y- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'U8 y))] -> case toBoundedInteger x of- Just x' -> toExpr $ x' `op` y- Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Prim (Prim'U8 x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedInteger y of- Just y' -> toExpr $ x `op` y'- Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Infer (Infer'Number y))] -> case (toBoundedInteger x, toBoundedInteger y) of- (Just x', Just y') -> toExpr $ x' `op` y'- _ -> runtimeThrow RuntimeError'IncompatibleType- (_:_:[]) -> runtimeThrow RuntimeError'IncompatibleType- _ -> runtimeThrow RuntimeError'TooManyArguments- where- toExpr v = return $ Expr'Val (toVal v)--u16Expr :: RuntimeThrower m => (Word16 -> Word16 -> Word16) -> Expr m-u16Expr op = Expr'Fn . Fn $ \args ->- case args of- (_:[]) -> runtimeThrow RuntimeError'TooFewArguments- [Expr'Val (Val'Prim (Prim'U16 x)), Expr'Val (Val'Prim (Prim'U16 y))] -> toExpr $ x `op` y- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'U16 y))] -> case toBoundedInteger x of- Just x' -> toExpr $ x' `op` y- Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Prim (Prim'U16 x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedInteger y of- Just y' -> toExpr $ x `op` y'- Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Infer (Infer'Number y))] -> case (toBoundedInteger x, toBoundedInteger y) of- (Just x', Just y') -> toExpr $ x' `op` y'- _ -> runtimeThrow RuntimeError'IncompatibleType- (_:_:[]) -> runtimeThrow RuntimeError'IncompatibleType- _ -> runtimeThrow RuntimeError'TooManyArguments- where- toExpr v = return $ Expr'Val (toVal v)--u32Expr :: RuntimeThrower m => (Word32 -> Word32 -> Word32) -> Expr m-u32Expr op = Expr'Fn . Fn $ \args ->- case args of- (_:[]) -> runtimeThrow RuntimeError'TooFewArguments- [Expr'Val (Val'Prim (Prim'U32 x)), Expr'Val (Val'Prim (Prim'U32 y))] -> toExpr $ x `op` y- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'U32 y))] -> case toBoundedInteger x of- Just x' -> toExpr $ x' `op` y- Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Prim (Prim'U32 x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedInteger y of- Just y' -> toExpr $ x `op` y'- Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Infer (Infer'Number y))] -> case (toBoundedInteger x, toBoundedInteger y) of- (Just x', Just y') -> toExpr $ x' `op` y'- _ -> runtimeThrow RuntimeError'IncompatibleType- (_:_:[]) -> runtimeThrow RuntimeError'IncompatibleType- _ -> runtimeThrow RuntimeError'TooManyArguments- where- toExpr v = return $ Expr'Val (toVal v)--u64Expr :: RuntimeThrower m => (Word64 -> Word64 -> Word64) -> Expr m-u64Expr op = Expr'Fn . Fn $ \args ->+intExpr :: RuntimeThrower m => (Int -> Int -> Int) -> Expr m+intExpr op = Expr'Fn . Fn $ \args -> case args of (_:[]) -> runtimeThrow RuntimeError'TooFewArguments- [Expr'Val (Val'Prim (Prim'U64 x)), Expr'Val (Val'Prim (Prim'U64 y))] -> toExpr $ x `op` y- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'U64 y))] -> case toBoundedInteger x of+ [Expr'Val (Val'Prim (Prim'Int x)), Expr'Val (Val'Prim (Prim'Int y))] -> toExpr $ x `op` y+ [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'Int y))] -> case toBoundedInteger x of Just x' -> toExpr $ x' `op` y Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Prim (Prim'U64 x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedInteger y of+ [Expr'Val (Val'Prim (Prim'Int x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedInteger y of Just y' -> toExpr $ x `op` y' Nothing -> runtimeThrow RuntimeError'IncompatibleType [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Infer (Infer'Number y))] -> case (toBoundedInteger x, toBoundedInteger y) of@@ -958,33 +753,14 @@ where toExpr v = return $ Expr'Val (toVal v) -f32Expr :: RuntimeThrower m => (Float -> Float -> Float) -> Expr m-f32Expr op = Expr'Fn . Fn $ \args ->- case args of- (_:[]) -> runtimeThrow RuntimeError'TooFewArguments- [Expr'Val (Val'Prim (Prim'F32 x)), Expr'Val (Val'Prim (Prim'F32 y))] -> toExpr $ x `op` y- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'F32 y))] -> case toBoundedRealFloat x of- x' -> toExpr $ eitherCollapse x' `op` y- [Expr'Val (Val'Prim (Prim'F32 x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedRealFloat y of- y' -> toExpr $ x `op` eitherCollapse y'- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Infer (Infer'Number y))] -> case (toBoundedRealFloat x, toBoundedRealFloat y) of- (x', y') -> toExpr $ eitherCollapse x' `op` eitherCollapse y'- (_:_:[]) -> runtimeThrow RuntimeError'IncompatibleType- _ -> runtimeThrow RuntimeError'TooManyArguments- where- toExpr v = return $ Expr'Val (toVal v)--f64Expr :: RuntimeThrower m => (Double -> Double -> Double) -> Expr m-f64Expr op = Expr'Fn . Fn $ \args ->+floatExpr :: RuntimeThrower m => (Double -> Double -> Double) -> Expr m+floatExpr op = Expr'Fn . Fn $ \args -> case args of (_:[]) -> runtimeThrow RuntimeError'TooFewArguments- [Expr'Val (Val'Prim (Prim'F64 x)), Expr'Val (Val'Prim (Prim'F64 y))] -> toExpr $ x `op` y- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'F64 y))] -> case toBoundedRealFloat x of- x' -> toExpr $ eitherCollapse x' `op` y- [Expr'Val (Val'Prim (Prim'F64 x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedRealFloat y of- y' -> toExpr $ x `op` eitherCollapse y'- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Infer (Infer'Number y))] -> case (toBoundedRealFloat x, toBoundedRealFloat y) of- (x', y') -> toExpr $ eitherCollapse x' `op` eitherCollapse y'+ [Expr'Val (Val'Prim (Prim'Float x)), Expr'Val (Val'Prim (Prim'Float y))] -> toExpr $ x `op` y+ [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'Float y))] -> toExpr $ toRealFloat x `op` y+ [Expr'Val (Val'Prim (Prim'Float x)), Expr'Val (Val'Infer (Infer'Number y))] -> toExpr $ x `op` toRealFloat y+ [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Infer (Infer'Number y))] -> toExpr $ toRealFloat x `op` toRealFloat y (_:_:[]) -> runtimeThrow RuntimeError'IncompatibleType _ -> runtimeThrow RuntimeError'TooManyArguments where@@ -992,84 +768,26 @@ boolExpr :: RuntimeThrower m => (Scientific -> Scientific -> Bool)- -> (Int8 -> Int8 -> Bool)- -> (Int16 -> Int16 -> Bool)- -> (Int32 -> Int32 -> Bool)- -> (Int64 -> Int64 -> Bool)- -> (Word8 -> Word8 -> Bool)- -> (Word16 -> Word16 -> Bool)- -> (Word32 -> Word32 -> Bool)- -> (Word64 -> Word64 -> Bool)+ -> (Int -> Int -> Bool)+ -> (Double -> Double -> Bool) -> (Val -> Val -> Bool) -> Expr m-boolExpr num i8 i16 i32 i64 u8 u16 u32 u64 val = Expr'Fn . Fn $ \args ->+boolExpr num int float val = Expr'Fn . Fn $ \args -> case args of (_:[]) -> runtimeThrow RuntimeError'TooFewArguments [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Infer (Infer'Number y))] -> toExpr $ x `num` y - [Expr'Val (Val'Prim (Prim'I8 x)), Expr'Val (Val'Prim (Prim'I8 y))] -> toExpr $ x `i8` y- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'I8 y))] -> case toBoundedInteger x of- Just x' -> toExpr $ x' `i8` y- Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Prim (Prim'I8 x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedInteger y of- Just y' -> toExpr $ x `i8` y'- Nothing -> runtimeThrow RuntimeError'IncompatibleType-- [Expr'Val (Val'Prim (Prim'I16 x)), Expr'Val (Val'Prim (Prim'I16 y))] -> toExpr $ x `i16` y- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'I16 y))] -> case toBoundedInteger x of- Just x' -> toExpr $ x' `i16` y- Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Prim (Prim'I16 x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedInteger y of- Just y' -> toExpr $ x `i16` y'- Nothing -> runtimeThrow RuntimeError'IncompatibleType-- [Expr'Val (Val'Prim (Prim'I32 x)), Expr'Val (Val'Prim (Prim'I32 y))] -> toExpr $ x `i32` y- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'I32 y))] -> case toBoundedInteger x of- Just x' -> toExpr $ x' `i32` y- Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Prim (Prim'I32 x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedInteger y of- Just y' -> toExpr $ x `i32` y'- Nothing -> runtimeThrow RuntimeError'IncompatibleType-- [Expr'Val (Val'Prim (Prim'I64 x)), Expr'Val (Val'Prim (Prim'I64 y))] -> toExpr $ x `i64` y- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'I64 y))] -> case toBoundedInteger x of- Just x' -> toExpr $ x' `i64` y- Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Prim (Prim'I64 x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedInteger y of- Just y' -> toExpr $ x `i64` y'- Nothing -> runtimeThrow RuntimeError'IncompatibleType-- [Expr'Val (Val'Prim (Prim'U8 x)), Expr'Val (Val'Prim (Prim'U8 y))] -> toExpr $ x `u8` y- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'U8 y))] -> case toBoundedInteger x of- Just x' -> toExpr $ x' `u8` y- Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Prim (Prim'U8 x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedInteger y of- Just y' -> toExpr $ x `u8` y'- Nothing -> runtimeThrow RuntimeError'IncompatibleType-- [Expr'Val (Val'Prim (Prim'U16 x)), Expr'Val (Val'Prim (Prim'U16 y))] -> toExpr $ x `u16` y- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'U16 y))] -> case toBoundedInteger x of- Just x' -> toExpr $ x' `u16` y- Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Prim (Prim'U16 x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedInteger y of- Just y' -> toExpr $ x `u16` y'- Nothing -> runtimeThrow RuntimeError'IncompatibleType-- [Expr'Val (Val'Prim (Prim'U32 x)), Expr'Val (Val'Prim (Prim'U32 y))] -> toExpr $ x `u32` y- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'U32 y))] -> case toBoundedInteger x of- Just x' -> toExpr $ x' `u32` y+ [Expr'Val (Val'Prim (Prim'Int x)), Expr'Val (Val'Prim (Prim'Int y))] -> toExpr $ x `int` y+ [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'Int y))] -> case toBoundedInteger x of+ Just x' -> toExpr $ x' `int` y Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Prim (Prim'U32 x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedInteger y of- Just y' -> toExpr $ x `u32` y'+ [Expr'Val (Val'Prim (Prim'Int x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedInteger y of+ Just y' -> toExpr $ x `int` y' Nothing -> runtimeThrow RuntimeError'IncompatibleType - [Expr'Val (Val'Prim (Prim'U64 x)), Expr'Val (Val'Prim (Prim'U64 y))] -> toExpr $ x `u64` y- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'U64 y))] -> case toBoundedInteger x of- Just x' -> toExpr $ x' `u64` y- Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Prim (Prim'U64 x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedInteger y of- Just y' -> toExpr $ x `u64` y'- Nothing -> runtimeThrow RuntimeError'IncompatibleType+ [Expr'Val (Val'Prim (Prim'Float x)), Expr'Val (Val'Prim (Prim'Float y))] -> toExpr $ x `float` y+ [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'Float y))] -> toExpr $ toRealFloat x `float` y+ [Expr'Val (Val'Prim (Prim'Float x)), Expr'Val (Val'Infer (Infer'Number y))] -> toExpr $ x `float` toRealFloat y [Expr'Val x, Expr'Val y] -> toExpr $ x `val` y @@ -1080,83 +798,25 @@ numExpr :: (RuntimeThrower m, ToVal a) => (Scientific -> Scientific -> a)- -> (Int8 -> Int8 -> a)- -> (Int16 -> Int16 -> a)- -> (Int32 -> Int32 -> a)- -> (Int64 -> Int64 -> a)- -> (Word8 -> Word8 -> a)- -> (Word16 -> Word16 -> a)- -> (Word32 -> Word32 -> a)- -> (Word64 -> Word64 -> a)+ -> (Int -> Int -> a)+ -> (Double -> Double -> a) -> Expr m-numExpr num i8 i16 i32 i64 u8 u16 u32 u64 = Expr'Fn . Fn $ \args ->+numExpr num int float = Expr'Fn . Fn $ \args -> case args of (_:[]) -> runtimeThrow RuntimeError'TooFewArguments [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Infer (Infer'Number y))] -> toExpr $ x `num` y - [Expr'Val (Val'Prim (Prim'I8 x)), Expr'Val (Val'Prim (Prim'I8 y))] -> toExpr $ x `i8` y- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'I8 y))] -> case toBoundedInteger x of- Just x' -> toExpr $ x' `i8` y- Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Prim (Prim'I8 x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedInteger y of- Just y' -> toExpr $ x `i8` y'- Nothing -> runtimeThrow RuntimeError'IncompatibleType-- [Expr'Val (Val'Prim (Prim'I16 x)), Expr'Val (Val'Prim (Prim'I16 y))] -> toExpr $ x `i16` y- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'I16 y))] -> case toBoundedInteger x of- Just x' -> toExpr $ x' `i16` y- Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Prim (Prim'I16 x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedInteger y of- Just y' -> toExpr $ x `i16` y'- Nothing -> runtimeThrow RuntimeError'IncompatibleType-- [Expr'Val (Val'Prim (Prim'I32 x)), Expr'Val (Val'Prim (Prim'I32 y))] -> toExpr $ x `i32` y- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'I32 y))] -> case toBoundedInteger x of- Just x' -> toExpr $ x' `i32` y- Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Prim (Prim'I32 x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedInteger y of- Just y' -> toExpr $ x `i32` y'- Nothing -> runtimeThrow RuntimeError'IncompatibleType-- [Expr'Val (Val'Prim (Prim'I64 x)), Expr'Val (Val'Prim (Prim'I64 y))] -> toExpr $ x `i64` y- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'I64 y))] -> case toBoundedInteger x of- Just x' -> toExpr $ x' `i64` y- Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Prim (Prim'I64 x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedInteger y of- Just y' -> toExpr $ x `i64` y'- Nothing -> runtimeThrow RuntimeError'IncompatibleType-- [Expr'Val (Val'Prim (Prim'U8 x)), Expr'Val (Val'Prim (Prim'U8 y))] -> toExpr $ x `u8` y- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'U8 y))] -> case toBoundedInteger x of- Just x' -> toExpr $ x' `u8` y- Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Prim (Prim'U8 x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedInteger y of- Just y' -> toExpr $ x `u8` y'- Nothing -> runtimeThrow RuntimeError'IncompatibleType-- [Expr'Val (Val'Prim (Prim'U16 x)), Expr'Val (Val'Prim (Prim'U16 y))] -> toExpr $ x `u16` y- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'U16 y))] -> case toBoundedInteger x of- Just x' -> toExpr $ x' `u16` y- Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Prim (Prim'U16 x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedInteger y of- Just y' -> toExpr $ x `u16` y'- Nothing -> runtimeThrow RuntimeError'IncompatibleType-- [Expr'Val (Val'Prim (Prim'U32 x)), Expr'Val (Val'Prim (Prim'U32 y))] -> toExpr $ x `u32` y- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'U32 y))] -> case toBoundedInteger x of- Just x' -> toExpr $ x' `u32` y+ [Expr'Val (Val'Prim (Prim'Int x)), Expr'Val (Val'Prim (Prim'Int y))] -> toExpr $ x `int` y+ [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'Int y))] -> case toBoundedInteger x of+ Just x' -> toExpr $ x' `int` y Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Prim (Prim'U32 x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedInteger y of- Just y' -> toExpr $ x `u32` y'+ [Expr'Val (Val'Prim (Prim'Int x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedInteger y of+ Just y' -> toExpr $ x `int` y' Nothing -> runtimeThrow RuntimeError'IncompatibleType - [Expr'Val (Val'Prim (Prim'U64 x)), Expr'Val (Val'Prim (Prim'U64 y))] -> toExpr $ x `u64` y- [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'U64 y))] -> case toBoundedInteger x of- Just x' -> toExpr $ x' `u64` y- Nothing -> runtimeThrow RuntimeError'IncompatibleType- [Expr'Val (Val'Prim (Prim'U64 x)), Expr'Val (Val'Infer (Infer'Number y))] -> case toBoundedInteger y of- Just y' -> toExpr $ x `u64` y'- Nothing -> runtimeThrow RuntimeError'IncompatibleType+ [Expr'Val (Val'Prim (Prim'Float x)), Expr'Val (Val'Prim (Prim'Float y))] -> toExpr $ x `float` y+ [Expr'Val (Val'Infer (Infer'Number x)), Expr'Val (Val'Prim (Prim'Float y))] -> toExpr $ toRealFloat x `float` y+ [Expr'Val (Val'Prim (Prim'Float x)), Expr'Val (Val'Infer (Infer'Number y))] -> toExpr $ x `float` toRealFloat y (_:_:[]) -> runtimeThrow RuntimeError'IncompatibleType _ -> runtimeThrow RuntimeError'TooManyArguments@@ -1173,22 +833,22 @@ toExpr v = return $ Expr'Val (toVal v) eqExpr :: RuntimeThrower m => Expr m-eqExpr = boolExpr (==) (==) (==) (==) (==) (==) (==) (==) (==) (==)+eqExpr = boolExpr (==) (==) (==) (==) neqExpr :: RuntimeThrower m => Expr m-neqExpr = boolExpr (/=) (/=) (/=) (/=) (/=) (/=) (/=) (/=) (/=) (/=)+neqExpr = boolExpr (/=) (/=) (/=) (/=) ltExpr :: RuntimeThrower m => Expr m-ltExpr = numExpr (<) (<) (<) (<) (<) (<) (<) (<) (<)+ltExpr = numExpr (<) (<) (<) lteExpr :: RuntimeThrower m => Expr m-lteExpr = numExpr (<=) (<=) (<=) (<=) (<=) (<=) (<=) (<=) (<=)+lteExpr = numExpr (<=) (<=) (<=) gtExpr :: RuntimeThrower m => Expr m-gtExpr = numExpr (>) (>) (>) (>) (>) (>) (>) (>) (>)+gtExpr = numExpr (>) (>) (>) gteExpr :: RuntimeThrower m => Expr m-gteExpr = numExpr (>=) (>=) (>=) (>=) (>=) (>=) (>=) (>=) (>=)+gteExpr = numExpr (>=) (>=) (>=) concatExpr :: RuntimeThrower m => Expr m concatExpr = Expr'Fn . Fn $ \args ->@@ -1206,9 +866,6 @@ case args of (_:[]) -> runtimeThrow RuntimeError'TooFewArguments xs -> return $ Expr'Tuple $ Tuple xs--eitherCollapse :: Either a a -> a-eitherCollapse = either id id --
library/Fluid/Types.hs view
@@ -31,8 +31,6 @@ import Data.String (IsString(..)) import Data.Scientific import Data.Proxy-import Data.Int-import Data.Word import GHC.Generics newtype Major = Major Int@@ -273,35 +271,11 @@ instance HasType Text where getType _ = "String" -instance HasType Int8 where- getType _ = "I8"--instance HasType Int16 where- getType _ = "I16"--instance HasType Int32 where- getType _ = "I32"--instance HasType Int64 where- getType _ = "I64"--instance HasType Word8 where- getType _ = "U8"--instance HasType Word16 where- getType _ = "U16"--instance HasType Word32 where- getType _ = "U32"--instance HasType Word64 where- getType _ = "U64"--instance HasType Float where- getType _ = "F32"+instance HasType Int where+ getType _ = "Int" instance HasType Double where- getType _ = "F64"+ getType _ = "Float" instance HasType a => HasType (Maybe a) where getType x = Type "Option" [getType (p x)] Nothing
library/Fluid/Val.hs view
@@ -23,8 +23,6 @@ import Data.Map (Map) import Data.Scientific (toBoundedInteger, toRealFloat) import Data.Text (Text)-import Data.Int-import Data.Word import GHC.Generics (Generic) import Fluid.Types@@ -115,35 +113,11 @@ instance ToVal Text where toVal s = Val'Prim $ Prim'String s -instance ToVal Int8 where- toVal i = Val'Prim $ Prim'I8 i--instance ToVal Int16 where- toVal i = Val'Prim $ Prim'I16 i--instance ToVal Int32 where- toVal i = Val'Prim $ Prim'I32 i--instance ToVal Int64 where- toVal i = Val'Prim $ Prim'I64 i--instance ToVal Word8 where- toVal u = Val'Prim $ Prim'U8 u--instance ToVal Word16 where- toVal u = Val'Prim $ Prim'U16 u--instance ToVal Word32 where- toVal u = Val'Prim $ Prim'U32 u--instance ToVal Word64 where- toVal u = Val'Prim $ Prim'U64 u--instance ToVal Float where- toVal f = Val'Prim $ Prim'F32 f+instance ToVal Int where+ toVal i = Val'Prim $ Prim'Int i instance ToVal Double where- toVal d = Val'Prim $ Prim'F64 d+ toVal d = Val'Prim $ Prim'Float d instance ToVal a => ToVal (Maybe a) where toVal Nothing = Val'Infer Infer'Null@@ -296,61 +270,14 @@ fromVal (Val'Prim (Prim'String s)) = Just s fromVal _ = Nothing -instance FromVal Int8 where- fromVal = \case- Val'Prim (Prim'I8 i) -> Just i- Val'Infer (Infer'Number n) -> toBoundedInteger n- _ -> Nothing--instance FromVal Int16 where- fromVal = \case- Val'Prim (Prim'I16 i) -> Just i- Val'Infer (Infer'Number n) -> toBoundedInteger n- _ -> Nothing--instance FromVal Int32 where- fromVal = \case- Val'Prim (Prim'I32 i) -> Just i- Val'Infer (Infer'Number n) -> toBoundedInteger n- _ -> Nothing--instance FromVal Int64 where- fromVal = \case- Val'Prim (Prim'I64 i) -> Just i- Val'Infer (Infer'Number n) -> toBoundedInteger n- _ -> Nothing--instance FromVal Word8 where- fromVal = \case- Val'Prim (Prim'U8 u) -> Just u- Val'Infer (Infer'Number n) -> toBoundedInteger n- _ -> Nothing--instance FromVal Word16 where- fromVal = \case- Val'Prim (Prim'U16 u) -> Just u- Val'Infer (Infer'Number n) -> toBoundedInteger n- _ -> Nothing--instance FromVal Word32 where- fromVal = \case- Val'Prim (Prim'U32 u) -> Just u- Val'Infer (Infer'Number n) -> toBoundedInteger n- _ -> Nothing--instance FromVal Word64 where+instance FromVal Int where fromVal = \case- Val'Prim (Prim'U64 u) -> Just u+ Val'Prim (Prim'Int i) -> Just i Val'Infer (Infer'Number n) -> toBoundedInteger n _ -> Nothing -instance FromVal Float where- fromVal (Val'Prim (Prim'F32 f)) = Just f- fromVal (Val'Infer (Infer'Number n)) = Just $ toRealFloat n- fromVal _ = Nothing- instance FromVal Double where- fromVal (Val'Prim (Prim'F64 f)) = Just f+ fromVal (Val'Prim (Prim'Float f)) = Just f fromVal (Val'Infer (Infer'Number n)) = Just $ toRealFloat n fromVal _ = Nothing
package.yaml view
@@ -1,5 +1,5 @@ name: fluid-idl-version: '0.0.4'+version: '0.0.5' category: Web synopsis: Fluid | The Programmatic IDL description: Fluid | The Programmatic IDL@@ -52,12 +52,11 @@ dependencies: - aeson - base >= 4.7 && < 5- - fluid+ - fluid-idl - containers - hspec - scientific - text- - tuple - vector ghc-options: - -rtsopts
tests/AstSpec.hs view
@@ -26,15 +26,15 @@ context "Type" $ do it "string only" $ shouldBe (parseMaybe parseJSON (String "MyType"))- (Just $ Type "MyType" [])+ (Just $ Type "MyType" [] Nothing) it "object with no param" $ shouldBe (parseMaybe parseJSON $ object ["n" .= String "MyType"])- (Just $ Type "MyType" [])+ (Just $ Type "MyType" [] Nothing) it "object with param" $ shouldBe (parseMaybe parseJSON $ object ["n" .= String "MyType", "p" .= String "MyParam"])- (Just $ Type "MyType" ["MyParam"])+ (Just $ Type "MyType" ["MyParam"] Nothing) describe "parse Ast" $ do it "Ref" $ shouldBe@@ -61,8 +61,8 @@ context "Lambda" $ do it "simple" $ shouldBe- (parseAst $ Array $ V.fromList ["fn", Array $ V.fromList [ object [ "myVar" .= String "Int64" ] ], Bool True])- (Just $ Ast'Lambda $ Lambda [("myVar", Type "Int64" [])] (Ast'Const $ Const'Bool True))+ (parseAst $ Array $ V.fromList ["fn", Array $ V.fromList [ object [ "myVar" .= String "Int" ] ], Bool True])+ (Just $ Ast'Lambda $ Lambda [("myVar", Type "Int" [] Nothing)] (Ast'Const $ Const'Bool True)) context "List" $ do it "simple" $ shouldBe
tests/ClientSpec.hs view
@@ -1,15 +1,14 @@ module ClientSpec (spec) where import Test.Hspec-import Data.Int import Fluid.Client -_helloWorld :: Expr (Int32, Int32)+_helloWorld :: Expr (Int, Int) _helloWorld = dO $ do- x <- def "x" (i32 0)- f <- defn "f" (fn2 "a" "b" add)- stmt $ tuple2 x (f -< (x, i32 10))+ x <- def "x" (int 0)+ f <- defn "f" (fn2 "a" "b" addInt)+ stmt $ tuple2 x (f -< (x, int 10)) spec :: Spec spec = do
tests/ValSpec.hs view
@@ -8,6 +8,7 @@ import Fluid.Types import Fluid.Val+import Fluid.Prim spec :: Spec spec = do@@ -17,15 +18,15 @@ (Just $ Val'ApiVal $ ApiVal'Enumeral $ Enumeral "None" Nothing) it "Struct" $ shouldBe (parseMaybe parseJSON $ object [ "x" .= True ])- (Just $ Val'ApiVal $ ApiVal'Struct $ Struct $ Map.fromList [("x", Val'Const $ Const'Bool True)] )+ (Just $ Val'ApiVal $ ApiVal'Struct $ Struct $ Map.fromList [("x", Val'Prim $ Prim'Bool True)] ) it "Struct" $ shouldBe (parseMaybe parseJSON $ object [ "x" .= object [ "tag" .= ("None" :: Text) ] ]) (Just $ Val'ApiVal $ ApiVal'Struct $ Struct $ Map.fromList [("x", Val'ApiVal $ ApiVal'Enumeral $ Enumeral "None" Nothing)] ) describe "parse types from val" $ do context "Option" $ do it "None" $ shouldBe- (fromVal $ Val'Const Const'Null)+ (fromVal $ Val'Infer Infer'Null) (Just Nothing :: Maybe (Maybe Bool)) it "Some" $ shouldBe- (fromVal $ Val'Const $ Const'Bool $ True)+ (fromVal $ Val'Prim $ Prim'Bool $ True) (Just (Just True) :: Maybe (Maybe Bool))