lvm.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. /*
  2. ** $Id: lvm.c,v 1.225 2002/04/10 12:11:07 roberto Exp roberto $
  3. ** Lua virtual machine
  4. ** See Copyright Notice in lua.h
  5. */
  6. #include <stdarg.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include "lua.h"
  11. #include "ldebug.h"
  12. #include "ldo.h"
  13. #include "lfunc.h"
  14. #include "lgc.h"
  15. #include "lobject.h"
  16. #include "lopcodes.h"
  17. #include "lstate.h"
  18. #include "lstring.h"
  19. #include "ltable.h"
  20. #include "ltm.h"
  21. #include "lvm.h"
  22. /* limit for table tag-method chains (to avoid loops) */
  23. #define MAXTAGLOOP 10000
  24. static void luaV_checkGC (lua_State *L, StkId top) {
  25. if (G(L)->nblocks >= G(L)->GCthreshold) {
  26. L->top = top; /* limit for active registers */
  27. luaC_collectgarbage(L);
  28. L->top = L->ci->top; /* restore old top position */
  29. }
  30. }
  31. const TObject *luaV_tonumber (const TObject *obj, TObject *n) {
  32. lua_Number num;
  33. if (ttype(obj) == LUA_TNUMBER) return obj;
  34. if (ttype(obj) == LUA_TSTRING && luaO_str2d(svalue(obj), &num)) {
  35. setnvalue(n, num);
  36. return n;
  37. }
  38. else
  39. return NULL;
  40. }
  41. int luaV_tostring (lua_State *L, TObject *obj) {
  42. if (ttype(obj) != LUA_TNUMBER)
  43. return 0;
  44. else {
  45. char s[32]; /* 16 digits, sign, point and \0 (+ some extra...) */
  46. lua_number2str(s, nvalue(obj));
  47. setsvalue(obj, luaS_new(L, s));
  48. return 1;
  49. }
  50. }
  51. static void traceexec (lua_State *L) {
  52. CallInfo *ci = L->ci;
  53. Proto *p = ci_func(ci)->l.p;
  54. int newline = p->lineinfo[pcRel(*ci->pc, p)];
  55. if (pcRel(*ci->pc, p) == 0) /* tracing may be starting now? */
  56. ci->savedpc = *ci->pc; /* initialize `savedpc' */
  57. /* calls linehook when enters a new line or jumps back (loop) */
  58. if (*ci->pc <= ci->savedpc || newline != p->lineinfo[pcRel(ci->savedpc, p)]) {
  59. luaD_lineHook(L, newline);
  60. ci = L->ci; /* previous call may reallocate `ci' */
  61. }
  62. ci->savedpc = *ci->pc;
  63. }
  64. static void callTMres (lua_State *L, const TObject *f,
  65. const TObject *p1, const TObject *p2, TObject *result ) {
  66. ptrdiff_t res = savestack(L, result);
  67. setobj(L->top, f); /* push function */
  68. setobj(L->top+1, p1); /* 1st argument */
  69. setobj(L->top+2, p2); /* 2nd argument */
  70. luaD_checkstack(L, 3); /* cannot check before (could invalidate p1, p2) */
  71. L->top += 3;
  72. luaD_call(L, L->top - 3, 1);
  73. result = restorestack(L, res); /* previous call may change stack */
  74. setobj(result, --L->top); /* get result */
  75. }
  76. static void callTM (lua_State *L, const TObject *f,
  77. const TObject *p1, const TObject *p2, const TObject *p3) {
  78. setobj(L->top, f); /* push function */
  79. setobj(L->top+1, p1); /* 1st argument */
  80. setobj(L->top+2, p2); /* 2nd argument */
  81. setobj(L->top+3, p3); /* 3th argument */
  82. luaD_checkstack(L, 4); /* cannot check before (could invalidate p1...p3) */
  83. L->top += 4;
  84. luaD_call(L, L->top - 4, 0);
  85. }
  86. /*
  87. ** Function to index a table.
  88. ** Receives the table at `t' and the key at `key'.
  89. ** leaves the result at `res'.
  90. */
  91. void luaV_gettable (lua_State *L, const TObject *t, TObject *key, StkId res) {
  92. const TObject *tm;
  93. int loop = 0;
  94. init:
  95. if (ttype(t) == LUA_TTABLE) { /* `t' is a table? */
  96. Table *et = hvalue(t)->metatable;
  97. if ((tm = fasttm(L, et, TM_GETTABLE)) == NULL) { /* no gettable TM? */
  98. const TObject *h = luaH_get(hvalue(t), key); /* do a primitive get */
  99. /* result is no nil or there is no `index' tag method? */
  100. if (ttype(h) != LUA_TNIL || /* no nil? */
  101. (tm = fasttm(L, et, TM_INDEX)) == NULL) { /* or no index TM? */
  102. setobj(res, h); /* default get */
  103. return;
  104. }
  105. }
  106. /* else will try the tag method */
  107. } else { /* not a table; try a `gettable' tag method */
  108. if (ttype(tm = luaT_gettmbyobj(L, t, TM_GETTABLE)) == LUA_TNIL) {
  109. luaG_typeerror(L, t, "index");
  110. return; /* to avoid warnings */
  111. }
  112. }
  113. if (ttype(tm) == LUA_TFUNCTION)
  114. callTMres(L, tm, t, key, res);
  115. else {
  116. if (++loop == MAXTAGLOOP) luaD_runerror(L, "loop in gettable");
  117. t = tm;
  118. goto init; /* return luaV_gettable(L, tm, key, res); */
  119. }
  120. }
  121. /*
  122. ** Receives table at `t', key at `key' and value at `val'.
  123. */
  124. void luaV_settable (lua_State *L, const TObject *t, TObject *key, StkId val) {
  125. const TObject *tm;
  126. int loop = 0;
  127. init:
  128. if (ttype(t) == LUA_TTABLE) { /* `t' is a table? */
  129. Table *et = hvalue(t)->metatable;
  130. if ((tm = fasttm(L, et, TM_SETTABLE)) == NULL) { /* no TM? */
  131. luaH_set(L, hvalue(t), key, val); /* do a primitive set */
  132. return;
  133. }
  134. /* else will try the tag method */
  135. } else { /* not a table; try a `settable' tag method */
  136. if (ttype(tm = luaT_gettmbyobj(L, t, TM_SETTABLE)) == LUA_TNIL) {
  137. luaG_typeerror(L, t, "index");
  138. return; /* to avoid warnings */
  139. }
  140. }
  141. if (ttype(tm) == LUA_TFUNCTION)
  142. callTM(L, tm, t, key, val);
  143. else {
  144. if (++loop == MAXTAGLOOP) luaD_runerror(L, "loop in settable");
  145. t = tm;
  146. goto init; /* luaV_settable(L, tm, key, val); */
  147. }
  148. }
  149. static int call_binTM (lua_State *L, const TObject *p1, const TObject *p2,
  150. TObject *res, TMS event) {
  151. const TObject *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */
  152. if (ttype(tm) == LUA_TNIL)
  153. tm = luaT_gettmbyobj(L, p2, event); /* try second operand */
  154. if (ttype(tm) != LUA_TFUNCTION) return 0;
  155. callTMres(L, tm, p1, p2, res);
  156. return 1;
  157. }
  158. static void call_arith (lua_State *L, StkId p1, const TObject *p2,
  159. StkId res, TMS event) {
  160. if (!call_binTM(L, p1, p2, res, event))
  161. luaG_aritherror(L, p1, p2);
  162. }
  163. static int luaV_strlessthan (const TString *ls, const TString *rs) {
  164. const char *l = getstr(ls);
  165. size_t ll = ls->tsv.len;
  166. const char *r = getstr(rs);
  167. size_t lr = rs->tsv.len;
  168. for (;;) {
  169. int temp = strcoll(l, r);
  170. if (temp != 0) return (temp < 0);
  171. else { /* strings are equal up to a `\0' */
  172. size_t len = strlen(l); /* index of first `\0' in both strings */
  173. if (len == lr) /* r is finished? */
  174. return 0; /* l is equal or greater than r */
  175. else if (len == ll) /* l is finished? */
  176. return 1; /* l is smaller than r (because r is not finished) */
  177. /* both strings longer than `len'; go on comparing (after the `\0') */
  178. len++;
  179. l += len; ll -= len; r += len; lr -= len;
  180. }
  181. }
  182. }
  183. int luaV_lessthan (lua_State *L, const TObject *l, const TObject *r) {
  184. if (ttype(l) == LUA_TNUMBER && ttype(r) == LUA_TNUMBER)
  185. return (nvalue(l) < nvalue(r));
  186. else if (ttype(l) == LUA_TSTRING && ttype(r) == LUA_TSTRING)
  187. return luaV_strlessthan(tsvalue(l), tsvalue(r));
  188. else { /* try TM */
  189. if (!call_binTM(L, l, r, L->top, TM_LT))
  190. luaG_ordererror(L, l, r);
  191. return !l_isfalse(L->top);
  192. }
  193. }
  194. void luaV_strconc (lua_State *L, int total, int last) {
  195. do {
  196. StkId top = L->ci->base + last + 1;
  197. int n = 2; /* number of elements handled in this pass (at least 2) */
  198. if (!tostring(L, top-2) || !tostring(L, top-1)) {
  199. if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT))
  200. luaG_concaterror(L, top-2, top-1);
  201. } else if (tsvalue(top-1)->tsv.len > 0) { /* if len=0, do nothing */
  202. /* at least two string values; get as many as possible */
  203. lu_mem tl = cast(lu_mem, tsvalue(top-1)->tsv.len) +
  204. cast(lu_mem, tsvalue(top-2)->tsv.len);
  205. char *buffer;
  206. int i;
  207. while (n < total && tostring(L, top-n-1)) { /* collect total length */
  208. tl += tsvalue(top-n-1)->tsv.len;
  209. n++;
  210. }
  211. if (tl > MAX_SIZET) luaD_runerror(L, "string size overflow");
  212. buffer = luaO_openspace(L, tl, char);
  213. tl = 0;
  214. for (i=n; i>0; i--) { /* concat all strings */
  215. size_t l = tsvalue(top-i)->tsv.len;
  216. memcpy(buffer+tl, svalue(top-i), l);
  217. tl += l;
  218. }
  219. setsvalue(top-n, luaS_newlstr(L, buffer, tl));
  220. }
  221. total -= n-1; /* got `n' strings to create 1 new */
  222. last -= n-1;
  223. } while (total > 1); /* repeat until only 1 result left */
  224. }
  225. static void powOp (lua_State *L, StkId ra, StkId rb, StkId rc) {
  226. const TObject *b = rb;
  227. const TObject *c = rc;
  228. TObject tempb, tempc;
  229. if (tonumber(b, &tempb) && tonumber(c, &tempc)) {
  230. TObject f, o;
  231. setsvalue(&o, luaS_newliteral(L, "pow"));
  232. luaV_gettable(L, gt(L), &o, &f);
  233. if (ttype(&f) != LUA_TFUNCTION)
  234. luaD_runerror(L, "`pow' (for `^' operator) is not a function");
  235. callTMres(L, &f, b, c, ra);
  236. }
  237. else
  238. call_arith(L, rb, rc, ra, TM_POW);
  239. }
  240. /*
  241. ** some macros for common tasks in `luaV_execute'
  242. */
  243. #define runtime_check(L, c) { if (!(c)) return 0; }
  244. #define RA(i) (base+GETARG_A(i))
  245. #define RB(i) (base+GETARG_B(i))
  246. #define RC(i) (base+GETARG_C(i))
  247. #define RKC(i) ((GETARG_C(i) < MAXSTACK) ? \
  248. base+GETARG_C(i) : \
  249. k+GETARG_C(i)-MAXSTACK)
  250. #define KBc(i) (k+GETARG_Bc(i))
  251. #define Arith(op, optm) { \
  252. const TObject *b = RB(i); const TObject *c = RKC(i); \
  253. TObject tempb, tempc; \
  254. if (tonumber(b, &tempb) && tonumber(c, &tempc)) { \
  255. setnvalue(ra, nvalue(b) op nvalue(c)); \
  256. } else \
  257. call_arith(L, RB(i), RKC(i), ra, optm); \
  258. }
  259. #define dojump(pc, i) ((pc) += (i))
  260. StkId luaV_execute (lua_State *L) {
  261. StkId base;
  262. LClosure *cl;
  263. TObject *k;
  264. const Instruction *pc;
  265. callentry: /* entry point when calling new functions */
  266. L->ci->pc = &pc;
  267. L->ci->pb = &base;
  268. pc = L->ci->savedpc;
  269. retentry: /* entry point when returning to old functions */
  270. base = L->ci->base;
  271. cl = &clvalue(base - 1)->l;
  272. k = cl->p->k;
  273. /* main loop of interpreter */
  274. for (;;) {
  275. const Instruction i = *pc++;
  276. StkId ra;
  277. if (L->linehook)
  278. traceexec(L);
  279. ra = RA(i);
  280. lua_assert(L->top <= L->stack + L->stacksize && L->top >= L->ci->base);
  281. lua_assert(L->top == L->ci->top ||
  282. GET_OPCODE(i) == OP_CALL || GET_OPCODE(i) == OP_TAILCALL ||
  283. GET_OPCODE(i) == OP_RETURN || GET_OPCODE(i) == OP_SETLISTO);
  284. switch (GET_OPCODE(i)) {
  285. case OP_MOVE: {
  286. setobj(ra, RB(i));
  287. break;
  288. }
  289. case OP_LOADK: {
  290. setobj(ra, KBc(i));
  291. break;
  292. }
  293. case OP_LOADBOOL: {
  294. setbvalue(ra, GETARG_B(i));
  295. if (GETARG_C(i)) pc++; /* skip next instruction (if C) */
  296. break;
  297. }
  298. case OP_LOADNIL: {
  299. TObject *rb = RB(i);
  300. do {
  301. setnilvalue(rb--);
  302. } while (rb >= ra);
  303. break;
  304. }
  305. case OP_GETUPVAL: {
  306. int b = GETARG_B(i);
  307. setobj(ra, cl->upvals[b]->v);
  308. break;
  309. }
  310. case OP_GETGLOBAL: {
  311. lua_assert(ttype(KBc(i)) == LUA_TSTRING);
  312. luaV_gettable(L, gt(L), KBc(i), ra);
  313. break;
  314. }
  315. case OP_GETTABLE: {
  316. luaV_gettable(L, RB(i), RKC(i), ra);
  317. break;
  318. }
  319. case OP_SETGLOBAL: {
  320. lua_assert(ttype(KBc(i)) == LUA_TSTRING);
  321. luaV_settable(L, gt(L), KBc(i), ra);
  322. break;
  323. }
  324. case OP_SETUPVAL: {
  325. int b = GETARG_B(i);
  326. setobj(cl->upvals[b]->v, ra);
  327. break;
  328. }
  329. case OP_SETTABLE: {
  330. luaV_settable(L, RB(i), RKC(i), ra);
  331. break;
  332. }
  333. case OP_NEWTABLE: {
  334. int b = GETARG_B(i);
  335. if (b > 0) b = twoto(b-1);
  336. sethvalue(ra, luaH_new(L, b, GETARG_C(i)));
  337. luaV_checkGC(L, ra+1);
  338. break;
  339. }
  340. case OP_SELF: {
  341. StkId rb = RB(i);
  342. setobj(ra+1, rb);
  343. luaV_gettable(L, rb, RKC(i), ra);
  344. break;
  345. }
  346. case OP_ADD: {
  347. Arith( + , TM_ADD);
  348. break;
  349. }
  350. case OP_SUB: {
  351. Arith( - , TM_SUB);
  352. break;
  353. }
  354. case OP_MUL: {
  355. Arith( * , TM_MUL);
  356. break;
  357. }
  358. case OP_DIV: {
  359. Arith( / , TM_DIV);
  360. break;
  361. }
  362. case OP_POW: {
  363. powOp(L, ra, RB(i), RKC(i));
  364. break;
  365. }
  366. case OP_UNM: {
  367. const TObject *rb = RB(i);
  368. if (tonumber(rb, ra)) {
  369. setnvalue(ra, -nvalue(rb));
  370. }
  371. else {
  372. TObject temp;
  373. setnilvalue(&temp);
  374. call_arith(L, RB(i), &temp, ra, TM_UNM);
  375. }
  376. break;
  377. }
  378. case OP_NOT: {
  379. int res = l_isfalse(RB(i)); /* next assignment may change this value */
  380. setbvalue(ra, res);
  381. break;
  382. }
  383. case OP_CONCAT: {
  384. int b = GETARG_B(i);
  385. int c = GETARG_C(i);
  386. luaV_strconc(L, c-b+1, c); /* may change `base' (and `ra') */
  387. setobj(base+GETARG_A(i), base+b);
  388. luaV_checkGC(L, base+c+1);
  389. break;
  390. }
  391. case OP_JMP: {
  392. dojump(pc, GETARG_sBc(i));
  393. break;
  394. }
  395. case OP_TESTEQ: { /* skip next instruction if test fails */
  396. if (!luaO_equalObj(ra, RKC(i))) pc++;
  397. break;
  398. }
  399. case OP_TESTNE: {
  400. if (luaO_equalObj(ra, RKC(i))) pc++;
  401. break;
  402. }
  403. case OP_TESTLT: {
  404. if (!luaV_lessthan(L, ra, RKC(i))) pc++;
  405. break;
  406. }
  407. case OP_TESTLE: { /* b <= c === !(c<b) */
  408. if (luaV_lessthan(L, RKC(i), ra)) pc++;
  409. break;
  410. }
  411. case OP_TESTGT: { /* b > c === (c<b) */
  412. if (!luaV_lessthan(L, RKC(i), ra)) pc++;
  413. break;
  414. }
  415. case OP_TESTGE: { /* b >= c === !(b<c) */
  416. if (luaV_lessthan(L, ra, RKC(i))) pc++;
  417. break;
  418. }
  419. case OP_TESTT: {
  420. StkId rb = RB(i);
  421. if (l_isfalse(rb)) pc++;
  422. else setobj(ra, rb);
  423. break;
  424. }
  425. case OP_TESTF: {
  426. StkId rb = RB(i);
  427. if (!l_isfalse(rb)) pc++;
  428. else setobj(ra, rb);
  429. break;
  430. }
  431. case OP_CALL: {
  432. StkId firstResult;
  433. int b = GETARG_B(i);
  434. int nresults;
  435. if (b != 0) L->top = ra+b; /* else previous instruction set top */
  436. nresults = GETARG_C(i) - 1;
  437. firstResult = luaD_precall(L, ra);
  438. if (firstResult) {
  439. if (firstResult > L->top) { /* yield? */
  440. (L->ci-1)->savedpc = pc;
  441. return NULL;
  442. }
  443. /* it was a C function (`precall' called it); adjust results */
  444. luaD_poscall(L, nresults, firstResult);
  445. if (nresults >= 0) L->top = L->ci->top;
  446. }
  447. else { /* it is a Lua function: `call' it */
  448. (L->ci-1)->savedpc = pc;
  449. goto callentry;
  450. }
  451. break;
  452. }
  453. case OP_TAILCALL: {
  454. int b = GETARG_B(i);
  455. if (L->openupval) luaF_close(L, base);
  456. if (b != 0) L->top = ra+b; /* else previous instruction set top */
  457. luaD_poscall(L, LUA_MULTRET, ra); /* move down function and args. */
  458. ra = luaD_precall(L, base-1);
  459. if (ra == NULL) goto callentry; /* it is a Lua function */
  460. else if (ra > L->top) return NULL; /* yield??? */
  461. else goto ret;
  462. }
  463. case OP_RETURN: {
  464. int b;
  465. if (L->openupval) luaF_close(L, base);
  466. b = GETARG_B(i);
  467. if (b != 0) L->top = ra+b-1;
  468. lua_assert(L->ci->pc == &pc);
  469. }
  470. ret: {
  471. CallInfo *ci;
  472. ci = L->ci - 1;
  473. if (ci->pc != &pc) /* previous function was running `here'? */
  474. return ra; /* no: return */
  475. else { /* yes: continue its execution */
  476. int nresults;
  477. lua_assert(ttype(ci->base-1) == LUA_TFUNCTION);
  478. pc = ci->savedpc;
  479. lua_assert(GET_OPCODE(*(pc-1)) == OP_CALL);
  480. nresults = GETARG_C(*(pc-1)) - 1;
  481. luaD_poscall(L, nresults, ra);
  482. if (nresults >= 0) L->top = L->ci->top;
  483. goto retentry;
  484. }
  485. break;
  486. }
  487. case OP_FORLOOP: {
  488. lua_Number step, index, limit;
  489. int j = GETARG_sBc(i);
  490. const TObject *plimit = ra+1;
  491. const TObject *pstep = ra+2;
  492. if (ttype(ra) != LUA_TNUMBER)
  493. luaD_runerror(L, "`for' initial value must be a number");
  494. if (!tonumber(plimit, ra+1))
  495. luaD_runerror(L, "`for' limit must be a number");
  496. if (!tonumber(pstep, ra+2))
  497. luaD_runerror(L, "`for' step must be a number");
  498. step = nvalue(pstep);
  499. index = nvalue(ra) + step; /* increment index */
  500. limit = nvalue(plimit);
  501. if (step > 0 ? index <= limit : index >= limit) {
  502. dojump(pc, j); /* jump back */
  503. chgnvalue(ra, index); /* update index */
  504. }
  505. break;
  506. }
  507. case OP_TFORLOOP: {
  508. setobj(ra+4, ra+2);
  509. setobj(ra+3, ra+1);
  510. setobj(ra+2, ra);
  511. L->top = ra+5;
  512. luaD_call(L, ra+2, GETARG_C(i) + 1);
  513. L->top = L->ci->top;
  514. if (ttype(ra+2) != LUA_TNIL) pc++; /* skip jump (keep looping) */
  515. break;
  516. }
  517. case OP_TFORPREP: {
  518. if (ttype(ra) == LUA_TTABLE) {
  519. setobj(ra+1, ra);
  520. setsvalue(ra, luaS_new(L, "next"));
  521. luaV_gettable(L, gt(L), ra, ra);
  522. }
  523. break;
  524. }
  525. case OP_SETLIST:
  526. case OP_SETLISTO: {
  527. int bc;
  528. int n;
  529. Table *h;
  530. runtime_check(L, ttype(ra) == LUA_TTABLE);
  531. h = hvalue(ra);
  532. bc = GETARG_Bc(i);
  533. if (GET_OPCODE(i) == OP_SETLIST)
  534. n = (bc&(LFIELDS_PER_FLUSH-1)) + 1;
  535. else {
  536. n = L->top - ra - 1;
  537. L->top = L->ci->top;
  538. }
  539. bc &= ~(LFIELDS_PER_FLUSH-1); /* bc = bc - bc%FPF */
  540. for (; n > 0; n--)
  541. luaH_setnum(L, h, bc+n, ra+n);
  542. break;
  543. }
  544. case OP_CLOSE: {
  545. luaF_close(L, ra);
  546. break;
  547. }
  548. case OP_CLOSURE: {
  549. Proto *p;
  550. Closure *ncl;
  551. int nup, j;
  552. p = cl->p->p[GETARG_Bc(i)];
  553. nup = p->nupvalues;
  554. ncl = luaF_newLclosure(L, nup);
  555. ncl->l.p = p;
  556. for (j=0; j<nup; j++, pc++) {
  557. if (GET_OPCODE(*pc) == OP_GETUPVAL)
  558. ncl->l.upvals[j] = cl->upvals[GETARG_B(*pc)];
  559. else {
  560. lua_assert(GET_OPCODE(*pc) == OP_MOVE);
  561. ncl->l.upvals[j] = luaF_findupval(L, base + GETARG_B(*pc));
  562. }
  563. }
  564. setclvalue(ra, ncl);
  565. luaV_checkGC(L, L->top);
  566. break;
  567. }
  568. }
  569. }
  570. }