diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-01-23 15:50:29 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-01-23 15:50:29 -0200 |
commit | 2998049f510fdc73daf35ba3741fedb7faa775cc (patch) | |
tree | 12a695b3bef4c4992f9c47536ab0158360d27bb7 | |
parent | 24ccc7c0384537e2978320471e82c7979596d7fb (diff) | |
download | lua-2998049f510fdc73daf35ba3741fedb7faa775cc.tar.gz lua-2998049f510fdc73daf35ba3741fedb7faa775cc.tar.bz2 lua-2998049f510fdc73daf35ba3741fedb7faa775cc.zip |
local variable stack needs only the name of the variable (TreeNode);
this way is simpler and faster than old way.
-rw-r--r-- | lua.stx | 31 |
1 files changed, 12 insertions, 19 deletions
@@ -1,6 +1,6 @@ | |||
1 | %{ | 1 | %{ |
2 | 2 | ||
3 | char *rcs_luastx = "$Id: lua.stx,v 3.25 1995/10/26 17:02:50 roberto Exp roberto $"; | 3 | char *rcs_luastx = "$Id: lua.stx,v 3.26 1996/01/22 18:39:37 roberto Exp roberto $"; |
4 | 4 | ||
5 | #include <stdio.h> | 5 | #include <stdio.h> |
6 | #include <stdlib.h> | 6 | #include <stdlib.h> |
@@ -44,7 +44,7 @@ static Long varbuffer[MAXVAR]; /* variables in an assignment list; | |||
44 | static int nvarbuffer=0; /* number of variables at a list */ | 44 | static int nvarbuffer=0; /* number of variables at a list */ |
45 | 45 | ||
46 | #define MAXLOCALS 32 | 46 | #define MAXLOCALS 32 |
47 | static Word localvar[MAXLOCALS]; /* store local variable names */ | 47 | static TreeNode *localvar[MAXLOCALS]; /* store local variable names */ |
48 | static int nlocalvar=0; /* number of local variables */ | 48 | static int nlocalvar=0; /* number of local variables */ |
49 | 49 | ||
50 | #define MAXFIELDS FIELDS_PER_FLUSH*2 | 50 | #define MAXFIELDS FIELDS_PER_FLUSH*2 |
@@ -146,7 +146,7 @@ static void flush_list (int m, int n) | |||
146 | code_byte(n); | 146 | code_byte(n); |
147 | } | 147 | } |
148 | 148 | ||
149 | static void add_localvar (Word name) | 149 | static void add_localvar (TreeNode *name) |
150 | { | 150 | { |
151 | if (nlocalvar < MAXLOCALS) | 151 | if (nlocalvar < MAXLOCALS) |
152 | localvar[nlocalvar++] = name; | 152 | localvar[nlocalvar++] = name; |
@@ -154,7 +154,7 @@ static void add_localvar (Word name) | |||
154 | lua_error ("too many local variables"); | 154 | lua_error ("too many local variables"); |
155 | } | 155 | } |
156 | 156 | ||
157 | static void store_localvar (Word name, int n) | 157 | static void store_localvar (TreeNode *name, int n) |
158 | { | 158 | { |
159 | if (nlocalvar+n < MAXLOCALS) | 159 | if (nlocalvar+n < MAXLOCALS) |
160 | localvar[nlocalvar+n] = name; | 160 | localvar[nlocalvar+n] = name; |
@@ -197,7 +197,7 @@ static void code_number (float f) | |||
197 | /* | 197 | /* |
198 | ** Search a local name and if find return its index. If do not find return -1 | 198 | ** Search a local name and if find return its index. If do not find return -1 |
199 | */ | 199 | */ |
200 | static int lua_localname (Word n) | 200 | static int lua_localname (TreeNode *n) |
201 | { | 201 | { |
202 | int i; | 202 | int i; |
203 | for (i=nlocalvar-1; i >= 0; i--) | 203 | for (i=nlocalvar-1; i >= 0; i--) |
@@ -481,7 +481,7 @@ funcname : var { $$ =$1; init_func(); } | |||
481 | code_word(luaI_findconstant($3)); | 481 | code_word(luaI_findconstant($3)); |
482 | $$ = 0; /* indexed variable */ | 482 | $$ = 0; /* indexed variable */ |
483 | init_func(); | 483 | init_func(); |
484 | add_localvar(luaI_findsymbolbyname("self")); | 484 | add_localvar(lua_constcreate("self")); |
485 | } | 485 | } |
486 | ; | 486 | ; |
487 | 487 | ||
@@ -672,14 +672,8 @@ parlist : /* empty */ { lua_codeadjust(0); $$ = lua_linenumber; } | |||
672 | | parlist1 { lua_codeadjust(0); $$ = lua_linenumber; } | 672 | | parlist1 { lua_codeadjust(0); $$ = lua_linenumber; } |
673 | ; | 673 | ; |
674 | 674 | ||
675 | parlist1 : NAME | 675 | parlist1 : NAME { add_localvar($1); } |
676 | { | 676 | | parlist1 ',' NAME { add_localvar($3); } |
677 | add_localvar(luaI_findsymbol($1)); | ||
678 | } | ||
679 | | parlist1 ',' NAME | ||
680 | { | ||
681 | add_localvar(luaI_findsymbol($3)); | ||
682 | } | ||
683 | ; | 677 | ; |
684 | 678 | ||
685 | fieldlist : lfieldlist | 679 | fieldlist : lfieldlist |
@@ -759,10 +753,9 @@ var : singlevar { $$ = $1; } | |||
759 | 753 | ||
760 | singlevar : NAME | 754 | singlevar : NAME |
761 | { | 755 | { |
762 | Word s = luaI_findsymbol($1); | 756 | int local = lua_localname($1); |
763 | int local = lua_localname (s); | ||
764 | if (local == -1) /* global var */ | 757 | if (local == -1) /* global var */ |
765 | $$ = s + 1; /* return positive value */ | 758 | $$ = luaI_findsymbol($1)+1; /* return positive value */ |
766 | else | 759 | else |
767 | $$ = -(local+1); /* return negative value */ | 760 | $$ = -(local+1); /* return negative value */ |
768 | } | 761 | } |
@@ -771,10 +764,10 @@ singlevar : NAME | |||
771 | varexp : var { lua_pushvar($1); } | 764 | varexp : var { lua_pushvar($1); } |
772 | ; | 765 | ; |
773 | 766 | ||
774 | localdeclist : NAME {store_localvar(luaI_findsymbol($1), 0); $$ = 1;} | 767 | localdeclist : NAME {store_localvar($1, 0); $$ = 1;} |
775 | | localdeclist ',' NAME | 768 | | localdeclist ',' NAME |
776 | { | 769 | { |
777 | store_localvar(luaI_findsymbol($3), $1); | 770 | store_localvar($3, $1); |
778 | $$ = $1+1; | 771 | $$ = $1+1; |
779 | } | 772 | } |
780 | ; | 773 | ; |