Refactor code generation of global-scope expressions