lvm.c 17 KB

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