Add a simple serialize() function so we can round-trip trees

More tests would be great, but for now I added a few basic checks in the
existing style.