@@ -393,8 +393,7 @@ RewriterVar* JitFragmentWriter::emitGetBlockLocal(InternedString s, int vreg) {
393393 if (it == local_syms.end ()) {
394394 auto r = emitGetLocal (s, vreg);
395395 assert (r->reftype == RefType::OWNED);
396- emitSetLocal (s, vreg, false , imm (nullptr )); // clear out the vreg
397- emitSetBlockLocal (s, r);
396+ emitSetBlockLocal (s, vreg, r);
398397 return r;
399398 }
400399 return it->second ;
@@ -403,6 +402,8 @@ RewriterVar* JitFragmentWriter::emitGetBlockLocal(InternedString s, int vreg) {
403402void JitFragmentWriter::emitKillTemporary (InternedString s, int vreg) {
404403 if (!local_syms.count (s))
405404 emitSetLocal (s, vreg, false , imm (nullptr ));
405+ else
406+ local_syms[s]->refUsed ();
406407}
407408
408409RewriterVar* JitFragmentWriter::emitGetBoxedLocal (BoxedString* s) {
@@ -558,8 +559,19 @@ std::vector<RewriterVar*> JitFragmentWriter::emitUnpackIntoArray(RewriterVar* v,
558559}
559560
560561RewriterVar* JitFragmentWriter::emitYield (RewriterVar* v) {
561- auto rtn = call (false , (void *)ASTInterpreterJitInterface::yieldHelper, getInterp (), v)->setType (RefType::OWNED);
562+ llvm::SmallVector<RewriterVar*, 8 > local_args;
563+ local_args.push_back (interp->getAttr (ASTInterpreterJitInterface::getCreatedClosureOffset ()));
564+ for (auto && sym : local_syms) {
565+ if (sym.second ->reftype == RefType::OWNED)
566+ local_args.push_back (sym.second );
567+ }
568+ auto && args = allocArgs (local_args, RewriterVar::SetattrType::REF_USED);
569+ RewriterVar* generator = interp->getAttr (ASTInterpreterJitInterface::getGeneratorOffset ());
570+ auto rtn = call (false , (void *)yield, generator, v, args, imm (local_args.size ()))->setType (RefType::OWNED);
562571 v->refConsumed ();
572+ for (auto && var : local_args) {
573+ var->refUsed ();
574+ }
563575 return rtn;
564576}
565577
@@ -650,10 +662,13 @@ void JitFragmentWriter::emitSetAttr(AST_expr* node, RewriterVar* obj, BoxedStrin
650662 attr->refConsumed (rtn.second );
651663}
652664
653- void JitFragmentWriter::emitSetBlockLocal (InternedString s, STOLEN(RewriterVar*) v) {
665+ void JitFragmentWriter::emitSetBlockLocal (InternedString s, int vreg, STOLEN(RewriterVar*) v) {
654666 if (LOG_BJIT_ASSEMBLY)
655667 comment (" BJIT: emitSetBlockLocal() start" );
656668 RewriterVar* prev = local_syms[s];
669+ if (!prev) {
670+ emitSetLocal (s, vreg, false , imm (nullptr )); // clear out the vreg
671+ }
657672 local_syms[s] = v;
658673 if (LOG_BJIT_ASSEMBLY)
659674 comment (" BJIT: emitSetBlockLocal() end" );
0 commit comments