fix constant folding of array accesses
rewrite arithmetic constant folding

this also fixes a bug where the storage instead of the arithmetic mode
was used.