lvm.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. /*
  2. ** $Id: lvm.c,v 1.82 2000/01/24 20:14:07 roberto Exp roberto $
  3. ** Lua virtual machine
  4. ** See Copyright Notice in lua.h
  5. */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #define LUA_REENTRANT
  10. #include "lauxlib.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. #ifdef OLD_ANSI
  23. #define strcoll(a,b) strcmp(a,b)
  24. #endif
  25. #define highbyte(L, x) ((x)<<8)
  26. /*
  27. ** Extra stack size to run a function:
  28. ** LUA_T_LINE(1), NAME(1), TM calls(3) (plus some extra...)
  29. */
  30. #define EXTRA_STACK 8
  31. static TaggedString *strconc (lua_State *L, const TaggedString *l,
  32. const TaggedString *r) {
  33. long nl = l->u.s.len;
  34. long nr = r->u.s.len;
  35. char *buffer = luaL_openspace(L, nl+nr);
  36. memcpy(buffer, l->str, nl);
  37. memcpy(buffer+nl, r->str, nr);
  38. return luaS_newlstr(L, buffer, nl+nr);
  39. }
  40. int luaV_tonumber (TObject *obj) { /* LUA_NUMBER */
  41. if (ttype(obj) != LUA_T_STRING)
  42. return 1;
  43. else {
  44. if (!luaO_str2d(svalue(obj), &nvalue(obj)))
  45. return 2;
  46. ttype(obj) = LUA_T_NUMBER;
  47. return 0;
  48. }
  49. }
  50. int luaV_tostring (lua_State *L, TObject *obj) { /* LUA_NUMBER */
  51. if (ttype(obj) != LUA_T_NUMBER)
  52. return 1;
  53. else {
  54. char s[32]; /* 16 digits, sign, point and \0 (+ some extra...) */
  55. sprintf(s, "%.16g", (double)nvalue(obj));
  56. tsvalue(obj) = luaS_new(L, s);
  57. ttype(obj) = LUA_T_STRING;
  58. return 0;
  59. }
  60. }
  61. void luaV_setn (lua_State *L, Hash *t, int val) {
  62. TObject index, value;
  63. ttype(&index) = LUA_T_STRING; tsvalue(&index) = luaS_new(L, "n");
  64. ttype(&value) = LUA_T_NUMBER; nvalue(&value) = val;
  65. luaH_set(L, t, &index, &value);
  66. }
  67. void luaV_closure (lua_State *L, int nelems) {
  68. if (nelems > 0) {
  69. Closure *c = luaF_newclosure(L, nelems);
  70. c->consts[0] = *(L->top-1);
  71. L->top -= nelems;
  72. while (nelems--)
  73. c->consts[nelems+1] = *(L->top-1+nelems);
  74. ttype(L->top-1) = (ttype(&c->consts[0]) == LUA_T_CPROTO) ?
  75. LUA_T_CCLOSURE : LUA_T_LCLOSURE;
  76. (L->top-1)->value.cl = c;
  77. }
  78. }
  79. /*
  80. ** Function to index a table.
  81. ** Receives the table at top-2 and the index at top-1.
  82. */
  83. void luaV_gettable (lua_State *L, StkId top) {
  84. TObject *table = top-2;
  85. const TObject *im;
  86. if (ttype(table) != LUA_T_ARRAY) { /* not a table, get gettable method */
  87. im = luaT_getimbyObj(L, table, IM_GETTABLE);
  88. if (ttype(im) == LUA_T_NIL) {
  89. L->top = top;
  90. luaG_indexerror(L, table);
  91. }
  92. }
  93. else { /* object is a table... */
  94. int tg = table->value.a->htag;
  95. im = luaT_getim(L, tg, IM_GETTABLE);
  96. if (ttype(im) == LUA_T_NIL) { /* and does not have a `gettable' method */
  97. const TObject *h = luaH_get(L, avalue(table), table+1);
  98. if (ttype(h) == LUA_T_NIL &&
  99. (ttype(im=luaT_getim(L, tg, IM_INDEX)) != LUA_T_NIL)) {
  100. /* result is nil and there is an `index' tag method */
  101. L->top = top;
  102. luaD_callTM(L, im, 2, 1); /* calls it */
  103. }
  104. else
  105. *table = *h; /* `push' result into table position */
  106. return;
  107. }
  108. /* else it has a `gettable' method, go through to next command */
  109. }
  110. /* object is not a table, or it has a `gettable' method */
  111. L->top = top;
  112. luaD_callTM(L, im, 2, 1);
  113. }
  114. /*
  115. ** Receives table at *t, index at *(t+1) and value at `top'.
  116. ** WARNING: caller must assure 3 extra stack slots (to call a tag method)
  117. */
  118. void luaV_settable (lua_State *L, StkId t, StkId top) {
  119. const TObject *im;
  120. if (ttype(t) != LUA_T_ARRAY) { /* not a table, get `settable' method */
  121. L->top = top;
  122. im = luaT_getimbyObj(L, t, IM_SETTABLE);
  123. if (ttype(im) == LUA_T_NIL)
  124. luaG_indexerror(L, t);
  125. }
  126. else { /* object is a table... */
  127. im = luaT_getim(L, avalue(t)->htag, IM_SETTABLE);
  128. if (ttype(im) == LUA_T_NIL) { /* and does not have a `settable' method */
  129. luaH_set(L, avalue(t), t+1, top-1);
  130. return;
  131. }
  132. /* else it has a `settable' method, go through to next command */
  133. }
  134. /* object is not a table, or it has a `settable' method */
  135. /* prepare arguments and call the tag method */
  136. *(top+2) = *(top-1);
  137. *(top+1) = *(t+1);
  138. *(top) = *t;
  139. *(top-1) = *im;
  140. L->top = top+3;
  141. luaD_call(L, top-1, 0);
  142. }
  143. void luaV_rawsettable (lua_State *L, StkId t) {
  144. if (ttype(t) != LUA_T_ARRAY)
  145. lua_error(L, "indexed expression not a table");
  146. else {
  147. luaH_set(L, avalue(t), t+1, L->top-1);
  148. L->top -= 3;
  149. }
  150. }
  151. /*
  152. ** WARNING: caller must assure 3 extra stack slots (to call a tag method)
  153. */
  154. void luaV_getglobal (lua_State *L, GlobalVar *gv, StkId top) {
  155. const TObject *value = &gv->value;
  156. TObject *im = luaT_getimbyObj(L, value, IM_GETGLOBAL);
  157. if (ttype(im) == LUA_T_NIL) /* is there a tag method? */
  158. *top = *value; /* default behavior */
  159. else { /* tag method */
  160. *top = *im;
  161. ttype(top+1) = LUA_T_STRING;
  162. tsvalue(top+1) = gv->name; /* global name */
  163. *(top+2) = *value;
  164. L->top = top+3;
  165. luaD_call(L, top, 1);
  166. }
  167. }
  168. /*
  169. ** WARNING: caller must assure 3 extra stack slots (to call a tag method)
  170. */
  171. void luaV_setglobal (lua_State *L, GlobalVar *gv, StkId top) {
  172. const TObject *oldvalue = &gv->value;
  173. const TObject *im = luaT_getimbyObj(L, oldvalue, IM_SETGLOBAL);
  174. if (ttype(im) == LUA_T_NIL) /* is there a tag method? */
  175. gv->value = *(top-1);
  176. else {
  177. *(top+2) = *(top-1); /* new value */
  178. *(top+1) = *oldvalue;
  179. ttype(top) = LUA_T_STRING;
  180. tsvalue(top) = gv->name;
  181. *(top-1) = *im;
  182. L->top = top+3;
  183. luaD_call(L, top-1, 0);
  184. }
  185. }
  186. static void call_binTM (lua_State *L, StkId top, IMS event, const char *msg) {
  187. /* try first operand */
  188. const TObject *im = luaT_getimbyObj(L, top-2, event);
  189. L->top = top;
  190. if (ttype(im) == LUA_T_NIL) {
  191. im = luaT_getimbyObj(L, top-1, event); /* try second operand */
  192. if (ttype(im) == LUA_T_NIL) {
  193. im = luaT_getim(L, 0, event); /* try a `global' method */
  194. if (ttype(im) == LUA_T_NIL)
  195. lua_error(L, msg);
  196. }
  197. }
  198. lua_pushstring(L, luaT_eventname[event]);
  199. luaD_callTM(L, im, 3, 1);
  200. }
  201. static void call_arith (lua_State *L, StkId top, IMS event) {
  202. call_binTM(L, top, event, "unexpected type in arithmetic operation");
  203. }
  204. static int luaV_strcomp (const TaggedString *ls, const TaggedString *rs) {
  205. const char *l = ls->str;
  206. long ll = ls->u.s.len;
  207. const char *r = rs->str;
  208. long lr = rs->u.s.len;
  209. for (;;) {
  210. long temp = strcoll(l, r);
  211. if (temp != 0) return temp;
  212. /* strings are equal up to a '\0' */
  213. temp = strlen(l); /* index of first '\0' in both strings */
  214. if (temp == ll) /* l is finished? */
  215. return (temp == lr) ? 0 : -1; /* l is equal or smaller than r */
  216. else if (temp == lr) /* r is finished? */
  217. return 1; /* l is greater than r (because l is not finished) */
  218. /* both strings longer than temp; go on comparing (after the '\0') */
  219. temp++;
  220. l += temp; ll -= temp; r += temp; lr -= temp;
  221. }
  222. }
  223. void luaV_comparison (lua_State *L) {
  224. const TObject *l = L->top-2;
  225. const TObject *r = L->top-1;
  226. int result;
  227. if (ttype(l) == LUA_T_NUMBER && ttype(r) == LUA_T_NUMBER)
  228. result = nvalue(l) < nvalue(r);
  229. else if (ttype(l) == LUA_T_STRING && ttype(r) == LUA_T_STRING)
  230. result = luaV_strcomp(tsvalue(l), tsvalue(r)) < 0;
  231. else {
  232. call_binTM(L, L->top, IM_LT, "unexpected type in comparison");
  233. return;
  234. }
  235. L->top--;
  236. if (result) {
  237. nvalue(L->top-1) = 1.0;
  238. ttype(L->top-1) = LUA_T_NUMBER;
  239. }
  240. else
  241. ttype(L->top-1) = LUA_T_NIL;
  242. }
  243. void luaV_pack (lua_State *L, StkId firstelem, int nvararg, TObject *tab) {
  244. int i;
  245. Hash *htab;
  246. htab = avalue(tab) = luaH_new(L, nvararg+1); /* +1 for field `n' */
  247. ttype(tab) = LUA_T_ARRAY;
  248. for (i=0; i<nvararg; i++)
  249. luaH_setint(L, htab, i+1, firstelem+i);
  250. luaV_setn(L, htab, nvararg); /* store counter in field `n' */
  251. }
  252. static void adjust_varargs (lua_State *L, StkId base, int nfixargs) {
  253. TObject arg;
  254. int nvararg = (L->top-base) - nfixargs;
  255. if (nvararg < 0) {
  256. luaV_pack(L, base, 0, &arg);
  257. luaD_adjusttop(L, base, nfixargs);
  258. }
  259. else {
  260. luaV_pack(L, base+nfixargs, nvararg, &arg);
  261. L->top = base+nfixargs;
  262. }
  263. *L->top++ = arg;
  264. }
  265. /*
  266. ** Executes the given Lua function. Parameters are between [base,top).
  267. ** Returns n such that the the results are between [n,top).
  268. */
  269. StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf,
  270. StkId base) {
  271. register StkId top; /* keep top local, for performance */
  272. register const Byte *pc = tf->code;
  273. TaggedString **strcnst = tf->strcnst;
  274. if (L->callhook)
  275. luaD_callHook(L, base-1, L->callhook, "call");
  276. luaD_checkstack(L, (*pc++)+EXTRA_STACK);
  277. if (*pc < ZEROVARARG)
  278. luaD_adjusttop(L, base, *(pc++));
  279. else { /* varargs */
  280. adjust_varargs(L, base, (*pc++)-ZEROVARARG);
  281. luaC_checkGC(L);
  282. }
  283. top = L->top;
  284. for (;;) {
  285. register int aux = 0;
  286. switchentry:
  287. switch ((OpCode)*pc++) {
  288. case ENDCODE:
  289. return L->top; /* no results */
  290. case RETCODE:
  291. L->top = top;
  292. return base+(*pc++);
  293. case CALL: aux = *pc++;
  294. L->top = top;
  295. luaD_call(L, base+(*pc++), aux);
  296. top = L->top;
  297. break;
  298. case TAILCALL: aux = *pc++;
  299. L->top = top;
  300. luaD_call(L, base+(*pc++), MULT_RET);
  301. return base+aux;
  302. case PUSHNIL: aux = *pc++;
  303. do {
  304. ttype(top++) = LUA_T_NIL;
  305. } while (aux--);
  306. break;
  307. case POP: aux = *pc++;
  308. top -= aux;
  309. break;
  310. case PUSHNUMBERW: aux += highbyte(L, *pc++);
  311. case PUSHNUMBER: aux += *pc++;
  312. ttype(top) = LUA_T_NUMBER;
  313. nvalue(top) = aux;
  314. top++;
  315. break;
  316. case PUSHNUMBERNEGW: aux += highbyte(L, *pc++);
  317. case PUSHNUMBERNEG: aux += *pc++;
  318. ttype(top) = LUA_T_NUMBER;
  319. nvalue(top) = -aux;
  320. top++;
  321. break;
  322. case PUSHSTRCNSTW: aux += highbyte(L, *pc++);
  323. case PUSHSTRCNST: aux += *pc++;
  324. ttype(top) = LUA_T_STRING;
  325. tsvalue(top) = strcnst[aux];
  326. top++;
  327. break;
  328. case PUSHNUMCNSTW: aux += highbyte(L, *pc++);
  329. case PUSHNUMCNST: aux += *pc++;
  330. ttype(top) = LUA_T_NUMBER;
  331. nvalue(top) = tf->numcnst[aux];
  332. top++;
  333. break;
  334. case PUSHUPVALUE: aux = *pc++;
  335. *top++ = cl->consts[aux+1];
  336. break;
  337. case PUSHLOCAL: aux = *pc++;
  338. *top++ = *(base+aux);
  339. break;
  340. case GETGLOBALW: aux += highbyte(L, *pc++);
  341. case GETGLOBAL: aux += *pc++;
  342. luaV_getglobal(L, strcnst[aux]->u.s.gv, top);
  343. top++;
  344. break;
  345. case GETTABLE:
  346. luaV_gettable(L, top);
  347. top--;
  348. break;
  349. case GETDOTTEDW: aux += highbyte(L, *pc++);
  350. case GETDOTTED: aux += *pc++;
  351. ttype(top) = LUA_T_STRING;
  352. tsvalue(top++) = strcnst[aux];
  353. luaV_gettable(L, top);
  354. top--;
  355. break;
  356. case PUSHSELFW: aux += highbyte(L, *pc++);
  357. case PUSHSELF: aux += *pc++; {
  358. TObject receiver;
  359. receiver = *(top-1);
  360. ttype(top) = LUA_T_STRING;
  361. tsvalue(top++) = strcnst[aux];
  362. luaV_gettable(L, top);
  363. *(top-1) = receiver;
  364. break;
  365. }
  366. case CREATEARRAYW: aux += highbyte(L, *pc++);
  367. case CREATEARRAY: aux += *pc++;
  368. L->top = top;
  369. luaC_checkGC(L);
  370. avalue(top) = luaH_new(L, aux);
  371. ttype(top) = LUA_T_ARRAY;
  372. top++;
  373. break;
  374. case SETLOCAL: aux = *pc++;
  375. *(base+aux) = *(--top);
  376. break;
  377. case SETGLOBALW: aux += highbyte(L, *pc++);
  378. case SETGLOBAL: aux += *pc++;
  379. luaV_setglobal(L, strcnst[aux]->u.s.gv, top);
  380. top--;
  381. break;
  382. case SETTABLEPOP:
  383. luaV_settable(L, top-3, top);
  384. top -= 3; /* pop table, index, and value */
  385. break;
  386. case SETTABLE:
  387. luaV_settable(L, top-3-(*pc++), top);
  388. top--; /* pop value */
  389. break;
  390. case SETLISTW: aux += highbyte(L, *pc++);
  391. case SETLIST: aux += *pc++; {
  392. int n = *(pc++);
  393. Hash *arr = avalue(top-n-1);
  394. L->top = top-n; /* final value of `top' (in case of errors) */
  395. aux *= LFIELDS_PER_FLUSH;
  396. for (; n; n--)
  397. luaH_setint(L, arr, n+aux, --top);
  398. break;
  399. }
  400. case SETMAP: aux = *pc++; {
  401. StkId finaltop = top-2*(aux+1);
  402. Hash *arr = avalue(finaltop-1);
  403. L->top = finaltop; /* final value of `top' (in case of errors) */
  404. do {
  405. luaH_set(L, arr, top-2, top-1);
  406. top-=2;
  407. } while (aux--);
  408. break;
  409. }
  410. case NEQOP: aux = 1;
  411. case EQOP:
  412. top--;
  413. aux = (luaO_equalObj(top-1, top) != aux);
  414. booleanresult:
  415. if (aux) {
  416. ttype(top-1) = LUA_T_NUMBER;
  417. nvalue(top-1) = 1.0;
  418. }
  419. else ttype(top-1) = LUA_T_NIL;
  420. break;
  421. case LTOP:
  422. top--;
  423. if (ttype(top-1) == LUA_T_NUMBER && ttype(top) == LUA_T_NUMBER)
  424. aux = nvalue(top-1) < nvalue(top);
  425. else if (ttype(top-1) == LUA_T_STRING && ttype(top) == LUA_T_STRING)
  426. aux = luaV_strcomp(tsvalue(top-1), tsvalue(top)) < 0;
  427. else {
  428. call_binTM(L, top+1, IM_LT, "unexpected type in comparison");
  429. break;
  430. }
  431. goto booleanresult;
  432. case LEOP:
  433. top--;
  434. if (ttype(top-1) == LUA_T_NUMBER && ttype(top) == LUA_T_NUMBER)
  435. aux = nvalue(top-1) <= nvalue(top);
  436. else if (ttype(top-1) == LUA_T_STRING && ttype(top) == LUA_T_STRING)
  437. aux = luaV_strcomp(tsvalue(top-1), tsvalue(top)) <= 0;
  438. else {
  439. call_binTM(L, top+1, IM_LE, "unexpected type in comparison");
  440. break;
  441. }
  442. goto booleanresult;
  443. case GTOP:
  444. top--;
  445. if (ttype(top-1) == LUA_T_NUMBER && ttype(top) == LUA_T_NUMBER)
  446. aux = nvalue(top-1) > nvalue(top);
  447. else if (ttype(top-1) == LUA_T_STRING && ttype(top) == LUA_T_STRING)
  448. aux = luaV_strcomp(tsvalue(top-1), tsvalue(top)) > 0;
  449. else {
  450. call_binTM(L, top+1, IM_GT, "unexpected type in comparison");
  451. break;
  452. }
  453. goto booleanresult;
  454. case GEOP:
  455. top--;
  456. if (ttype(top-1) == LUA_T_NUMBER && ttype(top) == LUA_T_NUMBER)
  457. aux = nvalue(top-1) >= nvalue(top);
  458. else if (ttype(top-1) == LUA_T_STRING && ttype(top) == LUA_T_STRING)
  459. aux = luaV_strcomp(tsvalue(top-1), tsvalue(top)) >= 0;
  460. else {
  461. call_binTM(L, top+1, IM_GE, "unexpected type in comparison");
  462. break;
  463. }
  464. goto booleanresult;
  465. case ADDOP:
  466. if (tonumber(top-1) || tonumber(top-2))
  467. call_arith(L, top, IM_ADD);
  468. else
  469. nvalue(top-2) += nvalue(top-1);
  470. top--;
  471. break;
  472. case SUBOP:
  473. if (tonumber(top-1) || tonumber(top-2))
  474. call_arith(L, top, IM_SUB);
  475. else
  476. nvalue(top-2) -= nvalue(top-1);
  477. top--;
  478. break;
  479. case MULTOP:
  480. if (tonumber(top-1) || tonumber(top-2))
  481. call_arith(L, top, IM_MUL);
  482. else
  483. nvalue(top-2) *= nvalue(top-1);
  484. top--;
  485. break;
  486. case DIVOP:
  487. if (tonumber(top-1) || tonumber(top-2))
  488. call_arith(L, top, IM_DIV);
  489. else
  490. nvalue(top-2) /= nvalue(top-1);
  491. top--;
  492. break;
  493. case POWOP:
  494. call_binTM(L, top, IM_POW, "undefined operation");
  495. top--;
  496. break;
  497. case CONCOP:
  498. if (tostring(L, top-2) || tostring(L, top-1))
  499. call_binTM(L, top, IM_CONCAT, "unexpected type for concatenation");
  500. else
  501. tsvalue(top-2) = strconc(L, tsvalue(top-2), tsvalue(top-1));
  502. top--;
  503. L->top = top;
  504. luaC_checkGC(L);
  505. break;
  506. case MINUSOP:
  507. if (tonumber(top-1)) {
  508. ttype(top) = LUA_T_NIL;
  509. call_arith(L, top+1, IM_UNM);
  510. }
  511. else
  512. nvalue(top-1) = - nvalue(top-1);
  513. break;
  514. case NOTOP:
  515. ttype(top-1) =
  516. (ttype(top-1) == LUA_T_NIL) ? LUA_T_NUMBER : LUA_T_NIL;
  517. nvalue(top-1) = 1;
  518. break;
  519. case ONTJMPW: aux += highbyte(L, *pc++);
  520. case ONTJMP: aux += *pc++;
  521. if (ttype(top-1) != LUA_T_NIL) pc += aux;
  522. else top--;
  523. break;
  524. case ONFJMPW: aux += highbyte(L, *pc++);
  525. case ONFJMP: aux += *pc++;
  526. if (ttype(top-1) == LUA_T_NIL) pc += aux;
  527. else top--;
  528. break;
  529. case JMPW: aux += highbyte(L, *pc++);
  530. case JMP: aux += *pc++;
  531. pc += aux;
  532. break;
  533. case IFFJMPW: aux += highbyte(L, *pc++);
  534. case IFFJMP: aux += *pc++;
  535. if (ttype(--top) == LUA_T_NIL) pc += aux;
  536. break;
  537. case IFTUPJMPW: aux += highbyte(L, *pc++);
  538. case IFTUPJMP: aux += *pc++;
  539. if (ttype(--top) != LUA_T_NIL) pc -= aux;
  540. break;
  541. case IFFUPJMPW: aux += highbyte(L, *pc++);
  542. case IFFUPJMP: aux += *pc++;
  543. if (ttype(--top) == LUA_T_NIL) pc -= aux;
  544. break;
  545. case CLOSUREW: aux += highbyte(L, *pc++);
  546. case CLOSURE: aux += *pc++;
  547. ttype(top) = LUA_T_LPROTO;
  548. tfvalue(top) = tf->protocnst[aux];
  549. L->top = ++top;
  550. aux = *pc++; /* number of upvalues */
  551. luaV_closure(L, aux);
  552. luaC_checkGC(L);
  553. top -= aux;
  554. break;
  555. case SETLINEW: aux += highbyte(L, *pc++);
  556. case SETLINE: aux += *pc++;
  557. if ((base-2)->ttype != LUA_T_LINE) {
  558. /* open space for LINE and NAME values */
  559. int i = top-base;
  560. while (i--) base[i+2] = base[i];
  561. base += 2;
  562. top += 2;
  563. (base-1)->ttype = LUA_T_NIL; /* initial value for NAME */
  564. (base-2)->ttype = LUA_T_LINE;
  565. }
  566. (base-2)->value.i = aux;
  567. if (L->linehook) {
  568. L->top = top;
  569. luaD_lineHook(L, base-3, aux);
  570. }
  571. break;
  572. case SETNAMEW: aux += highbyte(L, *pc++);
  573. case SETNAME: aux += *pc++;
  574. if ((base-2)->ttype == LUA_T_LINE) { /* function has debug info? */
  575. (base-1)->ttype = -(*pc++);
  576. (base-1)->value.i = aux;
  577. }
  578. break;
  579. case LONGARGW: aux += highbyte(L, *pc++);
  580. case LONGARG: aux += *pc++;
  581. aux = highbyte(L, highbyte(L, aux));
  582. goto switchentry; /* do not reset `aux' */
  583. }
  584. }
  585. }