diff --git a/backends/GenerateC.hs b/backends/GenerateC.hs index 881b3f3..92a09b0 100644 --- a/backends/GenerateC.hs +++ b/backends/GenerateC.hs @@ -1581,7 +1581,7 @@ realFormals (A.Formal am t n) genProcSpec :: Level -> A.Name -> A.SpecType -> Bool -> CGen () genProcSpec lvl n (A.Proc _ (sm, rm) fs (Just p)) forwardDecl = do cs <- getCompState - let (header, params) = if n `Set.member` csParProcs cs + let (header, params) = if n `Map.member` csParProcs cs || rm == A.Recursive then (genParHeader, genParParams) else (genNormalHeader, return ()) diff --git a/data/CompState.hs b/data/CompState.hs index c54a3c7..945ae6d 100644 --- a/data/CompState.hs +++ b/data/CompState.hs @@ -71,6 +71,10 @@ data NameType = -- | An item that has been pulled up. type PulledItem = (Meta, Either A.Specification A.Process) -- Either Spec or ProcThen +-- | Whether a wrapper is for a FORK or a PAR +data ParOrFork = ParWrapper | ForkWrapper + deriving (Show, Eq, Typeable, Data) + -- | An index to identify an item involved in the type unification. newtype UnifyIndex = UnifyIndex (Meta, Either Int A.Name) deriving (Typeable, Data) @@ -154,7 +158,7 @@ data CompState = CompState { csFunctionReturns :: Map String [A.Type], csPulledItems :: [[PulledItem]], csAdditionalArgs :: Map String [A.Actual], - csParProcs :: Set A.Name, + csParProcs :: Map A.Name ParOrFork, csUnifyId :: Int, -- The string is the operator, the name is the munged function name csOperators :: [(String, A.Name, [A.Type])], @@ -215,7 +219,7 @@ emptyState = CompState { csFunctionReturns = Map.empty, csPulledItems = [], csAdditionalArgs = Map.empty, - csParProcs = Set.empty, + csParProcs = Map.empty, csUnifyId = 0, csOperators = [], csWarnings = [] diff --git a/pregen/GenNavAST.hs b/pregen/GenNavAST.hs index 435c1db..50d2ba6 100644 --- a/pregen/GenNavAST.hs +++ b/pregen/GenNavAST.hs @@ -42,6 +42,7 @@ main = do , genMapInstance (undefined :: String) (undefined :: [AST.Type]) , genMapInstance (undefined :: String) (undefined :: [AST.Actual]) , genMapInstance (undefined :: String) (undefined :: Set.Set CompState.NameAttr) + , genMapInstance (undefined :: AST.Name) (undefined :: CompState.ParOrFork) -- All the sets that are in CompState: , genSetInstance (undefined :: Errors.WarningType) , genSetInstance (undefined :: String) diff --git a/transformations/SimplifyProcs.hs b/transformations/SimplifyProcs.hs index db8b844..f1f2de4 100644 --- a/transformations/SimplifyProcs.hs +++ b/transformations/SimplifyProcs.hs @@ -21,6 +21,7 @@ module SimplifyProcs (simplifyProcs, fixLowReplicators) where import Control.Monad.State import Data.Generics (Data) +import qualified Data.Map as Map import Data.Maybe import qualified Data.Set as Set @@ -122,16 +123,16 @@ parsToProcs = pass "Wrap PAR subprocesses in PROCs" = do s' <- doStructured s return $ A.Par m pm s' doProcess (A.Fork m n p) - = wrapProcess (A.Fork m n) m p >>* A.Seq m + = wrapProcess (A.Fork m n, ForkWrapper) m p >>* A.Seq m doProcess p = return p -- FIXME This should be generic and in Pass. doStructured :: A.Structured A.Process -> PassM (A.Structured A.Process) - doStructured = transformOnly (wrapProcess id) + doStructured = transformOnly (wrapProcess (id, ParWrapper)) - wrapProcess wrap m p + wrapProcess (wrap, ty) m p = do s@(A.Specification _ n _) <- makeNonceProc m p - modify (\cs -> cs { csParProcs = Set.insert n (csParProcs cs) }) + modify (\cs -> cs { csParProcs = Map.insert n ty (csParProcs cs) }) return $ A.Spec m s (A.Only m (wrap $ A.ProcCall m n [])) -- | Turn parallel assignment into multiple single assignments through temporaries.