Introduced a ShareMode in the AST, and used it in the channel attributes (rather than Bool)

This commit is contained in:
Neil Brown 2009-03-22 22:29:39 +00:00
parent 7b52565270
commit 8492dc03d4
11 changed files with 36 additions and 31 deletions

View File

@ -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, [])

View File

@ -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]

View File

@ -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"

View File

@ -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.

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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"

View File

@ -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 =

View File

@ -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