From 0337cf842fbf22ef601dde87983e48936f790e17 Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Fri, 11 May 2007 01:58:34 +0000 Subject: [PATCH] Constant-fold table elements --- fco2/Parse.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fco2/Parse.hs b/fco2/Parse.hs index 1fac3e3..3ab4727 100644 --- a/fco2/Parse.hs +++ b/fco2/Parse.hs @@ -855,9 +855,12 @@ tableElems return (lr, A.Array [dim] A.Byte) <|> do m <- md es <- tryXVX sLeft (noTypeContext $ sepBy1 expression sComma) sRight - ets <- mapM typeOfExpression es + -- Constant fold early, so that tables have a better chance of + -- becoming constants. + (es', _, _) <- liftM unzip3 $ sequence [constantFold e | e <- es] + ets <- mapM typeOfExpression es' defT <- tableType m ets - return (A.ArrayLiteral m (map A.ArrayElemExpr es), defT) + return (A.ArrayLiteral m (map A.ArrayElemExpr es'), defT) "table elements" stringLiteral :: OccParser (A.LiteralRepr, A.Dimension)