Better type system for casting etc.

This version will not work correctly.
Arrays use unsigned long sizes.
Nicer generated type names for arrays.

Nb. This might be unsafe.
Report the correct location for cast errors.