From cfccd38c518fa8618eec8f8c38e95fb23f8b0312 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Fri, 21 Mar 2008 19:22:29 +0000 Subject: [PATCH] Changed transformConstr to transform list-typed array constructors to build up a list rather than subscripting it --- transformations/SimplifyExprs.hs | 44 +++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/transformations/SimplifyExprs.hs b/transformations/SimplifyExprs.hs index c9b16db..b51ade9 100644 --- a/transformations/SimplifyExprs.hs +++ b/transformations/SimplifyExprs.hs @@ -194,7 +194,7 @@ transformConstr = doGeneric `ext1M` doStructured doGeneric :: Data t => t -> PassM t doGeneric = makeGeneric transformConstr - -- This takes a constructor expression: + -- For arrays, this takes a constructor expression: -- VAL type name IS [i = rep | expr]: -- ... -- and produces this: @@ -208,19 +208,33 @@ transformConstr = doGeneric `ext1M` doStructured -- name[indexvar] := expr -- indexvar := indexvar + 1 -- ... + -- + -- For lists, it takes the similar expression and produces: + -- type name: + -- PROCTHEN + -- SEQ i = rep + -- name += [expr] doStructured :: Data a => A.Structured a -> PassM (A.Structured a) doStructured (A.Spec m (A.Specification m' n (A.IsExpr _ _ _ expr@(A.ExprConstr m'' (A.RepConstr _ t rep exp)))) scope) - = do indexVarSpec@(A.Specification _ indexName _) <- makeNonceVariable "array_constr_index" m'' A.Int A.VariableName A.Original - let indexVar = A.Variable m'' indexName - scope' <- doGeneric scope - - return $ declDest $ A.ProcThen m'' - (A.Seq m'' $ A.Spec m'' indexVarSpec $ A.Several m'' [ - assignIndex0 indexVar, - A.Rep m'' rep $ A.Only m'' $ A.Seq m'' $ A.Several m'' - [ assignItem indexVar, incrementIndex indexVar ] - ]) - scope' + = do scope' <- doGeneric scope + case t of + A.Array {} -> + do indexVarSpec@(A.Specification _ indexName _) <- makeNonceVariable "array_constr_index" m'' A.Int A.VariableName A.Original + let indexVar = A.Variable m'' indexName + + return $ declDest $ A.ProcThen m'' + (A.Seq m'' $ A.Spec m'' indexVarSpec $ + A.Several m'' [assignIndex0 indexVar, + A.Rep m'' rep $ A.Only m'' $ A.Seq m'' $ + A.Several m'' + [ assignItem indexVar + , incrementIndex indexVar ] + ]) + scope' + A.List {} -> + return $ declDest $ A.ProcThen m'' + (A.Seq m'' $ A.Rep m'' rep $ appendItem) + scope' where declDest :: Data a => A.Structured a -> A.Structured a declDest = A.Spec m (A.Specification m' n (A.Declaration m' t)) @@ -238,6 +252,12 @@ transformConstr = doGeneric `ext1M` doStructured (A.Subscript m'' A.NoCheck $ A.ExprVariable m'' indexVar) $ A.Variable m'' n] $ A.ExpressionList m'' [exp] + appendItem :: A.Structured A.Process + appendItem = A.Only m'' $ A.Assign m'' [A.Variable m'' n] $ + A.ExpressionList m'' [A.Dyadic m'' A.Concat + (A.ExprVariable m'' $ A.Variable m'' n) + (A.Literal m'' t $ A.ListLiteral m'' [exp])] + doStructured s = doGeneric s -- | Find things that need to be moved up to their enclosing Structured, and do