lvm.c 19 KB

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