2
0

lvm.c 17 KB

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