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.
This commit is contained in:
Adam Sampson 2008-03-17 18:34:23 +00:00
parent b21f020862
commit 1fb6adb005
2 changed files with 21 additions and 7 deletions

View File

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

View File

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