Independent controls of various properties of electromagnetic (EM) waves are crucially required in a wide range of applications. Programmable metasurface is a promising candidate to provide an advanced platform for manipulating EM waves. Here, we propose an approach that can arbitrarily control the polarization direction and phases of reflected waves in linear and nonlinear ways using a stacked programmable metasurface. Further, we extend the space-time-coding theory to incorporate the dimension of polarization, which provides an extra degree of freedom for manipulating EM waves. As proof-of-principle application examples, we consider polarization rotation, phase manipulation, and beam steering at linear and nonlinear frequencies. For validation, we design, fabricate, and measure a metasurface sample. The experimental results show good agreement with theoretical predictions and simulations. The proposed approach has a wide range of applications in various areas, such as imaging, data storage, and wireless communication.