Make the generated code more deterministic

The order of evaluation of arguments to non-special forms is not
defined.  With codegen-old, it can in fact vary according to the
results of the sort function.  So make sure that the order is
deterministic where it matters to the generated code.
Implement sort with mergesort

The quicksort implementation was short, but easily succumbed to
quadratic worst-case behaviour.