packages feed

modulo 1.7.3 → 1.7.4

raw patch · 4 files changed

+57/−4 lines, 4 filesdep +mtl

Dependencies added: mtl

Files

modulo.cabal view
@@ -1,6 +1,6 @@  name:               modulo-version:            1.7.3+version:            1.7.4 cabal-version:      >= 1.6 author:             Hans Hoglund maintainer:         Hans Hoglund <hans@hanshoglund.se>@@ -24,6 +24,7 @@ library                         build-depends:          base            >= 4 && < 5,+        mtl,         semigroups,          nats,          data-default,
src/Language/Modulo/Rename.hs view
@@ -1,5 +1,5 @@ -{-# LANGUAGE DisambiguateRecordFields, TypeFamilies,+{-# LANGUAGE DisambiguateRecordFields, TypeFamilies, OverloadedStrings, BangPatterns,     StandaloneDeriving, DeriveFunctor, DeriveFoldable, GeneralizedNewtypeDeriving #-}  -------------------------------------------------------------------------------------@@ -14,11 +14,15 @@ -------------------------------------------------------------------------------------  module Language.Modulo.Rename (+        addParams,         rename   ) where  import Control.Arrow import Control.Exception+import Control.Monad.State+import Data.Traversable+import qualified Data.Char as Char import Data.List (isSuffixOf) import Data.Maybe (catMaybes) import Data.List.NonEmpty ( NonEmpty(..) )@@ -30,6 +34,53 @@ import Language.Modulo.Util.Unmangle (unmangle)  import qualified Data.List.NonEmpty as NonEmpty++-- | Add default parameter names to functions.+--   (Replaces 'Nothing' with the unqualified type name).+--+--   Mainly useful for documentation.+--+addParams :: Module -> Module+addParams mod@(Module n opt doc is ds) = Module n opt doc is (map (fmap decl) ds)+    where+        decl (FunctionDecl n t)  = FunctionDecl n (funType t)+        decl x = x                                          +        +        funType (Function as r) = Function (firstComp disamb $ fmap funParam as) r++        funParam (Nothing,AliasType n) = (Just $ nameEnd n,                  AliasType n)+        funParam (Nothing,PrimType t)  = (Just $ Name $ firstLower $ (++ "_") $ show t, PrimType t)+        funParam (n,t) = (n,t)+        +        nameEnd (QName _ n) = Name $ firstLower n+        nameEnd (Name n)    = Name $ firstLower  n+        firstLower [] = []+        firstLower (x:xs) = Char.toLower x : xs++-- type ParamNames = [Name]+-- -- Monad for param names disambiguition+-- type Param a = State ParamNames a+-- param :: a -> Param a+-- param = return+-- getParam :: Param a -> a+-- getParam = fst . (`runState` [])   ++disamb :: [Maybe Name] -> [Maybe Name]+disamb = snd . List.mapAccumL getUnambName []+    where+        getUnambName !taken Nothing = (taken, Nothing) +        getUnambName !taken (Just x) = +            if not (x `elem` taken) then (x:taken, Just x)+                else getUnambName taken (Just $ incName x)++incName :: Name -> Name+incName (QName m !n) = QName m (n ++ "_")+incName (Name !n)    = Name (n ++ "_")++-- TODO iso (uncurry zip) zip+firstComp :: ([a] -> [a']) -> [(a,b)] -> [(a',b)]+firstComp f = uncurry zip . first f . unzip+  -- | -- Rewrite all unqualified names as qualified names.
src/Language/Modulo/Util.hs view
@@ -75,6 +75,7 @@   + ------------------------------------------------------------------------------------- -- List -------------------------------------------------------------------------------------
src/Main.hs view
@@ -73,7 +73,7 @@ readPrimBool = LispPrimBool . (=<<) parsePrimTypeMaybe  -version = "modulo-1.7.3"+version = "modulo-1.7.4" header  = "Usage: modulo [options]\n" ++           "Usage: modulo [options] files...\n" ++           "\n" ++@@ -147,7 +147,7 @@         unsafeRename :: [ModulePath] -> Module -> IO Module         unsafeRename paths m = do             deps <- loadDependencies (withStdModulePaths paths) m-            return $ rename deps m+            return $ addParams $ rename deps m                      unsafeParse :: String -> Module         unsafeParse s = case (parse s) of