diff --git a/backends/BackendPasses.hs b/backends/BackendPasses.hs index b6ed884..a2056ae 100644 --- a/backends/BackendPasses.hs +++ b/backends/BackendPasses.hs @@ -441,7 +441,7 @@ mobileReturn = cOnlyPass "Add MOBILE returns" [] [] recurse return $ surr $ A.ProcCall m n as' doProcess p = descend p - chanT t = A.Chan (A.ChanAttributes False False) t + chanT t = A.Chan (A.ChanAttributes A.Unshared A.Unshared) t addChansAct :: Meta -> [(A.Formal, A.Actual)] -> PassM (A.Process -> A.Process, [A.Actual]) addChansAct _ [] = return (id, []) diff --git a/backends/GenerateCPPCSP.hs b/backends/GenerateCPPCSP.hs index a285a0e..ccd09dc 100644 --- a/backends/GenerateCPPCSP.hs +++ b/backends/GenerateCPPCSP.hs @@ -655,10 +655,10 @@ cppgetCType m t am | isChan t A.ChanEnd A.DirOutput _ innerT -> ("csp::Chanout", innerT) A.Chan attr innerT -> ( case (A.caWritingShared attr,A.caReadingShared attr) of - (False,False) -> "csp::One2OneChannel" - (False,True) -> "csp::One2AnyChannel" - (True,False) -> "csp::Any2OneChannel" - (True,True) -> "csp::Any2AnyChannel" + (A.Unshared,A.Unshared) -> "csp::One2OneChannel" + (A.Unshared,A.Shared) -> "csp::One2AnyChannel" + (A.Shared,A.Unshared) -> "csp::Any2OneChannel" + (A.Shared,A.Shared) -> "csp::Any2AnyChannel" , innerT) innerCT <- cppTypeInsideChannel innerT return $ Template chanType [innerCT] diff --git a/common/ShowCode.hs b/common/ShowCode.hs index 7111b97..bfd3c6d 100644 --- a/common/ShowCode.hs +++ b/common/ShowCode.hs @@ -254,10 +254,10 @@ instance ShowOccam A.Type where where shared = case (A.caWritingShared ca, A.caReadingShared ca) of - (False, False) -> "" - (True, False) -> "SHARED! " - (False, True) -> "SHARED? " - (True, True) -> "SHARED " + (A.Unshared, A.Unshared) -> "" + (A.Shared, A.Unshared) -> "SHARED! " + (A.Unshared, A.Shared) -> "SHARED? " + (A.Shared, A.Shared) -> "SHARED " direction = case dir of A.DirInput -> "?" @@ -267,10 +267,10 @@ instance ShowOccam A.Type where where shared = case (A.caWritingShared ca, A.caReadingShared ca) of - (False, False) -> "" - (True, False) -> "SHARED! " - (False, True) -> "SHARED? " - (True, True) -> "SHARED " + (A.Unshared, A.Unshared) -> "" + (A.Shared, A.Unshared) -> "SHARED! " + (A.Unshared, A.Shared) -> "SHARED? " + (A.Shared, A.Shared) -> "SHARED " showOccamM (A.Counted ct et) = showOccamM ct >> tell ["::"] >> showOccamM et showOccamM (A.Port t) = tell ["PORT "] >> showOccamM t showOccamM (A.UserDataType n) = showName n >> helper "{data type}" @@ -293,12 +293,12 @@ instance ShowRain A.Type where = tell ["channel ", ao (A.caWritingShared attr), "2", ao (A.caReadingShared attr)," "] >> showRainM t where - ao :: Bool -> String - ao b = if b then "any" else "one" + ao :: A.ShareMode -> String + ao b = if b == A.Shared then "any" else "one" showRainM (A.ChanEnd dir attr t) = case dir of - A.DirInput -> tell [if A.caReadingShared attr then "shared" else "", " ?"] >> showRainM t - A.DirOutput -> tell [if A.caWritingShared attr then "shared" else "", " !"] >> showRainM t + A.DirInput -> tell [if A.caReadingShared attr == A.Shared then "shared" else "", " ?"] >> showRainM t + A.DirOutput -> tell [if A.caWritingShared attr == A.Shared then "shared" else "", " !"] >> showRainM t where ao :: Bool -> String ao b = if b then "any" else "one" diff --git a/common/Types.hs b/common/Types.hs index e585646..b529c4b 100644 --- a/common/Types.hs +++ b/common/Types.hs @@ -235,7 +235,7 @@ typeOfVariable (A.DirectedVariable m dir v) if dir == dir' then return t else dieP m $ "Attempted to reverse direction of a channel-end" - A.Infer -> return $ A.ChanEnd dir (A.ChanAttributes False False) A.Infer + A.Infer -> return $ A.ChanEnd dir (A.ChanAttributes A.Unshared A.Unshared) A.Infer _ -> diePC m $ formatCode "Direction specified on non-channel variable of type: %" t -- | Get the abbreviation mode of a variable. diff --git a/data/AST.hs b/data/AST.hs index ad17d03..8c9a0d5 100644 --- a/data/AST.hs +++ b/data/AST.hs @@ -80,10 +80,15 @@ data Direction = | DirOutput -- ^ The output end. deriving (Show, Eq, Typeable, Data) +data ShareMode + = Unshared + | Shared + deriving (Show, Eq, Typeable, Data) + -- | Attributes of the type of a channel. data ChanAttributes = ChanAttributes { - caWritingShared :: Bool, - caReadingShared :: Bool + caWritingShared :: ShareMode, + caReadingShared :: ShareMode } deriving (Show, Eq, Typeable, Data) diff --git a/frontends/OccamTypes.hs b/frontends/OccamTypes.hs index dc9831d..51a9c59 100644 --- a/frontends/OccamTypes.hs +++ b/frontends/OccamTypes.hs @@ -433,8 +433,8 @@ checkChannel wantDir c when (wantDir /= dir) $ dieP m $ "Channel directions do not match" -- Check it's not shared in the direction we're using. case (ws, rs, wantDir) of - (False, _, A.DirOutput) -> ok - (_, False, A.DirInput) -> ok + (A.Unshared, _, A.DirOutput) -> ok + (_, A.Unshared, A.DirInput) -> ok _ -> dieP m $ "Shared channel must be claimed before use" return innerT diff --git a/frontends/OccamTypesTest.hs b/frontends/OccamTypesTest.hs index 6552a5c..0899600 100644 --- a/frontends/OccamTypesTest.hs +++ b/frontends/OccamTypesTest.hs @@ -74,7 +74,7 @@ startState where intsT = A.Array [A.UnknownDimension] A.Int arrayLit = A.ArrayListLiteral m $ A.Several m [] - chanT t = A.Chan (A.ChanAttributes False False) t + chanT t = A.Chan (A.ChanAttributes A.Unshared A.Unshared) t chanIntT = chanT A.Int countedIntsT = chanT $ A.UserProtocol (simpleName "countedInts") iirT = chanT $ A.UserProtocol (simpleName "iir") @@ -564,7 +564,7 @@ testOccamTypes = TestList coord2E = A.Literal m coord2T coord2 coord3T = A.Record (simpleName "COORD3") coord3 = A.RecordLiteral m [realE, realE, realE] - chanT t = A.Chan (A.ChanAttributes False False) t + chanT t = A.Chan (A.ChanAttributes A.Unshared A.Unshared) t chanIntT = chanT A.Int chansIntT = A.Array [dimension 2] $ chanT A.Int uchansIntT = A.Array [A.UnknownDimension] $ chanT A.Int diff --git a/frontends/ParseOccam.hs b/frontends/ParseOccam.hs index 113deaa..afbb922 100644 --- a/frontends/ParseOccam.hs +++ b/frontends/ParseOccam.hs @@ -545,7 +545,7 @@ dataType channelType :: OccParser A.Type channelType - = do { sCHAN; optional sOF; p <- protocol; return $ A.Chan A.ChanAttributes {A.caWritingShared = False, A.caReadingShared = False} p } + = do { sCHAN; optional sOF; p <- protocol; return $ A.Chan A.ChanAttributes {A.caWritingShared = A.Unshared, A.caReadingShared = A.Unshared} p } <|> arrayType channelType "channel type" diff --git a/frontends/ParseRain.hs b/frontends/ParseRain.hs index 626ca4c..f42c0c1 100644 --- a/frontends/ParseRain.hs +++ b/frontends/ParseRain.hs @@ -167,9 +167,9 @@ dataType <|> do {reserved "sint32" ; return A.Int32} <|> do {reserved "sint64" ; return A.Int64} <|> do {reserved "time" ; return A.Time} - <|> do {sChannel ; inner <- dataType ; return $ A.Chan (A.ChanAttributes {A.caWritingShared = False, A.caReadingShared = False}) inner} - <|> do {sIn ; inner <- dataType ; return $ A.ChanEnd A.DirInput (A.ChanAttributes {A.caWritingShared = False, A.caReadingShared = False}) inner} - <|> do {sOut ; inner <- dataType ; return $ A.ChanEnd A.DirOutput (A.ChanAttributes {A.caWritingShared = False, A.caReadingShared = False}) inner} + <|> do {sChannel ; inner <- dataType ; return $ A.Chan (A.ChanAttributes {A.caWritingShared = A.Unshared, A.caReadingShared = A.Unshared}) inner} + <|> do {sIn ; inner <- dataType ; return $ A.ChanEnd A.DirInput (A.ChanAttributes {A.caWritingShared = A.Unshared, A.caReadingShared = A.Unshared}) inner} + <|> do {sOut ; inner <- dataType ; return $ A.ChanEnd A.DirOutput (A.ChanAttributes {A.caWritingShared = A.Unshared, A.caReadingShared = A.Unshared}) inner} <|> do {sLeftQ ; inner <- dataType ; sRightQ ; return $ A.List inner} <|> do {(m,n) <- identifier ; return $ A.UserDataType A.Name {A.nameMeta = m, A.nameName = n}} "data type" diff --git a/frontends/ParseRainTest.hs b/frontends/ParseRainTest.hs index de05751..abfd4df 100644 --- a/frontends/ParseRainTest.hs +++ b/frontends/ParseRainTest.hs @@ -531,7 +531,7 @@ testTopLevelDecl = passTop (ind, input, exp) = pass (input, RP.topLevelDecl, assertPatternMatch ("testTopLevelDecl " ++ show ind) $ pat $ A.Several m exp) nonShared :: A.ChanAttributes -nonShared = A.ChanAttributes { A.caWritingShared = False, A.caReadingShared = False} +nonShared = A.ChanAttributes { A.caWritingShared = A.Unshared, A.caReadingShared = A.Unshared} testDataType :: [ParseTest A.Type] testDataType = diff --git a/frontends/RainTypes.hs b/frontends/RainTypes.hs index 2209220..0a851cc 100644 --- a/frontends/RainTypes.hs +++ b/frontends/RainTypes.hs @@ -283,7 +283,7 @@ markCommTypes = checkDepthM2 checkInputOutput checkAltInput checkInput :: A.Variable -> A.Variable -> Meta -> a -> RainTypeM () checkInput chanVar destVar m p = astTypeOf destVar >>= markUnify chanVar . A.ChanEnd A.DirInput (A.ChanAttributes - False False) + A.Unshared A.Unshared) checkWait :: RainTypeCheck A.InputMode checkWait (A.InputTimerFor m exp) = markUnify A.Time exp @@ -299,7 +299,7 @@ markCommTypes = checkDepthM2 checkInputOutput checkAltInput checkInputOutput (A.Input _ _ im@(A.InputTimerRead {})) = checkWait im checkInputOutput p@(A.Output m chanVar [A.OutExpression m' srcExp]) = astTypeOf srcExp >>= markUnify chanVar . A.ChanEnd A.DirOutput (A.ChanAttributes - False False) + A.Unshared A.Unshared) checkInputOutput _ = return () checkAltInput :: RainTypeCheck A.Alternative