lua.stx 19 KB

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