lua.stx 19 KB

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