Generate more natural replicator loops when base == 0
This commit is contained in:
parent
ccda7402e2
commit
7d2013d3f1
|
@ -544,17 +544,39 @@ genReplicator rep body
|
|||
body
|
||||
tell ["}\n"]
|
||||
|
||||
isZero :: A.Expression -> Bool
|
||||
isZero (A.ExprLiteral _ (A.Literal _ A.Int (A.IntLiteral _ "0"))) = True
|
||||
isZero _ = False
|
||||
|
||||
genReplicatorLoop :: A.Replicator -> CGen ()
|
||||
genReplicatorLoop (A.For m n base count)
|
||||
genReplicatorLoop (A.For m index base count)
|
||||
= if isZero base
|
||||
then genSimpleReplicatorLoop index count
|
||||
else genGeneralReplicatorLoop index base count
|
||||
|
||||
genSimpleReplicatorLoop :: A.Name -> A.Expression -> CGen ()
|
||||
genSimpleReplicatorLoop index count
|
||||
= do tell ["int "]
|
||||
genName index
|
||||
tell [" = 0; "]
|
||||
genName index
|
||||
tell [" < "]
|
||||
genExpression count
|
||||
tell ["; "]
|
||||
genName index
|
||||
tell ["++"]
|
||||
|
||||
genGeneralReplicatorLoop :: A.Name -> A.Expression -> A.Expression -> CGen ()
|
||||
genGeneralReplicatorLoop index base count
|
||||
= do counter <- makeNonce "replicator_count"
|
||||
tell ["int ", counter, " = "]
|
||||
genExpression count
|
||||
tell [", "]
|
||||
genName n
|
||||
genName index
|
||||
tell [" = "]
|
||||
genExpression base
|
||||
tell ["; ", counter, " > 0; ", counter, "--, "]
|
||||
genName n
|
||||
genName index
|
||||
tell ["++"]
|
||||
|
||||
genReplicatorSize :: A.Replicator -> CGen ()
|
||||
|
|
|
@ -46,6 +46,9 @@ works correctly.
|
|||
|
||||
## Passes
|
||||
|
||||
Expression simplification -- this should use generics, so that we can have a
|
||||
default behaviour that simplifies expressions inside another one.
|
||||
|
||||
Output item expressions should be pulled up to variables.
|
||||
|
||||
Before code generation, have a pass that resolves all the DATA TYPE .. IS
|
||||
|
@ -64,9 +67,6 @@ Multidimensional array literals won't work.
|
|||
We could have genSpec generate {} around specs if it's not immediately inside
|
||||
another spec (which'd require some extra boolean arguments to find out).
|
||||
|
||||
Replicator loops should be special-cased for when base == 0 to generate the
|
||||
sort of loop a C programmer would normally write.
|
||||
|
||||
genTopLevel should look at what interface the PROC is actually expecting, like
|
||||
occ21 does.
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user