lua.stx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  1. %{
  2. char *rcs_luastx = "$Id: lua.stx,v 1.4 1994/02/13 20:38:20 roberto Exp celes $";
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include "mm.h"
  7. #include "opcode.h"
  8. #include "hash.h"
  9. #include "inout.h"
  10. #include "table.h"
  11. #include "lua.h"
  12. #define LISTING 0
  13. #ifndef ALIGNMENT
  14. #define ALIGNMENT (sizeof(void *))
  15. #endif
  16. #ifndef MAXCODE
  17. #define MAXCODE 1024
  18. #endif
  19. static long buffer[MAXCODE*sizeof(Byte)/sizeof(long)];
  20. static Byte *code = (Byte *)buffer;
  21. static long mainbuffer[MAXCODE];
  22. static Byte *maincode = (Byte *)mainbuffer;
  23. static Byte *basepc;
  24. static Byte *pc;
  25. #define MAXVAR 32
  26. static long varbuffer[MAXVAR]; /* variables in an assignment list;
  27. it's long to store negative Word values */
  28. static int nvarbuffer=0; /* number of variables at a list */
  29. static Word localvar[STACKGAP]; /* store local variable names */
  30. static int nlocalvar=0; /* number of local variables */
  31. #define MAXFIELDS FIELDS_PER_FLUSH*2
  32. static Word fields[MAXFIELDS]; /* fieldnames to be flushed */
  33. static int nfields=0;
  34. static int ntemp; /* number of temporary var into stack */
  35. static int err; /* flag to indicate error */
  36. /* Internal functions */
  37. static void code_byte (Byte c)
  38. {
  39. if (pc-basepc>MAXCODE-1)
  40. {
  41. lua_error ("code buffer overflow");
  42. err = 1;
  43. }
  44. *pc++ = c;
  45. }
  46. #define align(t,n) align_n(sizeof(t),n)
  47. static void align_n (unsigned size, int gap)
  48. {
  49. if (size > ALIGNMENT) size = ALIGNMENT;
  50. while (((pc+gap-code)%size) != 0) /* +gap to include BYTECODEs */
  51. code_byte (NOP);
  52. }
  53. static void code_word (Word n)
  54. {
  55. if (pc-basepc>MAXCODE-sizeof(Word))
  56. {
  57. lua_error ("code buffer overflow");
  58. err = 1;
  59. }
  60. *((Word *)pc) = n;
  61. pc += sizeof(Word);
  62. }
  63. static void code_float (float n)
  64. {
  65. if (pc-basepc>MAXCODE-sizeof(float))
  66. {
  67. lua_error ("code buffer overflow");
  68. err = 1;
  69. }
  70. *((float *)pc) = n;
  71. pc += sizeof(float);
  72. }
  73. static void push_field (Word name)
  74. {
  75. if (nfields < STACKGAP-1)
  76. fields[nfields++] = name;
  77. else
  78. {
  79. lua_error ("too many fields in a constructor");
  80. err = 1;
  81. }
  82. }
  83. static void flush_record (int n)
  84. {
  85. int i;
  86. if (n == 0) return;
  87. align(Word,2); /* two bytes before the actual word */
  88. code_byte(STORERECORD);
  89. code_byte(n);
  90. for (i=0; i<n; i++)
  91. code_word(lua_findconstant(s_name(fields[--nfields])));
  92. ntemp -= n;
  93. }
  94. static void flush_list (int m, int n)
  95. {
  96. if (n == 0) return;
  97. if (m == 0)
  98. code_byte(STORELIST0);
  99. else
  100. {
  101. code_byte(STORELIST);
  102. code_byte(m);
  103. }
  104. code_byte(n);
  105. ntemp-=n;
  106. }
  107. static void incr_ntemp (void)
  108. {
  109. if (ntemp+nlocalvar+MAXVAR+1 < STACKGAP)
  110. ntemp++;
  111. else
  112. {
  113. lua_error ("stack overflow");
  114. err = 1;
  115. }
  116. }
  117. static void add_nlocalvar (int n)
  118. {
  119. if (ntemp+nlocalvar+MAXVAR+n < STACKGAP)
  120. nlocalvar += n;
  121. else
  122. {
  123. lua_error ("too many local variables or expression too complicate");
  124. err = 1;
  125. }
  126. }
  127. static void incr_nvarbuffer (void)
  128. {
  129. if (nvarbuffer < MAXVAR-1)
  130. nvarbuffer++;
  131. else
  132. {
  133. lua_error ("variable buffer overflow");
  134. err = 1;
  135. }
  136. }
  137. static void code_number (float f)
  138. { Word i = (Word)f;
  139. if (f == (float)i) /* f has an (short) integer value */
  140. {
  141. if (i <= 2) code_byte(PUSH0 + i);
  142. else if (i <= 255)
  143. {
  144. code_byte(PUSHBYTE);
  145. code_byte(i);
  146. }
  147. else
  148. {
  149. align(Word,1);
  150. code_byte(PUSHWORD);
  151. code_word(i);
  152. }
  153. }
  154. else
  155. {
  156. align(float,1);
  157. code_byte(PUSHFLOAT);
  158. code_float(f);
  159. }
  160. incr_ntemp();
  161. }
  162. %}
  163. %union
  164. {
  165. int vInt;
  166. long vLong;
  167. float vFloat;
  168. Word vWord;
  169. Byte *pByte;
  170. }
  171. %start functionlist
  172. %token WRONGTOKEN
  173. %token NIL
  174. %token IF THEN ELSE ELSEIF WHILE DO REPEAT UNTIL END
  175. %token RETURN
  176. %token LOCAL
  177. %token <vFloat> NUMBER
  178. %token <vWord> FUNCTION NAME STRING
  179. %token <vInt> DEBUG
  180. %type <pByte> PrepJump
  181. %type <vInt> expr, exprlist, exprlist1, varlist1, typeconstructor
  182. %type <vInt> fieldlist, localdeclist
  183. %type <vInt> ffieldlist, ffieldlist1
  184. %type <vInt> lfieldlist, lfieldlist1
  185. %type <vLong> var, objectname
  186. %left AND OR
  187. %left '=' NE '>' '<' LE GE
  188. %left CONC
  189. %left '+' '-'
  190. %left '*' '/'
  191. %left UNARY NOT
  192. %% /* beginning of rules section */
  193. functionlist : /* empty */
  194. | functionlist { pc=basepc=maincode; nlocalvar=0;} stat sc
  195. {
  196. maincode=pc;
  197. #if LISTING
  198. PrintCode(basepc,maincode);
  199. #endif
  200. }
  201. | functionlist function
  202. | functionlist setdebug
  203. ;
  204. function : FUNCTION NAME {pc=basepc=code; nlocalvar=0;} '(' parlist ')'
  205. {
  206. if (lua_debug)
  207. {
  208. align(Word,1);
  209. code_byte(SETFUNCTION);
  210. code_word(lua_nfile-1);
  211. code_word($2);
  212. }
  213. lua_codeadjust (0);
  214. }
  215. block
  216. END
  217. {
  218. if (lua_debug) code_byte(RESET);
  219. code_byte(RETCODE); code_byte(nlocalvar);
  220. s_tag($2) = T_FUNCTION;
  221. s_bvalue($2) = calloc (pc-code, sizeof(Byte));
  222. memcpy (s_bvalue($2), code, (pc-code)*sizeof(Byte));
  223. #if LISTING
  224. PrintCode(code,pc);
  225. #endif
  226. }
  227. ;
  228. statlist : /* empty */
  229. | statlist stat sc
  230. ;
  231. stat : {
  232. ntemp = 0;
  233. if (lua_debug)
  234. {
  235. align(Word,1); code_byte(SETLINE); code_word(lua_linenumber);
  236. }
  237. }
  238. stat1
  239. sc : /* empty */ | ';' ;
  240. stat1 : IF expr1 THEN PrepJump block PrepJump elsepart END
  241. {
  242. {
  243. Byte *elseinit = $6 + sizeof(Word)+1;
  244. if (pc - elseinit == 0) /* no else */
  245. {
  246. pc -= sizeof(Word)+1;
  247. /* if (*(pc-1) == NOP) --pc; */
  248. elseinit = pc;
  249. }
  250. else
  251. {
  252. *($6) = JMP;
  253. *((Word *)($6+1)) = pc - elseinit;
  254. }
  255. *($4) = IFFJMP;
  256. *((Word *)($4+1)) = elseinit - ($4 + sizeof(Word)+1);
  257. }
  258. }
  259. | WHILE {$<pByte>$ = pc;} expr1 DO PrepJump block PrepJump END
  260. {
  261. *($5) = IFFJMP;
  262. *((Word *)($5+1)) = pc - ($5 + sizeof(Word)+1);
  263. *($7) = UPJMP;
  264. *((Word *)($7+1)) = pc - $<pByte>2;
  265. }
  266. | REPEAT {$<pByte>$ = pc;} block UNTIL expr1 PrepJump
  267. {
  268. *($6) = IFFUPJMP;
  269. *((Word *)($6+1)) = pc - $<pByte>2;
  270. }
  271. | varlist1 '=' exprlist1
  272. {
  273. {
  274. int i;
  275. if ($3 == 0 || nvarbuffer != ntemp - $1 * 2)
  276. lua_codeadjust ($1 * 2 + nvarbuffer);
  277. for (i=nvarbuffer-1; i>=0; i--)
  278. lua_codestore (i);
  279. if ($1 > 1 || ($1 == 1 && varbuffer[0] != 0))
  280. lua_codeadjust (0);
  281. }
  282. }
  283. | functioncall { lua_codeadjust (0); }
  284. | typeconstructor { lua_codeadjust (0); }
  285. | LOCAL localdeclist decinit { add_nlocalvar($2); lua_codeadjust (0); }
  286. ;
  287. elsepart : /* empty */
  288. | ELSE block
  289. | ELSEIF expr1 THEN PrepJump block PrepJump elsepart
  290. {
  291. {
  292. Byte *elseinit = $6 + sizeof(Word)+1;
  293. if (pc - elseinit == 0) /* no else */
  294. {
  295. pc -= sizeof(Word)+1;
  296. /* if (*(pc-1) == NOP) --pc; */
  297. elseinit = pc;
  298. }
  299. else
  300. {
  301. *($6) = JMP;
  302. *((Word *)($6+1)) = pc - elseinit;
  303. }
  304. *($4) = IFFJMP;
  305. *((Word *)($4+1)) = elseinit - ($4 + sizeof(Word)+1);
  306. }
  307. }
  308. ;
  309. block : {$<vInt>$ = nlocalvar;} statlist {ntemp = 0;} ret
  310. {
  311. if (nlocalvar != $<vInt>1)
  312. {
  313. nlocalvar = $<vInt>1;
  314. lua_codeadjust (0);
  315. }
  316. }
  317. ;
  318. ret : /* empty */
  319. | { if (lua_debug){align(Word,1);code_byte(SETLINE);code_word(lua_linenumber);}}
  320. RETURN exprlist sc
  321. {
  322. if (lua_debug) code_byte(RESET);
  323. code_byte(RETCODE); code_byte(nlocalvar);
  324. }
  325. ;
  326. PrepJump : /* empty */
  327. {
  328. align(Word,1);
  329. $$ = pc;
  330. code_byte(0); /* open space */
  331. code_word (0);
  332. }
  333. expr1 : expr { if ($1 == 0) {lua_codeadjust (ntemp+1); incr_ntemp();}}
  334. ;
  335. expr : '(' expr ')' { $$ = $2; }
  336. | expr1 '=' expr1 { code_byte(EQOP); $$ = 1; ntemp--;}
  337. | expr1 '<' expr1 { code_byte(LTOP); $$ = 1; ntemp--;}
  338. | expr1 '>' expr1 { code_byte(LEOP); code_byte(NOTOP); $$ = 1; ntemp--;}
  339. | expr1 NE expr1 { code_byte(EQOP); code_byte(NOTOP); $$ = 1; ntemp--;}
  340. | expr1 LE expr1 { code_byte(LEOP); $$ = 1; ntemp--;}
  341. | expr1 GE expr1 { code_byte(LTOP); code_byte(NOTOP); $$ = 1; ntemp--;}
  342. | expr1 '+' expr1 { code_byte(ADDOP); $$ = 1; ntemp--;}
  343. | expr1 '-' expr1 { code_byte(SUBOP); $$ = 1; ntemp--;}
  344. | expr1 '*' expr1 { code_byte(MULTOP); $$ = 1; ntemp--;}
  345. | expr1 '/' expr1 { code_byte(DIVOP); $$ = 1; ntemp--;}
  346. | expr1 CONC expr1 { code_byte(CONCOP); $$ = 1; ntemp--;}
  347. | '+' expr1 %prec UNARY { $$ = 1; }
  348. | '-' expr1 %prec UNARY { code_byte(MINUSOP); $$ = 1;}
  349. | typeconstructor { $$ = $1; }
  350. | '@' '(' dimension ')'
  351. {
  352. code_byte(CREATEARRAY);
  353. $$ = 1;
  354. }
  355. | var { lua_pushvar ($1); $$ = 1;}
  356. | NUMBER { code_number($1); $$ = 1; }
  357. | STRING
  358. {
  359. align(Word,1);
  360. code_byte(PUSHSTRING);
  361. code_word($1);
  362. $$ = 1;
  363. incr_ntemp();
  364. }
  365. | NIL {code_byte(PUSHNIL); $$ = 1; incr_ntemp();}
  366. | functioncall
  367. {
  368. $$ = 0;
  369. if (lua_debug)
  370. {
  371. align(Word,1); code_byte(SETLINE); code_word(lua_linenumber);
  372. }
  373. }
  374. | NOT expr1 { code_byte(NOTOP); $$ = 1;}
  375. | expr1 AND PrepJump {code_byte(POP); ntemp--;} expr1
  376. {
  377. *($3) = ONFJMP;
  378. *((Word *)($3+1)) = pc - ($3 + sizeof(Word)+1);
  379. $$ = 1;
  380. }
  381. | expr1 OR PrepJump {code_byte(POP); ntemp--;} expr1
  382. {
  383. *($3) = ONTJMP;
  384. *((Word *)($3+1)) = pc - ($3 + sizeof(Word)+1);
  385. $$ = 1;
  386. }
  387. ;
  388. typeconstructor: '@'
  389. {
  390. code_byte(PUSHBYTE);
  391. $<pByte>$ = pc; code_byte(0);
  392. incr_ntemp();
  393. code_byte(CREATEARRAY);
  394. }
  395. objectname fieldlist
  396. {
  397. *($<pByte>2) = $4;
  398. if ($3 < 0) /* there is no function to be called */
  399. {
  400. $$ = 1;
  401. }
  402. else
  403. {
  404. lua_pushvar ($3+1);
  405. code_byte(PUSHMARK);
  406. incr_ntemp();
  407. code_byte(PUSHOBJECT);
  408. incr_ntemp();
  409. code_byte(CALLFUNC);
  410. ntemp -= 4;
  411. $$ = 0;
  412. if (lua_debug)
  413. {
  414. align(Word,1); code_byte(SETLINE); code_word(lua_linenumber);
  415. }
  416. }
  417. }
  418. ;
  419. dimension : /* empty */ { code_byte(PUSHNIL); incr_ntemp();}
  420. | expr1
  421. ;
  422. functioncall : functionvalue {code_byte(PUSHMARK); $<vInt>$ = ntemp; incr_ntemp();}
  423. '(' exprlist ')' { code_byte(CALLFUNC); ntemp = $<vInt>2-1;}
  424. functionvalue : var {lua_pushvar ($1); }
  425. ;
  426. exprlist : /* empty */ { $$ = 1; }
  427. | exprlist1 { $$ = $1; }
  428. ;
  429. exprlist1 : expr { $$ = $1; }
  430. | exprlist1 ',' {if (!$1){lua_codeadjust (ntemp+1); incr_ntemp();}}
  431. expr {$$ = $4;}
  432. ;
  433. parlist : /* empty */
  434. | parlist1
  435. ;
  436. parlist1 : NAME {localvar[nlocalvar]=$1; add_nlocalvar(1);}
  437. | parlist1 ',' NAME {localvar[nlocalvar]=$3; add_nlocalvar(1);}
  438. ;
  439. objectname : /* empty */ {$$=-1;}
  440. | NAME {$$=$1;}
  441. ;
  442. fieldlist : '{' ffieldlist '}' { flush_record($2%FIELDS_PER_FLUSH); $$ = $2; }
  443. | '[' lfieldlist ']'
  444. {
  445. flush_list($2/FIELDS_PER_FLUSH, $2%FIELDS_PER_FLUSH);
  446. $$ = $2;
  447. }
  448. ;
  449. ffieldlist : /* empty */ { $$ = 0; }
  450. | ffieldlist1 { $$ = $1; }
  451. ;
  452. ffieldlist1 : ffield {$$=1;}
  453. | ffieldlist1 ',' ffield
  454. {
  455. $$=$1+1;
  456. if ($$%FIELDS_PER_FLUSH == 0) flush_record(FIELDS_PER_FLUSH);
  457. }
  458. ;
  459. ffield : NAME '=' expr1 { push_field($1); }
  460. ;
  461. lfieldlist : /* empty */ { $$ = 0; }
  462. | lfieldlist1 { $$ = $1; }
  463. ;
  464. lfieldlist1 : expr1 {$$=1;}
  465. | lfieldlist1 ',' expr1
  466. {
  467. $$=$1+1;
  468. if ($$%FIELDS_PER_FLUSH == 0)
  469. flush_list($$/FIELDS_PER_FLUSH - 1, FIELDS_PER_FLUSH);
  470. }
  471. ;
  472. varlist1 : var
  473. {
  474. nvarbuffer = 0;
  475. varbuffer[nvarbuffer] = $1; incr_nvarbuffer();
  476. $$ = ($1 == 0) ? 1 : 0;
  477. }
  478. | varlist1 ',' var
  479. {
  480. varbuffer[nvarbuffer] = $3; incr_nvarbuffer();
  481. $$ = ($3 == 0) ? $1 + 1 : $1;
  482. }
  483. ;
  484. var : NAME
  485. {
  486. int local = lua_localname ($1);
  487. if (local == -1) /* global var */
  488. $$ = $1 + 1; /* return positive value */
  489. else
  490. $$ = -(local+1); /* return negative value */
  491. }
  492. | var {lua_pushvar ($1);} '[' expr1 ']'
  493. {
  494. $$ = 0; /* indexed variable */
  495. }
  496. | var {lua_pushvar ($1);} '.' NAME
  497. {
  498. align(Word,1);
  499. code_byte(PUSHSTRING);
  500. code_word(lua_findconstant (s_name($4))); incr_ntemp();
  501. $$ = 0; /* indexed variable */
  502. }
  503. ;
  504. localdeclist : NAME {localvar[nlocalvar]=$1; $$ = 1;}
  505. | localdeclist ',' NAME {localvar[nlocalvar+$1]=$3; $$ = $1+1;}
  506. ;
  507. decinit : /* empty */
  508. | '=' exprlist1
  509. ;
  510. setdebug : DEBUG {lua_debug = $1;}
  511. %%
  512. /*
  513. ** Search a local name and if find return its index. If do not find return -1
  514. */
  515. static int lua_localname (Word n)
  516. {
  517. int i;
  518. for (i=nlocalvar-1; i >= 0; i--)
  519. if (n == localvar[i]) return i; /* local var */
  520. return -1; /* global var */
  521. }
  522. /*
  523. ** Push a variable given a number. If number is positive, push global variable
  524. ** indexed by (number -1). If negative, push local indexed by ABS(number)-1.
  525. ** Otherwise, if zero, push indexed variable (record).
  526. */
  527. static void lua_pushvar (long number)
  528. {
  529. if (number > 0) /* global var */
  530. {
  531. align(Word,1);
  532. code_byte(PUSHGLOBAL);
  533. code_word(number-1);
  534. incr_ntemp();
  535. }
  536. else if (number < 0) /* local var */
  537. {
  538. number = (-number) - 1;
  539. if (number < 10) code_byte(PUSHLOCAL0 + number);
  540. else
  541. {
  542. code_byte(PUSHLOCAL);
  543. code_byte(number);
  544. }
  545. incr_ntemp();
  546. }
  547. else
  548. {
  549. code_byte(PUSHINDEXED);
  550. ntemp--;
  551. }
  552. }
  553. static void lua_codeadjust (int n)
  554. {
  555. code_byte(ADJUST);
  556. code_byte(n + nlocalvar);
  557. }
  558. static void lua_codestore (int i)
  559. {
  560. if (varbuffer[i] > 0) /* global var */
  561. {
  562. align(Word,1);
  563. code_byte(STOREGLOBAL);
  564. code_word(varbuffer[i]-1);
  565. }
  566. else if (varbuffer[i] < 0) /* local var */
  567. {
  568. int number = (-varbuffer[i]) - 1;
  569. if (number < 10) code_byte(STORELOCAL0 + number);
  570. else
  571. {
  572. code_byte(STORELOCAL);
  573. code_byte(number);
  574. }
  575. }
  576. else /* indexed var */
  577. {
  578. int j;
  579. int upper=0; /* number of indexed variables upper */
  580. int param; /* number of itens until indexed expression */
  581. for (j=i+1; j <nvarbuffer; j++)
  582. if (varbuffer[j] == 0) upper++;
  583. param = upper*2 + i;
  584. if (param == 0)
  585. code_byte(STOREINDEXED0);
  586. else
  587. {
  588. code_byte(STOREINDEXED);
  589. code_byte(param);
  590. }
  591. }
  592. }
  593. void yyerror (char *s)
  594. {
  595. static char msg[256];
  596. sprintf (msg,"%s near \"%s\" at line %d in file \"%s\"",
  597. s, lua_lasttext (), lua_linenumber, lua_filename());
  598. lua_error (msg);
  599. err = 1;
  600. }
  601. int yywrap (void)
  602. {
  603. return 1;
  604. }
  605. /*
  606. ** Parse LUA code and execute global statement.
  607. ** Return 0 on success or 1 on error.
  608. */
  609. int lua_parse (void)
  610. {
  611. Byte *initcode = maincode;
  612. err = 0;
  613. if (yyparse () || (err==1)) return 1;
  614. *maincode++ = HALT;
  615. if (lua_execute (initcode)) return 1;
  616. maincode = initcode;
  617. return 0;
  618. }
  619. #if LISTING
  620. static void PrintCode (Byte *p, Byte *end)
  621. {
  622. printf ("\n\nCODE\n");
  623. while (p != end)
  624. {
  625. switch ((OpCode)*p)
  626. {
  627. case NOP: printf ("%d NOP\n", (p++)-code); break;
  628. case PUSHNIL: printf ("%d PUSHNIL\n", (p++)-code); break;
  629. case PUSH0: case PUSH1: case PUSH2:
  630. printf ("%d PUSH%c\n", p-code, *p-PUSH0+'0');
  631. p++;
  632. break;
  633. case PUSHBYTE:
  634. printf ("%d PUSHBYTE %d\n", p-code, *(++p));
  635. p++;
  636. break;
  637. case PUSHWORD:
  638. printf ("%d PUSHWORD %d\n", p-code, *((Word *)(p+1)));
  639. p += 1 + sizeof(Word);
  640. break;
  641. case PUSHFLOAT:
  642. printf ("%d PUSHFLOAT %f\n", p-code, *((float *)(p+1)));
  643. p += 1 + sizeof(float);
  644. break;
  645. case PUSHSTRING:
  646. printf ("%d PUSHSTRING %d\n", p-code, *((Word *)(p+1)));
  647. p += 1 + sizeof(Word);
  648. break;
  649. case PUSHLOCAL0: case PUSHLOCAL1: case PUSHLOCAL2: case PUSHLOCAL3:
  650. case PUSHLOCAL4: case PUSHLOCAL5: case PUSHLOCAL6: case PUSHLOCAL7:
  651. case PUSHLOCAL8: case PUSHLOCAL9:
  652. printf ("%d PUSHLOCAL%c\n", p-code, *p-PUSHLOCAL0+'0');
  653. p++;
  654. break;
  655. case PUSHLOCAL: printf ("%d PUSHLOCAL %d\n", p-code, *(++p));
  656. p++;
  657. break;
  658. case PUSHGLOBAL:
  659. printf ("%d PUSHGLOBAL %d\n", p-code, *((Word *)(p+1)));
  660. p += 1 + sizeof(Word);
  661. break;
  662. case PUSHINDEXED: printf ("%d PUSHINDEXED\n", (p++)-code); break;
  663. case PUSHMARK: printf ("%d PUSHMARK\n", (p++)-code); break;
  664. case PUSHOBJECT: printf ("%d PUSHOBJECT\n", (p++)-code); break;
  665. case STORELOCAL0: case STORELOCAL1: case STORELOCAL2: case STORELOCAL3:
  666. case STORELOCAL4: case STORELOCAL5: case STORELOCAL6: case STORELOCAL7:
  667. case STORELOCAL8: case STORELOCAL9:
  668. printf ("%d STORELOCAL%c\n", p-code, *p-STORELOCAL0+'0');
  669. p++;
  670. break;
  671. case STORELOCAL:
  672. printf ("%d STORELOCAL %d\n", p-code, *(++p));
  673. p++;
  674. break;
  675. case STOREGLOBAL:
  676. printf ("%d STOREGLOBAL %d\n", p-code, *((Word *)(p+1)));
  677. p += 1 + sizeof(Word);
  678. break;
  679. case STOREINDEXED0: printf ("%d STOREINDEXED0\n", (p++)-code); break;
  680. case STOREINDEXED: printf ("%d STOREINDEXED %d\n", p-code, *(++p));
  681. p++;
  682. break;
  683. case STORELIST0:
  684. printf("%d STORELIST0 %d\n", p-code, *(++p));
  685. p++;
  686. break;
  687. case STORELIST:
  688. printf("%d STORELIST %d %d\n", p-code, *(p+1), *(p+2));
  689. p+=3;
  690. break;
  691. case STORERECORD:
  692. printf("%d STORERECORD %d\n", p-code, *(++p));
  693. p += *p*sizeof(Word) + 1;
  694. break;
  695. case ADJUST:
  696. printf ("%d ADJUST %d\n", p-code, *(++p));
  697. p++;
  698. break;
  699. case CREATEARRAY: printf ("%d CREATEARRAY\n", (p++)-code); break;
  700. case EQOP: printf ("%d EQOP\n", (p++)-code); break;
  701. case LTOP: printf ("%d LTOP\n", (p++)-code); break;
  702. case LEOP: printf ("%d LEOP\n", (p++)-code); break;
  703. case ADDOP: printf ("%d ADDOP\n", (p++)-code); break;
  704. case SUBOP: printf ("%d SUBOP\n", (p++)-code); break;
  705. case MULTOP: printf ("%d MULTOP\n", (p++)-code); break;
  706. case DIVOP: printf ("%d DIVOP\n", (p++)-code); break;
  707. case CONCOP: printf ("%d CONCOP\n", (p++)-code); break;
  708. case MINUSOP: printf ("%d MINUSOP\n", (p++)-code); break;
  709. case NOTOP: printf ("%d NOTOP\n", (p++)-code); break;
  710. case ONTJMP:
  711. printf ("%d ONTJMP %d\n", p-code, *((Word *)(p+1)));
  712. p += sizeof(Word) + 1;
  713. break;
  714. case ONFJMP:
  715. printf ("%d ONFJMP %d\n", p-code, *((Word *)(p+1)));
  716. p += sizeof(Word) + 1;
  717. break;
  718. case JMP:
  719. printf ("%d JMP %d\n", p-code, *((Word *)(p+1)));
  720. p += sizeof(Word) + 1;
  721. break;
  722. case UPJMP:
  723. printf ("%d UPJMP %d\n", p-code, *((Word *)(p+1)));
  724. p += sizeof(Word) + 1;
  725. break;
  726. case IFFJMP:
  727. printf ("%d IFFJMP %d\n", p-code, *((Word *)(p+1)));
  728. p += sizeof(Word) + 1;
  729. break;
  730. case IFFUPJMP:
  731. printf ("%d IFFUPJMP %d\n", p-code, *((Word *)(p+1)));
  732. p += sizeof(Word) + 1;
  733. break;
  734. case POP: printf ("%d POP\n", (p++)-code); break;
  735. case CALLFUNC: printf ("%d CALLFUNC\n", (p++)-code); break;
  736. case RETCODE:
  737. printf ("%d RETCODE %d\n", p-code, *(++p));
  738. p++;
  739. break;
  740. default: printf ("%d Cannot happen\n", (p++)-code); break;
  741. }
  742. }
  743. }
  744. #endif