Feldspar/feldspar-compiler — pull request #14 by emwap (2012-11-02 07:54:29+00:00)
Title: Improve compilation of MutableArray and MutableReference

Please review these changes. The intention is to improve the result of compilation by reducing the number of variables allocated, as seen in the example below.

```haskell
import Feldspar.Vector.Push as VP

prog :: Vector1 WordN -> Vector1 WordN -> PushVector (Vector1 WordN)
prog = VP.scanl (\a b -> a ++ a)
```

`icompile prog` before:
```c
{
uint32_t v13;
struct array v2 = {0};
struct array v4 = {0};
struct array v9 = {0};

v13 = getLength(v1);
initArray(&v2, (0 - sizeof(struct array)), v13);
initArray(&v4, sizeof(uint32_t), getLength(v0));
copyArray(&v4, v0);
for(uint32_t v5 = 0; v5 < v13; v5 += 1)
{
initArray(&v9, sizeof(uint32_t), getLength(&v4));
copyArray(&v9, &v4);
initArray(&at(struct array,&v2,v5), sizeof(uint32_t), getLength(&v9));
copyArray(&at(struct array,&v2,v5), &v9);
}
initArray(out, (0 - sizeof(struct array)), getLength(&v2));
copyArray(out, &v2);
freeArray(&v2);
freeArray(&v4);
freeArray(&v9);
}
```

`icompile prog` after:
```c
{
uint32_t v13;
struct array v4 = {0};

v13 = getLength(v1);
setLength(out, v13);
initArray(&v4, sizeof(uint32_t), getLength(v0));
copyArray(&v4, v0);
for(uint32_t v5 = 0; v5 < v13; v5 += 1)
{
initArray(&at(struct array,out,v5), sizeof(uint32_t), getLength(&v4));
copyArray(&at(struct array,out,v5), &v4);
}
freeArray(&v4);
}
```

cc @emilaxelsson, @pjonsson