Codegen for yield with scope