Added a Concat operator for lists, and added support for it (and list assignment) to the backends

This commit is contained in:
Neil Brown 2008-03-21 19:20:15 +00:00
parent da5801ad03
commit bc7e682119
5 changed files with 45 additions and 1 deletions

View File

@ -91,6 +91,8 @@ cgenOps = GenOps {
genInputItem = cgenInputItem,
genIntrinsicFunction = cgenIntrinsicFunction,
genIntrinsicProc = cgenIntrinsicProc,
genListAssign = cgenListAssign,
genListConcat = cgenListConcat,
genListLiteral = cgenListLiteral,
genListSize = cgenListSize,
genLiteral = cgenLiteral,
@ -513,12 +515,15 @@ genLitSuffix A.UInt64 = tell ["ULL"]
genLitSuffix A.Real32 = tell ["F"]
genLitSuffix _ = return ()
cgenListLiteral :: [A.Expression] -> A.Type -> CGen()
cgenListLiteral :: [A.Expression] -> A.Type -> CGen ()
cgenListLiteral _ _ = call genMissing "C backend does not yet support lists"
cgenListSize :: A.Variable -> CGen ()
cgenListSize _ = call genMissing "C backend does not yet support lists"
cgenListAssign :: A.Variable -> A.Expression -> CGen ()
cgenListAssign _ _ = call genMissing "C backend does not yet support lists"
cgenLiteralRepr :: A.LiteralRepr -> A.Type -> CGen ()
cgenLiteralRepr (A.RealLiteral m s) t = tell [s] >> genLitSuffix t
cgenLiteralRepr (A.IntLiteral m s) t
@ -951,8 +956,12 @@ cgenDyadic _ A.Less e f = call genSimpleDyadic "<" e f
cgenDyadic _ A.More e f = call genSimpleDyadic ">" e f
cgenDyadic _ A.LessEq e f = call genSimpleDyadic "<=" e f
cgenDyadic _ A.MoreEq e f = call genSimpleDyadic ">=" e f
cgenDyadic _ A.Concat e f = call genListConcat e f
--}}}
cgenListConcat :: A.Expression -> A.Expression -> CGen ()
cgenListConcat _ _ = call genMissing "C backend does not yet support lists"
--{{{ input/output items
cgenInputItem :: A.Variable -> A.InputItem -> CGen ()
cgenInputItem c (A.InCounted m cv av)
@ -1454,6 +1463,7 @@ cgenAssign m [v] (A.ExpressionList _ [e])
-- Assignment of channel-ends, but not channels, is possible (at least in Rain):
A.Chan A.DirInput _ _ -> doAssign v e
A.Chan A.DirOutput _ _ -> doAssign v e
A.List _ -> call genListAssign v e
_ -> call genMissingC $ formatCode "assignment of type %" t
where
doAssign :: A.Variable -> A.Expression -> CGen ()

View File

@ -132,6 +132,8 @@ data GenOps = GenOps {
genInputItem :: A.Variable -> A.InputItem -> CGen (),
genIntrinsicFunction :: Meta -> String -> [A.Expression] -> CGen (),
genIntrinsicProc :: Meta -> String -> [A.Actual] -> CGen (),
genListAssign :: A.Variable -> A.Expression -> CGen (),
genListConcat :: A.Expression -> A.Expression -> CGen (),
genListLiteral :: [A.Expression] -> A.Type -> CGen (),
genListSize :: A.Variable -> CGen (),
genLiteral :: A.LiteralRepr -> A.Type -> CGen (),

View File

@ -65,6 +65,8 @@ cppgenOps = cgenOps {
genGetTime = cppgenGetTime,
genIf = cppgenIf,
genInputItem = cppgenInputItem,
genListAssign = cppgenListAssign,
genListConcat = cppgenListConcat,
genListSize = cppgenListSize,
genListLiteral = cppgenListLiteral,
genOutputCase = cppgenOutputCase,
@ -684,6 +686,13 @@ cppgenType t
Just s -> tell [s]
Nothing -> call genMissingC $ formatCode "genType %" t
cppgenListAssign :: A.Variable -> A.Expression -> CGen ()
cppgenListAssign v e
= do call genVariable v
tell ["="]
call genExpression e
tell [";"]
cppgenListSize :: A.Variable -> CGen ()
cppgenListSize v
= do call genVariable v
@ -695,6 +704,14 @@ cppgenListLiteral es t
tell ["()"]
mapM_ (\e -> tell ["("] >> call genExpression e >> tell [")"]) es
cppgenListConcat :: A.Expression -> A.Expression -> CGen ()
cppgenListConcat a b
= do tell ["("]
call genExpression a
tell ["+"]
call genExpression b
tell [")"]
cppgenReplicatorLoop :: A.Replicator -> CGen ()
cppgenReplicatorLoop rep@(A.For {}) = cgenReplicatorLoop rep
cppgenReplicatorLoop (A.ForEach m n (A.ExprVariable _ v))

View File

@ -307,6 +307,7 @@ data DyadicOp =
| And | Or
| Eq | NotEq | Less | More | LessEq | MoreEq
| After
| Concat
deriving (Show, Eq, Ord, Typeable, Data)
-- | An item in an input.

View File

@ -215,6 +215,12 @@ public:
{
data.push_back(t);
}
//Copy construction has the same behaviour as assignment:
inline tockList(const tockList<T>& _rhs)
{
*this = _rhs;
}
inline tockList& operator()(const T& t)
{
@ -250,6 +256,14 @@ public:
//TODO add beginParEach
//TODO add functions for concatenation
//By default, the class is mobile, so operator+ adds to this list
//and effectively blanks the other
inline tockList<T> operator+(const tockList<T>& _rhs) const
{
data.splice(data.end(), _rhs.data);
return *this;
}
//By default the class acts like a mobile thing:
inline void operator=(const tockList<T>& _rhs)