Dynamics of quadruple systems composed of two binaries: stars, white dwarfs, and implications for Ia supernovae