Changed transformConstr to transform list-typed array constructors to build up a list rather than subscripting it

This commit is contained in:
Neil Brown 2008-03-21 19:22:29 +00:00
parent a1daf15576
commit cfccd38c51

View File

@ -194,7 +194,7 @@ transformConstr = doGeneric `ext1M` doStructured
doGeneric :: Data t => t -> PassM t doGeneric :: Data t => t -> PassM t
doGeneric = makeGeneric transformConstr doGeneric = makeGeneric transformConstr
-- This takes a constructor expression: -- For arrays, this takes a constructor expression:
-- VAL type name IS [i = rep | expr]: -- VAL type name IS [i = rep | expr]:
-- ... -- ...
-- and produces this: -- and produces this:
@ -208,19 +208,33 @@ transformConstr = doGeneric `ext1M` doStructured
-- name[indexvar] := expr -- name[indexvar] := expr
-- indexvar := indexvar + 1 -- 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 :: 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) 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 = 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 let indexVar = A.Variable m'' indexName
scope' <- doGeneric scope
return $ declDest $ A.ProcThen m'' return $ declDest $ A.ProcThen m''
(A.Seq m'' $ A.Spec m'' indexVarSpec $ A.Several m'' [ (A.Seq m'' $ A.Spec m'' indexVarSpec $
assignIndex0 indexVar, A.Several m'' [assignIndex0 indexVar,
A.Rep m'' rep $ A.Only m'' $ A.Seq m'' $ A.Several m'' A.Rep m'' rep $ A.Only m'' $ A.Seq m'' $
[ assignItem indexVar, incrementIndex indexVar ] A.Several m''
[ assignItem indexVar
, incrementIndex indexVar ]
]) ])
scope' scope'
A.List {} ->
return $ declDest $ A.ProcThen m''
(A.Seq m'' $ A.Rep m'' rep $ appendItem)
scope'
where where
declDest :: Data a => A.Structured a -> A.Structured a declDest :: Data a => A.Structured a -> A.Structured a
declDest = A.Spec m (A.Specification m' n (A.Declaration m' t)) 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.Subscript m'' A.NoCheck $ A.ExprVariable m'' indexVar) $
A.Variable m'' n] $ A.ExpressionList m'' [exp] 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 doStructured s = doGeneric s
-- | Find things that need to be moved up to their enclosing Structured, and do -- | Find things that need to be moved up to their enclosing Structured, and do