lvm.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. /*
  2. ** $Id: lvm.c,v 1.30 1998/06/11 18:21:37 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 (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. void luaV_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. Hash *htab;
  238. if (nvararg < 0) nvararg = 0;
  239. htab = avalue(tab) = luaH_new(nvararg+1); /* +1 for field 'n' */
  240. ttype(tab) = LUA_T_ARRAY;
  241. for (i=0; i<nvararg; i++)
  242. luaH_setint(htab, i+1, firstelem+i);
  243. /* store counter in field "n" */ {
  244. TObject index, extra;
  245. ttype(&index) = LUA_T_STRING;
  246. tsvalue(&index) = luaS_new("n");
  247. ttype(&extra) = LUA_T_NUMBER;
  248. nvalue(&extra) = nvararg;
  249. *(luaH_set(htab, &index)) = extra;
  250. }
  251. }
  252. static void adjust_varargs (StkId first_extra_arg)
  253. {
  254. TObject arg;
  255. luaV_pack(first_extra_arg,
  256. (L->stack.top-L->stack.stack)-first_extra_arg, &arg);
  257. luaD_adjusttop(first_extra_arg);
  258. *L->stack.top++ = arg;
  259. }
  260. /*
  261. ** Execute the given opcode, until a RET. Parameters are between
  262. ** [stack+base,top). Returns n such that the the results are between
  263. ** [stack+n,top).
  264. */
  265. StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base)
  266. {
  267. struct Stack *S = &L->stack; /* to optimize */
  268. Byte *pc = tf->code;
  269. TObject *consts = tf->consts;
  270. if (lua_callhook)
  271. luaD_callHook(base, tf, 0);
  272. luaD_checkstack((*pc++)+EXTRA_STACK);
  273. if (*pc < ZEROVARARG)
  274. luaD_adjusttop(base+*(pc++));
  275. else { /* varargs */
  276. luaC_checkGC();
  277. adjust_varargs(base+(*pc++)-ZEROVARARG);
  278. }
  279. while (1) {
  280. int aux;
  281. switch ((OpCode)(aux = *pc++)) {
  282. case PUSHNIL0:
  283. ttype(S->top++) = LUA_T_NIL;
  284. break;
  285. case PUSHNIL:
  286. aux = *pc++;
  287. do {
  288. ttype(S->top++) = LUA_T_NIL;
  289. } while (aux--);
  290. break;
  291. case PUSHNUMBER:
  292. aux = *pc++; goto pushnumber;
  293. case PUSHNUMBERW:
  294. aux = next_word(pc); goto pushnumber;
  295. case PUSHNUMBER0: case PUSHNUMBER1: case PUSHNUMBER2:
  296. aux -= PUSHNUMBER0;
  297. pushnumber:
  298. ttype(S->top) = LUA_T_NUMBER;
  299. nvalue(S->top) = aux;
  300. S->top++;
  301. break;
  302. case PUSHLOCAL:
  303. aux = *pc++; goto pushlocal;
  304. case PUSHLOCAL0: case PUSHLOCAL1: case PUSHLOCAL2: case PUSHLOCAL3:
  305. case PUSHLOCAL4: case PUSHLOCAL5: case PUSHLOCAL6: case PUSHLOCAL7:
  306. aux -= PUSHLOCAL0;
  307. pushlocal:
  308. *S->top++ = *((S->stack+base) + aux);
  309. break;
  310. case GETGLOBALW:
  311. aux = next_word(pc); goto getglobal;
  312. case GETGLOBAL:
  313. aux = *pc++; goto getglobal;
  314. case GETGLOBAL0: case GETGLOBAL1: case GETGLOBAL2: case GETGLOBAL3:
  315. case GETGLOBAL4: case GETGLOBAL5: case GETGLOBAL6: case GETGLOBAL7:
  316. aux -= GETGLOBAL0;
  317. getglobal:
  318. luaV_getglobal(tsvalue(&consts[aux]));
  319. break;
  320. case GETTABLE:
  321. luaV_gettable();
  322. break;
  323. case GETDOTTEDW:
  324. aux = next_word(pc); goto getdotted;
  325. case GETDOTTED:
  326. aux = *pc++; goto getdotted;
  327. case GETDOTTED0: case GETDOTTED1: case GETDOTTED2: case GETDOTTED3:
  328. case GETDOTTED4: case GETDOTTED5: case GETDOTTED6: case GETDOTTED7:
  329. aux -= GETDOTTED0;
  330. getdotted:
  331. *S->top++ = consts[aux];
  332. luaV_gettable();
  333. break;
  334. case PUSHSELFW:
  335. aux = next_word(pc); goto pushself;
  336. case PUSHSELF:
  337. aux = *pc++; goto pushself;
  338. case PUSHSELF0: case PUSHSELF1: case PUSHSELF2: case PUSHSELF3:
  339. case PUSHSELF4: case PUSHSELF5: case PUSHSELF6: case PUSHSELF7:
  340. aux -= PUSHSELF0;
  341. pushself: {
  342. TObject receiver = *(S->top-1);
  343. *S->top++ = consts[aux];
  344. luaV_gettable();
  345. *S->top++ = receiver;
  346. break;
  347. }
  348. case PUSHCONSTANTW:
  349. aux = next_word(pc); goto pushconstant;
  350. case PUSHCONSTANT:
  351. aux = *pc++; goto pushconstant;
  352. case PUSHCONSTANT0: case PUSHCONSTANT1: case PUSHCONSTANT2:
  353. case PUSHCONSTANT3: case PUSHCONSTANT4: case PUSHCONSTANT5:
  354. case PUSHCONSTANT6: case PUSHCONSTANT7:
  355. aux -= PUSHCONSTANT0;
  356. pushconstant:
  357. *S->top++ = consts[aux];
  358. break;
  359. case PUSHUPVALUE:
  360. aux = *pc++; goto pushupvalue;
  361. case PUSHUPVALUE0: case PUSHUPVALUE1:
  362. aux -= PUSHUPVALUE0;
  363. pushupvalue:
  364. *S->top++ = cl->consts[aux+1];
  365. break;
  366. case SETLOCAL:
  367. aux = *pc++; goto setlocal;
  368. case SETLOCAL0: case SETLOCAL1: case SETLOCAL2: case SETLOCAL3:
  369. case SETLOCAL4: case SETLOCAL5: case SETLOCAL6: case SETLOCAL7:
  370. aux -= SETLOCAL0;
  371. setlocal:
  372. *((S->stack+base) + aux) = *(--S->top);
  373. break;
  374. case SETGLOBALW:
  375. aux = next_word(pc); goto setglobal;
  376. case SETGLOBAL:
  377. aux = *pc++; goto setglobal;
  378. case SETGLOBAL0: case SETGLOBAL1: case SETGLOBAL2: case SETGLOBAL3:
  379. case SETGLOBAL4: case SETGLOBAL5: case SETGLOBAL6: case SETGLOBAL7:
  380. aux -= SETGLOBAL0;
  381. setglobal:
  382. luaV_setglobal(tsvalue(&consts[aux]));
  383. break;
  384. case SETTABLE0:
  385. luaV_settable(S->top-3, 1);
  386. break;
  387. case SETTABLE:
  388. luaV_settable(S->top-3-(*pc++), 2);
  389. break;
  390. case SETLISTW:
  391. aux = next_word(pc); aux *= LFIELDS_PER_FLUSH; goto setlist;
  392. case SETLIST:
  393. aux = *(pc++) * LFIELDS_PER_FLUSH; goto setlist;
  394. case SETLIST0:
  395. aux = 0;
  396. setlist: {
  397. int n = *(pc++);
  398. TObject *arr = S->top-n-1;
  399. for (; n; n--) {
  400. ttype(S->top) = LUA_T_NUMBER;
  401. nvalue(S->top) = n+aux;
  402. *(luaH_set(avalue(arr), S->top)) = *(S->top-1);
  403. S->top--;
  404. }
  405. break;
  406. }
  407. case SETMAP0:
  408. aux = 0; goto setmap;
  409. case SETMAP:
  410. aux = *pc++;
  411. setmap: {
  412. TObject *arr = S->top-(2*aux)-3;
  413. do {
  414. *(luaH_set(avalue(arr), S->top-2)) = *(S->top-1);
  415. S->top-=2;
  416. } while (aux--);
  417. break;
  418. }
  419. case POP:
  420. aux = *pc++; goto pop;
  421. case POP0: case POP1:
  422. aux -= POP0;
  423. pop:
  424. S->top -= (aux+1);
  425. break;
  426. case CREATEARRAYW:
  427. aux = next_word(pc); goto createarray;
  428. case CREATEARRAY0: case CREATEARRAY1:
  429. aux -= CREATEARRAY0; goto createarray;
  430. case CREATEARRAY:
  431. aux = *pc++;
  432. createarray:
  433. luaC_checkGC();
  434. avalue(S->top) = luaH_new(aux);
  435. ttype(S->top) = LUA_T_ARRAY;
  436. S->top++;
  437. break;
  438. case EQOP: case NEQOP: {
  439. int res = luaO_equalObj(S->top-2, S->top-1);
  440. S->top--;
  441. if (aux == NEQOP) res = !res;
  442. ttype(S->top-1) = res ? LUA_T_NUMBER : LUA_T_NIL;
  443. nvalue(S->top-1) = 1;
  444. break;
  445. }
  446. case LTOP:
  447. luaV_comparison(LUA_T_NUMBER, LUA_T_NIL, LUA_T_NIL, IM_LT);
  448. break;
  449. case LEOP:
  450. luaV_comparison(LUA_T_NUMBER, LUA_T_NUMBER, LUA_T_NIL, IM_LE);
  451. break;
  452. case GTOP:
  453. luaV_comparison(LUA_T_NIL, LUA_T_NIL, LUA_T_NUMBER, IM_GT);
  454. break;
  455. case GEOP:
  456. luaV_comparison(LUA_T_NIL, LUA_T_NUMBER, LUA_T_NUMBER, IM_GE);
  457. break;
  458. case ADDOP: {
  459. TObject *l = S->top-2;
  460. TObject *r = S->top-1;
  461. if (tonumber(r) || tonumber(l))
  462. call_arith(IM_ADD);
  463. else {
  464. nvalue(l) += nvalue(r);
  465. --S->top;
  466. }
  467. break;
  468. }
  469. case SUBOP: {
  470. TObject *l = S->top-2;
  471. TObject *r = S->top-1;
  472. if (tonumber(r) || tonumber(l))
  473. call_arith(IM_SUB);
  474. else {
  475. nvalue(l) -= nvalue(r);
  476. --S->top;
  477. }
  478. break;
  479. }
  480. case MULTOP: {
  481. TObject *l = S->top-2;
  482. TObject *r = S->top-1;
  483. if (tonumber(r) || tonumber(l))
  484. call_arith(IM_MUL);
  485. else {
  486. nvalue(l) *= nvalue(r);
  487. --S->top;
  488. }
  489. break;
  490. }
  491. case DIVOP: {
  492. TObject *l = S->top-2;
  493. TObject *r = S->top-1;
  494. if (tonumber(r) || tonumber(l))
  495. call_arith(IM_DIV);
  496. else {
  497. nvalue(l) /= nvalue(r);
  498. --S->top;
  499. }
  500. break;
  501. }
  502. case POWOP:
  503. call_binTM(IM_POW, "undefined operation");
  504. break;
  505. case CONCOP: {
  506. TObject *l = S->top-2;
  507. TObject *r = S->top-1;
  508. if (tostring(l) || tostring(r))
  509. call_binTM(IM_CONCAT, "unexpected type for concatenation");
  510. else {
  511. tsvalue(l) = strconc(tsvalue(l), tsvalue(r));
  512. --S->top;
  513. }
  514. luaC_checkGC();
  515. break;
  516. }
  517. case MINUSOP:
  518. if (tonumber(S->top-1)) {
  519. ttype(S->top) = LUA_T_NIL;
  520. S->top++;
  521. call_arith(IM_UNM);
  522. }
  523. else
  524. nvalue(S->top-1) = - nvalue(S->top-1);
  525. break;
  526. case NOTOP:
  527. ttype(S->top-1) =
  528. (ttype(S->top-1) == LUA_T_NIL) ? LUA_T_NUMBER : LUA_T_NIL;
  529. nvalue(S->top-1) = 1;
  530. break;
  531. case ONTJMPW:
  532. aux = next_word(pc); goto ontjmp;
  533. case ONTJMP:
  534. aux = *pc++;
  535. ontjmp:
  536. if (ttype(S->top-1) != LUA_T_NIL) pc += aux;
  537. else S->top--;
  538. break;
  539. case ONFJMPW:
  540. aux = next_word(pc); goto onfjmp;
  541. case ONFJMP:
  542. aux = *pc++;
  543. onfjmp:
  544. if (ttype(S->top-1) == LUA_T_NIL) pc += aux;
  545. else S->top--;
  546. break;
  547. case JMPW:
  548. aux = next_word(pc); goto jmp;
  549. case JMP:
  550. aux = *pc++;
  551. jmp:
  552. pc += aux;
  553. break;
  554. case IFFJMPW:
  555. aux = next_word(pc); goto iffjmp;
  556. case IFFJMP:
  557. aux = *pc++;
  558. iffjmp:
  559. if (ttype(--S->top) == LUA_T_NIL) pc += aux;
  560. break;
  561. case IFTUPJMPW:
  562. aux = next_word(pc); goto iftupjmp;
  563. case IFTUPJMP:
  564. aux = *pc++;
  565. iftupjmp:
  566. if (ttype(--S->top) != LUA_T_NIL) pc -= aux;
  567. break;
  568. case IFFUPJMPW:
  569. aux = next_word(pc); goto iffupjmp;
  570. case IFFUPJMP:
  571. aux = *pc++;
  572. iffupjmp:
  573. if (ttype(--S->top) == LUA_T_NIL) pc -= aux;
  574. break;
  575. case CLOSUREW:
  576. aux = next_word(pc); goto closure;
  577. case CLOSURE:
  578. aux = *pc++;
  579. closure:
  580. *S->top++ = consts[aux];
  581. luaV_closure(*pc++);
  582. luaC_checkGC();
  583. break;
  584. case CALLFUNC:
  585. aux = *pc++; goto callfunc;
  586. case CALLFUNC0: case CALLFUNC1:
  587. aux -= CALLFUNC0;
  588. callfunc: {
  589. StkId newBase = (S->top-S->stack)-(*pc++);
  590. luaD_call(newBase, aux);
  591. break;
  592. }
  593. case ENDCODE:
  594. S->top = S->stack + base;
  595. /* goes through */
  596. case RETCODE:
  597. if (lua_callhook)
  598. luaD_callHook(base, NULL, 1);
  599. return (base + ((aux==RETCODE) ? *pc : 0));
  600. case SETLINEW:
  601. aux = next_word(pc); goto setline;
  602. case SETLINE:
  603. aux = *pc++;
  604. setline:
  605. if ((S->stack+base-1)->ttype != LUA_T_LINE) {
  606. /* open space for LINE value */
  607. luaD_openstack((S->top-S->stack)-base);
  608. base++;
  609. (S->stack+base-1)->ttype = LUA_T_LINE;
  610. }
  611. (S->stack+base-1)->value.i = aux;
  612. if (lua_linehook)
  613. luaD_lineHook(aux);
  614. break;
  615. #ifdef DEBUG
  616. default:
  617. LUA_INTERNALERROR("opcode doesn't match");
  618. #endif
  619. }
  620. }
  621. }