Fixed handling swap in vmgen

Fixes #1305. I hope I did it right.