lvm.c 18 KB

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