** create a new Lua closure, push it in the stack, and initialize ** its upvalues. Note that the closure is not cached if prototype is ** already black (which means that 'cache' was already cleared by the ** GC). */
| 676 | ** GC). |
| 677 | */ |
| 678 | static void pushclosure(lua_State *L, Proto *p, UpVal **encup, StkId base, |
| 679 | StkId ra) { |
| 680 | int nup = p->sizeupvalues; |
| 681 | Upvaldesc *uv = p->upvalues; |
| 682 | int i; |
| 683 | LClosure *ncl = luaF_newLclosure(L, nup); |
| 684 | ncl->p = p; |
| 685 | setclLvalue(L, ra, ncl); /* anchor new closure in stack */ |
| 686 | for (i = 0; i < nup; i++) { /* fill in its upvalues */ |
| 687 | if (uv[i].instack) /* upvalue refers to local variable? */ |
| 688 | ncl->upvals[i] = luaF_findupval(L, base + uv[i].idx); |
| 689 | else /* get upvalue from enclosing function */ |
| 690 | ncl->upvals[i] = encup[uv[i].idx]; |
| 691 | if (nullptr != ncl->upvals[i]) |
| 692 | ncl->upvals[i]->refcount++; |
| 693 | /* new closure is white, so we do not need a barrier here */ |
| 694 | } |
| 695 | if (!isblack(p)) /* cache will not break GC invariant? */ |
| 696 | p->cache = ncl; /* save it on cache for reuse */ |
| 697 | } |
| 698 | |
| 699 | /* |
| 700 | ** finish execution of an opcode interrupted by an yield |
no test coverage detected