Extract generator runtime into its own file

See #1007