lvm.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. /*
  2. ** $Id: lvm.c,v 1.29 1998/05/31 22:18:24 roberto Exp roberto $
  3. ** Lua virtual machine
  4. ** See Copyright Notice in lua.h
  5. */
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include "lauxlib.h"
  9. #include "ldo.h"
  10. #include "lfunc.h"
  11. #include "lgc.h"
  12. #include "lmem.h"
  13. #include "lopcodes.h"
  14. #include "lstate.h"
  15. #include "lstring.h"
  16. #include "ltable.h"
  17. #include "ltm.h"
  18. #include "luadebug.h"
  19. #include "lvm.h"
  20. #ifdef OLD_ANSI
  21. #define strcoll(a,b) strcmp(a,b)
  22. #endif
  23. #define skip_word(pc) (pc+=2)
  24. #define get_word(pc) ((*(pc)<<8)+(*((pc)+1)))
  25. #define next_word(pc) (pc+=2, get_word(pc-2))
  26. /* Extra stack size to run a function: LUA_T_LINE(1), TM calls(2), ... */
  27. #define EXTRA_STACK 5
  28. static TaggedString *strconc (TaggedString *l, TaggedString *r)
  29. {
  30. size_t nl = l->u.s.len;
  31. size_t nr = r->u.s.len;
  32. char *buffer = luaL_openspace(nl+nr+1);
  33. memcpy(buffer, l->str, nl);
  34. memcpy(buffer+nl, r->str, nr);
  35. return luaS_newlstr(buffer, nl+nr);
  36. }
  37. int luaV_tonumber (TObject *obj)
  38. { /* LUA_NUMBER */
  39. double t;
  40. char c;
  41. if (ttype(obj) != LUA_T_STRING)
  42. return 1;
  43. else if (sscanf(svalue(obj), "%lf %c",&t, &c) == 1) {
  44. nvalue(obj) = (real)t;
  45. ttype(obj) = LUA_T_NUMBER;
  46. return 0;
  47. }
  48. else
  49. return 2;
  50. }
  51. int luaV_tostring (TObject *obj)
  52. { /* LUA_NUMBER */
  53. if (ttype(obj) != LUA_T_NUMBER)
  54. return 1;
  55. else {
  56. char s[60];
  57. real f = nvalue(obj);
  58. int i;
  59. if ((real)(-MAX_INT) <= f && f <= (real)MAX_INT && (real)(i=(int)f) == f)
  60. sprintf (s, "%d", i);
  61. else
  62. sprintf (s, NUMBER_FMT, nvalue(obj));
  63. tsvalue(obj) = luaS_new(s);
  64. ttype(obj) = LUA_T_STRING;
  65. return 0;
  66. }
  67. }
  68. void luaV_closure (int nelems)
  69. {
  70. if (nelems > 0) {
  71. struct Stack *S = &L->stack;
  72. Closure *c = luaF_newclosure(nelems);
  73. c->consts[0] = *(S->top-1);
  74. memcpy(&c->consts[1], S->top-(nelems+1), nelems*sizeof(TObject));
  75. S->top -= nelems;
  76. ttype(S->top-1) = LUA_T_CLOSURE;
  77. (S->top-1)->value.cl = c;
  78. }
  79. }
  80. /*
  81. ** Function to index a table.
  82. ** Receives the table at top-2 and the index at top-1.
  83. */
  84. void luaV_gettable (void)
  85. {
  86. struct Stack *S = &L->stack;
  87. TObject *im;
  88. if (ttype(S->top-2) != LUA_T_ARRAY) /* not a table, get "gettable" method */
  89. im = luaT_getimbyObj(S->top-2, IM_GETTABLE);
  90. else { /* object is a table... */
  91. int tg = (S->top-2)->value.a->htag;
  92. im = luaT_getim(tg, IM_GETTABLE);
  93. if (ttype(im) == LUA_T_NIL) { /* and does not have a "gettable" method */
  94. TObject *h = luaH_get(avalue(S->top-2), S->top-1);
  95. if (h != NULL && ttype(h) != LUA_T_NIL) {
  96. --S->top;
  97. *(S->top-1) = *h;
  98. }
  99. else if (ttype(im=luaT_getim(tg, IM_INDEX)) != LUA_T_NIL)
  100. luaD_callTM(im, 2, 1);
  101. else {
  102. --S->top;
  103. ttype(S->top-1) = LUA_T_NIL;
  104. }
  105. return;
  106. }
  107. /* else it has a "gettable" method, go through to next command */
  108. }
  109. /* object is not a table, or it has a "gettable" method */
  110. if (ttype(im) != LUA_T_NIL)
  111. luaD_callTM(im, 2, 1);
  112. else
  113. lua_error("indexed expression not a table");
  114. }
  115. /*
  116. ** Function to store indexed based on values at the stack.top
  117. ** mode = 0: raw store (without tag methods)
  118. ** mode = 1: normal store (with tag methods)
  119. ** mode = 2: "deep L->stack.stack" store (with tag methods)
  120. */
  121. void luaV_settable (TObject *t, int mode)
  122. {
  123. struct Stack *S = &L->stack;
  124. TObject *im = (mode == 0) ? NULL : luaT_getimbyObj(t, IM_SETTABLE);
  125. if (ttype(t) == LUA_T_ARRAY && (im == NULL || ttype(im) == LUA_T_NIL)) {
  126. TObject *h = luaH_set(avalue(t), t+1);
  127. *h = *(S->top-1);
  128. S->top -= (mode == 2) ? 1 : 3;
  129. }
  130. else { /* object is not a table, and/or has a specific "settable" method */
  131. if (im && ttype(im) != LUA_T_NIL) {
  132. if (mode == 2) {
  133. *(S->top+1) = *(L->stack.top-1);
  134. *(S->top) = *(t+1);
  135. *(S->top-1) = *t;
  136. S->top += 2; /* WARNING: caller must assure stack space */
  137. }
  138. luaD_callTM(im, 3, 0);
  139. }
  140. else
  141. lua_error("indexed expression not a table");
  142. }
  143. }
  144. void luaV_getglobal (TaggedString *ts)
  145. {
  146. /* WARNING: caller must assure stack space */
  147. TObject *value = &ts->u.s.globalval;
  148. TObject *im = luaT_getimbyObj(value, IM_GETGLOBAL);
  149. if (ttype(im) == LUA_T_NIL) { /* default behavior */
  150. *L->stack.top++ = *value;
  151. }
  152. else {
  153. struct Stack *S = &L->stack;
  154. ttype(S->top) = LUA_T_STRING;
  155. tsvalue(S->top) = ts;
  156. S->top++;
  157. *S->top++ = *value;
  158. luaD_callTM(im, 2, 1);
  159. }
  160. }
  161. void luaV_setglobal (TaggedString *ts)
  162. {
  163. TObject *oldvalue = &ts->u.s.globalval;
  164. TObject *im = luaT_getimbyObj(oldvalue, IM_SETGLOBAL);
  165. if (ttype(im) == LUA_T_NIL) /* default behavior */
  166. luaS_rawsetglobal(ts, --L->stack.top);
  167. else {
  168. /* WARNING: caller must assure stack space */
  169. struct Stack *S = &L->stack;
  170. TObject newvalue = *(S->top-1);
  171. ttype(S->top-1) = LUA_T_STRING;
  172. tsvalue(S->top-1) = ts;
  173. *S->top++ = *oldvalue;
  174. *S->top++ = newvalue;
  175. luaD_callTM(im, 3, 0);
  176. }
  177. }
  178. static void call_binTM (IMS event, char *msg)
  179. {
  180. TObject *im = luaT_getimbyObj(L->stack.top-2, event);/* try first operand */
  181. if (ttype(im) == LUA_T_NIL) {
  182. im = luaT_getimbyObj(L->stack.top-1, event); /* try second operand */
  183. if (ttype(im) == LUA_T_NIL) {
  184. im = luaT_getim(0, event); /* try a 'global' i.m. */
  185. if (ttype(im) == LUA_T_NIL)
  186. lua_error(msg);
  187. }
  188. }
  189. lua_pushstring(luaT_eventname[event]);
  190. luaD_callTM(im, 3, 1);
  191. }
  192. static void call_arith (IMS event)
  193. {
  194. call_binTM(event, "unexpected type in arithmetic operation");
  195. }
  196. static int strcomp (char *l, long ll, char *r, long lr)
  197. {
  198. for (;;) {
  199. long temp = strcoll(l, r);
  200. if (temp != 0) return temp;
  201. /* strings are equal up to a '\0' */
  202. temp = strlen(l); /* index of first '\0' in both strings */
  203. if (temp == ll) /* l is finished? */
  204. return (temp == lr) ? 0 : -1; /* l is equal or smaller than r */
  205. else if (temp == lr) /* r is finished? */
  206. return 1; /* l is greater than r (because l is not finished) */
  207. /* both strings longer than temp; go on comparing (after the '\0') */
  208. temp++;
  209. l += temp; ll -= temp; r += temp; lr -= temp;
  210. }
  211. }
  212. static void comparison (lua_Type ttype_less, lua_Type ttype_equal,
  213. lua_Type ttype_great, IMS op)
  214. {
  215. struct Stack *S = &L->stack;
  216. TObject *l = S->top-2;
  217. TObject *r = S->top-1;
  218. int result;
  219. if (ttype(l) == LUA_T_NUMBER && ttype(r) == LUA_T_NUMBER)
  220. result = (nvalue(l) < nvalue(r)) ? -1 : (nvalue(l) == nvalue(r)) ? 0 : 1;
  221. else if (ttype(l) == LUA_T_STRING && ttype(r) == LUA_T_STRING)
  222. result = strcomp(svalue(l), tsvalue(l)->u.s.len,
  223. svalue(r), tsvalue(r)->u.s.len);
  224. else {
  225. call_binTM(op, "unexpected type in comparison");
  226. return;
  227. }
  228. S->top--;
  229. nvalue(S->top-1) = 1;
  230. ttype(S->top-1) = (result < 0) ? ttype_less :
  231. (result == 0) ? ttype_equal : ttype_great;
  232. }
  233. void luaV_pack (StkId firstel, int nvararg, TObject *tab)
  234. {
  235. TObject *firstelem = L->stack.stack+firstel;
  236. int i;
  237. if (nvararg < 0) nvararg = 0;
  238. avalue(tab) = luaH_new(nvararg+1); /* +1 for field 'n' */
  239. ttype(tab) = LUA_T_ARRAY;
  240. for (i=0; i<nvararg; i++) {
  241. TObject index;
  242. ttype(&index) = LUA_T_NUMBER;
  243. nvalue(&index) = i+1;
  244. *(luaH_set(avalue(tab), &index)) = *(firstelem+i);
  245. }
  246. /* store counter in field "n" */ {
  247. TObject index, extra;
  248. ttype(&index) = LUA_T_STRING;
  249. tsvalue(&index) = luaS_new("n");
  250. ttype(&extra) = LUA_T_NUMBER;
  251. nvalue(&extra) = nvararg;
  252. *(luaH_set(avalue(tab), &index)) = extra;
  253. }
  254. }
  255. static void adjust_varargs (StkId first_extra_arg)
  256. {
  257. TObject arg;
  258. luaV_pack(first_extra_arg,
  259. (L->stack.top-L->stack.stack)-first_extra_arg, &arg);
  260. luaD_adjusttop(first_extra_arg);
  261. *L->stack.top++ = arg;
  262. }
  263. /*
  264. ** Execute the given opcode, until a RET. Parameters are between
  265. ** [stack+base,top). Returns n such that the the results are between
  266. ** [stack+n,top).
  267. */
  268. StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base)
  269. {
  270. struct Stack *S = &L->stack; /* to optimize */
  271. Byte *pc = tf->code;
  272. TObject *consts = tf->consts;
  273. if (lua_callhook)
  274. luaD_callHook(base, tf, 0);
  275. luaD_checkstack((*pc++)+EXTRA_STACK);
  276. if (*pc < ZEROVARARG)
  277. luaD_adjusttop(base+*(pc++));
  278. else { /* varargs */
  279. luaC_checkGC();
  280. adjust_varargs(base+(*pc++)-ZEROVARARG);
  281. }
  282. while (1) {
  283. int aux;
  284. switch ((OpCode)(aux = *pc++)) {
  285. case PUSHNIL0:
  286. ttype(S->top++) = LUA_T_NIL;
  287. break;
  288. case PUSHNIL:
  289. aux = *pc++;
  290. do {
  291. ttype(S->top++) = LUA_T_NIL;
  292. } while (aux--);
  293. break;
  294. case PUSHNUMBER:
  295. aux = *pc++; goto pushnumber;
  296. case PUSHNUMBERW:
  297. aux = next_word(pc); goto pushnumber;
  298. case PUSHNUMBER0: case PUSHNUMBER1: case PUSHNUMBER2:
  299. aux -= PUSHNUMBER0;
  300. pushnumber:
  301. ttype(S->top) = LUA_T_NUMBER;
  302. nvalue(S->top) = aux;
  303. S->top++;
  304. break;
  305. case PUSHLOCAL:
  306. aux = *pc++; goto pushlocal;
  307. case PUSHLOCAL0: case PUSHLOCAL1: case PUSHLOCAL2: case PUSHLOCAL3:
  308. case PUSHLOCAL4: case PUSHLOCAL5: case PUSHLOCAL6: case PUSHLOCAL7:
  309. aux -= PUSHLOCAL0;
  310. pushlocal:
  311. *S->top++ = *((S->stack+base) + aux);
  312. break;
  313. case GETGLOBALW:
  314. aux = next_word(pc); goto getglobal;
  315. case GETGLOBAL:
  316. aux = *pc++; goto getglobal;
  317. case GETGLOBAL0: case GETGLOBAL1: case GETGLOBAL2: case GETGLOBAL3:
  318. case GETGLOBAL4: case GETGLOBAL5: case GETGLOBAL6: case GETGLOBAL7:
  319. aux -= GETGLOBAL0;
  320. getglobal:
  321. luaV_getglobal(tsvalue(&consts[aux]));
  322. break;
  323. case GETTABLE:
  324. luaV_gettable();
  325. break;
  326. case GETDOTTEDW:
  327. aux = next_word(pc); goto getdotted;
  328. case GETDOTTED:
  329. aux = *pc++; goto getdotted;
  330. case GETDOTTED0: case GETDOTTED1: case GETDOTTED2: case GETDOTTED3:
  331. case GETDOTTED4: case GETDOTTED5: case GETDOTTED6: case GETDOTTED7:
  332. aux -= GETDOTTED0;
  333. getdotted:
  334. *S->top++ = consts[aux];
  335. luaV_gettable();
  336. break;
  337. case PUSHSELFW:
  338. aux = next_word(pc); goto pushself;
  339. case PUSHSELF:
  340. aux = *pc++; goto pushself;
  341. case PUSHSELF0: case PUSHSELF1: case PUSHSELF2: case PUSHSELF3:
  342. case PUSHSELF4: case PUSHSELF5: case PUSHSELF6: case PUSHSELF7:
  343. aux -= PUSHSELF0;
  344. pushself: {
  345. TObject receiver = *(S->top-1);
  346. *S->top++ = consts[aux];
  347. luaV_gettable();
  348. *S->top++ = receiver;
  349. break;
  350. }
  351. case PUSHCONSTANTW:
  352. aux = next_word(pc); goto pushconstant;
  353. case PUSHCONSTANT:
  354. aux = *pc++; goto pushconstant;
  355. case PUSHCONSTANT0: case PUSHCONSTANT1: case PUSHCONSTANT2:
  356. case PUSHCONSTANT3: case PUSHCONSTANT4: case PUSHCONSTANT5:
  357. case PUSHCONSTANT6: case PUSHCONSTANT7:
  358. aux -= PUSHCONSTANT0;
  359. pushconstant:
  360. *S->top++ = consts[aux];
  361. break;
  362. case PUSHUPVALUE:
  363. aux = *pc++; goto pushupvalue;
  364. case PUSHUPVALUE0: case PUSHUPVALUE1:
  365. aux -= PUSHUPVALUE0;
  366. pushupvalue:
  367. *S->top++ = cl->consts[aux+1];
  368. break;
  369. case SETLOCAL:
  370. aux = *pc++; goto setlocal;
  371. case SETLOCAL0: case SETLOCAL1: case SETLOCAL2: case SETLOCAL3:
  372. case SETLOCAL4: case SETLOCAL5: case SETLOCAL6: case SETLOCAL7:
  373. aux -= SETLOCAL0;
  374. setlocal:
  375. *((S->stack+base) + aux) = *(--S->top);
  376. break;
  377. case SETGLOBALW:
  378. aux = next_word(pc); goto setglobal;
  379. case SETGLOBAL:
  380. aux = *pc++; goto setglobal;
  381. case SETGLOBAL0: case SETGLOBAL1: case SETGLOBAL2: case SETGLOBAL3:
  382. case SETGLOBAL4: case SETGLOBAL5: case SETGLOBAL6: case SETGLOBAL7:
  383. aux -= SETGLOBAL0;
  384. setglobal:
  385. luaV_setglobal(tsvalue(&consts[aux]));
  386. break;
  387. case SETTABLE0:
  388. luaV_settable(S->top-3, 1);
  389. break;
  390. case SETTABLE:
  391. luaV_settable(S->top-3-(*pc++), 2);
  392. break;
  393. case SETLISTW:
  394. aux = next_word(pc); aux *= LFIELDS_PER_FLUSH; goto setlist;
  395. case SETLIST:
  396. aux = *(pc++) * LFIELDS_PER_FLUSH; goto setlist;
  397. case SETLIST0:
  398. aux = 0;
  399. setlist: {
  400. int n = *(pc++);
  401. TObject *arr = S->top-n-1;
  402. for (; n; n--) {
  403. ttype(S->top) = LUA_T_NUMBER;
  404. nvalue(S->top) = n+aux;
  405. *(luaH_set(avalue(arr), S->top)) = *(S->top-1);
  406. S->top--;
  407. }
  408. break;
  409. }
  410. case SETMAP0:
  411. aux = 0; goto setmap;
  412. case SETMAP:
  413. aux = *pc++;
  414. setmap: {
  415. TObject *arr = S->top-(2*aux)-3;
  416. do {
  417. *(luaH_set(avalue(arr), S->top-2)) = *(S->top-1);
  418. S->top-=2;
  419. } while (aux--);
  420. break;
  421. }
  422. case POP:
  423. aux = *pc++; goto pop;
  424. case POP0: case POP1:
  425. aux -= POP0;
  426. pop:
  427. S->top -= (aux+1);
  428. break;
  429. case CREATEARRAYW:
  430. aux = next_word(pc); goto createarray;
  431. case CREATEARRAY0: case CREATEARRAY1:
  432. aux -= CREATEARRAY0; goto createarray;
  433. case CREATEARRAY:
  434. aux = *pc++;
  435. createarray:
  436. luaC_checkGC();
  437. avalue(S->top) = luaH_new(aux);
  438. ttype(S->top) = LUA_T_ARRAY;
  439. S->top++;
  440. break;
  441. case EQOP: case NEQOP: {
  442. int res = luaO_equalObj(S->top-2, S->top-1);
  443. S->top--;
  444. if (aux == NEQOP) res = !res;
  445. ttype(S->top-1) = res ? LUA_T_NUMBER : LUA_T_NIL;
  446. nvalue(S->top-1) = 1;
  447. break;
  448. }
  449. case LTOP:
  450. comparison(LUA_T_NUMBER, LUA_T_NIL, LUA_T_NIL, IM_LT);
  451. break;
  452. case LEOP:
  453. comparison(LUA_T_NUMBER, LUA_T_NUMBER, LUA_T_NIL, IM_LE);
  454. break;
  455. case GTOP:
  456. comparison(LUA_T_NIL, LUA_T_NIL, LUA_T_NUMBER, IM_GT);
  457. break;
  458. case GEOP:
  459. comparison(LUA_T_NIL, LUA_T_NUMBER, LUA_T_NUMBER, IM_GE);
  460. break;
  461. case ADDOP: {
  462. TObject *l = S->top-2;
  463. TObject *r = S->top-1;
  464. if (tonumber(r) || tonumber(l))
  465. call_arith(IM_ADD);
  466. else {
  467. nvalue(l) += nvalue(r);
  468. --S->top;
  469. }
  470. break;
  471. }
  472. case SUBOP: {
  473. TObject *l = S->top-2;
  474. TObject *r = S->top-1;
  475. if (tonumber(r) || tonumber(l))
  476. call_arith(IM_SUB);
  477. else {
  478. nvalue(l) -= nvalue(r);
  479. --S->top;
  480. }
  481. break;
  482. }
  483. case MULTOP: {
  484. TObject *l = S->top-2;
  485. TObject *r = S->top-1;
  486. if (tonumber(r) || tonumber(l))
  487. call_arith(IM_MUL);
  488. else {
  489. nvalue(l) *= nvalue(r);
  490. --S->top;
  491. }
  492. break;
  493. }
  494. case DIVOP: {
  495. TObject *l = S->top-2;
  496. TObject *r = S->top-1;
  497. if (tonumber(r) || tonumber(l))
  498. call_arith(IM_DIV);
  499. else {
  500. nvalue(l) /= nvalue(r);
  501. --S->top;
  502. }
  503. break;
  504. }
  505. case POWOP:
  506. call_binTM(IM_POW, "undefined operation");
  507. break;
  508. case CONCOP: {
  509. TObject *l = S->top-2;
  510. TObject *r = S->top-1;
  511. if (tostring(l) || tostring(r))
  512. call_binTM(IM_CONCAT, "unexpected type for concatenation");
  513. else {
  514. tsvalue(l) = strconc(tsvalue(l), tsvalue(r));
  515. --S->top;
  516. }
  517. luaC_checkGC();
  518. break;
  519. }
  520. case MINUSOP:
  521. if (tonumber(S->top-1)) {
  522. ttype(S->top) = LUA_T_NIL;
  523. S->top++;
  524. call_arith(IM_UNM);
  525. }
  526. else
  527. nvalue(S->top-1) = - nvalue(S->top-1);
  528. break;
  529. case NOTOP:
  530. ttype(S->top-1) =
  531. (ttype(S->top-1) == LUA_T_NIL) ? LUA_T_NUMBER : LUA_T_NIL;
  532. nvalue(S->top-1) = 1;
  533. break;
  534. case ONTJMPW:
  535. aux = next_word(pc); goto ontjmp;
  536. case ONTJMP:
  537. aux = *pc++;
  538. ontjmp:
  539. if (ttype(S->top-1) != LUA_T_NIL) pc += aux;
  540. else S->top--;
  541. break;
  542. case ONFJMPW:
  543. aux = next_word(pc); goto onfjmp;
  544. case ONFJMP:
  545. aux = *pc++;
  546. onfjmp:
  547. if (ttype(S->top-1) == LUA_T_NIL) pc += aux;
  548. else S->top--;
  549. break;
  550. case JMPW:
  551. aux = next_word(pc); goto jmp;
  552. case JMP:
  553. aux = *pc++;
  554. jmp:
  555. pc += aux;
  556. break;
  557. case IFFJMPW:
  558. aux = next_word(pc); goto iffjmp;
  559. case IFFJMP:
  560. aux = *pc++;
  561. iffjmp:
  562. if (ttype(--S->top) == LUA_T_NIL) pc += aux;
  563. break;
  564. case IFTUPJMPW:
  565. aux = next_word(pc); goto iftupjmp;
  566. case IFTUPJMP:
  567. aux = *pc++;
  568. iftupjmp:
  569. if (ttype(--S->top) != LUA_T_NIL) pc -= aux;
  570. break;
  571. case IFFUPJMPW:
  572. aux = next_word(pc); goto iffupjmp;
  573. case IFFUPJMP:
  574. aux = *pc++;
  575. iffupjmp:
  576. if (ttype(--S->top) == LUA_T_NIL) pc -= aux;
  577. break;
  578. case CLOSUREW:
  579. aux = next_word(pc); goto closure;
  580. case CLOSURE:
  581. aux = *pc++;
  582. closure:
  583. *S->top++ = consts[aux];
  584. luaV_closure(*pc++);
  585. luaC_checkGC();
  586. break;
  587. case CALLFUNC:
  588. aux = *pc++; goto callfunc;
  589. case CALLFUNC0: case CALLFUNC1:
  590. aux -= CALLFUNC0;
  591. callfunc: {
  592. StkId newBase = (S->top-S->stack)-(*pc++);
  593. luaD_call(newBase, aux);
  594. break;
  595. }
  596. case ENDCODE:
  597. S->top = S->stack + base;
  598. /* goes through */
  599. case RETCODE:
  600. if (lua_callhook)
  601. luaD_callHook(base, NULL, 1);
  602. return (base + ((aux==RETCODE) ? *pc : 0));
  603. case SETLINEW:
  604. aux = next_word(pc); goto setline;
  605. case SETLINE:
  606. aux = *pc++;
  607. setline:
  608. if ((S->stack+base-1)->ttype != LUA_T_LINE) {
  609. /* open space for LINE value */
  610. luaD_openstack((S->top-S->stack)-base);
  611. base++;
  612. (S->stack+base-1)->ttype = LUA_T_LINE;
  613. }
  614. (S->stack+base-1)->value.i = aux;
  615. if (lua_linehook)
  616. luaD_lineHook(aux);
  617. break;
  618. #ifdef DEBUG
  619. default:
  620. LUA_INTERNALERROR("opcode doesn't match");
  621. #endif
  622. }
  623. }
  624. }