Turn more code in global_gen into AST generating code