Closed master-q closed 5 years ago
An easy example sum
:
int sum(int n) {
int i, sum = 0;
for (i = 1; i <= n; i++) {
sum = sum + i;
}
return sum;
}
int main() {
return sum(5) - 15;
}
A hard example fib
:
int fib(int n) {
int f0 = 0, f1 = 1;
while (n-- > 0) {
int tmp = f1;
f1 = f0 + f1;
f0 = tmp;
}
return f0;
}
int main() {
return fib(10) - 55;
}
They should be modified on C -> C
stage instead of C -> ATS
stage?
while (n-- > 0)
pattern can be supported on makeCond :: C.CExpr -> St.State IEnv (A.Expression Pos)
.
for (i = 1; i <= n; i++)
pattern can be just converted onto A.Binary A.Mutate
at interpretExpr
.
But both of them just use interpretExpr
.
makeCond :: C.CExpr -> St.State IEnv (A.Expression Pos)
makeCond cond@(C.CBinary C.CLeOp _ _ _) = interpretExpr cond
makeCond cond@(C.CBinary C.CGrOp _ _ _) = interpretExpr cond
makeCond cond@(C.CBinary C.CLeqOp _ _ _) = interpretExpr cond
makeCond cond@(C.CBinary C.CGeqOp _ _ _) = interpretExpr cond
makeCond cond@(C.CBinary C.CEqOp _ _ _) = interpretExpr cond
makeCond cond@(C.CBinary C.CNeqOp _ _ _) = interpretExpr cond
makeCond cond = do
cond' <- interpretExpr cond
return $ A.Binary A.NotEq cond' (A.IntLit 0)
interpretExpr
should return a just-expr, pre-exprs and post-exprs...
Partly supported at 68224d3dcaf6cea6dd78d0eaf3c8337811ba93a7.
Is it easy?