diff options
| author | Waldemar Celes <celes@tecgraf.puc-rio.br> | 1995-04-11 14:56:30 -0300 |
|---|---|---|
| committer | Waldemar Celes <celes@tecgraf.puc-rio.br> | 1995-04-11 14:56:30 -0300 |
| commit | 8156604823aa487f4436d33fe89302598faab3db (patch) | |
| tree | 6ed6e5ec52c397e8e3ce11fec01440fd4287b1ab /lua.stx | |
| parent | 36b6fdda833d4dd4a866d2c96ac42062b2b29af9 (diff) | |
| download | lua-8156604823aa487f4436d33fe89302598faab3db.tar.gz lua-8156604823aa487f4436d33fe89302598faab3db.tar.bz2 lua-8156604823aa487f4436d33fe89302598faab3db.zip | |
run-time stack now is controled at run time, instead of
compilation time.
Diffstat (limited to 'lua.stx')
| -rw-r--r-- | lua.stx | 50 |
1 files changed, 28 insertions, 22 deletions
| @@ -1,6 +1,6 @@ | |||
| 1 | %{ | 1 | %{ |
| 2 | 2 | ||
| 3 | char *rcs_luastx = "$Id: lua.stx,v 3.16 1994/12/27 20:41:11 celes Exp roberto $"; | 3 | char *rcs_luastx = "$Id: lua.stx,v 3.17 1995/01/13 22:11:12 roberto Exp celes $"; |
| 4 | 4 | ||
| 5 | #include <stdio.h> | 5 | #include <stdio.h> |
| 6 | #include <stdlib.h> | 6 | #include <stdlib.h> |
| @@ -41,7 +41,8 @@ static Long varbuffer[MAXVAR]; /* variables in an assignment list; | |||
| 41 | it's long to store negative Word values */ | 41 | it's long to store negative Word values */ |
| 42 | static int nvarbuffer=0; /* number of variables at a list */ | 42 | static int nvarbuffer=0; /* number of variables at a list */ |
| 43 | 43 | ||
| 44 | static Word localvar[STACKGAP]; /* store local variable names */ | 44 | #define MAXLOCALS 32 |
| 45 | static Word localvar[MAXLOCALS]; /* store local variable names */ | ||
| 45 | static int nlocalvar=0; /* number of local variables */ | 46 | static int nlocalvar=0; /* number of local variables */ |
| 46 | 47 | ||
| 47 | #define MAXFIELDS FIELDS_PER_FLUSH*2 | 48 | #define MAXFIELDS FIELDS_PER_FLUSH*2 |
| @@ -103,10 +104,10 @@ static void code_word_at (Byte *p, Word n) | |||
| 103 | 104 | ||
| 104 | static void push_field (Word name) | 105 | static void push_field (Word name) |
| 105 | { | 106 | { |
| 106 | if (nfields < STACKGAP-1) | 107 | if (nfields < MAXFIELDS) |
| 107 | fields[nfields++] = name; | 108 | fields[nfields++] = name; |
| 108 | else | 109 | else |
| 109 | lua_error ("too many fields in a constructor"); | 110 | lua_error ("too many fields in nested constructors"); |
| 110 | } | 111 | } |
| 111 | 112 | ||
| 112 | static void flush_record (int n) | 113 | static void flush_record (int n) |
| @@ -135,18 +136,26 @@ static void flush_list (int m, int n) | |||
| 135 | code_byte(n); | 136 | code_byte(n); |
| 136 | } | 137 | } |
| 137 | 138 | ||
| 138 | static void add_nlocalvar (int n) | 139 | static void add_localvar (Word name) |
| 139 | { | 140 | { |
| 140 | if (MAX_TEMPS+nlocalvar+MAXVAR+n < STACKGAP) | 141 | if (nlocalvar < MAXLOCALS) |
| 141 | nlocalvar += n; | 142 | localvar[nlocalvar++] = name; |
| 142 | else | 143 | else |
| 143 | lua_error ("too many local variables"); | 144 | lua_error ("too many local variables"); |
| 144 | } | 145 | } |
| 145 | 146 | ||
| 146 | static void incr_nvarbuffer (void) | 147 | static void store_localvar (Word name, int n) |
| 147 | { | 148 | { |
| 148 | if (nvarbuffer < MAXVAR-1) | 149 | if (nlocalvar+n < MAXLOCALS) |
| 149 | nvarbuffer++; | 150 | localvar[nlocalvar+n] = name; |
| 151 | else | ||
| 152 | lua_error ("too many local variables"); | ||
| 153 | } | ||
| 154 | |||
| 155 | static void add_varbuffer (Long var) | ||
| 156 | { | ||
| 157 | if (nvarbuffer < MAXVAR) | ||
| 158 | varbuffer[nvarbuffer++] = var; | ||
| 150 | else | 159 | else |
| 151 | lua_error ("variable buffer overflow"); | 160 | lua_error ("variable buffer overflow"); |
| 152 | } | 161 | } |
| @@ -436,8 +445,7 @@ function : FUNCTION NAME | |||
| 436 | method : FUNCTION NAME ':' NAME | 445 | method : FUNCTION NAME ':' NAME |
| 437 | { | 446 | { |
| 438 | init_function($4); | 447 | init_function($4); |
| 439 | localvar[nlocalvar]=luaI_findsymbolbyname("self"); | 448 | add_localvar(luaI_findsymbolbyname("self")); |
| 440 | add_nlocalvar(1); | ||
| 441 | } | 449 | } |
| 442 | body | 450 | body |
| 443 | { | 451 | { |
| @@ -506,9 +514,9 @@ stat1 : IF expr1 THEN PrepJump block PrepJump elsepart END | |||
| 506 | } | 514 | } |
| 507 | | functioncall { code_byte(0); } | 515 | | functioncall { code_byte(0); } |
| 508 | | LOCAL localdeclist decinit | 516 | | LOCAL localdeclist decinit |
| 509 | { add_nlocalvar($2); | 517 | { nlocalvar += $2; |
| 510 | adjust_mult_assign($2, $3, 0); | 518 | adjust_mult_assign($2, $3, 0); |
| 511 | } | 519 | } |
| 512 | ; | 520 | ; |
| 513 | 521 | ||
| 514 | elsepart : /* empty */ | 522 | elsepart : /* empty */ |
| @@ -632,13 +640,11 @@ parlist : /* empty */ { lua_codeadjust(0); } | |||
| 632 | 640 | ||
| 633 | parlist1 : NAME | 641 | parlist1 : NAME |
| 634 | { | 642 | { |
| 635 | localvar[nlocalvar]=luaI_findsymbol($1); | 643 | add_localvar(luaI_findsymbol($1)); |
| 636 | add_nlocalvar(1); | ||
| 637 | } | 644 | } |
| 638 | | parlist1 ',' NAME | 645 | | parlist1 ',' NAME |
| 639 | { | 646 | { |
| 640 | localvar[nlocalvar]=luaI_findsymbol($3); | 647 | add_localvar(luaI_findsymbol($3)); |
| 641 | add_nlocalvar(1); | ||
| 642 | } | 648 | } |
| 643 | ; | 649 | ; |
| 644 | 650 | ||
| @@ -683,12 +689,12 @@ lfieldlist1 : expr1 {$$=1;} | |||
| 683 | varlist1 : var | 689 | varlist1 : var |
| 684 | { | 690 | { |
| 685 | nvarbuffer = 0; | 691 | nvarbuffer = 0; |
| 686 | varbuffer[nvarbuffer] = $1; incr_nvarbuffer(); | 692 | add_varbuffer($1); |
| 687 | $$ = ($1 == 0) ? 1 : 0; | 693 | $$ = ($1 == 0) ? 1 : 0; |
| 688 | } | 694 | } |
| 689 | | varlist1 ',' var | 695 | | varlist1 ',' var |
| 690 | { | 696 | { |
| 691 | varbuffer[nvarbuffer] = $3; incr_nvarbuffer(); | 697 | add_varbuffer($3); |
| 692 | $$ = ($3 == 0) ? $1 + 1 : $1; | 698 | $$ = ($3 == 0) ? $1 + 1 : $1; |
| 693 | } | 699 | } |
| 694 | ; | 700 | ; |
| @@ -720,10 +726,10 @@ singlevar : NAME | |||
| 720 | varexp : var { lua_pushvar($1); } | 726 | varexp : var { lua_pushvar($1); } |
| 721 | ; | 727 | ; |
| 722 | 728 | ||
| 723 | localdeclist : NAME {localvar[nlocalvar]=luaI_findsymbol($1); $$ = 1;} | 729 | localdeclist : NAME {store_localvar(luaI_findsymbol($1), 0); $$ = 1;} |
| 724 | | localdeclist ',' NAME | 730 | | localdeclist ',' NAME |
| 725 | { | 731 | { |
| 726 | localvar[nlocalvar+$1]=luaI_findsymbol($3); | 732 | store_localvar(luaI_findsymbol($3), $1); |
| 727 | $$ = $1+1; | 733 | $$ = $1+1; |
| 728 | } | 734 | } |
| 729 | ; | 735 | ; |
