14 #define ALIGNMENT (sizeof(void *))
20 static long buffer
[MAXCODE
];
21 static Byte
*code
= (Byte
*)buffer
;
22 static long mainbuffer
[MAXCODE
];
23 static Byte
*maincode
= (Byte
*)mainbuffer
;
28 static long varbuffer
[MAXVAR
];
29 static Byte nvarbuffer
=0; /* number of variables at a list */
31 static Word localvar
[STACKGAP
];
32 static Byte nlocalvar
=0; /* number of local variables */
33 static int ntemp
; /* number of temporary var into stack */
34 static int err
; /* flag to indicate error */
36 /* Internal functions */
37 #define align(n) align_n(sizeof(n))
39 static void code_byte (Byte c
)
41 if (pc
-basepc
>MAXCODE
-1)
43 lua_error ("code buffer overflow");
49 static void code_word (Word n
)
51 if (pc
-basepc
>MAXCODE
-sizeof(Word
))
53 lua_error ("code buffer overflow");
60 static void code_float (float n
)
62 if (pc
-basepc
>MAXCODE
-sizeof(float))
64 lua_error ("code buffer overflow");
71 static void incr_ntemp (void)
73 if (ntemp
+nlocalvar
+MAXVAR
+1 < STACKGAP
)
77 lua_error ("stack overflow");
82 static void incr_nlocalvar (void)
84 if (ntemp
+nlocalvar
+MAXVAR
+1 < STACKGAP
)
88 lua_error ("too many local variables or expression too complicate");
93 static void incr_nvarbuffer (void)
95 if (nvarbuffer
< MAXVAR
-1)
99 lua_error ("variable buffer overflow");
104 static void align_n (unsigned size
)
106 if (size
> ALIGNMENT
) size
= ALIGNMENT
;
107 while (((pc
+1-code
)%size
) != 0) /* +1 to include BYTECODE */
111 static void code_number (float f
)
113 if (f
== i
) /* f has an integer value */
115 if (i
<= 2) code_byte(PUSH0
+ i
);
131 code_byte(PUSHFLOAT
);
160 # define FUNCTION 270
172 #define yyclearin yychar = -1
173 #define yyerrok yyerrflag = 0
175 extern int yyerrflag
;
177 #define YYMAXDEPTH 150
179 YYSTYPE yylval
, yyval
;
180 # define YYERRCODE 256
186 ** Search a local name and if find return its index. If do not find return -1
188 static int lua_localname (Word n
)
191 for (i
=nlocalvar
-1; i
>= 0; i
--)
192 if (n
== localvar
[i
]) return i
; /* local var */
193 return -1; /* global var */
197 ** Push a variable given a number. If number is positive, push global variable
198 ** indexed by (number -1). If negative, push local indexed by ABS(number)-1.
199 ** Otherwise, if zero, push indexed variable (record).
201 static void lua_pushvar (long number
)
203 if (number
> 0) /* global var */
206 code_byte(PUSHGLOBAL
);
210 else if (number
< 0) /* local var */
212 number
= (-number
) - 1;
213 if (number
< 10) code_byte(PUSHLOCAL0
+ number
);
216 code_byte(PUSHLOCAL
);
223 code_byte(PUSHINDEXED
);
228 static void lua_codeadjust (int n
)
231 code_byte(n
+ nlocalvar
);
234 static void lua_codestore (int i
)
236 if (varbuffer
[i
] > 0) /* global var */
239 code_byte(STOREGLOBAL
);
240 code_word(varbuffer
[i
]-1);
242 else if (varbuffer
[i
] < 0) /* local var */
244 int number
= (-varbuffer
[i
]) - 1;
245 if (number
< 10) code_byte(STORELOCAL0
+ number
);
248 code_byte(STORELOCAL
);
252 else /* indexed var */
255 int upper
=0; /* number of indexed variables upper */
256 int param
; /* number of itens until indexed expression */
257 for (j
=i
+1; j
<nvarbuffer
; j
++)
258 if (varbuffer
[j
] == 0) upper
++;
261 code_byte(STOREINDEXED0
);
264 code_byte(STOREINDEXED
);
270 void yyerror (char *s
)
272 static char msg
[256];
273 sprintf (msg
,"%s near \"%s\" at line %d in file \"%s\"",
274 s
, lua_lasttext (), lua_linenumber
, lua_filename());
286 ** Parse LUA code and execute global statement.
287 ** Return 0 on success or 1 on error.
291 Byte
*initcode
= maincode
;
293 if (yyparse () || (err
==1)) return 1;
295 if (lua_execute (initcode
)) return 1;
303 static void PrintCode (void)
306 printf ("\n\nCODE\n");
311 case NOP
: printf ("%d NOP\n", (p
++)-code
); break;
312 case PUSHNIL
: printf ("%d PUSHNIL\n", (p
++)-code
); break;
313 case PUSH0
: case PUSH1
: case PUSH2
:
314 printf ("%d PUSH%c\n", p
-code
, *p
-PUSH0
+'0');
318 printf ("%d PUSHBYTE %d\n", p
-code
, *(++p
));
322 printf ("%d PUSHWORD %d\n", p
-code
, *((Word
*)(p
+1)));
323 p
+= 1 + sizeof(Word
);
326 printf ("%d PUSHFLOAT %f\n", p
-code
, *((float *)(p
+1)));
327 p
+= 1 + sizeof(float);
330 printf ("%d PUSHSTRING %d\n", p
-code
, *((Word
*)(p
+1)));
331 p
+= 1 + sizeof(Word
);
333 case PUSHLOCAL0
: case PUSHLOCAL1
: case PUSHLOCAL2
: case PUSHLOCAL3
:
334 case PUSHLOCAL4
: case PUSHLOCAL5
: case PUSHLOCAL6
: case PUSHLOCAL7
:
335 case PUSHLOCAL8
: case PUSHLOCAL9
:
336 printf ("%d PUSHLOCAL%c\n", p
-code
, *p
-PUSHLOCAL0
+'0');
339 case PUSHLOCAL
: printf ("%d PUSHLOCAL %d\n", p
-code
, *(++p
));
343 printf ("%d PUSHGLOBAL %d\n", p
-code
, *((Word
*)(p
+1)));
344 p
+= 1 + sizeof(Word
);
346 case PUSHINDEXED
: printf ("%d PUSHINDEXED\n", (p
++)-code
); break;
347 case PUSHMARK
: printf ("%d PUSHMARK\n", (p
++)-code
); break;
348 case PUSHOBJECT
: printf ("%d PUSHOBJECT\n", (p
++)-code
); break;
349 case STORELOCAL0
: case STORELOCAL1
: case STORELOCAL2
: case STORELOCAL3
:
350 case STORELOCAL4
: case STORELOCAL5
: case STORELOCAL6
: case STORELOCAL7
:
351 case STORELOCAL8
: case STORELOCAL9
:
352 printf ("%d STORELOCAL%c\n", p
-code
, *p
-STORELOCAL0
+'0');
356 printf ("%d STORELOCAK %d\n", p
-code
, *(++p
));
360 printf ("%d STOREGLOBAL %d\n", p
-code
, *((Word
*)(p
+1)));
361 p
+= 1 + sizeof(Word
);
363 case STOREINDEXED0
: printf ("%d STOREINDEXED0\n", (p
++)-code
); break;
364 case STOREINDEXED
: printf ("%d STOREINDEXED %d\n", p
-code
, *(++p
));
367 case STOREFIELD
: printf ("%d STOREFIELD\n", (p
++)-code
); break;
369 printf ("%d ADJUST %d\n", p
-code
, *(++p
));
372 case CREATEARRAY
: printf ("%d CREATEARRAY\n", (p
++)-code
); break;
373 case EQOP
: printf ("%d EQOP\n", (p
++)-code
); break;
374 case LTOP
: printf ("%d LTOP\n", (p
++)-code
); break;
375 case LEOP
: printf ("%d LEOP\n", (p
++)-code
); break;
376 case ADDOP
: printf ("%d ADDOP\n", (p
++)-code
); break;
377 case SUBOP
: printf ("%d SUBOP\n", (p
++)-code
); break;
378 case MULTOP
: printf ("%d MULTOP\n", (p
++)-code
); break;
379 case DIVOP
: printf ("%d DIVOP\n", (p
++)-code
); break;
380 case CONCOP
: printf ("%d CONCOP\n", (p
++)-code
); break;
381 case MINUSOP
: printf ("%d MINUSOP\n", (p
++)-code
); break;
382 case NOTOP
: printf ("%d NOTOP\n", (p
++)-code
); break;
384 printf ("%d ONTJMP %d\n", p
-code
, *((Word
*)(p
+1)));
385 p
+= sizeof(Word
) + 1;
388 printf ("%d ONFJMP %d\n", p
-code
, *((Word
*)(p
+1)));
389 p
+= sizeof(Word
) + 1;
392 printf ("%d JMP %d\n", p
-code
, *((Word
*)(p
+1)));
393 p
+= sizeof(Word
) + 1;
396 printf ("%d UPJMP %d\n", p
-code
, *((Word
*)(p
+1)));
397 p
+= sizeof(Word
) + 1;
400 printf ("%d IFFJMP %d\n", p
-code
, *((Word
*)(p
+1)));
401 p
+= sizeof(Word
) + 1;
404 printf ("%d IFFUPJMP %d\n", p
-code
, *((Word
*)(p
+1)));
405 p
+= sizeof(Word
) + 1;
407 case POP
: printf ("%d POP\n", (p
++)-code
); break;
408 case CALLFUNC
: printf ("%d CALLFUNC\n", (p
++)-code
); break;
410 printf ("%d RETCODE %d\n", p
-code
, *(++p
));
413 default: printf ("%d Cannot happen\n", (p
++)-code
); break;
485 54, 52, 136, 53, 13, 55, 54, 52, 14, 53,
486 15, 55, 5, 166, 18, 6, 129, 21, 47, 46,
487 48, 107, 104, 97, 47, 46, 48, 54, 52, 80,
488 53, 21, 55, 54, 52, 40, 53, 9, 55, 54,
489 52, 158, 53, 160, 55, 47, 46, 48, 159, 101,
490 81, 47, 46, 48, 10, 54, 52, 126, 53, 67,
491 55, 54, 52, 60, 53, 155, 55, 148, 149, 135,
492 147, 108, 150, 47, 46, 48, 73, 23, 75, 47,
493 46, 48, 7, 25, 38, 153, 26, 164, 27, 117,
494 61, 62, 74, 11, 76, 54, 24, 127, 65, 66,
495 55, 37, 154, 151, 103, 111, 72, 28, 93, 94,
496 82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
497 92, 116, 59, 77, 54, 52, 118, 53, 99, 55,
498 110, 95, 64, 44, 70, 109, 29, 33, 105, 106,
499 42, 112, 41, 165, 139, 19, 17, 152, 79, 123,
500 43, 119, 20, 114, 113, 98, 63, 144, 143, 122,
501 68, 39, 36, 130, 35, 120, 12, 8, 102, 125,
502 128, 141, 78, 69, 70, 71, 142, 131, 132, 140,
503 22, 124, 4, 3, 2, 121, 96, 138, 146, 137,
504 134, 157, 133, 115, 16, 1, 0, 0, 0, 0,
505 0, 0, 0, 156, 0, 0, 0, 0, 161, 0,
506 0, 0, 0, 162, 0, 0, 0, 168, 0, 172,
507 145, 163, 171, 0, 174, 0, 0, 0, 169, 156,
508 167, 170, 173, 57, 58, 49, 50, 51, 56, 57,
509 58, 49, 50, 51, 56, 175, 0, 0, 100, 0,
510 45, 0, 0, 0, 0, 70, 0, 0, 0, 0,
511 57, 58, 49, 50, 51, 56, 57, 58, 49, 50,
512 51, 56, 0, 0, 0, 0, 0, 56, 0, 0,
513 0, 0, 0, 0, 0, 0, 0, 0, 57, 58,
514 49, 50, 51, 56, 0, 0, 49, 50, 51, 56,
515 32, 0, 0, 0, 0, 0, 0, 0, 0, 0,
516 0, 0, 30, 0, 21, 31, 0, 34 };
519 -1000, -258, -1000, -1000, -1000, -234, -1000, 34, -254, -1000,
520 -1000, -1000, -1000, 43, -1000, -1000, 40, -1000, -236, -1000,
521 -1000, -1000, 93, -9, -1000, 43, 43, 43, 92, -1000,
522 -1000, -1000, -1000, -1000, 43, 43, -1000, 43, -240, 62,
523 31, -13, 48, 83, -242, -1000, 43, 43, 43, 43,
524 43, 43, 43, 43, 43, 43, 43, -1000, -1000, 90,
525 13, -1000, -1000, -248, 43, 19, -15, -216, -1000, 60,
526 -1000, -1000, -249, -1000, -1000, 43, -250, 43, 89, 61,
527 -1000, -1000, -3, -3, -3, -3, -3, -3, 53, 53,
528 -1000, -1000, 82, -1000, -1000, -1000, -2, -1000, 85, 13,
529 -1000, 43, -1000, -1000, 31, 43, -36, -1000, 56, 60,
530 -1000, -255, -1000, 43, 43, -1000, -269, -1000, -1000, -1000,
531 13, 34, -1000, 43, -1000, 13, -1000, -1000, -1000, -1000,
532 -193, 19, 19, -53, 59, -1000, -1000, -8, 58, 43,
533 -1000, -1000, -1000, -1000, -226, -1000, -218, -223, -1000, 43,
534 -1000, -269, 26, -1000, -1000, -1000, 13, -253, 43, -1000,
535 -1000, -1000, -42, -1000, 43, 43, -1000, 34, -1000, 13,
536 -1000, -1000, -1000, -1000, -193, -1000 };
539 0, 195, 50, 96, 71, 135, 194, 193, 192, 190,
540 189, 187, 136, 186, 184, 82, 54, 183, 182, 180,
541 172, 170, 59, 168, 167, 166, 63, 70, 164, 162,
542 137, 161, 160, 159, 158, 157, 156, 155, 154, 153,
543 152, 150, 149, 148, 69, 147, 144, 65, 143, 142,
547 0, 1, 14, 1, 1, 1, 19, 21, 17, 23,
548 23, 24, 15, 16, 16, 25, 28, 25, 29, 25,
549 25, 25, 25, 27, 27, 27, 32, 33, 22, 34,
550 35, 34, 2, 26, 3, 3, 3, 3, 3, 3,
551 3, 3, 3, 3, 3, 3, 3, 3, 36, 3,
552 3, 3, 3, 3, 3, 3, 3, 38, 3, 39,
553 3, 37, 37, 41, 30, 40, 4, 4, 5, 42,
554 5, 20, 20, 43, 43, 13, 13, 7, 7, 8,
555 8, 9, 9, 45, 44, 10, 10, 46, 11, 48,
556 11, 47, 6, 6, 12, 49, 12, 50, 12, 31,
557 31, 51, 52, 51, 18 };
560 0, 0, 1, 9, 4, 4, 1, 1, 19, 0,
561 6, 1, 4, 0, 2, 17, 1, 17, 1, 13,
562 7, 3, 4, 0, 4, 15, 1, 1, 9, 0,
563 1, 9, 1, 3, 7, 7, 7, 7, 7, 7,
564 7, 7, 7, 7, 7, 7, 5, 5, 1, 9,
565 9, 3, 3, 3, 3, 3, 5, 1, 11, 1,
566 11, 1, 2, 1, 11, 3, 1, 3, 3, 1,
567 9, 0, 2, 3, 7, 1, 3, 7, 7, 1,
568 3, 3, 7, 1, 9, 1, 3, 1, 5, 1,
569 9, 3, 3, 7, 3, 1, 11, 1, 9, 5,
573 -1000, -1, -14, -17, -18, 270, 273, -15, -24, 271,
574 -16, 59, -25, 258, 262, 264, -6, -30, 268, -12,
575 -40, 271, -19, -26, -3, 40, 43, 45, 64, -12,
576 269, 272, 257, -30, 274, -28, -29, 61, 44, -31,
577 271, -49, -50, -41, 40, 259, 61, 60, 62, 277,
578 278, 279, 43, 45, 42, 47, 280, 275, 276, -3,
579 -26, -26, -26, -36, 40, -26, -26, -22, -32, -5,
580 -3, -12, 44, -51, 61, 91, 46, 40, -20, -43,
581 271, -2, -26, -26, -26, -26, -26, -26, -26, -26,
582 -26, -26, -26, -2, -2, 41, -13, 271, -37, -26,
583 263, 265, -23, 44, 271, -52, -26, 271, -4, -5,
584 41, 44, -22, -38, -39, -7, 123, 91, 41, -2,
585 -26, -15, -33, -42, -51, -26, 93, 41, -21, 271,
586 -2, -26, -26, -8, -9, -44, 271, -10, -11, -46,
587 -22, -2, -16, -34, -35, -3, -22, -27, 260, 261,
588 125, 44, -45, 93, 44, -47, -26, -2, 267, 266,
589 266, -22, -26, -44, 61, -48, 266, -4, 259, -26,
590 -47, -16, -2, -22, -2, -27 };
593 1, -2, 11, 4, 5, 0, 104, 13, 0, 6,
594 3, 14, 12, 0, 16, 18, 0, 21, 0, -2,
595 63, 94, 0, 0, 33, 0, 0, 0, 48, -2,
596 52, 53, 54, 55, 0, 0, 26, 0, 0, 22,
597 101, 0, 0, 0, 71, 32, 0, 0, 0, 0,
598 0, 0, 0, 0, 0, 0, 0, 32, 32, 33,
599 0, 46, 47, 75, 61, 56, 0, 0, 9, 20,
600 -2, -2, 0, 99, 102, 0, 0, 66, 0, 72,
601 73, 26, 35, 36, 37, 38, 39, 40, 41, 42,
602 43, 44, 45, 57, 59, 34, 0, 76, 0, 62,
603 32, 0, -2, 69, 101, 0, 0, 98, 0, 67,
604 7, 0, 32, 0, 0, 49, 79, -2, 50, 26,
605 32, 13, -2, 0, 100, 103, 96, 64, 26, 74,
606 23, 58, 60, 0, 80, 81, 83, 0, 86, 0,
607 32, 19, 10, 28, 0, -2, 0, 0, 26, 0,
608 77, 0, 0, 78, 89, 88, 91, 0, 66, 8,
609 15, 24, 0, 82, 0, 0, 17, 13, 32, 84,
610 90, 31, 26, 32, 23, 25 };
611 typedef struct { char *t_name
; int t_val
; } yytoktype
;
613 # define YYDEBUG 0 /* don't allow debugging */
653 "-unknown-", -1 /* ends search */
658 "-no such reduction-",
659 "functionlist : /* empty */",
660 "functionlist : functionlist",
661 "functionlist : functionlist stat sc",
662 "functionlist : functionlist function",
663 "functionlist : functionlist setdebug",
664 "function : FUNCTION NAME",
665 "function : FUNCTION NAME '(' parlist ')'",
666 "function : FUNCTION NAME '(' parlist ')' block END",
667 "statlist : /* empty */",
668 "statlist : statlist stat sc",
669 "stat : /* empty */",
673 "stat1 : IF expr1 THEN PrepJump block PrepJump elsepart END",
675 "stat1 : WHILE expr1 DO PrepJump block PrepJump END",
677 "stat1 : REPEAT block UNTIL expr1 PrepJump",
678 "stat1 : varlist1 '=' exprlist1",
679 "stat1 : functioncall",
680 "stat1 : LOCAL declist",
681 "elsepart : /* empty */",
682 "elsepart : ELSE block",
683 "elsepart : ELSEIF expr1 THEN PrepJump block PrepJump elsepart",
684 "block : /* empty */",
686 "block : statlist ret",
689 "ret : RETURN exprlist sc",
690 "PrepJump : /* empty */",
692 "expr : '(' expr ')'",
693 "expr : expr1 '=' expr1",
694 "expr : expr1 '<' expr1",
695 "expr : expr1 '>' expr1",
696 "expr : expr1 NE expr1",
697 "expr : expr1 LE expr1",
698 "expr : expr1 GE expr1",
699 "expr : expr1 '+' expr1",
700 "expr : expr1 '-' expr1",
701 "expr : expr1 '*' expr1",
702 "expr : expr1 '/' expr1",
703 "expr : expr1 CONC expr1",
707 "expr : '@' objectname fieldlist",
708 "expr : '@' '(' dimension ')'",
713 "expr : functioncall",
715 "expr : expr1 AND PrepJump",
716 "expr : expr1 AND PrepJump expr1",
717 "expr : expr1 OR PrepJump",
718 "expr : expr1 OR PrepJump expr1",
719 "dimension : /* empty */",
721 "functioncall : functionvalue",
722 "functioncall : functionvalue '(' exprlist ')'",
723 "functionvalue : var",
724 "exprlist : /* empty */",
725 "exprlist : exprlist1",
727 "exprlist1 : exprlist1 ','",
728 "exprlist1 : exprlist1 ',' expr",
729 "parlist : /* empty */",
730 "parlist : parlist1",
732 "parlist1 : parlist1 ',' NAME",
733 "objectname : /* empty */",
735 "fieldlist : '{' ffieldlist '}'",
736 "fieldlist : '[' lfieldlist ']'",
737 "ffieldlist : /* empty */",
738 "ffieldlist : ffieldlist1",
739 "ffieldlist1 : ffield",
740 "ffieldlist1 : ffieldlist1 ',' ffield",
742 "ffield : NAME '=' expr1",
743 "lfieldlist : /* empty */",
744 "lfieldlist : lfieldlist1",
745 "lfieldlist1 : /* empty */",
746 "lfieldlist1 : lfield",
747 "lfieldlist1 : lfieldlist1 ','",
748 "lfieldlist1 : lfieldlist1 ',' lfield",
751 "varlist1 : varlist1 ',' var",
754 "var : var '[' expr1 ']'",
756 "var : var '.' NAME",
757 "declist : NAME init",
758 "declist : declist ',' NAME init",
759 "init : /* empty */",
765 #line 1 "/usr/lib/yaccpar"
766 /* @(#)yaccpar 1.10 89/04/04 SMI; from S5R3 1.10 */
769 ** Skeleton parser driver for yacc output
773 ** yacc user known macros and defines
775 #define YYERROR goto yyerrlab
776 #define YYACCEPT { free(yys); free(yyv); return(0); }
777 #define YYABORT { free(yys); free(yyv); return(1); }
778 #define YYBACKUP( newtoken, newvalue )\
780 if ( yychar >= 0 || ( yyr2[ yytmp ] >> 1 ) != 1 )\
782 yyerror( "syntax error - cannot backup" );\
790 #define YYRECOVERING() (!!yyerrflag)
792 # define YYDEBUG 1 /* make debugging available */
796 ** user known globals
798 int yydebug
; /* set to 1 to get debugging */
801 ** driver internal defines
803 #define YYFLAG (-1000)
806 ** static variables used by the parser
808 static YYSTYPE
*yyv
; /* value stack */
809 static int *yys
; /* state stack */
811 static YYSTYPE
*yypv
; /* top of value stack */
812 static int *yyps
; /* top of state stack */
814 static int yystate
; /* current state */
815 static int yytmp
; /* extra var (lasts between blocks) */
817 int yynerrs
; /* number of errors */
819 int yyerrflag
; /* error recovery flag */
820 int yychar
; /* current input token number */
824 ** yyparse - return 0 if worked, 1 if syntax error not recovered from
829 register YYSTYPE
*yypvt
; /* top of value stack for $vars */
830 unsigned yymaxdepth
= YYMAXDEPTH
;
833 ** Initialize externals - yyparse may be called more than once
835 yyv
= (YYSTYPE
*)malloc(yymaxdepth
*sizeof(YYSTYPE
));
836 yys
= (int*)malloc(yymaxdepth
*sizeof(int));
839 yyerror( "out of memory" );
852 register YYSTYPE
*yy_pv
; /* top of value stack */
853 register int *yy_ps
; /* top of state stack */
854 register int yy_state
; /* current state */
855 register int yy_n
; /* internal state number info */
858 ** get globals into registers.
859 ** branch to here only if YYBACKUP was called.
868 ** get globals into registers.
869 ** either we just started, or we just finished a reduction
877 ** top of for (;;) loop while no reductions done
881 ** put a state and value onto the stacks
885 ** if debugging, look up token value in list of value vs.
886 ** name pairs. 0 and negative (-1) are special values.
887 ** Note: linear search is used since time is not a real
888 ** consideration while debugging.
894 (void)printf( "State %d, token ", yy_state
);
896 (void)printf( "end-of-file\n" );
897 else if ( yychar
< 0 )
898 (void)printf( "-none-\n" );
901 for ( yy_i
= 0; yytoks
[yy_i
].t_val
>= 0;
904 if ( yytoks
[yy_i
].t_val
== yychar
)
907 (void)printf( "%s\n", yytoks
[yy_i
].t_name
);
911 if ( ++yy_ps
>= &yys
[ yymaxdepth
] ) /* room on stack? */
914 ** reallocate and recover. Note that pointers
915 ** have to be reset, or bad things will happen
917 int yyps_index
= (yy_ps
- yys
);
918 int yypv_index
= (yy_pv
- yyv
);
919 int yypvt_index
= (yypvt
- yyv
);
920 yymaxdepth
+= YYMAXDEPTH
;
921 yyv
= (YYSTYPE
*)realloc((char*)yyv
,
922 yymaxdepth
* sizeof(YYSTYPE
));
923 yys
= (int*)realloc((char*)yys
,
924 yymaxdepth
* sizeof(int));
927 yyerror( "yacc stack overflow" );
930 yy_ps
= yys
+ yyps_index
;
931 yy_pv
= yyv
+ yypv_index
;
932 yypvt
= yyv
+ yypvt_index
;
938 ** we have a new state - find out what to do
941 if ( ( yy_n
= yypact
[ yy_state
] ) <= YYFLAG
)
942 goto yydefault
; /* simple state */
945 ** if debugging, need to mark whether new token grabbed
949 if ( ( yychar
< 0 ) && ( ( yychar
= yylex() ) < 0 ) )
950 yychar
= 0; /* reached EOF */
952 if ( yydebug
&& yytmp
)
956 (void)printf( "Received token " );
958 (void)printf( "end-of-file\n" );
959 else if ( yychar
< 0 )
960 (void)printf( "-none-\n" );
963 for ( yy_i
= 0; yytoks
[yy_i
].t_val
>= 0;
966 if ( yytoks
[yy_i
].t_val
== yychar
)
969 (void)printf( "%s\n", yytoks
[yy_i
].t_name
);
973 if ( ( ( yy_n
+= yychar
) < 0 ) || ( yy_n
>= YYLAST
) )
975 if ( yychk
[ yy_n
= yyact
[ yy_n
] ] == yychar
) /*valid shift*/
986 if ( ( yy_n
= yydef
[ yy_state
] ) == -2 )
991 if ( ( yychar
< 0 ) && ( ( yychar
= yylex() ) < 0 ) )
992 yychar
= 0; /* reached EOF */
994 if ( yydebug
&& yytmp
)
998 (void)printf( "Received token " );
1000 (void)printf( "end-of-file\n" );
1001 else if ( yychar
< 0 )
1002 (void)printf( "-none-\n" );
1006 yytoks
[yy_i
].t_val
>= 0;
1009 if ( yytoks
[yy_i
].t_val
1015 (void)printf( "%s\n", yytoks
[yy_i
].t_name
);
1018 #endif /* YYDEBUG */
1020 ** look through exception table
1023 register int *yyxi
= yyexca
;
1025 while ( ( *yyxi
!= -1 ) ||
1026 ( yyxi
[1] != yy_state
) )
1030 while ( ( *(yyxi
+= 2) >= 0 ) &&
1031 ( *yyxi
!= yychar
) )
1033 if ( ( yy_n
= yyxi
[1] ) < 0 )
1039 ** check for syntax error
1041 if ( yy_n
== 0 ) /* have an error */
1043 /* no worry about speed here! */
1044 switch ( yyerrflag
)
1046 case 0: /* new error */
1047 yyerror( "syntax error" );
1051 ** get globals into registers.
1052 ** we have a user generated syntax type error
1060 case 2: /* incompletely recovered error */
1064 ** find state where "error" is a legal
1067 while ( yy_ps
>= yys
)
1069 yy_n
= yypact
[ *yy_ps
] + YYERRCODE
;
1070 if ( yy_n
>= 0 && yy_n
< YYLAST
&&
1071 yychk
[yyact
[yy_n
]] == YYERRCODE
) {
1073 ** simulate shift of "error"
1075 yy_state
= yyact
[ yy_n
];
1079 ** current state has no shift on
1080 ** "error", pop stack
1083 # define _POP_ "Error recovery pops state %d, uncovers state %d\n"
1085 (void)printf( _POP_
, *yy_ps
,
1093 ** there is no state on stack with "error" as
1094 ** a valid shift. give up.
1097 case 3: /* no shift yet; eat a token */
1100 ** if debugging, look up token in list of
1101 ** pairs. 0 and negative shouldn't occur,
1102 ** but since timing doesn't matter when
1103 ** debugging, it doesn't hurt to leave the
1110 (void)printf( "Error recovery discards " );
1112 (void)printf( "token end-of-file\n" );
1113 else if ( yychar
< 0 )
1114 (void)printf( "token -none-\n" );
1118 yytoks
[yy_i
].t_val
>= 0;
1121 if ( yytoks
[yy_i
].t_val
1127 (void)printf( "token %s\n",
1128 yytoks
[yy_i
].t_name
);
1131 #endif /* YYDEBUG */
1132 if ( yychar
== 0 ) /* reached EOF. quit */
1137 }/* end if ( yy_n == 0 ) */
1139 ** reduction by production yy_n
1140 ** put stack tops, etc. so things right after switch
1144 ** if debugging, print the string that is the user's
1145 ** specification of the reduction which is just about
1149 (void)printf( "Reduce by (%d) \"%s\"\n",
1150 yy_n
, yyreds
[ yy_n
] );
1152 yytmp
= yy_n
; /* value to switch over */
1153 yypvt
= yy_pv
; /* $vars top of value stack */
1155 ** Look in goto table for next state
1156 ** Sorry about using yy_state here as temporary
1157 ** register variable, but why not, if it works...
1158 ** If yyr2[ yy_n ] doesn't have the low order bit
1159 ** set, then there is no action to be done for
1160 ** this reduction. So, no saving & unsaving of
1161 ** registers done. The only difference between the
1162 ** code just after the if and the body of the if is
1163 ** the goto yy_stack in the body. This way the test
1164 ** can be made before the choice of what to do is needed.
1167 /* length of production doubled with extra bit */
1168 register int yy_len
= yyr2
[ yy_n
];
1170 if ( !( yy_len
& 01 ) )
1173 yyval
= ( yy_pv
-= yy_len
)[1]; /* $$ = $1 */
1174 yy_state
= yypgo
[ yy_n
= yyr1
[ yy_n
] ] +
1175 *( yy_ps
-= yy_len
) + 1;
1176 if ( yy_state
>= YYLAST
||
1178 yyact
[ yy_state
] ] != -yy_n
)
1180 yy_state
= yyact
[ yypgo
[ yy_n
] ];
1185 yyval
= ( yy_pv
-= yy_len
)[1]; /* $$ = $1 */
1186 yy_state
= yypgo
[ yy_n
= yyr1
[ yy_n
] ] +
1187 *( yy_ps
-= yy_len
) + 1;
1188 if ( yy_state
>= YYLAST
||
1189 yychk
[ yy_state
= yyact
[ yy_state
] ] != -yy_n
)
1191 yy_state
= yyact
[ yypgo
[ yy_n
] ];
1194 /* save until reenter driver code */
1200 ** code supplied by user is placed in this switch
1206 # line 179 "lua.stx"
1207 {pc
=basepc
=maincode
; nlocalvar
=0;} break;
1209 # line 179 "lua.stx"
1210 {maincode
=pc
;} break;
1212 # line 184 "lua.stx"
1213 {pc
=basepc
=code
; nlocalvar
=0;} break;
1215 # line 185 "lua.stx"
1220 code_byte(SETFUNCTION
);
1221 code_word(yypvt
[-5].vWord
);
1222 code_word(yypvt
[-4].vWord
);
1227 # line 197 "lua.stx"
1229 if (lua_debug
) code_byte(RESET
);
1230 code_byte(RETCODE
); code_byte(nlocalvar
);
1231 s_tag(yypvt
[-7].vWord
) = T_FUNCTION
;
1232 s_bvalue(yypvt
[-7].vWord
) = calloc (pc
-code
, sizeof(Byte
));
1233 memcpy (s_bvalue(yypvt
[-7].vWord
), code
, (pc
-code
)*sizeof(Byte
));
1236 # line 210 "lua.stx"
1241 align(Word
); code_byte(SETLINE
); code_word(lua_linenumber
);
1245 # line 223 "lua.stx"
1248 Byte
*elseinit
= yypvt
[-2].pByte
+ sizeof(Word
)+1;
1249 if (pc
- elseinit
== 0) /* no else */
1251 pc
-= sizeof(Word
)+1;
1252 /* if (*(pc-1) == NOP) --pc; */
1257 *(yypvt
[-2].pByte
) = JMP
;
1258 *((Word
*)(yypvt
[-2].pByte
+1)) = pc
- elseinit
;
1260 *(yypvt
[-4].pByte
) = IFFJMP
;
1261 *((Word
*)(yypvt
[-4].pByte
+1)) = elseinit
- (yypvt
[-4].pByte
+ sizeof(Word
)+1);
1265 # line 242 "lua.stx"
1266 {yyval
.pByte
= pc
;} break;
1268 # line 244 "lua.stx"
1270 *(yypvt
[-3].pByte
) = IFFJMP
;
1271 *((Word
*)(yypvt
[-3].pByte
+1)) = pc
- (yypvt
[-3].pByte
+ sizeof(Word
)+1);
1273 *(yypvt
[-1].pByte
) = UPJMP
;
1274 *((Word
*)(yypvt
[-1].pByte
+1)) = pc
- yypvt
[-6].pByte
;
1277 # line 252 "lua.stx"
1278 {yyval
.pByte
= pc
;} break;
1280 # line 254 "lua.stx"
1282 *(yypvt
[-0].pByte
) = IFFUPJMP
;
1283 *((Word
*)(yypvt
[-0].pByte
+1)) = pc
- yypvt
[-4].pByte
;
1286 # line 261 "lua.stx"
1290 if (yypvt
[-0].vInt
== 0 || nvarbuffer
!= ntemp
- yypvt
[-2].vInt
* 2)
1291 lua_codeadjust (yypvt
[-2].vInt
* 2 + nvarbuffer
);
1292 for (i
=nvarbuffer
-1; i
>=0; i
--)
1294 if (yypvt
[-2].vInt
> 1 || (yypvt
[-2].vInt
== 1 && varbuffer
[0] != 0))
1299 # line 272 "lua.stx"
1300 { lua_codeadjust (0); } break;
1302 # line 279 "lua.stx"
1305 Byte
*elseinit
= yypvt
[-1].pByte
+ sizeof(Word
)+1;
1306 if (pc
- elseinit
== 0) /* no else */
1308 pc
-= sizeof(Word
)+1;
1309 /* if (*(pc-1) == NOP) --pc; */
1314 *(yypvt
[-1].pByte
) = JMP
;
1315 *((Word
*)(yypvt
[-1].pByte
+1)) = pc
- elseinit
;
1317 *(yypvt
[-3].pByte
) = IFFJMP
;
1318 *((Word
*)(yypvt
[-3].pByte
+1)) = elseinit
- (yypvt
[-3].pByte
+ sizeof(Word
)+1);
1322 # line 299 "lua.stx"
1323 {yyval
.vInt
= nlocalvar
;} break;
1325 # line 299 "lua.stx"
1328 # line 300 "lua.stx"
1330 if (nlocalvar
!= yypvt
[-3].vInt
)
1332 nlocalvar
= yypvt
[-3].vInt
;
1337 # line 310 "lua.stx"
1338 { if (lua_debug
){align(Word
);code_byte(SETLINE
);code_word(lua_linenumber
);}} break;
1340 # line 312 "lua.stx"
1342 if (lua_debug
) code_byte(RESET
);
1343 code_byte(RETCODE
); code_byte(nlocalvar
);
1346 # line 319 "lua.stx"
1350 code_byte(0); /* open space */
1354 # line 326 "lua.stx"
1355 { if (yypvt
[-0].vInt
== 0) {lua_codeadjust (ntemp
+1); incr_ntemp();}} break;
1357 # line 329 "lua.stx"
1358 { yyval
.vInt
= yypvt
[-1].vInt
; } break;
1360 # line 330 "lua.stx"
1361 { code_byte(EQOP
); yyval
.vInt
= 1; ntemp
--;} break;
1363 # line 331 "lua.stx"
1364 { code_byte(LTOP
); yyval
.vInt
= 1; ntemp
--;} break;
1366 # line 332 "lua.stx"
1367 { code_byte(LEOP
); code_byte(NOTOP
); yyval
.vInt
= 1; ntemp
--;} break;
1369 # line 333 "lua.stx"
1370 { code_byte(EQOP
); code_byte(NOTOP
); yyval
.vInt
= 1; ntemp
--;} break;
1372 # line 334 "lua.stx"
1373 { code_byte(LEOP
); yyval
.vInt
= 1; ntemp
--;} break;
1375 # line 335 "lua.stx"
1376 { code_byte(LTOP
); code_byte(NOTOP
); yyval
.vInt
= 1; ntemp
--;} break;
1378 # line 336 "lua.stx"
1379 { code_byte(ADDOP
); yyval
.vInt
= 1; ntemp
--;} break;
1381 # line 337 "lua.stx"
1382 { code_byte(SUBOP
); yyval
.vInt
= 1; ntemp
--;} break;
1384 # line 338 "lua.stx"
1385 { code_byte(MULTOP
); yyval
.vInt
= 1; ntemp
--;} break;
1387 # line 339 "lua.stx"
1388 { code_byte(DIVOP
); yyval
.vInt
= 1; ntemp
--;} break;
1390 # line 340 "lua.stx"
1391 { code_byte(CONCOP
); yyval
.vInt
= 1; ntemp
--;} break;
1393 # line 341 "lua.stx"
1394 { yyval
.vInt
= 1; } break;
1396 # line 342 "lua.stx"
1397 { code_byte(MINUSOP
); yyval
.vInt
= 1;} break;
1399 # line 344 "lua.stx"
1401 code_byte(PUSHBYTE
);
1402 yyval
.pByte
= pc
; code_byte(0);
1404 code_byte(CREATEARRAY
);
1407 # line 351 "lua.stx"
1409 *(yypvt
[-2].pByte
) = yypvt
[-0].vInt
;
1410 if (yypvt
[-1].vLong
< 0) /* there is no function to be called */
1416 lua_pushvar (yypvt
[-1].vLong
+1);
1417 code_byte(PUSHMARK
);
1419 code_byte(PUSHOBJECT
);
1421 code_byte(CALLFUNC
);
1426 align(Word
); code_byte(SETLINE
); code_word(lua_linenumber
);
1431 # line 374 "lua.stx"
1433 code_byte(CREATEARRAY
);
1437 # line 378 "lua.stx"
1438 { lua_pushvar (yypvt
[-0].vLong
); yyval
.vInt
= 1;} break;
1440 # line 379 "lua.stx"
1441 { code_number(yypvt
[-0].vFloat
); yyval
.vInt
= 1; } break;
1443 # line 381 "lua.stx"
1446 code_byte(PUSHSTRING
);
1447 code_word(yypvt
[-0].vWord
);
1452 # line 388 "lua.stx"
1453 {code_byte(PUSHNIL
); yyval
.vInt
= 1; incr_ntemp();} break;
1455 # line 390 "lua.stx"
1460 align(Word
); code_byte(SETLINE
); code_word(lua_linenumber
);
1464 # line 397 "lua.stx"
1465 { code_byte(NOTOP
); yyval
.vInt
= 1;} break;
1467 # line 398 "lua.stx"
1468 {code_byte(POP
); ntemp
--;} break;
1470 # line 399 "lua.stx"
1472 *(yypvt
[-2].pByte
) = ONFJMP
;
1473 *((Word
*)(yypvt
[-2].pByte
+1)) = pc
- (yypvt
[-2].pByte
+ sizeof(Word
)+1);
1477 # line 404 "lua.stx"
1478 {code_byte(POP
); ntemp
--;} break;
1480 # line 405 "lua.stx"
1482 *(yypvt
[-2].pByte
) = ONTJMP
;
1483 *((Word
*)(yypvt
[-2].pByte
+1)) = pc
- (yypvt
[-2].pByte
+ sizeof(Word
)+1);
1487 # line 412 "lua.stx"
1488 { code_byte(PUSHNIL
); incr_ntemp();} break;
1490 # line 416 "lua.stx"
1491 {code_byte(PUSHMARK
); yyval
.vInt
= ntemp
; incr_ntemp();} break;
1493 # line 417 "lua.stx"
1494 { code_byte(CALLFUNC
); ntemp
= yypvt
[-3].vInt
-1;} break;
1496 # line 419 "lua.stx"
1497 {lua_pushvar (yypvt
[-0].vLong
); } break;
1499 # line 422 "lua.stx"
1500 { yyval
.vInt
= 1; } break;
1502 # line 423 "lua.stx"
1503 { yyval
.vInt
= yypvt
[-0].vInt
; } break;
1505 # line 426 "lua.stx"
1506 { yyval
.vInt
= yypvt
[-0].vInt
; } break;
1508 # line 427 "lua.stx"
1509 {if (!yypvt
[-1].vInt
){lua_codeadjust (ntemp
+1); incr_ntemp();}} break;
1511 # line 428 "lua.stx"
1512 {yyval
.vInt
= yypvt
[-0].vInt
;} break;
1514 # line 435 "lua.stx"
1515 {localvar
[nlocalvar
]=yypvt
[-0].vWord
; incr_nlocalvar();} break;
1517 # line 436 "lua.stx"
1518 {localvar
[nlocalvar
]=yypvt
[-0].vWord
; incr_nlocalvar();} break;
1520 # line 439 "lua.stx"
1521 {yyval
.vLong
=-1;} break;
1523 # line 440 "lua.stx"
1524 {yyval
.vLong
=yypvt
[-0].vWord
;} break;
1526 # line 443 "lua.stx"
1527 { yyval
.vInt
= yypvt
[-1].vInt
; } break;
1529 # line 444 "lua.stx"
1530 { yyval
.vInt
= yypvt
[-1].vInt
; } break;
1532 # line 447 "lua.stx"
1533 { yyval
.vInt
= 0; } break;
1535 # line 448 "lua.stx"
1536 { yyval
.vInt
= yypvt
[-0].vInt
; } break;
1538 # line 451 "lua.stx"
1539 {yyval
.vInt
=1;} break;
1541 # line 452 "lua.stx"
1542 {yyval
.vInt
=yypvt
[-2].vInt
+1;} break;
1544 # line 456 "lua.stx"
1547 code_byte(PUSHSTRING
);
1548 code_word(lua_findconstant (s_name(yypvt
[-0].vWord
)));
1552 # line 463 "lua.stx"
1554 code_byte(STOREFIELD
);
1558 # line 469 "lua.stx"
1559 { yyval
.vInt
= 0; } break;
1561 # line 470 "lua.stx"
1562 { yyval
.vInt
= yypvt
[-0].vInt
; } break;
1564 # line 473 "lua.stx"
1565 { code_number(1); } break;
1567 # line 473 "lua.stx"
1568 {yyval
.vInt
=1;} break;
1570 # line 474 "lua.stx"
1571 { code_number(yypvt
[-1].vInt
+1); } break;
1573 # line 475 "lua.stx"
1574 {yyval
.vInt
=yypvt
[-3].vInt
+1;} break;
1576 # line 479 "lua.stx"
1578 code_byte(STOREFIELD
);
1582 # line 486 "lua.stx"
1585 varbuffer
[nvarbuffer
] = yypvt
[-0].vLong
; incr_nvarbuffer();
1586 yyval
.vInt
= (yypvt
[-0].vLong
== 0) ? 1 : 0;
1589 # line 492 "lua.stx"
1591 varbuffer
[nvarbuffer
] = yypvt
[-0].vLong
; incr_nvarbuffer();
1592 yyval
.vInt
= (yypvt
[-0].vLong
== 0) ? yypvt
[-2].vInt
+ 1 : yypvt
[-2].vInt
;
1595 # line 499 "lua.stx"
1597 int local
= lua_localname (yypvt
[-0].vWord
);
1598 if (local
== -1) /* global var */
1599 yyval
.vLong
= yypvt
[-0].vWord
+ 1; /* return positive value */
1601 yyval
.vLong
= -(local
+1); /* return negative value */
1604 # line 507 "lua.stx"
1605 {lua_pushvar (yypvt
[-0].vLong
);} break;
1607 # line 508 "lua.stx"
1609 yyval
.vLong
= 0; /* indexed variable */
1612 # line 511 "lua.stx"
1613 {lua_pushvar (yypvt
[-0].vLong
);} break;
1615 # line 512 "lua.stx"
1618 code_byte(PUSHSTRING
);
1619 code_word(lua_findconstant (s_name(yypvt
[-0].vWord
))); incr_ntemp();
1620 yyval
.vLong
= 0; /* indexed variable */
1623 # line 520 "lua.stx"
1624 {localvar
[nlocalvar
]=yypvt
[-1].vWord
; incr_nlocalvar();} break;
1626 # line 521 "lua.stx"
1627 {localvar
[nlocalvar
]=yypvt
[-1].vWord
; incr_nlocalvar();} break;
1629 # line 524 "lua.stx"
1630 { code_byte(PUSHNIL
); } break;
1632 # line 525 "lua.stx"
1635 # line 528 "lua.stx"
1636 {lua_debug
= yypvt
[-0].vInt
;} break;
1638 goto yystack
; /* reset registers in driver code */