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:
parent
b21f020862
commit
1fb6adb005
|
@ -904,13 +904,20 @@ expression
|
||||||
|
|
||||||
arrayConstructor :: OccParser A.Expression
|
arrayConstructor :: OccParser A.Expression
|
||||||
arrayConstructor
|
arrayConstructor
|
||||||
= do m <- md
|
= do m <- md
|
||||||
sLeft
|
sLeft
|
||||||
r <- replicator
|
r <- replicator
|
||||||
sBar
|
sBar
|
||||||
e <- expression
|
r' <- scopeInRep r
|
||||||
sRight
|
ctx <- getTypeContext
|
||||||
return $ A.ExprConstr m $ A.RepConstr m r e
|
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 :: OccParser A.Expression
|
||||||
associativeOpExpression
|
associativeOpExpression
|
||||||
|
|
7
testcases/array-constructor.occ
Normal file
7
testcases/array-constructor.occ
Normal 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
|
||||||
|
:
|
Loading…
Reference in New Issue
Block a user