Added a sub-type to Timers, to support multiple types

This commit is contained in:
Neil Brown 2008-03-23 22:20:16 +00:00
parent 38aca16514
commit c68aa42277
7 changed files with 17 additions and 10 deletions

View File

@ -324,7 +324,7 @@ cgetScalarType A.Int32 = Just "int32_t"
cgetScalarType A.Int64 = Just "int64_t" cgetScalarType A.Int64 = Just "int64_t"
cgetScalarType A.Real32 = Just "float" cgetScalarType A.Real32 = Just "float"
cgetScalarType A.Real64 = Just "double" cgetScalarType A.Real64 = Just "double"
cgetScalarType A.Timer = Just "Time" cgetScalarType (A.Timer A.OccamTimer) = Just "Time"
cgetScalarType A.Time = Just "Time" cgetScalarType A.Time = Just "Time"
cgetScalarType _ = Nothing cgetScalarType _ = Nothing

View File

@ -642,7 +642,7 @@ cppgetScalarType A.Int32 = Just "int32_t"
cppgetScalarType A.Int64 = Just "int64_t" cppgetScalarType A.Int64 = Just "int64_t"
cppgetScalarType A.Real32 = Just "float" cppgetScalarType A.Real32 = Just "float"
cppgetScalarType A.Real64 = Just "double" cppgetScalarType A.Real64 = Just "double"
cppgetScalarType A.Timer = Just "csp::Time" cppgetScalarType (A.Timer A.OccamTimer) = Just "csp::Time"
cppgetScalarType A.Time = Just "csp::Time" cppgetScalarType A.Time = Just "csp::Time"
cppgetScalarType _ = Nothing cppgetScalarType _ = Nothing

View File

@ -230,7 +230,7 @@ testGenType = TestList
,testBothSame "GenType 102" "int*" (tcall genType $ A.Array [dimension 5, A.UnknownDimension] A.Int) ,testBothSame "GenType 102" "int*" (tcall genType $ A.Array [dimension 5, A.UnknownDimension] A.Int)
,testBothSame "GenType 103" "foo" (tcall genType $ A.Record (simpleName "foo")) ,testBothSame "GenType 103" "foo" (tcall genType $ A.Record (simpleName "foo"))
,testBoth "GenType 200" "Time" "csp::Time" (tcall genType A.Time) ,testBoth "GenType 200" "Time" "csp::Time" (tcall genType A.Time)
,testBoth "GenType 201" "Time" "csp::Time" (tcall genType A.Timer) ,testBoth "GenType 201" "Time" "csp::Time" (tcall genType $ A.Timer A.OccamTimer)
,testBothSame "GenType 250" "int*" (tcall genType $ A.Mobile $ A.Array [dimension 5, dimension 2, dimension 9] A.Int) ,testBothSame "GenType 250" "int*" (tcall genType $ A.Mobile $ A.Array [dimension 5, dimension 2, dimension 9] A.Int)
,testBothSame "GenType 251" "int*" (tcall genType $ A.Mobile $ A.Array [dimension 5, A.UnknownDimension] A.Int) ,testBothSame "GenType 251" "int*" (tcall genType $ A.Mobile $ A.Array [dimension 5, A.UnknownDimension] A.Int)
@ -486,9 +486,9 @@ testDeclaration = TestList
--Timers: --Timers:
,testBoth "genDeclaration 500" "Time foo;" "csp::Time foo;" ,testBoth "genDeclaration 500" "Time foo;" "csp::Time foo;"
(tcall3 genDeclaration A.Timer foo False) (tcall3 genDeclaration (A.Timer A.OccamTimer) foo False)
,testBoth "genDeclaration 501" "Time foo[20];" "csp::Time foo[20];" ,testBoth "genDeclaration 501" "Time foo[20];" "csp::Time foo[20];"
(tcall3 genDeclaration (A.Array [dimension 20] A.Timer) foo False) (tcall3 genDeclaration (A.Array [dimension 20] (A.Timer A.OccamTimer)) foo False)
] ]
where where
stateR t = defRecord "REC" "bar" t stateR t = defRecord "REC" "bar" t

View File

@ -223,7 +223,7 @@ instance ShowOccam A.Type where
showOccamM A.Real32 = tell ["REAL32"] showOccamM A.Real32 = tell ["REAL32"]
showOccamM A.Real64 = tell ["REAL64"] showOccamM A.Real64 = tell ["REAL64"]
showOccamM A.Any = tell ["ANY"] showOccamM A.Any = tell ["ANY"]
showOccamM A.Timer = tell ["TIMER"] showOccamM (A.Timer _) = tell ["TIMER"]
showOccamM A.Time = tell ["TIME"] showOccamM A.Time = tell ["TIME"]
showOccamM (A.Mobile t) = tell ["MOBILE "] >> showOccamM t showOccamM (A.Mobile t) = tell ["MOBILE "] >> showOccamM t

View File

@ -98,6 +98,13 @@ data ChanAttributes = ChanAttributes {
} }
deriving (Show, Eq, Typeable, Data) deriving (Show, Eq, Typeable, Data)
-- | In future we will probably add more timers to this list, especially for
-- occam. But for now we just differentiate between an occam timer (which
-- reads into something of type Int), and a Rain timer (which reads into something
-- of type Time).
data TimerType = OccamTimer | RainTimer
deriving (Eq, Show, Ord, Typeable, Data)
-- | A data or protocol type. -- | A data or protocol type.
-- The two concepts aren't unified in occam, but they are here, because it -- The two concepts aren't unified in occam, but they are here, because it
-- makes sense to be able to ask what type a particular name is defined to -- makes sense to be able to ask what type a particular name is defined to
@ -132,7 +139,7 @@ data Type =
-- | A counted input or output. -- | A counted input or output.
| Counted Type Type | Counted Type Type
| Any | Any
| Timer | Timer TimerType
| Time | Time
| Port Type | Port Type
| Mobile Type | Mobile Type

View File

@ -628,7 +628,7 @@ channelType
timerType :: OccParser A.Type timerType :: OccParser A.Type
timerType timerType
= do { sTIMER; return $ A.Timer } = do { sTIMER; return $ A.Timer A.OccamTimer }
<|> arrayType timerType <|> arrayType timerType
<?> "timer type" <?> "timer type"
@ -1969,7 +1969,7 @@ actual (A.Formal am t n)
_ -> _ ->
case stripArrayType t of case stripArrayType t of
A.Chan {} -> var (channelOfType t) A.Chan {} -> var (channelOfType t)
A.Timer -> var timer A.Timer {} -> var timer
A.Port _ -> var (portOfType t) A.Port _ -> var (portOfType t)
_ -> var (variableOfType t) _ -> var (variableOfType t)
<?> "actual of type " ++ showOccam t ++ " for " ++ show n <?> "actual of type " ++ showOccam t ++ " for " ++ show n

View File

@ -298,7 +298,7 @@ excludeNonRainFeatures = excludeConstr
[ con0 A.Real32 [ con0 A.Real32
,con0 A.Real64 ,con0 A.Real64
,con2 A.Counted ,con2 A.Counted
,con0 A.Timer ,con1 A.Timer
,con1 A.Port ,con1 A.Port
,con2 A.BytesInExpr ,con2 A.BytesInExpr
,con2 A.BytesInType ,con2 A.BytesInType