aboutsummaryrefslogtreecommitdiff
path: root/lua.stx
diff options
context:
space:
mode:
Diffstat (limited to 'lua.stx')
-rw-r--r--lua.stx50
1 files changed, 23 insertions, 27 deletions
diff --git a/lua.stx b/lua.stx
index d803d4ba..cb0a29d3 100644
--- a/lua.stx
+++ b/lua.stx
@@ -1,6 +1,6 @@
1%{ 1%{
2 2
3char *rcs_luastx = "$Id: lua.stx,v 3.43 1997/01/31 14:27:11 roberto Exp roberto $"; 3char *rcs_luastx = "$Id: lua.stx,v 3.44 1997/02/13 16:18:39 roberto Exp roberto $";
4 4
5#include <stdio.h> 5#include <stdio.h>
6#include <stdlib.h> 6#include <stdlib.h>
@@ -50,8 +50,6 @@ static TaggedString *localvar[MAXLOCALS]; /* store local variable names */
50static int nlocalvar=0; /* number of local variables */ 50static int nlocalvar=0; /* number of local variables */
51 51
52#define MAXFIELDS FIELDS_PER_FLUSH*2 52#define MAXFIELDS FIELDS_PER_FLUSH*2
53static Word fields[MAXFIELDS]; /* fieldnames to be flushed */
54static int nfields=0;
55 53
56int lua_debug = 0; 54int lua_debug = 0;
57 55
@@ -103,22 +101,11 @@ static void code_word_at (Byte *p, int n)
103 memcpy(p, &w, sizeof(Word)); 101 memcpy(p, &w, sizeof(Word));
104} 102}
105 103
106static void push_field (Word name)
107{
108 if (nfields < MAXFIELDS)
109 fields[nfields++] = name;
110 else
111 yyerror ("too many fields in nested constructors");
112}
113
114static void flush_record (int n) 104static void flush_record (int n)
115{ 105{
116 int i;
117 if (n == 0) return; 106 if (n == 0) return;
118 code_byte(STORERECORD); 107 code_byte(STOREMAP);
119 code_byte(n); 108 code_byte(n);
120 for (i=0; i<n; i++)
121 code_word(fields[--nfields]);
122} 109}
123 110
124static void flush_list (int m, int n) 111static void flush_list (int m, int n)
@@ -161,6 +148,17 @@ static void add_varbuffer (Long var)
161 yyerror ("variable buffer overflow"); 148 yyerror ("variable buffer overflow");
162} 149}
163 150
151static void code_string (Word w)
152{
153 code_byte(PUSHSTRING);
154 code_word(w);
155}
156
157static void code_constant (TaggedString *s)
158{
159 code_string(luaI_findconstant(s));
160}
161
164static void code_number (float f) 162static void code_number (float f)
165{ 163{
166 Word i; 164 Word i;
@@ -477,8 +475,7 @@ function : FUNCTION funcname body
477funcname : var { $$ =$1; init_func(); } 475funcname : var { $$ =$1; init_func(); }
478 | varexp ':' NAME 476 | varexp ':' NAME
479 { 477 {
480 code_byte(PUSHSTRING); 478 code_constant($3);
481 code_word(luaI_findconstant($3));
482 $$ = 0; /* indexed variable */ 479 $$ = 0; /* indexed variable */
483 init_func(); 480 init_func();
484 add_localvar(luaI_createfixedstring("self")); 481 add_localvar(luaI_createfixedstring("self"));
@@ -605,9 +602,8 @@ expr : '(' expr ')' { $$ = $2; }
605 | NUMBER { code_number($1); $$ = 0; } 602 | NUMBER { code_number($1); $$ = 0; }
606 | STRING 603 | STRING
607 { 604 {
608 code_byte(PUSHSTRING); 605 code_string($1);
609 code_word($1); 606 $$ = 0;
610 $$ = 0;
611 } 607 }
612 | NIL {code_byte(PUSHNIL); $$ = 0; } 608 | NIL {code_byte(PUSHNIL); $$ = 0; }
613 | functioncall { $$ = $1; } 609 | functioncall { $$ = $1; }
@@ -723,12 +719,13 @@ ffieldlist1 : ffield {$$=1;}
723 } 719 }
724 ; 720 ;
725 721
726ffield : NAME '=' expr1 722ffield : ffieldkey '=' expr1
727 {
728 push_field(luaI_findconstant($1));
729 }
730 ; 723 ;
731 724
725ffieldkey : '[' expr1 ']'
726 | NAME { code_constant($1); }
727 ;
728
732lfieldlist : /* empty */ { $$ = 0; } 729lfieldlist : /* empty */ { $$ = 0; }
733 | lfieldlist1 lastcomma { $$ = $1; } 730 | lfieldlist1 lastcomma { $$ = $1; }
734 ; 731 ;
@@ -762,9 +759,8 @@ var : singlevar { $$ = $1; }
762 } 759 }
763 | varexp '.' NAME 760 | varexp '.' NAME
764 { 761 {
765 code_byte(PUSHSTRING); 762 code_constant($3);
766 code_word(luaI_findconstant($3)); 763 $$ = 0; /* indexed variable */
767 $$ = 0; /* indexed variable */
768 } 764 }
769 ; 765 ;
770 766