compile: factored out compileToken function

Also moved sortRules to compileUnsafe
sort: no longer return the array