lua.stx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  1. %{
  2. char *rcs_luastx = "$Id: lua.stx,v 2.1 1994/04/15 19:02:04 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 1
  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(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. char *pChar;
  159. Word vWord;
  160. Byte *pByte;
  161. }
  162. %start functionlist
  163. %token WRONGTOKEN
  164. %token NIL
  165. %token IF THEN ELSE ELSEIF WHILE DO REPEAT UNTIL END
  166. %token RETURN
  167. %token LOCAL
  168. %token <vFloat> NUMBER
  169. %token <vWord> FUNCTION STRING
  170. %token <pChar> NAME
  171. %token <vInt> DEBUG
  172. %type <pByte> PrepJump
  173. %type <vInt> expr, exprlist, exprlist1, varlist1, typeconstructor
  174. %type <vInt> fieldlist, localdeclist
  175. %type <vInt> ffieldlist, ffieldlist1
  176. %type <vInt> lfieldlist, lfieldlist1
  177. %type <vLong> var, objectname
  178. %left AND OR
  179. %left '=' NE '>' '<' LE GE
  180. %left CONC
  181. %left '+' '-'
  182. %left '*' '/'
  183. %left UNARY NOT
  184. %% /* beginning of rules section */
  185. functionlist : /* empty */
  186. | functionlist { pc=basepc=maincode; nlocalvar=0;} stat sc
  187. {
  188. maincode=pc;
  189. }
  190. | functionlist function
  191. | functionlist setdebug
  192. ;
  193. function : FUNCTION NAME
  194. {
  195. $<vWord>$ = lua_findsymbol($2);
  196. pc=basepc=code;
  197. nlocalvar=0;
  198. }
  199. '(' parlist ')'
  200. {
  201. if (lua_debug)
  202. {
  203. code_byte(SETFUNCTION);
  204. code_word(lua_nfile-1);
  205. code_word($<vWord>3);
  206. }
  207. lua_codeadjust (0);
  208. }
  209. block
  210. END
  211. {
  212. if (lua_debug) code_byte(RESET);
  213. code_byte(RETCODE); code_byte(nlocalvar);
  214. s_tag($<vWord>3) = T_FUNCTION;
  215. s_bvalue($<vWord>3) = calloc (pc-code, sizeof(Byte));
  216. memcpy (s_bvalue($<vWord>3), code, (pc-code)*sizeof(Byte));
  217. #if LISTING
  218. PrintCode(code,pc,(Byte*)buffer);
  219. #endif
  220. }
  221. ;
  222. statlist : /* empty */
  223. | statlist stat sc
  224. ;
  225. stat : {
  226. ntemp = 0;
  227. if (lua_debug)
  228. {
  229. code_byte(SETLINE); code_word(lua_linenumber);
  230. }
  231. }
  232. stat1
  233. sc : /* empty */ | ';' ;
  234. stat1 : IF expr1 THEN PrepJump block PrepJump elsepart END
  235. {
  236. {
  237. Byte *elseinit = $6 + sizeof(Word)+1;
  238. if (pc - elseinit == 0) /* no else */
  239. {
  240. pc -= sizeof(Word)+1;
  241. elseinit = pc;
  242. }
  243. else
  244. {
  245. *($6) = JMP;
  246. code_word_at($6+1, pc - elseinit);
  247. }
  248. *($4) = IFFJMP;
  249. code_word_at($4+1, elseinit - ($4 + sizeof(Word)+1));
  250. }
  251. }
  252. | WHILE {$<pByte>$ = pc;} expr1 DO PrepJump block PrepJump END
  253. {
  254. *($5) = IFFJMP;
  255. code_word_at($5+1, pc - ($5 + sizeof(Word)+1));
  256. *($7) = UPJMP;
  257. code_word_at($7+1, pc - $<pByte>2);
  258. }
  259. | REPEAT {$<pByte>$ = pc;} block UNTIL expr1 PrepJump
  260. {
  261. *($6) = IFFUPJMP;
  262. code_word_at($6+1, pc - $<pByte>2);
  263. }
  264. | varlist1 '=' exprlist1
  265. {
  266. {
  267. int i;
  268. if ($3 == 0 || nvarbuffer != ntemp - $1 * 2)
  269. lua_codeadjust ($1 * 2 + nvarbuffer);
  270. for (i=nvarbuffer-1; i>=0; i--)
  271. lua_codestore (i);
  272. if ($1 > 1 || ($1 == 1 && varbuffer[0] != 0))
  273. lua_codeadjust (0);
  274. }
  275. }
  276. | functioncall { lua_codeadjust (0); }
  277. | typeconstructor { lua_codeadjust (0); }
  278. | LOCAL localdeclist decinit { add_nlocalvar($2); lua_codeadjust (0); }
  279. ;
  280. elsepart : /* empty */
  281. | ELSE block
  282. | ELSEIF expr1 THEN PrepJump block PrepJump elsepart
  283. {
  284. {
  285. Byte *elseinit = $6 + sizeof(Word)+1;
  286. if (pc - elseinit == 0) /* no else */
  287. {
  288. pc -= sizeof(Word)+1;
  289. /* if (*(pc-1) == NOP) --pc; */
  290. elseinit = pc;
  291. }
  292. else
  293. {
  294. *($6) = JMP;
  295. code_word_at($6+1, pc - elseinit);
  296. }
  297. *($4) = IFFJMP;
  298. code_word_at($4+1, elseinit - ($4 + sizeof(Word)+1));
  299. }
  300. }
  301. ;
  302. block : {$<vInt>$ = nlocalvar;} statlist {ntemp = 0;} ret
  303. {
  304. if (nlocalvar != $<vInt>1)
  305. {
  306. nlocalvar = $<vInt>1;
  307. lua_codeadjust (0);
  308. }
  309. }
  310. ;
  311. ret : /* empty */
  312. | { if (lua_debug){code_byte(SETLINE);code_word(lua_linenumber);}}
  313. RETURN exprlist sc
  314. {
  315. if (lua_debug) code_byte(RESET);
  316. code_byte(RETCODE); code_byte(nlocalvar);
  317. }
  318. ;
  319. PrepJump : /* empty */
  320. {
  321. $$ = pc;
  322. code_byte(0); /* open space */
  323. code_word (0);
  324. }
  325. expr1 : expr { if ($1 == 0) {lua_codeadjust (ntemp+1); incr_ntemp();}}
  326. ;
  327. expr : '(' expr ')' { $$ = $2; }
  328. | expr1 '=' expr1 { code_byte(EQOP); $$ = 1; ntemp--;}
  329. | expr1 '<' expr1 { code_byte(LTOP); $$ = 1; ntemp--;}
  330. | expr1 '>' expr1 { code_byte(LEOP); code_byte(NOTOP); $$ = 1; ntemp--;}
  331. | expr1 NE expr1 { code_byte(EQOP); code_byte(NOTOP); $$ = 1; ntemp--;}
  332. | expr1 LE expr1 { code_byte(LEOP); $$ = 1; ntemp--;}
  333. | expr1 GE expr1 { code_byte(LTOP); code_byte(NOTOP); $$ = 1; ntemp--;}
  334. | expr1 '+' expr1 { code_byte(ADDOP); $$ = 1; ntemp--;}
  335. | expr1 '-' expr1 { code_byte(SUBOP); $$ = 1; ntemp--;}
  336. | expr1 '*' expr1 { code_byte(MULTOP); $$ = 1; ntemp--;}
  337. | expr1 '/' expr1 { code_byte(DIVOP); $$ = 1; ntemp--;}
  338. | expr1 CONC expr1 { code_byte(CONCOP); $$ = 1; ntemp--;}
  339. | '+' expr1 %prec UNARY { $$ = 1; }
  340. | '-' expr1 %prec UNARY { code_byte(MINUSOP); $$ = 1;}
  341. | typeconstructor { $$ = $1; }
  342. | '@' '(' dimension ')'
  343. {
  344. code_byte(CREATEARRAY);
  345. $$ = 1;
  346. }
  347. | var { lua_pushvar ($1); $$ = 1;}
  348. | NUMBER { code_number($1); $$ = 1; }
  349. | STRING
  350. {
  351. code_byte(PUSHSTRING);
  352. code_word($1);
  353. $$ = 1;
  354. incr_ntemp();
  355. }
  356. | NIL {code_byte(PUSHNIL); $$ = 1; incr_ntemp();}
  357. | functioncall
  358. {
  359. $$ = 0;
  360. if (lua_debug)
  361. {
  362. code_byte(SETLINE); code_word(lua_linenumber);
  363. }
  364. }
  365. | NOT expr1 { code_byte(NOTOP); $$ = 1;}
  366. | expr1 AND PrepJump {code_byte(POP); ntemp--;} expr1
  367. {
  368. *($3) = ONFJMP;
  369. code_word_at($3+1, pc - ($3 + sizeof(Word)+1));
  370. $$ = 1;
  371. }
  372. | expr1 OR PrepJump {code_byte(POP); ntemp--;} expr1
  373. {
  374. *($3) = ONTJMP;
  375. code_word_at($3+1, pc - ($3 + sizeof(Word)+1));
  376. $$ = 1;
  377. }
  378. ;
  379. typeconstructor: '@'
  380. {
  381. code_byte(PUSHBYTE);
  382. $<pByte>$ = pc; code_byte(0);
  383. incr_ntemp();
  384. code_byte(CREATEARRAY);
  385. }
  386. objectname fieldlist
  387. {
  388. *($<pByte>2) = $4;
  389. if ($3 < 0) /* there is no function to be called */
  390. {
  391. $$ = 1;
  392. }
  393. else
  394. {
  395. lua_pushvar ($3+1);
  396. code_byte(PUSHMARK);
  397. incr_ntemp();
  398. code_byte(PUSHOBJECT);
  399. incr_ntemp();
  400. code_byte(CALLFUNC);
  401. ntemp -= 4;
  402. $$ = 0;
  403. if (lua_debug)
  404. {
  405. code_byte(SETLINE); code_word(lua_linenumber);
  406. }
  407. }
  408. }
  409. ;
  410. dimension : /* empty */ { code_byte(PUSHNIL); incr_ntemp();}
  411. | expr1
  412. ;
  413. functioncall : functionvalue {code_byte(PUSHMARK); $<vInt>$ = ntemp; incr_ntemp();}
  414. '(' exprlist ')' { code_byte(CALLFUNC); ntemp = $<vInt>2-1;}
  415. functionvalue : var {lua_pushvar ($1); }
  416. ;
  417. exprlist : /* empty */ { $$ = 1; }
  418. | exprlist1 { $$ = $1; }
  419. ;
  420. exprlist1 : expr { $$ = $1; }
  421. | exprlist1 ',' {if (!$1){lua_codeadjust (ntemp+1); incr_ntemp();}}
  422. expr {$$ = $4;}
  423. ;
  424. parlist : /* empty */
  425. | parlist1
  426. ;
  427. parlist1 : NAME
  428. {
  429. localvar[nlocalvar]=lua_findsymbol($1);
  430. add_nlocalvar(1);
  431. }
  432. | parlist1 ',' NAME
  433. {
  434. localvar[nlocalvar]=lua_findsymbol($3);
  435. add_nlocalvar(1);
  436. }
  437. ;
  438. objectname : /* empty */ {$$=-1;}
  439. | NAME {$$=lua_findsymbol($1);}
  440. ;
  441. fieldlist : '{' ffieldlist '}'
  442. {
  443. flush_record($2%FIELDS_PER_FLUSH);
  444. $$ = $2;
  445. }
  446. | '[' lfieldlist ']'
  447. {
  448. flush_list($2/FIELDS_PER_FLUSH, $2%FIELDS_PER_FLUSH);
  449. $$ = $2;
  450. }
  451. ;
  452. ffieldlist : /* empty */ { $$ = 0; }
  453. | ffieldlist1 { $$ = $1; }
  454. ;
  455. ffieldlist1 : ffield {$$=1;}
  456. | ffieldlist1 ',' ffield
  457. {
  458. $$=$1+1;
  459. if ($$%FIELDS_PER_FLUSH == 0) flush_record(FIELDS_PER_FLUSH);
  460. }
  461. ;
  462. ffield : NAME {$<vWord>$ = lua_findconstant($1);} '=' expr1
  463. {
  464. push_field($<vWord>2);
  465. }
  466. ;
  467. lfieldlist : /* empty */ { $$ = 0; }
  468. | lfieldlist1 { $$ = $1; }
  469. ;
  470. lfieldlist1 : expr1 {$$=1;}
  471. | lfieldlist1 ',' expr1
  472. {
  473. $$=$1+1;
  474. if ($$%FIELDS_PER_FLUSH == 0)
  475. flush_list($$/FIELDS_PER_FLUSH - 1, FIELDS_PER_FLUSH);
  476. }
  477. ;
  478. varlist1 : var
  479. {
  480. nvarbuffer = 0;
  481. varbuffer[nvarbuffer] = $1; incr_nvarbuffer();
  482. $$ = ($1 == 0) ? 1 : 0;
  483. }
  484. | varlist1 ',' var
  485. {
  486. varbuffer[nvarbuffer] = $3; incr_nvarbuffer();
  487. $$ = ($3 == 0) ? $1 + 1 : $1;
  488. }
  489. ;
  490. var : NAME
  491. {
  492. Word s = lua_findsymbol($1);
  493. int local = lua_localname (s);
  494. if (local == -1) /* global var */
  495. $$ = s + 1; /* return positive value */
  496. else
  497. $$ = -(local+1); /* return negative value */
  498. }
  499. | var {lua_pushvar ($1);} '[' expr1 ']'
  500. {
  501. $$ = 0; /* indexed variable */
  502. }
  503. | var {lua_pushvar ($1);} '.' NAME
  504. {
  505. code_byte(PUSHSTRING);
  506. code_word(lua_findconstant($4)); incr_ntemp();
  507. $$ = 0; /* indexed variable */
  508. }
  509. ;
  510. localdeclist : NAME {localvar[nlocalvar]=lua_findsymbol($1); $$ = 1;}
  511. | localdeclist ',' NAME
  512. {
  513. localvar[nlocalvar+$1]=lua_findsymbol($3);
  514. $$ = $1+1;
  515. }
  516. ;
  517. decinit : /* empty */
  518. | '=' exprlist1
  519. ;
  520. setdebug : DEBUG {lua_debug = $1;}
  521. %%
  522. /*
  523. ** Search a local name and if find return its index. If do not find return -1
  524. */
  525. static int lua_localname (Word n)
  526. {
  527. int i;
  528. for (i=nlocalvar-1; i >= 0; i--)
  529. if (n == localvar[i]) return i; /* local var */
  530. return -1; /* global var */
  531. }
  532. /*
  533. ** Push a variable given a number. If number is positive, push global variable
  534. ** indexed by (number -1). If negative, push local indexed by ABS(number)-1.
  535. ** Otherwise, if zero, push indexed variable (record).
  536. */
  537. static void lua_pushvar (long number)
  538. {
  539. if (number > 0) /* global var */
  540. {
  541. code_byte(PUSHGLOBAL);
  542. code_word(number-1);
  543. incr_ntemp();
  544. }
  545. else if (number < 0) /* local var */
  546. {
  547. number = (-number) - 1;
  548. if (number < 10) code_byte(PUSHLOCAL0 + number);
  549. else
  550. {
  551. code_byte(PUSHLOCAL);
  552. code_byte(number);
  553. }
  554. incr_ntemp();
  555. }
  556. else
  557. {
  558. code_byte(PUSHINDEXED);
  559. ntemp--;
  560. }
  561. }
  562. static void lua_codeadjust (int n)
  563. {
  564. code_byte(ADJUST);
  565. code_byte(n + nlocalvar);
  566. }
  567. static void lua_codestore (int i)
  568. {
  569. if (varbuffer[i] > 0) /* global var */
  570. {
  571. code_byte(STOREGLOBAL);
  572. code_word(varbuffer[i]-1);
  573. }
  574. else if (varbuffer[i] < 0) /* local var */
  575. {
  576. int number = (-varbuffer[i]) - 1;
  577. if (number < 10) code_byte(STORELOCAL0 + number);
  578. else
  579. {
  580. code_byte(STORELOCAL);
  581. code_byte(number);
  582. }
  583. }
  584. else /* indexed var */
  585. {
  586. int j;
  587. int upper=0; /* number of indexed variables upper */
  588. int param; /* number of itens until indexed expression */
  589. for (j=i+1; j <nvarbuffer; j++)
  590. if (varbuffer[j] == 0) upper++;
  591. param = upper*2 + i;
  592. if (param == 0)
  593. code_byte(STOREINDEXED0);
  594. else
  595. {
  596. code_byte(STOREINDEXED);
  597. code_byte(param);
  598. }
  599. }
  600. }
  601. void yyerror (char *s)
  602. {
  603. static char msg[256];
  604. sprintf (msg,"%s near \"%s\" at line %d in file \"%s\"",
  605. s, lua_lasttext (), lua_linenumber, lua_filename());
  606. lua_error (msg);
  607. err = 1;
  608. }
  609. int yywrap (void)
  610. {
  611. return 1;
  612. }
  613. /*
  614. ** Parse LUA code and execute global statement.
  615. ** Return 0 on success or 1 on error.
  616. */
  617. int lua_parse (void)
  618. {
  619. Byte *initcode = maincode;
  620. err = 0;
  621. if (yyparse () || (err==1)) return 1;
  622. *maincode++ = HALT;
  623. #if LISTING
  624. PrintCode(basepc,maincode,(Byte*)mainbuffer);
  625. #endif
  626. if (lua_execute (initcode)) return 1;
  627. maincode = initcode;
  628. return 0;
  629. }
  630. #if LISTING
  631. static void PrintCode (Byte *p, Byte *end, Byte *code)
  632. {
  633. printf ("\n\nCODE\n");
  634. while (p != end)
  635. {
  636. switch ((OpCode)*p)
  637. {
  638. case PUSHNIL: printf ("%d PUSHNIL\n", (p++)-code); break;
  639. case PUSH0: case PUSH1: case PUSH2:
  640. printf ("%d PUSH%c\n", p-code, *p-PUSH0+'0');
  641. p++;
  642. break;
  643. case PUSHBYTE:
  644. printf ("%d PUSHBYTE %d\n", p-code, *(++p));
  645. p++;
  646. break;
  647. case PUSHWORD:
  648. {
  649. CodeWord c;
  650. int n = p-code;
  651. p++;
  652. get_word(c,p);
  653. printf ("%d PUSHWORD %d\n", n, c.w);
  654. }
  655. break;
  656. case PUSHFLOAT:
  657. {
  658. CodeFloat c;
  659. int n = p-code;
  660. p++;
  661. get_float(c,p);
  662. printf ("%d PUSHFLOAT %f\n", n, c.f);
  663. }
  664. break;
  665. case PUSHSTRING:
  666. {
  667. CodeWord c;
  668. int n = p-code;
  669. p++;
  670. get_word(c,p);
  671. printf ("%d PUSHSTRING %d\n", n, c.w);
  672. }
  673. break;
  674. case PUSHLOCAL0: case PUSHLOCAL1: case PUSHLOCAL2: case PUSHLOCAL3:
  675. case PUSHLOCAL4: case PUSHLOCAL5: case PUSHLOCAL6: case PUSHLOCAL7:
  676. case PUSHLOCAL8: case PUSHLOCAL9:
  677. printf ("%d PUSHLOCAL%c\n", p-code, *p-PUSHLOCAL0+'0');
  678. p++;
  679. break;
  680. case PUSHLOCAL: printf ("%d PUSHLOCAL %d\n", p-code, *(++p));
  681. p++;
  682. break;
  683. case PUSHGLOBAL:
  684. {
  685. CodeWord c;
  686. int n = p-code;
  687. p++;
  688. get_word(c,p);
  689. printf ("%d PUSHGLOBAL %d\n", n, c.w);
  690. }
  691. break;
  692. case PUSHINDEXED: printf ("%d PUSHINDEXED\n", (p++)-code); break;
  693. case PUSHMARK: printf ("%d PUSHMARK\n", (p++)-code); break;
  694. case PUSHOBJECT: printf ("%d PUSHOBJECT\n", (p++)-code); break;
  695. case STORELOCAL0: case STORELOCAL1: case STORELOCAL2: case STORELOCAL3:
  696. case STORELOCAL4: case STORELOCAL5: case STORELOCAL6: case STORELOCAL7:
  697. case STORELOCAL8: case STORELOCAL9:
  698. printf ("%d STORELOCAL%c\n", p-code, *p-STORELOCAL0+'0');
  699. p++;
  700. break;
  701. case STORELOCAL:
  702. printf ("%d STORELOCAL %d\n", p-code, *(++p));
  703. p++;
  704. break;
  705. case STOREGLOBAL:
  706. {
  707. CodeWord c;
  708. int n = p-code;
  709. p++;
  710. get_word(c,p);
  711. printf ("%d STOREGLOBAL %d\n", n, c.w);
  712. }
  713. break;
  714. case STOREINDEXED0: printf ("%d STOREINDEXED0\n", (p++)-code); break;
  715. case STOREINDEXED: printf ("%d STOREINDEXED %d\n", p-code, *(++p));
  716. p++;
  717. break;
  718. case STORELIST0:
  719. printf("%d STORELIST0 %d\n", p-code, *(++p));
  720. p++;
  721. break;
  722. case STORELIST:
  723. printf("%d STORELIST %d %d\n", p-code, *(p+1), *(p+2));
  724. p+=3;
  725. break;
  726. case STORERECORD:
  727. printf("%d STORERECORD %d\n", p-code, *(++p));
  728. p += *p*sizeof(Word) + 1;
  729. break;
  730. case ADJUST:
  731. printf ("%d ADJUST %d\n", p-code, *(++p));
  732. p++;
  733. break;
  734. case CREATEARRAY: printf ("%d CREATEARRAY\n", (p++)-code); break;
  735. case EQOP: printf ("%d EQOP\n", (p++)-code); break;
  736. case LTOP: printf ("%d LTOP\n", (p++)-code); break;
  737. case LEOP: printf ("%d LEOP\n", (p++)-code); break;
  738. case ADDOP: printf ("%d ADDOP\n", (p++)-code); break;
  739. case SUBOP: printf ("%d SUBOP\n", (p++)-code); break;
  740. case MULTOP: printf ("%d MULTOP\n", (p++)-code); break;
  741. case DIVOP: printf ("%d DIVOP\n", (p++)-code); break;
  742. case CONCOP: printf ("%d CONCOP\n", (p++)-code); break;
  743. case MINUSOP: printf ("%d MINUSOP\n", (p++)-code); break;
  744. case NOTOP: printf ("%d NOTOP\n", (p++)-code); break;
  745. case ONTJMP:
  746. {
  747. CodeWord c;
  748. int n = p-code;
  749. p++;
  750. get_word(c,p);
  751. printf ("%d ONTJMP %d\n", n, c.w);
  752. }
  753. break;
  754. case ONFJMP:
  755. {
  756. CodeWord c;
  757. int n = p-code;
  758. p++;
  759. get_word(c,p);
  760. printf ("%d ONFJMP %d\n", n, c.w);
  761. }
  762. break;
  763. case JMP:
  764. {
  765. CodeWord c;
  766. int n = p-code;
  767. p++;
  768. get_word(c,p);
  769. printf ("%d JMP %d\n", n, c.w);
  770. }
  771. break;
  772. case UPJMP:
  773. {
  774. CodeWord c;
  775. int n = p-code;
  776. p++;
  777. get_word(c,p);
  778. printf ("%d UPJMP %d\n", n, c.w);
  779. }
  780. break;
  781. case IFFJMP:
  782. {
  783. CodeWord c;
  784. int n = p-code;
  785. p++;
  786. get_word(c,p);
  787. printf ("%d IFFJMP %d\n", n, c.w);
  788. }
  789. break;
  790. case IFFUPJMP:
  791. {
  792. CodeWord c;
  793. int n = p-code;
  794. p++;
  795. get_word(c,p);
  796. printf ("%d IFFUPJMP %d\n", n, c.w);
  797. }
  798. break;
  799. case POP: printf ("%d POP\n", (p++)-code); break;
  800. case CALLFUNC: printf ("%d CALLFUNC\n", (p++)-code); break;
  801. case RETCODE:
  802. printf ("%d RETCODE %d\n", p-code, *(++p));
  803. p++;
  804. break;
  805. case HALT: printf ("%d HALT\n", (p++)-code); break;
  806. case SETFUNCTION:
  807. {
  808. CodeWord c1, c2;
  809. int n = p-code;
  810. p++;
  811. get_word(c1,p);
  812. get_word(c2,p);
  813. printf ("%d SETFUNCTION %d %d\n", n, c1.w, c2.w);
  814. }
  815. break;
  816. case SETLINE:
  817. {
  818. CodeWord c;
  819. int n = p-code;
  820. p++;
  821. get_word(c,p);
  822. printf ("%d SETLINE %d\n", n, c.w);
  823. }
  824. break;
  825. case RESET: printf ("%d RESET\n", (p++)-code); break;
  826. default: printf ("%d Cannot happen: code %d\n", (p++)-code, *(p-1)); break;
  827. }
  828. }
  829. }
  830. #endif