From 03f1b2d1157b9008324d48e6f8846684145b48b9 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Fri, 20 Mar 2009 20:53:51 +0000 Subject: [PATCH] Added a few more mobile things (DEFINED keyword, an intrinsic) --- common/Intrinsics.hs | 3 +++ common/Types.hs | 1 + data/AST.hs | 3 +++ frontends/LexOccam.x | 2 +- frontends/ParseOccam.hs | 21 +++++++++++++-------- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/common/Intrinsics.hs b/common/Intrinsics.hs index 281d30f..483a073 100644 --- a/common/Intrinsics.hs +++ b/common/Intrinsics.hs @@ -153,6 +153,9 @@ intrinsicProcs = , (A.ValAbbrev, A.Array [A.UnknownDimension] A.Byte, "string") ]) ] + ++ [("RESIZE.MOBILE.ARRAY.1D", [(A.Abbrev, A.Mobile A.Infer, "mobile") + ,(A.ValAbbrev, A.Int, "count") + ])] rainIntrinsicFunctions :: [(String, ([A.Type], [(A.Type, String)]))] rainIntrinsicFunctions = diff --git a/common/Types.hs b/common/Types.hs index 2d8ffac..de77839 100644 --- a/common/Types.hs +++ b/common/Types.hs @@ -293,6 +293,7 @@ typeOfExpression e A.OffsetOf m t n -> return A.Int A.AllocMobile _ t _ -> return t A.CloneMobile _ e -> typeOfExpression e + A.IsDefined {} -> return A.Bool --}}} -- | Gets the return type(s) of a function call from the 'CompState'. diff --git a/data/AST.hs b/data/AST.hs index 07d822d..ad17d03 100644 --- a/data/AST.hs +++ b/data/AST.hs @@ -283,6 +283,9 @@ data Expression = -- | A CLONE operation. The inner expression should have a Mobile type, and -- this will have the same type as the inner component: | CloneMobile Meta Expression + -- | The DEFINED operator. Returns a boolean as to whether the mobile type is + -- defined or not. + | IsDefined Meta Expression deriving (Show, Eq, Typeable, Data) -- | A list of expressions. diff --git a/frontends/LexOccam.x b/frontends/LexOccam.x index 2bbc2c2..6bd9508 100644 --- a/frontends/LexOccam.x +++ b/frontends/LexOccam.x @@ -54,7 +54,7 @@ $vertSpace = [\r\n] | "AFTER" | "ALT" | "AND" | "ANY" | "AT" | "BITAND" | "BITNOT" | "BITOR" | "BOOL" | "BYTE" | "BYTESIN" | "CASE" | "CHAN" | "CLONE" - | "DATA" + | "DATA" | "DEFINED" | "ELSE" | "FALSE" | "FOR" | "FROM" | "FUNCTION" | "IF" | "IN" | "INITIAL" | "INLINE" | "INT" | "INT16" | "INT32" | "INT64" diff --git a/frontends/ParseOccam.hs b/frontends/ParseOccam.hs index 9f0befa..113deaa 100644 --- a/frontends/ParseOccam.hs +++ b/frontends/ParseOccam.hs @@ -111,13 +111,13 @@ sSemi = reserved ";" --}}} --{{{ keywords sAFTER, sALT, sAND, sANY, sAT, sBITAND, sBITNOT, sBITOR, sBOOL, sBYTE, - sBYTESIN, sCASE, sCHAN, sCLONE, sDATA, sELSE, sFALSE, sFOR, sFROM, sFUNCTION, sIF, - sINLINE, sIN, sINITIAL, sINT, sINT16, sINT32, sINT64, sIS, sMINUS, sMOBILE, sMOSTNEG, - sMOSTPOS, sNOT, sOF, sOFFSETOF, sOR, sPACKED, sPAR, sPLACE, sPLACED, sPLUS, - sPORT, sPRI, sPROC, sPROCESSOR, sPROTOCOL, sREAL32, sREAL64, sRECORD, - sREC_RECURSIVE, sREM, sRESHAPES, sRESULT, sRETYPES, sROUND, sSEQ, sSIZE, - sSKIP, sSTEP, sSTOP, sTIMER, sTIMES, sTRUE, sTRUNC, sTYPE, sVAL, sVALOF, - sWHILE, sWORKSPACE, sVECSPACE + sBYTESIN, sCASE, sCHAN, sCLONE, sDATA, sDEFINED, sELSE, sFALSE, sFOR, sFROM, + sFUNCTION, sIF, sINLINE, sIN, sINITIAL, sINT, sINT16, sINT32, sINT64, sIS, + sMINUS, sMOBILE, sMOSTNEG, sMOSTPOS, sNOT, sOF, sOFFSETOF, sOR, sPACKED, + sPAR, sPLACE, sPLACED, sPLUS, sPORT, sPRI, sPROC, sPROCESSOR, sPROTOCOL, + sREAL32, sREAL64, sRECORD, sREC_RECURSIVE, sREM, sRESHAPES, sRESULT, + sRETYPES, sROUND, sSEQ, sSIZE, sSKIP, sSTEP, sSTOP, sTIMER, sTIMES, sTRUE, + sTRUNC, sTYPE, sVAL, sVALOF, sWHILE, sWORKSPACE, sVECSPACE :: OccParser () sAFTER = reserved "AFTER" @@ -135,6 +135,7 @@ sCASE = reserved "CASE" sCHAN = reserved "CHAN" sCLONE = reserved "CLONE" sDATA = reserved "DATA" +sDEFINED = reserved "DEFINED" sELSE = reserved "ELSE" sFALSE = reserved "FALSE" sFOR = reserved "FOR" @@ -535,7 +536,9 @@ dataType <|> do { sREAL32; return A.Real32 } <|> do { sREAL64; return A.Real64 } <|> arrayType dataType - <|> do { sMOBILE; dataType >>* A.Mobile } + -- Mobile arrays can lack dimensions: + <|> do { tryXV sMOBILE (specArrayType dataType) >>* A.Mobile } + <|> do { tryXV sMOBILE dataType >>* A.Mobile } <|> do { n <- try dataTypeName; return $ A.UserDataType n } <|> do { n <- try recordName; return $ A.Record n } "data type" @@ -706,6 +709,8 @@ expression <|> do { m <- md; sMOSTPOS; t <- dataType; return $ A.MostPos m t } <|> do { m <- md; sMOSTNEG; t <- dataType; return $ A.MostNeg m t } <|> do { m <- md; sCLONE; e <- expression; return $ A.CloneMobile m e } + <|> do { m <- md; sMOBILE; t <- dataType ; return $ A.AllocMobile m (A.Mobile t) Nothing } + <|> do { m <- md; sDEFINED; e <- expression; return $ A.IsDefined m e } <|> sizeExpr <|> do m <- md (l, o) <- tryVV operand dyadicOperator