aboutsummaryrefslogtreecommitdiff
path: root/lua.stx
diff options
context:
space:
mode:
authorWaldemar Celes <celes@tecgraf.puc-rio.br>1994-10-17 17:05:32 -0200
committerWaldemar Celes <celes@tecgraf.puc-rio.br>1994-10-17 17:05:32 -0200
commit424db1db0cefbcb14d23961e6613d0f8fbb3dae4 (patch)
tree195ee014de0063c2e5fd5943026d520178d77293 /lua.stx
parente9049cbfc91318f51c3d9efb867e4b9f07fcf750 (diff)
downloadlua-424db1db0cefbcb14d23961e6613d0f8fbb3dae4.tar.gz
lua-424db1db0cefbcb14d23961e6613d0f8fbb3dae4.tar.bz2
lua-424db1db0cefbcb14d23961e6613d0f8fbb3dae4.zip
power operator (^).
no more contructors (@). methods can be called on indexed variables. fixed debuging information.
Diffstat (limited to 'lua.stx')
-rw-r--r--lua.stx87
1 files changed, 37 insertions, 50 deletions
diff --git a/lua.stx b/lua.stx
index e71a8bda..44c57a80 100644
--- a/lua.stx
+++ b/lua.stx
@@ -1,6 +1,6 @@
1%{ 1%{
2 2
3char *rcs_luastx = "$Id: lua.stx,v 2.8 1994/10/11 13:02:39 celes Exp celes $"; 3char *rcs_luastx = "$Id: lua.stx,v 2.9 1994/10/11 14:38:17 celes Exp celes $";
4 4
5#include <stdio.h> 5#include <stdio.h>
6#include <stdlib.h> 6#include <stdlib.h>
@@ -237,11 +237,10 @@ static void init_function (void)
237%token <vInt> DEBUG 237%token <vInt> DEBUG
238 238
239%type <vLong> PrepJump 239%type <vLong> PrepJump
240%type <vInt> expr, exprlist, exprlist1, varlist1 240%type <vInt> expr, exprlist, exprlist1, varlist1, funcvalue
241%type <vInt> fieldlist, localdeclist 241%type <vInt> fieldlist, localdeclist
242%type <vInt> ffieldlist1 242%type <vInt> ffieldlist1
243%type <vInt> lfieldlist1 243%type <vInt> lfieldlist1
244%type <vInt> functionvalue
245%type <vLong> var, singlevar 244%type <vLong> var, singlevar
246 245
247 246
@@ -251,6 +250,7 @@ static void init_function (void)
251%left '+' '-' 250%left '+' '-'
252%left '*' '/' 251%left '*' '/'
253%left UNARY NOT 252%left UNARY NOT
253%right '^'
254 254
255 255
256%% /* beginning of rules section */ 256%% /* beginning of rules section */
@@ -322,7 +322,7 @@ method : FUNCTION NAME { $<vWord>$ = lua_findsymbol($2); } ':' NAME
322 if (lua_debug) 322 if (lua_debug)
323 { 323 {
324 code_byte(SETFUNCTION); 324 code_byte(SETFUNCTION);
325 code_word(lua_nfile-1); 325 code_code((Byte *)lua_file[lua_nfile-1]);
326 code_word($<vWord>6); 326 code_word($<vWord>6);
327 } 327 }
328 lua_codeadjust (0); 328 lua_codeadjust (0);
@@ -425,7 +425,6 @@ stat1 : IF expr1 THEN PrepJump block PrepJump elsepart END
425 } 425 }
426 } 426 }
427 | functioncall { lua_codeadjust (0); } 427 | functioncall { lua_codeadjust (0); }
428 | constructor { lua_codeadjust (0); }
429 | LOCAL localdeclist decinit { add_nlocalvar($2); lua_codeadjust (0); } 428 | LOCAL localdeclist decinit { add_nlocalvar($2); lua_codeadjust (0); }
430 ; 429 ;
431 430
@@ -480,8 +479,8 @@ PrepJump : /* empty */
480expr1 : expr { if ($1 == 0) {lua_codeadjust (ntemp+1); incr_ntemp();}} 479expr1 : expr { if ($1 == 0) {lua_codeadjust (ntemp+1); incr_ntemp();}}
481 ; 480 ;
482 481
483expr : '(' expr ')' { $$ = $2; } 482expr : '(' expr ')' { $$ = $2; }
484 | expr1 EQ expr1 { code_byte(EQOP); $$ = 1; ntemp--;} 483 | expr1 EQ expr1 { code_byte(EQOP); $$ = 1; ntemp--;}
485 | expr1 '<' expr1 { code_byte(LTOP); $$ = 1; ntemp--;} 484 | expr1 '<' expr1 { code_byte(LTOP); $$ = 1; ntemp--;}
486 | expr1 '>' expr1 { code_byte(LEOP); code_byte(NOTOP); $$ = 1; ntemp--;} 485 | expr1 '>' expr1 { code_byte(LEOP); code_byte(NOTOP); $$ = 1; ntemp--;}
487 | expr1 NE expr1 { code_byte(EQOP); code_byte(NOTOP); $$ = 1; ntemp--;} 486 | expr1 NE expr1 { code_byte(EQOP); code_byte(NOTOP); $$ = 1; ntemp--;}
@@ -491,14 +490,14 @@ expr : '(' expr ')' { $$ = $2; }
491 | expr1 '-' expr1 { code_byte(SUBOP); $$ = 1; ntemp--;} 490 | expr1 '-' expr1 { code_byte(SUBOP); $$ = 1; ntemp--;}
492 | expr1 '*' expr1 { code_byte(MULTOP); $$ = 1; ntemp--;} 491 | expr1 '*' expr1 { code_byte(MULTOP); $$ = 1; ntemp--;}
493 | expr1 '/' expr1 { code_byte(DIVOP); $$ = 1; ntemp--;} 492 | expr1 '/' expr1 { code_byte(DIVOP); $$ = 1; ntemp--;}
493 | expr1 '^' expr1 { code_byte(POWOP); $$ = 1; ntemp--;}
494 | expr1 CONC expr1 { code_byte(CONCOP); $$ = 1; ntemp--;} 494 | expr1 CONC expr1 { code_byte(CONCOP); $$ = 1; ntemp--;}
495 | '+' expr1 %prec UNARY { $$ = 1; } 495 | '+' expr1 %prec UNARY { $$ = 1; }
496 | '-' expr1 %prec UNARY { code_byte(MINUSOP); $$ = 1;} 496 | '-' expr1 %prec UNARY { code_byte(MINUSOP); $$ = 1;}
497 | constructor { $$ = 0; }
498 | table { $$ = 1; } 497 | table { $$ = 1; }
499 | var { lua_pushvar ($1); $$ = 1;} 498 | varexp { $$ = 1;}
500 | NUMBER { code_number($1); $$ = 1; } 499 | NUMBER { code_number($1); $$ = 1; }
501 | STRING 500 | STRING
502 { 501 {
503 code_byte(PUSHSTRING); 502 code_byte(PUSHSTRING);
504 code_word(lua_findconstant($1)); 503 code_word(lua_findconstant($1));
@@ -506,7 +505,7 @@ expr : '(' expr ')' { $$ = $2; }
506 incr_ntemp(); 505 incr_ntemp();
507 } 506 }
508 | NIL {code_byte(PUSHNIL); $$ = 1; incr_ntemp();} 507 | NIL {code_byte(PUSHNIL); $$ = 1; incr_ntemp();}
509 | functioncall 508 | functioncall
510 { 509 {
511 $$ = 0; 510 $$ = 0;
512 if (lua_debug) 511 if (lua_debug)
@@ -529,21 +528,6 @@ expr : '(' expr ')' { $$ = $2; }
529 } 528 }
530 ; 529 ;
531 530
532constructor : '@' singlevar table
533 {
534 lua_pushvar ($2);
535 code_byte(PUSHMARK);
536 incr_ntemp();
537 code_byte(PUSHOBJECT);
538 incr_ntemp();
539 code_byte(CALLFUNC);
540 ntemp -= 4;
541 if (lua_debug)
542 {
543 code_byte(SETLINE); code_word(lua_linenumber);
544 }
545 }
546 ;
547table : 531table :
548 { 532 {
549 code_byte(PUSHWORD); 533 code_byte(PUSHWORD);
@@ -557,25 +541,25 @@ table :
557 } 541 }
558 ; 542 ;
559 543
560functioncall : functionvalue 544functioncall : funcvalue funcParams { code_byte(CALLFUNC); ntemp = $1-1; }
545 ;
546funcvalue : varexp
561 { 547 {
562 code_byte(PUSHMARK); $<vInt>$ = ntemp; incr_ntemp(); 548 $$ = ntemp; code_byte(PUSHMARK); incr_ntemp();
563 if ($1 != 0) lua_pushvar($1);
564 } 549 }
565 '(' exprlist ')' { code_byte(CALLFUNC); ntemp = $<vInt>2-1;} 550 | varexp ':' NAME
551 {
552 code_byte(PUSHSTRING);
553 code_word(lua_findconstant($3));
554 incr_ntemp();
555 $$ = ntemp-1;
556 code_byte(PUSHMARKMET);
557 incr_ntemp();
558 }
566 ; 559 ;
567 560funcParams : '(' exprlist ')'
568functionvalue : var {lua_pushvar ($1); $$ = 0; } 561 | table
569 | singlevar ':' NAME 562 ;
570 {
571 $$ = $1;
572 lua_pushvar($1);
573 code_byte(PUSHSTRING);
574 code_word(lua_findconstant($3));
575 incr_ntemp();
576 lua_pushvar(0);
577 }
578 ;
579 563
580exprlist : /* empty */ { $$ = 1; } 564exprlist : /* empty */ { $$ = 1; }
581 | exprlist1 { $$ = $1; } 565 | exprlist1 { $$ = $1; }
@@ -654,14 +638,14 @@ varlist1 : var
654 ; 638 ;
655 639
656var : singlevar { $$ = $1; } 640var : singlevar { $$ = $1; }
657 | var {lua_pushvar ($1);} '[' expr1 ']' 641 | varexp '[' expr1 ']'
658 { 642 {
659 $$ = 0; /* indexed variable */ 643 $$ = 0; /* indexed variable */
660 } 644 }
661 | var {lua_pushvar ($1);} '.' NAME 645 | varexp '.' NAME
662 { 646 {
663 code_byte(PUSHSTRING); 647 code_byte(PUSHSTRING);
664 code_word(lua_findconstant($4)); incr_ntemp(); 648 code_word(lua_findconstant($3)); incr_ntemp();
665 $$ = 0; /* indexed variable */ 649 $$ = 0; /* indexed variable */
666 } 650 }
667 ; 651 ;
@@ -676,6 +660,9 @@ singlevar : NAME
676 $$ = -(local+1); /* return negative value */ 660 $$ = -(local+1); /* return negative value */
677 } 661 }
678 ; 662 ;
663
664varexp : var { lua_pushvar($1); }
665 ;
679 666
680localdeclist : NAME {localvar[nlocalvar]=lua_findsymbol($1); $$ = 1;} 667localdeclist : NAME {localvar[nlocalvar]=lua_findsymbol($1); $$ = 1;}
681 | localdeclist ',' NAME 668 | localdeclist ',' NAME
@@ -894,7 +881,6 @@ static void PrintCode (Byte *code, Byte *end)
894 break; 881 break;
895 case PUSHINDEXED: printf ("%d PUSHINDEXED\n", (p++)-code); break; 882 case PUSHINDEXED: printf ("%d PUSHINDEXED\n", (p++)-code); break;
896 case PUSHMARK: printf ("%d PUSHMARK\n", (p++)-code); break; 883 case PUSHMARK: printf ("%d PUSHMARK\n", (p++)-code); break;
897 case PUSHOBJECT: printf ("%d PUSHOBJECT\n", (p++)-code); break;
898 case STORELOCAL0: case STORELOCAL1: case STORELOCAL2: case STORELOCAL3: 884 case STORELOCAL0: case STORELOCAL1: case STORELOCAL2: case STORELOCAL3:
899 case STORELOCAL4: case STORELOCAL5: case STORELOCAL6: case STORELOCAL7: 885 case STORELOCAL4: case STORELOCAL5: case STORELOCAL6: case STORELOCAL7:
900 case STORELOCAL8: case STORELOCAL9: 886 case STORELOCAL8: case STORELOCAL9:
@@ -1008,12 +994,13 @@ static void PrintCode (Byte *code, Byte *end)
1008 case HALT: printf ("%d HALT\n", (p++)-code); break; 994 case HALT: printf ("%d HALT\n", (p++)-code); break;
1009 case SETFUNCTION: 995 case SETFUNCTION:
1010 { 996 {
1011 CodeWord c1, c2; 997 CodeCode c1;
998 CodeWord c1;
1012 int n = p-code; 999 int n = p-code;
1013 p++; 1000 p++;
1014 get_word(c1,p); 1001 get_code(c1,p);
1015 get_word(c2,p); 1002 get_word(c2,p);
1016 printf ("%d SETFUNCTION %d %d\n", n, c1.w, c2.w); 1003 printf ("%d SETFUNCTION %s %d\n", n, (char *)c1.b, c2.w);
1017 } 1004 }
1018 break; 1005 break;
1019 case SETLINE: 1006 case SETLINE: