Adjusted the C backend to work with the new step count
This commit is contained in:
parent
2c6f624ea3
commit
3e8273f4f6
|
@ -1104,31 +1104,13 @@ cgenReplicatorStart n rep
|
||||||
cgenReplicatorEnd :: A.Replicator -> CGen ()
|
cgenReplicatorEnd :: A.Replicator -> CGen ()
|
||||||
cgenReplicatorEnd rep = tell ["}"]
|
cgenReplicatorEnd rep = tell ["}"]
|
||||||
|
|
||||||
isZero :: A.Expression -> Bool
|
|
||||||
isZero (A.Literal _ A.Int (A.IntLiteral _ "0")) = True
|
|
||||||
isZero _ = False
|
|
||||||
|
|
||||||
cgenReplicatorLoop :: A.Name -> A.Replicator -> CGen ()
|
cgenReplicatorLoop :: A.Name -> A.Replicator -> CGen ()
|
||||||
cgenReplicatorLoop index (A.For m base count)
|
cgenReplicatorLoop index (A.For m base count step)
|
||||||
= if isZero base
|
-- It is now too hard to work out statically if we could make this a
|
||||||
then simple
|
-- simple loop (without an additional counter), because step may be
|
||||||
else general
|
-- negative (and that may be determined at run-time. So we will generate the
|
||||||
where
|
-- most general loop, and let the C compiler optimise if possibe:
|
||||||
simple :: CGen ()
|
= do counter <- csmLift $ makeNonce "replicator_count"
|
||||||
simple
|
|
||||||
= do tell ["int "]
|
|
||||||
genName index
|
|
||||||
tell ["=0;"]
|
|
||||||
genName index
|
|
||||||
tell ["<"]
|
|
||||||
call genExpression count
|
|
||||||
tell [";"]
|
|
||||||
genName index
|
|
||||||
tell ["++"]
|
|
||||||
|
|
||||||
general :: CGen ()
|
|
||||||
general
|
|
||||||
= do counter <- csmLift $ makeNonce "replicator_count"
|
|
||||||
tell ["int ", counter, "="]
|
tell ["int ", counter, "="]
|
||||||
call genExpression count
|
call genExpression count
|
||||||
tell [","]
|
tell [","]
|
||||||
|
@ -1137,7 +1119,8 @@ cgenReplicatorLoop index (A.For m base count)
|
||||||
call genExpression base
|
call genExpression base
|
||||||
tell [";", counter, ">0;", counter, "--,"]
|
tell [";", counter, ">0;", counter, "--,"]
|
||||||
genName index
|
genName index
|
||||||
tell ["++"]
|
tell ["+="]
|
||||||
|
call genExpression step
|
||||||
cgenReplicatorLoop _ _ = cgenMissing "ForEach loops not yet supported in the C backend"
|
cgenReplicatorLoop _ _ = cgenMissing "ForEach loops not yet supported in the C backend"
|
||||||
--}}}
|
--}}}
|
||||||
|
|
||||||
|
|
|
@ -450,10 +450,8 @@ testOverArray = TestList $ map testOverArray'
|
||||||
testReplicator :: Test
|
testReplicator :: Test
|
||||||
testReplicator = TestList
|
testReplicator = TestList
|
||||||
[
|
[
|
||||||
testBothSame "testReplicator 0" "for(int foo=0;foo<10;foo++){" (tcall2 genReplicatorStart foo
|
testBothSameR "testReplicator 1" "for\\(int ([[:alnum:]_]+)=10,foo=1;\\1>0;\\1--,foo\\+=3\\)\\{" (tcall2 genReplicatorStart
|
||||||
(A.For emptyMeta (intLiteral 0) (intLiteral 10)))
|
foo (A.For emptyMeta (intLiteral 1) (intLiteral 10) (intLiteral 3)))
|
||||||
,testBothSameR "testReplicator 1" "for\\(int ([[:alnum:]_]+)=10,foo=1;\\1>0;\\1--,foo\\+\\+\\)\\{" (tcall2 genReplicatorStart
|
|
||||||
foo (A.For emptyMeta (intLiteral 1) (intLiteral 10)))
|
|
||||||
]
|
]
|
||||||
|
|
||||||
testDeclaration :: Test
|
testDeclaration :: Test
|
||||||
|
|
Loading…
Reference in New Issue
Block a user