ddc-core-salt 0.4.2.1 → 0.4.3.1
raw patch · 26 files changed
+163/−276 lines, 26 filesdep −ddc-basedep ~basedep ~ddc-coredep ~transformersPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies removed: ddc-base
Dependency ranges changed: base, ddc-core, transformers
API changes (from Hackage documentation)
- DDC.Core.Salt.Exp: instance DDC.Core.Salt.Exp.FromAnnot (DDC.Core.Exp.DaCon.DaCon DDC.Core.Salt.Name.Name) (DDC.Core.Exp.DaCon.DaCon DDC.Core.Salt.Name.Name)
- DDC.Core.Salt.Exp: instance DDC.Core.Salt.Exp.FromAnnot (DDC.Type.Exp.Base.Bind DDC.Core.Salt.Name.Name) (DDC.Type.Exp.Base.Bind DDC.Core.Salt.Name.Name)
- DDC.Core.Salt.Exp: instance DDC.Core.Salt.Exp.FromAnnot (DDC.Type.Exp.Base.Bound DDC.Core.Salt.Name.Name) (DDC.Type.Exp.Base.Bound DDC.Core.Salt.Name.Name)
- DDC.Core.Salt.Exp: instance DDC.Core.Salt.Exp.FromAnnot (DDC.Type.Exp.Base.Type DDC.Core.Salt.Name.Name) (DDC.Type.Exp.Base.Type DDC.Core.Salt.Name.Name)
- DDC.Core.Salt.Name: instance DDC.Base.Name.CompoundName DDC.Core.Salt.Name.Name
- DDC.Core.Salt.Name: instance DDC.Base.Pretty.Pretty DDC.Core.Salt.Name.Name
- DDC.Core.Salt.Name: instance DDC.Base.Pretty.Pretty DDC.Core.Salt.Name.PrimLit
- DDC.Core.Salt.Name: instance DDC.Base.Pretty.Pretty DDC.Core.Salt.Name.PrimOp
- DDC.Core.Salt.Name: instance DDC.Base.Pretty.Pretty DDC.Core.Salt.Name.PrimVal
- DDC.Core.Salt.Platform: instance DDC.Base.Pretty.Pretty DDC.Core.Salt.Platform.Platform
+ DDC.Core.Salt: PrimLitChar :: !Char -> PrimLit
+ DDC.Core.Salt.Compounds: xChar :: a -> Char -> Exp a Name
+ DDC.Core.Salt.Exp: instance DDC.Core.Salt.Exp.FromAnnot (DDC.Core.Exp.DaCon.DaCon DDC.Core.Salt.Name.Name (DDC.Type.Exp.Simple.Exp.Type DDC.Core.Salt.Name.Name)) (DDC.Core.Exp.DaCon.DaCon DDC.Core.Salt.Name.Name (DDC.Type.Exp.Simple.Exp.Type DDC.Core.Salt.Name.Name))
+ DDC.Core.Salt.Exp: instance DDC.Core.Salt.Exp.FromAnnot (DDC.Type.Exp.Simple.Exp.Bind DDC.Core.Salt.Name.Name) (DDC.Type.Exp.Simple.Exp.Bind DDC.Core.Salt.Name.Name)
+ DDC.Core.Salt.Exp: instance DDC.Core.Salt.Exp.FromAnnot (DDC.Type.Exp.Simple.Exp.Bound DDC.Core.Salt.Name.Name) (DDC.Type.Exp.Simple.Exp.Bound DDC.Core.Salt.Name.Name)
+ DDC.Core.Salt.Exp: instance DDC.Core.Salt.Exp.FromAnnot (DDC.Type.Exp.Simple.Exp.Type DDC.Core.Salt.Name.Name) (DDC.Type.Exp.Simple.Exp.Type DDC.Core.Salt.Name.Name)
+ DDC.Core.Salt.Name: PrimLitChar :: !Char -> PrimLit
+ DDC.Core.Salt.Name: instance DDC.Data.Name.CompoundName DDC.Core.Salt.Name.Name
+ DDC.Core.Salt.Name: instance DDC.Data.Pretty.Pretty DDC.Core.Salt.Name.Name
+ DDC.Core.Salt.Name: instance DDC.Data.Pretty.Pretty DDC.Core.Salt.Name.PrimLit
+ DDC.Core.Salt.Name: instance DDC.Data.Pretty.Pretty DDC.Core.Salt.Name.PrimOp
+ DDC.Core.Salt.Name: instance DDC.Data.Pretty.Pretty DDC.Core.Salt.Name.PrimVal
+ DDC.Core.Salt.Platform: instance DDC.Data.Pretty.Pretty DDC.Core.Salt.Platform.Platform
- DDC.Core.Salt: lexExpString :: String -> Int -> String -> [Token (Tok Name)]
+ DDC.Core.Salt: lexExpString :: String -> Int -> String -> [Located (Token Name)]
- DDC.Core.Salt: lexModuleString :: String -> Int -> String -> [Token (Tok Name)]
+ DDC.Core.Salt: lexModuleString :: String -> Int -> String -> [Located (Token Name)]
- DDC.Core.Salt.Convert: seaNameOfSuper :: Maybe (ImportValue Name) -> Maybe (ExportSource Name) -> Name -> Maybe Doc
+ DDC.Core.Salt.Convert: seaNameOfSuper :: Maybe (ImportValue Name (Type Name)) -> Maybe (ExportSource Name (Type Name)) -> Name -> Maybe Doc
- DDC.Core.Salt.Profile: lexExpString :: String -> Int -> String -> [Token (Tok Name)]
+ DDC.Core.Salt.Profile: lexExpString :: String -> Int -> String -> [Located (Token Name)]
- DDC.Core.Salt.Profile: lexModuleString :: String -> Int -> String -> [Token (Tok Name)]
+ DDC.Core.Salt.Profile: lexModuleString :: String -> Int -> String -> [Located (Token Name)]
- DDC.Core.Salt.Runtime: runtimeImportKinds :: Map Name (ImportType Name)
+ DDC.Core.Salt.Runtime: runtimeImportKinds :: Map Name (ImportType Name (Type Name))
- DDC.Core.Salt.Runtime: runtimeImportTypes :: Map Name (ImportValue Name)
+ DDC.Core.Salt.Runtime: runtimeImportTypes :: Map Name (ImportValue Name (Type Name))
Files
- DDC/Core/Salt/Compounds.hs +2/−1
- DDC/Core/Salt/Compounds/Lit.hs +8/−4
- DDC/Core/Salt/Convert.hs +4/−4
- DDC/Core/Salt/Convert/Base.hs +2/−2
- DDC/Core/Salt/Convert/Exp.hs +5/−2
- DDC/Core/Salt/Convert/Init.hs +2/−2
- DDC/Core/Salt/Convert/Name.hs +8/−5
- DDC/Core/Salt/Convert/Prim.hs +1/−1
- DDC/Core/Salt/Convert/Super.hs +2/−3
- DDC/Core/Salt/Convert/Type.hs +4/−4
- DDC/Core/Salt/Env.hs +16/−13
- DDC/Core/Salt/Exp.hs +22/−22
- DDC/Core/Salt/Name.hs +35/−26
- DDC/Core/Salt/Name/Lit.hs +0/−152
- DDC/Core/Salt/Name/PrimArith.hs +1/−1
- DDC/Core/Salt/Name/PrimCall.hs +1/−1
- DDC/Core/Salt/Name/PrimCast.hs +1/−1
- DDC/Core/Salt/Name/PrimControl.hs +1/−1
- DDC/Core/Salt/Name/PrimStore.hs +1/−1
- DDC/Core/Salt/Name/PrimTyCon.hs +1/−1
- DDC/Core/Salt/Name/PrimVec.hs +1/−1
- DDC/Core/Salt/Platform.hs +2/−1
- DDC/Core/Salt/Profile.hs +33/−13
- DDC/Core/Salt/Runtime.hs +3/−3
- LICENSE +1/−1
- ddc-core-salt.cabal +6/−10
DDC/Core/Salt/Compounds.hs view
@@ -10,7 +10,8 @@ -- * Values -- ** Literals- , xBool, xNat, xInt, xSize, xWord, xFloat, xTag, xTextLit+ , xBool, xNat, xInt, xSize, xWord, xFloat, xTag+ , xChar, xTextLit -- ** Primitive arithmetic operators. , xNeg
DDC/Core/Salt/Compounds/Lit.hs view
@@ -1,9 +1,9 @@ module DDC.Core.Salt.Compounds.Lit ( xBool- , xNat, xInt, xSize+ , xNat, xInt, xSize , xWord, xFloat, xTag- , xTextLit)+ , xChar, xTextLit) where import DDC.Core.Salt.Compounds.PrimTyCon import DDC.Core.Salt.Name@@ -40,10 +40,14 @@ -- | A Literal @Nat#@ data constructor.-dcNat :: Integer -> DaCon Name+dcNat :: Integer -> DaCon Name (Type Name) dcNat i = DaConPrim (NameLitNat i) tNat +-- | A Character literal.+xChar :: a -> Char -> Exp a Name+xChar a c = XCon a (DaConPrim (NameLitChar c) (tWord 32))+ -- | A Text literal. xTextLit :: a -> Text -> Exp a Name-xTextLit a tx = XCon a (DaConPrim (NameLitTextLit tx) tTextLit)+xTextLit a tx = XCon a (DaConPrim (NameLitTextLit tx) tTextLit)
DDC/Core/Salt/Convert.hs view
@@ -24,11 +24,11 @@ import DDC.Core.Salt.Convert.Base import DDC.Core.Salt.Name import DDC.Core.Salt.Platform-import DDC.Core.Module as C+import DDC.Core.Module as C import DDC.Core.Exp.Annot-import DDC.Base.Pretty-import DDC.Control.Monad.Check (throw, evalCheck)-import qualified DDC.Type.Env as Env+import DDC.Data.Pretty+import DDC.Control.Check (throw, evalCheck)+import qualified DDC.Type.Env as Env -- | Convert a Disciple Core Salt module to C-source text.
DDC/Core/Salt/Convert/Base.hs view
@@ -11,7 +11,7 @@ import DDC.Core.Pretty import DDC.Core.Module import DDC.Core.Exp-import qualified DDC.Control.Monad.Check as G+import qualified DDC.Control.Check as G -- | Conversion Monad@@ -79,7 +79,7 @@ deriving Show -instance (Show a, Pretty a) => Pretty (Error a) where+instance Pretty (Error a) where ppr err = case err of ErrorUndefined var
DDC/Core/Salt/Convert/Exp.hs view
@@ -15,9 +15,10 @@ import DDC.Core.Module import DDC.Core.Exp.Annot import DDC.Type.Env (KindEnv, TypeEnv)-import DDC.Base.Pretty-import DDC.Control.Monad.Check (throw)+import DDC.Data.Pretty+import DDC.Control.Check (throw) import qualified DDC.Type.Env as Env+import qualified Data.Char as Char -- Config -----------------------------------------------------------------------------------------@@ -281,6 +282,7 @@ PrimLitNat i -> Just $ integer i PrimLitInt i -> Just $ integer i+ PrimLitChar c -> Just $ int (Char.ord c) PrimLitWord i bits | elem bits [8, 16, 32, 64]@@ -325,6 +327,7 @@ PrimLitNat i -> return $ integer i PrimLitInt i -> return $ integer i PrimLitWord i _ -> return $ integer i+ PrimLitChar c -> return $ int (Char.ord c) PrimLitTag i -> return $ integer i PrimLitVoid -> return $ text "void" _ -> throw $ ErrorRValueInvalid xx
DDC/Core/Salt/Convert/Init.hs view
@@ -42,8 +42,8 @@ -- | Patch the list of export definitions to export our wrapper instead -- of the original main function. patchMainExports - :: [(Name, ExportSource Name)] - -> [(Name, ExportSource Name)]+ :: [(Name, ExportSource Name (Type Name))] + -> [(Name, ExportSource Name (Type Name))] patchMainExports xx = case xx of
DDC/Core/Salt/Convert/Name.hs view
@@ -7,11 +7,11 @@ where import DDC.Core.Salt.Name import DDC.Core.Module-import DDC.Base.Pretty+import DDC.Type.Exp.Simple.Exp+import DDC.Data.Pretty import Data.Maybe - -- | Like 'sanitizeGlobal' but indicate that the name is going to be visible -- globally. sanitizeGlobal :: String -> String@@ -21,9 +21,9 @@ -- | Convert the Salt name of a supercombinator to a name we can use when -- defining the C function. seaNameOfSuper - :: Maybe (ImportValue Name) -- ^ How the super is imported- -> Maybe (ExportSource Name) -- ^ How the super is exported- -> Name -- ^ Name of the super.+ :: Maybe (ImportValue Name (Type Name)) -- ^ How the super is imported+ -> Maybe (ExportSource Name (Type Name)) -- ^ How the super is exported+ -> Name -- ^ Name of the super. -> Maybe Doc seaNameOfSuper mImport mExport nm@@ -55,6 +55,9 @@ -- -- We don't handle the other cases because we would need to -- produce a wrapper to conver the names.+ | Just str <- takeNameVar nm+ = Just $ text str+ | otherwise = Nothing
DDC/Core/Salt/Convert/Prim.hs view
@@ -6,7 +6,7 @@ , convPrimStore) where import DDC.Core.Salt.Name-import DDC.Base.Pretty+import DDC.Data.Pretty -- | Convert a primitive type constructor to C source text.
DDC/Core/Salt/Convert/Super.hs view
@@ -11,12 +11,11 @@ import DDC.Core.Module import DDC.Core.Exp.Annot import DDC.Type.Env (KindEnv, TypeEnv)-import DDC.Base.Pretty-import DDC.Control.Monad.Check (throw)+import DDC.Data.Pretty+import DDC.Control.Check (throw) import qualified DDC.Type.Env as Env import Control.Monad import Data.Maybe- -- | Convert a supercombinator definition to C source text.
DDC/Core/Salt/Convert/Type.hs view
@@ -10,8 +10,8 @@ import DDC.Core.Module as C import DDC.Core.Exp.Annot import DDC.Type.Env (KindEnv)-import DDC.Base.Pretty-import DDC.Control.Monad.Check (throw)+import DDC.Data.Pretty+import DDC.Control.Check (throw) import qualified DDC.Type.Env as Env @@ -60,8 +60,8 @@ -- | Convert a Salt function type to a C source prototype. convSuperTypeM :: KindEnv Name- -> Maybe (ImportValue Name)- -> Maybe (ExportSource Name)+ -> Maybe (ImportValue Name (Type Name))+ -> Maybe (ExportSource Name (Type Name)) -> Name -- ^ Local name of super. -> Type Name -- ^ Function type. -> ConvertM a Doc
DDC/Core/Salt/Env.hs view
@@ -20,9 +20,7 @@ import DDC.Core.Salt.Compounds import DDC.Core.Salt.Name import DDC.Type.DataDef-import DDC.Type.Compounds-import DDC.Type.Predicates-import DDC.Type.Exp+import DDC.Type.Exp.Simple import DDC.Type.Env (Env) import qualified DDC.Type.Env as Env @@ -148,15 +146,16 @@ typeOfPrimLit :: PrimLit -> Type Name typeOfPrimLit lit = case lit of- PrimLitVoid -> tVoid- PrimLitBool _ -> tBool- PrimLitNat _ -> tNat- PrimLitInt _ -> tInt- PrimLitSize _ -> tSize- PrimLitWord _ bits -> tWord bits- PrimLitFloat _ bits -> tFloat bits- PrimLitTextLit _ -> tTextLit- PrimLitTag _ -> tTag+ PrimLitVoid -> tVoid+ PrimLitBool _ -> tBool+ PrimLitNat _ -> tNat+ PrimLitInt _ -> tInt+ PrimLitSize _ -> tSize+ PrimLitWord _ bits -> tWord bits+ PrimLitFloat _ bits -> tFloat bits+ PrimLitChar _ -> tWord 32+ PrimLitTextLit _ -> tTextLit+ PrimLitTag _ -> tTag -- PrimCall -------------------------------------------------------------------@@ -204,7 +203,9 @@ TCon _ -> False - TForall _ t -> typeIsUnboxed t+ -- Higher kinded types are not values types,+ -- so we'll say they're not unboxed.+ TAbs{} -> False -- Pointers to objects are boxed. TApp{}@@ -214,6 +215,8 @@ TApp t1 t2 -> typeIsUnboxed t1 || typeIsUnboxed t2++ TForall _ t -> typeIsUnboxed t TSum{} -> False
DDC/Core/Salt/Exp.hs view
@@ -1,7 +1,7 @@ {-# LANGUAGE TypeFamilies #-} module DDC.Core.Salt.Exp - ( module DDC.Core.Exp.Generic.Exp+ ( module DDC.Core.Exp.Generic , FromAnnot (..) , ErrorFromAnnot (..) @@ -9,33 +9,33 @@ , Exp, Abs, Arg, Lets, Alt, Pat, Cast, Witness, WiCon , Type) where-import DDC.Core.Exp.Generic.Exp-import qualified DDC.Core.Exp.Generic.Exp as G+import DDC.Core.Exp.Generic+import qualified DDC.Core.Exp.Generic as G import qualified DDC.Core.Salt.Name as A-import qualified DDC.Core.Exp.Annot.Exp as N+import qualified DDC.Core.Exp.Annot as N import qualified DDC.Type.Exp as C --------------------------------------------------------------------------------------------------- -- Type synonyms for the Salt fragment.-type instance GAnnot A.Name = ()-type instance GBind A.Name = C.Bind A.Name-type instance GBound A.Name = C.Bound A.Name-type instance GPrim A.Name = A.PrimOp+type instance G.GAnnot A.Name = ()+type instance G.GBind A.Name = C.Bind A.Name+type instance G.GBound A.Name = C.Bound A.Name+type instance G.GPrim A.Name = A.PrimOp -type Annot = GAnnot A.Name-type Bind = GBind A.Name-type Bound = GBound A.Name-type Prim = GPrim A.Name-type Exp = GExp A.Name-type Abs = GAbs A.Name-type Arg = GArg A.Name-type Lets = GLets A.Name-type Alt = GAlt A.Name-type Pat = GPat A.Name-type Cast = GCast A.Name-type Witness = GWitness A.Name-type WiCon = GWiCon A.Name+type Annot = G.GAnnot A.Name+type Bind = G.GBind A.Name+type Bound = G.GBound A.Name+type Prim = G.GPrim A.Name+type Exp = G.GExp A.Name+type Abs = G.GAbs A.Name+type Arg = G.GArg A.Name+type Lets = G.GLets A.Name+type Alt = G.GAlt A.Name+type Pat = G.GPat A.Name+type Cast = G.GCast A.Name+type Witness = G.GWitness A.Name+type WiCon = G.GWiCon A.Name type Type = C.Type A.Name @@ -142,7 +142,7 @@ N.WType _ t -> G.WType <$> pure t -instance FromAnnot (N.DaCon A.Name) (N.DaCon A.Name) where+instance FromAnnot (N.DaCon A.Name (C.Type A.Name)) (N.DaCon A.Name (C.Type A.Name)) where fromAnnot dc = pure dc
DDC/Core/Salt/Name.hs view
@@ -57,12 +57,12 @@ -- * Primitive Literals , PrimLit (..) , readPrimLit- , readLitInteger- , readLitNat- , readLitInt- , readLitSize- , readLitWordOfBits- , readLitFloatOfBits+ , K.readLitInteger+ , K.readLitNat+ , K.readLitInt+ , K.readLitSize+ , K.readLitWordOfBits+ , K.readLitFloatOfBits , pattern NameLitVoid , pattern NameLitBool@@ -71,6 +71,7 @@ , pattern NameLitSize , pattern NameLitWord , pattern NameLitFloat+ , pattern NameLitChar , pattern NameLitTextLit , pattern NameLitTag @@ -86,16 +87,15 @@ import DDC.Core.Salt.Name.PrimStore import DDC.Core.Salt.Name.PrimTyCon import DDC.Core.Salt.Name.PrimVec-import DDC.Core.Salt.Name.Lit-import DDC.Core.Lexer.Names (isVarStart) import DDC.Data.ListUtils-import DDC.Base.Pretty-import DDC.Base.Name+import DDC.Data.Pretty+import DDC.Data.Name import Data.Typeable import Data.Char import Data.List import Control.DeepSeq import Data.Text (Text)+import qualified DDC.Core.Lexer.Tokens as K import qualified Data.Text as T @@ -146,6 +146,9 @@ extendName n str = NameExt n str + newVarName str+ = NameVar str+ splitName nn = case nn of NameExt n str -> Just (n, str)@@ -174,7 +177,7 @@ -- Variables. | c : _ <- str- , isVarStart c || c == '_'+ , K.isVarStart c || c == '_' = Just $ NameVar str | otherwise@@ -307,23 +310,26 @@ = PrimLitVoid -- | A boolean literal.- | PrimLitBool !Bool+ | PrimLitBool !Bool -- | A natural number literal.- | PrimLitNat !Integer+ | PrimLitNat !Integer -- | An integer number literal.- | PrimLitInt !Integer+ | PrimLitInt !Integer -- | A size literal.- | PrimLitSize !Integer+ | PrimLitSize !Integer -- | A word literal, of the given width.- | PrimLitWord !Integer !Int+ | PrimLitWord !Integer !Int -- | A floating point literal, of the given width.- | PrimLitFloat !Double !Int+ | PrimLitFloat !Double !Int + -- | A character literal.+ | PrimLitChar !Char+ -- | A text literal. | PrimLitTextLit !Text @@ -339,6 +345,7 @@ pattern NameLitSize x = NamePrimVal (PrimValLit (PrimLitSize x)) pattern NameLitWord x s = NamePrimVal (PrimValLit (PrimLitWord x s)) pattern NameLitFloat x s = NamePrimVal (PrimValLit (PrimLitFloat x s))+pattern NameLitChar x = NamePrimVal (PrimValLit (PrimLitChar x)) pattern NameLitTextLit x = NamePrimVal (PrimValLit (PrimLitTextLit x)) pattern NameLitTag x = NamePrimVal (PrimValLit (PrimLitTag x)) @@ -354,6 +361,7 @@ PrimLitSize i -> rnf i PrimLitWord i bits -> rnf i `seq` rnf bits PrimLitFloat f bits -> rnf f `seq` rnf bits+ PrimLitChar c -> rnf c PrimLitTextLit bs -> rnf bs PrimLitTag i -> rnf i @@ -367,10 +375,11 @@ PrimLitNat i -> integer i <> text "#" PrimLitInt i -> integer i <> text "i#" PrimLitSize i -> integer i <> text "s#"- PrimLitWord i bits -> integer i <> text "w" <> int bits <> text "#"- PrimLitFloat f bits -> double f <> text "f" <> int bits <> text "#"- PrimLitTextLit tx -> (text $ show $ T.unpack tx) <> text "#"- PrimLitTag i -> text "TAG" <> integer i <> text "#"+ PrimLitWord i bits -> integer i <> text "w" <> int bits <> text "#"+ PrimLitFloat f bits -> double f <> text "f" <> int bits <> text "#"+ PrimLitChar c -> text (show c) <> text "#"+ PrimLitTextLit tx -> (text $ show $ T.unpack tx) <> text "#"+ PrimLitTag i -> text "TAG" <> integer i <> text "#" -- | Read a primitive literal.@@ -386,28 +395,28 @@ -- Literal Nats | Just str' <- stripSuffix "#" str- , Just val <- readLitNat str'+ , Just val <- K.readLitNat str' = Just $ PrimLitNat val -- Literal Ints | Just str' <- stripSuffix "#" str- , Just val <- readLitInt str'+ , Just val <- K.readLitInt str' = Just $ PrimLitInt val -- Literal Sizes | Just str' <- stripSuffix "s#" str- , Just val <- readLitSize str'+ , Just val <- K.readLitSize str' = Just $ PrimLitSize val -- Literal Words | Just str' <- stripSuffix "#" str- , Just (val, bits) <- readLitWordOfBits str'+ , Just (val, bits) <- K.readLitWordOfBits str' , elem bits [8, 16, 32, 64] = Just $ PrimLitWord val bits -- Literal Floats | Just str' <- stripSuffix "#" str- , Just (val, bits) <- readLitFloatOfBits str'+ , Just (val, bits) <- K.readLitFloatOfBits str' , elem bits [32, 64] = Just $ PrimLitFloat val bits
− DDC/Core/Salt/Name/Lit.hs
@@ -1,152 +0,0 @@---- | Reading literal values.-module DDC.Core.Salt.Name.Lit- ( readLitInteger- , readLitNat- , readLitInt- , readLitSize- , readLitWordOfBits- , readLitFloatOfBits)--where-import Data.List-import Data.Char----- | Read a signed integer.-readLitInteger :: String -> Maybe Integer-readLitInteger [] = Nothing-readLitInteger str@(c:cs)- | '-' <- c- , all isDigit cs- = Just $ read str-- | all isDigit cs- = Just $ read str- - | otherwise- = Nothing- ---- | Read an integer with an explicit format specifier like @1234i@.-readLitNat :: String -> Maybe Integer-readLitNat str1- | (ds, "") <- span isDigit str1- , not $ null ds- = Just $ read ds-- | otherwise- = Nothing----- | Read an integer literal with an explicit format specifier like @1234i@.-readLitInt :: String -> Maybe Integer-readLitInt str1- | '-' : str2 <- str1- , (ds, "i") <- span isDigit str2- , not $ null ds- = Just $ negate $ read ds-- | (ds, "i") <- span isDigit str1- , not $ null ds- = Just $ read ds-- | otherwise- = Nothing----- | Read an size literal with an explicit format specifier like @1234s@.-readLitSize :: String -> Maybe Integer-readLitSize str1- | '-' : str2 <- str1- , (ds, "s") <- span isDigit str2- , not $ null ds- = Just $ negate $ read ds-- | (ds, "s") <- span isDigit str1- , not $ null ds- = Just $ read ds-- | otherwise- = Nothing----- | Read a word with an explicit format speficier.-readLitWordOfBits :: String -> Maybe (Integer, Int)-readLitWordOfBits str1- -- binary like 0b01001w32- | Just str2 <- stripPrefix "0b" str1- , (ds, str3) <- span (\c -> c == '0' || c == '1') str2- , not $ null ds- , Just str4 <- stripPrefix "w" str3- , (bs, "") <- span isDigit str4- , not $ null bs- , bits <- read bs- , length ds <= bits- = Just (readBinary ds, bits)-- -- hex like 0x0ffw32- | Just str2 <- stripPrefix "0x" str1- , (ds, str3) <- span (\c -> elem c ['0' .. '9']- || elem c ['A' .. 'F']- || elem c ['a' .. 'f']) str2- , not $ null ds- , Just str4 <- stripPrefix "w" str3- , (bs, "") <- span isDigit str4- , not $ null bs- , bits <- read bs- , length ds <= bits- = Just (readHex ds, bits)-- -- decimal like 1234w32- | (ds, str2) <- span isDigit str1- , not $ null ds- , Just str3 <- stripPrefix "w" str2- , (bs, "") <- span isDigit str3- , not $ null bs- = Just (read ds, read bs)-- | otherwise- = Nothing----- | Read a float literal with an explicit format specifier like @123.00f32#@.-readLitFloatOfBits :: String -> Maybe (Double, Int)-readLitFloatOfBits str1- | '-' : str2 <- str1- , Just (d, bs) <- readLitFloatOfBits str2- = Just (negate d, bs)-- | (ds1, str2) <- span isDigit str1- , not $ null ds1- , Just str3 <- stripPrefix "." str2- , (ds2, str4) <- span isDigit str3- , not $ null ds2- , Just str5 <- stripPrefix "f" str4- , (bs, "") <- span isDigit str5- , not $ null bs- = Just (read (ds1 ++ "." ++ ds2), read bs)-- | otherwise- = Nothing----- | Read a binary string as a number.-readBinary :: Num a => String -> a-readBinary digits- = foldl' (\acc b -> if b then 2 * acc + 1 else 2 * acc) 0- $ map (/= '0') digits----- | Read a hex string as a number.-readHex :: (Enum a, Num a) => String -> a-readHex digits- = foldl' (\acc d -> let Just v = lookup d table- in 16 * acc + v) 0- $ digits-- where table- = zip ['0' .. '9'] [0 .. 9]- ++ zip ['a' .. 'f'] [10 .. 15]- ++ zip ['A' .. 'F'] [10 .. 15]-
DDC/Core/Salt/Name/PrimArith.hs view
@@ -3,7 +3,7 @@ ( PrimArith (..) , readPrimArith) where-import DDC.Base.Pretty+import DDC.Data.Pretty import Control.DeepSeq import Data.List
DDC/Core/Salt/Name/PrimCall.hs view
@@ -3,7 +3,7 @@ ( PrimCall (..) , readPrimCall) where-import DDC.Base.Pretty+import DDC.Data.Pretty import Control.DeepSeq import Data.Char import Data.List
DDC/Core/Salt/Name/PrimCast.hs view
@@ -7,7 +7,7 @@ where import DDC.Core.Salt.Name.PrimTyCon import DDC.Core.Salt.Platform-import DDC.Base.Pretty+import DDC.Data.Pretty import Control.DeepSeq
DDC/Core/Salt/Name/PrimControl.hs view
@@ -3,7 +3,7 @@ ( PrimControl (..) , readPrimControl) where-import DDC.Base.Pretty+import DDC.Data.Pretty import Control.DeepSeq
DDC/Core/Salt/Name/PrimStore.hs view
@@ -3,7 +3,7 @@ ( PrimStore (..) , readPrimStore) where-import DDC.Base.Pretty+import DDC.Data.Pretty import Control.DeepSeq
DDC/Core/Salt/Name/PrimTyCon.hs view
@@ -12,7 +12,7 @@ where import DDC.Core.Salt.Platform import DDC.Data.ListUtils-import DDC.Base.Pretty+import DDC.Data.Pretty import Control.DeepSeq import Data.Char import Data.List
DDC/Core/Salt/Name/PrimVec.hs view
@@ -7,7 +7,7 @@ , lowerPrimVecToArith) where import DDC.Core.Salt.Name.PrimArith-import DDC.Base.Pretty+import DDC.Data.Pretty import Control.DeepSeq import Data.List import Data.Char
DDC/Core/Salt/Platform.hs view
@@ -4,7 +4,8 @@ , platform32 , platform64) where-import DDC.Base.Pretty+import DDC.Data.Pretty+ -- | Enough information about the platform to generate code for it. -- We need to know the pointer size and alignment constraints
DDC/Core/Salt/Profile.hs view
@@ -9,8 +9,7 @@ import DDC.Core.Salt.Name import DDC.Core.Fragment import DDC.Core.Lexer-import DDC.Data.Token-+import DDC.Data.SourcePos -- | Language profile for Disciple Core Salt. profile :: Profile Name @@ -23,9 +22,25 @@ , profilePrimTypes = primTypeEnv , profileTypeIsUnboxed = typeIsUnboxed , profileNameIsHole = Nothing - , profileMakeStringName = Just (\_sp t -> NameLitTextLit t) }+ , profileMakeLiteralName = Just makeLiteralName } +-- | Convert a literal to a Salt name.+makeLiteralName :: SourcePos -> Literal -> Bool -> Maybe Name+makeLiteralName _ lit True+ = case lit of+ LNat n -> Just $ NameLitNat n+ LInt i -> Just $ NameLitInt i+ LSize s -> Just $ NameLitSize s+ LWord i b -> Just $ NameLitWord i b+ LFloat f b -> Just $ NameLitFloat f b+ LChar c -> Just $ NameLitChar c+ LString tx -> Just $ NameLitTextLit tx++makeLiteralName _ _ _+ = Nothing++ -- | The Salt fragment doesn't support many features. -- No nested functions, no partial application and so on. features :: Features@@ -50,13 +65,15 @@ :: String -- ^ Source file name. -> Int -- ^ Starting line number. -> String -- ^ String to parse.- -> [Token (Tok Name)]+ -> [Located (Token Name)]+ lexModuleString sourceName lineStart str = map rn $ lexModuleWithOffside sourceName lineStart str- where rn (Token strTok sp) - = case renameTok readName strTok of- Just t' -> Token t' sp- Nothing -> Token (KErrorJunk "lexical error") sp+ where+ rn (Located sp strTok) + = case renameToken readName strTok of+ Just t' -> Located sp t'+ Nothing -> Located sp (KErrorJunk "lexical error") -- | Lex a string to tokens, using primitive names.@@ -64,10 +81,13 @@ :: String -- ^ Source file name. -> Int -- ^ Starting line number. -> String -- ^ String to parse.- -> [Token (Tok Name)]+ -> [Located (Token Name)]+ lexExpString sourceName lineStart str = map rn $ lexExp sourceName lineStart str- where rn (Token strTok sp) - = case renameTok readName strTok of- Just t' -> Token t' sp- Nothing -> Token (KErrorJunk "lexical error") sp+ where + rn (Located sp strTok) + = case renameToken readName strTok of+ Just t' -> Located sp t'+ Nothing -> Located sp (KErrorJunk "lexical error")+
DDC/Core/Salt/Runtime.hs view
@@ -42,7 +42,7 @@ import DDC.Core.Salt.Name import DDC.Core.Exp.Annot import DDC.Core.Module-import DDC.Base.Pretty+import DDC.Data.Pretty import qualified Data.Map as Map import Data.Map (Map) @@ -57,7 +57,7 @@ -- | Kind signatures for runtime types that we use when converting to Salt.-runtimeImportKinds :: Map Name (ImportType Name)+runtimeImportKinds :: Map Name (ImportType Name (Type Name)) runtimeImportKinds = Map.fromList [ rn ukTop ]@@ -66,7 +66,7 @@ -- | Type signatures for runtime funtions that we use when converting to Salt.-runtimeImportTypes :: Map Name (ImportValue Name)+runtimeImportTypes :: Map Name (ImportValue Name (Type Name)) runtimeImportTypes = Map.fromList [ rn utGetTag
LICENSE view
@@ -1,7 +1,7 @@ -------------------------------------------------------------------------------- The Disciplined Disciple Compiler License (MIT style) -Copyrite (K) 2007-2014 The Disciplined Disciple Compiler Strike Force+Copyrite (K) 2007-2016 The Disciplined Disciple Compiler Strike Force All rights reversed. Permission is hereby granted, free of charge, to any person obtaining a copy
ddc-core-salt.cabal view
@@ -1,5 +1,5 @@ Name: ddc-core-salt-Version: 0.4.2.1+Version: 0.4.3.1 License: MIT License-file: LICENSE Author: The Disciplined Disciple Compiler Strike Force@@ -14,15 +14,14 @@ Library Build-Depends: - base >= 4.6 && < 4.9,+ base >= 4.6 && < 4.10, array >= 0.4 && < 0.6, deepseq >= 1.3 && < 1.5, containers == 0.5.*, text >= 1.0 && < 1.3,- transformers == 0.4.*,+ transformers == 0.5.*, mtl == 2.2.1.*,- ddc-base == 0.4.2.*,- ddc-core == 0.4.2.*+ ddc-core == 0.4.3.* Exposed-modules: DDC.Core.Salt.Compounds@@ -52,7 +51,6 @@ DDC.Core.Salt.Convert.Super DDC.Core.Salt.Convert.Type - DDC.Core.Salt.Name.Lit DDC.Core.Salt.Name.PrimArith DDC.Core.Salt.Name.PrimCall DDC.Core.Salt.Name.PrimCast@@ -60,15 +58,13 @@ DDC.Core.Salt.Name.PrimStore DDC.Core.Salt.Name.PrimTyCon DDC.Core.Salt.Name.PrimVec- - DDC.Core.Salt.Convert.Base- - + GHC-options: -Wall -fno-warn-orphans -fno-warn-missing-signatures -fno-warn-missing-methods+ -fno-warn-missing-pattern-synonym-signatures -fno-warn-unused-do-bind Extensions: