From 1fb6adb0051e7a5f413a956a4a88c444d5d98369 Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Mon, 17 Mar 2008 18:34:23 +0000 Subject: [PATCH] Fix array constructors in occam. This works at least for simple examples, although it's probably a bit restrictive on the array indexes you're allowed; it should attempt to constant-fold them. --- frontends/ParseOccam.hs | 21 ++++++++++++++------- testcases/array-constructor.occ | 7 +++++++ 2 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 testcases/array-constructor.occ diff --git a/frontends/ParseOccam.hs b/frontends/ParseOccam.hs index 9be3923..e23bb96 100644 --- a/frontends/ParseOccam.hs +++ b/frontends/ParseOccam.hs @@ -904,13 +904,20 @@ expression arrayConstructor :: OccParser A.Expression arrayConstructor - = do m <- md - sLeft - r <- replicator - sBar - e <- expression - sRight - return $ A.ExprConstr m $ A.RepConstr m r e + = do m <- md + sLeft + r <- replicator + sBar + r' <- scopeInRep r + ctx <- getTypeContext + subCtx <- case ctx of + Just t@(A.Array _ _) -> trivialSubscriptType m t >>* Just + _ -> return Nothing + e <- inTypeContext subCtx expression + scopeOutRep r' + sRight + return $ A.ExprConstr m $ A.RepConstr m r' e + "array constructor expression" associativeOpExpression :: OccParser A.Expression associativeOpExpression diff --git a/testcases/array-constructor.occ b/testcases/array-constructor.occ new file mode 100644 index 0000000..a90e7be --- /dev/null +++ b/testcases/array-constructor.occ @@ -0,0 +1,7 @@ +PROC P () + VAL []INT array IS [1, 2, 3, 4]: + VAL []INT zeros IS [i = 0 FOR 20 | 0]: + VAL []INT nums IS [i = 0 FOR 20 | i]: + VAL []INT squares IS [i = 0 FOR 20 | i * i]: + SKIP +: