diff options
| -rw-r--r-- | ldo.c | 24 | ||||
| -rw-r--r-- | lparser.c | 51 |
2 files changed, 44 insertions, 31 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 1.28 1998/07/12 16:14:34 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.29 1998/08/21 17:43:44 roberto Exp $ |
| 3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -276,18 +276,17 @@ static void do_callinc (int nResults) | |||
| 276 | ** Execute a protected call. Assumes that function is at L->Cstack.base and | 276 | ** Execute a protected call. Assumes that function is at L->Cstack.base and |
| 277 | ** parameters are on top of it. Leave nResults on the stack. | 277 | ** parameters are on top of it. Leave nResults on the stack. |
| 278 | */ | 278 | */ |
| 279 | int luaD_protectedrun (int nResults) | 279 | int luaD_protectedrun (int nResults) { |
| 280 | { | ||
| 281 | jmp_buf myErrorJmp; | ||
| 282 | int status; | ||
| 283 | volatile struct C_Lua_Stack oldCLS = L->Cstack; | 280 | volatile struct C_Lua_Stack oldCLS = L->Cstack; |
| 281 | jmp_buf myErrorJmp; | ||
| 282 | volatile int status; | ||
| 284 | jmp_buf *volatile oldErr = L->errorJmp; | 283 | jmp_buf *volatile oldErr = L->errorJmp; |
| 285 | L->errorJmp = &myErrorJmp; | 284 | L->errorJmp = &myErrorJmp; |
| 286 | if (setjmp(myErrorJmp) == 0) { | 285 | if (setjmp(myErrorJmp) == 0) { |
| 287 | do_callinc(nResults); | 286 | do_callinc(nResults); |
| 288 | status = 0; | 287 | status = 0; |
| 289 | } | 288 | } |
| 290 | else { /* an error occurred: restore L->Cstack and L->stack.top */ | 289 | else { /* an error occurred: restore L->Cstack and L->stack.top */ |
| 291 | L->Cstack = oldCLS; | 290 | L->Cstack = oldCLS; |
| 292 | L->stack.top = L->stack.stack+L->Cstack.base; | 291 | L->stack.top = L->stack.stack+L->Cstack.base; |
| 293 | status = 1; | 292 | status = 1; |
| @@ -300,18 +299,20 @@ int luaD_protectedrun (int nResults) | |||
| 300 | /* | 299 | /* |
| 301 | ** returns 0 = chunk loaded; 1 = error; 2 = no more chunks to load | 300 | ** returns 0 = chunk loaded; 1 = error; 2 = no more chunks to load |
| 302 | */ | 301 | */ |
| 303 | static int protectedparser (ZIO *z, int bin) | 302 | static int protectedparser (ZIO *z, int bin) { |
| 304 | { | 303 | volatile struct C_Lua_Stack oldCLS = L->Cstack; |
| 304 | jmp_buf myErrorJmp; | ||
| 305 | volatile int status; | 305 | volatile int status; |
| 306 | TProtoFunc *volatile tf; | 306 | TProtoFunc *volatile tf; |
| 307 | jmp_buf myErrorJmp; | ||
| 308 | jmp_buf *volatile oldErr = L->errorJmp; | 307 | jmp_buf *volatile oldErr = L->errorJmp; |
| 309 | L->errorJmp = &myErrorJmp; | 308 | L->errorJmp = &myErrorJmp; |
| 310 | if (setjmp(myErrorJmp) == 0) { | 309 | if (setjmp(myErrorJmp) == 0) { |
| 311 | tf = bin ? luaU_undump1(z) : luaY_parser(z); | 310 | tf = bin ? luaU_undump1(z) : luaY_parser(z); |
| 312 | status = 0; | 311 | status = 0; |
| 313 | } | 312 | } |
| 314 | else { | 313 | else { /* an error occurred: restore L->Cstack and L->stack.top */ |
| 314 | L->Cstack = oldCLS; | ||
| 315 | L->stack.top = L->stack.stack+L->Cstack.base; | ||
| 315 | tf = NULL; | 316 | tf = NULL; |
| 316 | status = 1; | 317 | status = 1; |
| 317 | } | 318 | } |
| @@ -326,8 +327,7 @@ static int protectedparser (ZIO *z, int bin) | |||
| 326 | } | 327 | } |
| 327 | 328 | ||
| 328 | 329 | ||
| 329 | static int do_main (ZIO *z, int bin) | 330 | static int do_main (ZIO *z, int bin) { |
| 330 | { | ||
| 331 | int status; | 331 | int status; |
| 332 | do { | 332 | do { |
| 333 | long old_blocks = (luaC_checkGC(), L->nblocks); | 333 | long old_blocks = (luaC_checkGC(), L->nblocks); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.c,v 1.6 1998/12/23 14:06:57 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.7 1998/12/28 13:44:54 roberto Exp $ |
| 3 | ** LL(1) Parser and code generator for Lua | 3 | ** LL(1) Parser and code generator for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -285,12 +285,14 @@ static void luaI_registerlocalvar (FuncState *fs, TaggedString *varname, | |||
| 285 | int line) { | 285 | int line) { |
| 286 | if (fs->maxvars != -1) { /* debug information? */ | 286 | if (fs->maxvars != -1) { /* debug information? */ |
| 287 | TProtoFunc *f = fs->f; | 287 | TProtoFunc *f = fs->f; |
| 288 | if (fs->nvars >= fs->maxvars) | 288 | if (fs->nvars+2 > fs->maxvars) |
| 289 | fs->maxvars = luaM_growvector(&f->locvars, fs->maxvars, | 289 | fs->maxvars = luaM_growvector(&f->locvars, fs->maxvars+2, |
| 290 | LocVar, "", MAX_WORD); | 290 | LocVar, "", MAX_WORD); |
| 291 | f->locvars[fs->nvars].varname = varname; | 291 | f->locvars[fs->nvars].varname = varname; |
| 292 | f->locvars[fs->nvars].line = line; | 292 | f->locvars[fs->nvars].line = line; |
| 293 | fs->nvars++; | 293 | fs->nvars++; |
| 294 | f->locvars[fs->nvars].line = -1; /* flag end of vector */ | ||
| 295 | |||
| 294 | } | 296 | } |
| 295 | } | 297 | } |
| 296 | 298 | ||
| @@ -541,6 +543,9 @@ static void init_state (LexState *ls, FuncState *fs, TaggedString *filename) { | |||
| 541 | fs->maxvars = -1; /* flag no debug information */ | 543 | fs->maxvars = -1; /* flag no debug information */ |
| 542 | code_byte(fs, 0); /* to be filled with stacksize */ | 544 | code_byte(fs, 0); /* to be filled with stacksize */ |
| 543 | code_byte(fs, 0); /* to be filled with arg information */ | 545 | code_byte(fs, 0); /* to be filled with arg information */ |
| 546 | /* push function (to avoid GC) */ | ||
| 547 | tfvalue(L->stack.top) = f; ttype(L->stack.top) = LUA_T_PROTO; | ||
| 548 | incr_top; | ||
| 544 | } | 549 | } |
| 545 | 550 | ||
| 546 | 551 | ||
| @@ -556,6 +561,7 @@ static void close_func (LexState *ls) { | |||
| 556 | f->locvars = luaM_reallocvector(f->locvars, fs->nvars, LocVar); | 561 | f->locvars = luaM_reallocvector(f->locvars, fs->nvars, LocVar); |
| 557 | } | 562 | } |
| 558 | ls->fs = fs->prev; | 563 | ls->fs = fs->prev; |
| 564 | L->stack.top--; /* pop function */ | ||
| 559 | } | 565 | } |
| 560 | 566 | ||
| 561 | 567 | ||
| @@ -619,13 +625,20 @@ static void check_match (LexState *ls, int what, int who, int where) { | |||
| 619 | next(ls); | 625 | next(ls); |
| 620 | } | 626 | } |
| 621 | 627 | ||
| 622 | static TaggedString *checkname (LexState *ls) { | 628 | static int checkname (LexState *ls) { |
| 623 | TaggedString *ts; | 629 | int sc; |
| 624 | if (ls->token != NAME) | 630 | if (ls->token != NAME) |
| 625 | luaX_error(ls, "`NAME' expected"); | 631 | luaX_error(ls, "`NAME' expected"); |
| 626 | ts = ls->seminfo.ts; | 632 | sc = string_constant(ls->fs, ls->seminfo.ts); |
| 627 | next(ls); | 633 | next(ls); |
| 628 | return ts; | 634 | return sc; |
| 635 | } | ||
| 636 | |||
| 637 | |||
| 638 | static TaggedString *str_checkname (LexState *ls) { | ||
| 639 | /* call "checkname" to put string at constant table (to avoid GC) */ | ||
| 640 | int i = checkname(ls); | ||
| 641 | return tsvalue(&ls->fs->f->consts[i]); | ||
| 629 | } | 642 | } |
| 630 | 643 | ||
| 631 | 644 | ||
| @@ -801,12 +814,12 @@ static void block (LexState *ls) { | |||
| 801 | static int funcname (LexState *ls, vardesc *v) { | 814 | static int funcname (LexState *ls, vardesc *v) { |
| 802 | /* funcname -> NAME [':' NAME | '.' NAME] */ | 815 | /* funcname -> NAME [':' NAME | '.' NAME] */ |
| 803 | int needself = 0; | 816 | int needself = 0; |
| 804 | singlevar(ls, checkname(ls), v, 0); | 817 | singlevar(ls, str_checkname(ls), v, 0); |
| 805 | if (ls->token == ':' || ls->token == '.') { | 818 | if (ls->token == ':' || ls->token == '.') { |
| 806 | needself = (ls->token == ':'); | 819 | needself = (ls->token == ':'); |
| 807 | next(ls); | 820 | next(ls); |
| 808 | lua_pushvar(ls, v); | 821 | lua_pushvar(ls, v); |
| 809 | code_string(ls, checkname(ls)); | 822 | code_constant(ls, checkname(ls)); |
| 810 | v->k = VINDEXED; | 823 | v->k = VINDEXED; |
| 811 | } | 824 | } |
| 812 | return needself; | 825 | return needself; |
| @@ -980,7 +993,7 @@ static void simpleexp (LexState *ls, vardesc *v) { | |||
| 980 | break; | 993 | break; |
| 981 | 994 | ||
| 982 | case STRING: /* simpleexp -> STRING */ | 995 | case STRING: /* simpleexp -> STRING */ |
| 983 | code_string(ls, ls->seminfo.ts); | 996 | code_string(ls, ls->seminfo.ts); /* must use before "next" */ |
| 984 | next(ls); | 997 | next(ls); |
| 985 | v->k = VEXP; v->info = 0; | 998 | v->k = VEXP; v->info = 0; |
| 986 | break; | 999 | break; |
| @@ -1017,12 +1030,12 @@ static void simpleexp (LexState *ls, vardesc *v) { | |||
| 1017 | static void var_or_func (LexState *ls, vardesc *v) { | 1030 | static void var_or_func (LexState *ls, vardesc *v) { |
| 1018 | /* var_or_func -> ['%'] NAME var_or_func_tail */ | 1031 | /* var_or_func -> ['%'] NAME var_or_func_tail */ |
| 1019 | if (optional(ls, '%')) { /* upvalue? */ | 1032 | if (optional(ls, '%')) { /* upvalue? */ |
| 1020 | pushupvalue(ls, checkname(ls)); | 1033 | pushupvalue(ls, str_checkname(ls)); |
| 1021 | v->k = VEXP; | 1034 | v->k = VEXP; |
| 1022 | v->info = 0; /* closed expression */ | 1035 | v->info = 0; /* closed expression */ |
| 1023 | } | 1036 | } |
| 1024 | else /* variable name */ | 1037 | else /* variable name */ |
| 1025 | singlevar(ls, checkname(ls), v, 0); | 1038 | singlevar(ls, str_checkname(ls), v, 0); |
| 1026 | var_or_func_tail(ls, v); | 1039 | var_or_func_tail(ls, v); |
| 1027 | } | 1040 | } |
| 1028 | 1041 | ||
| @@ -1033,7 +1046,7 @@ static void var_or_func_tail (LexState *ls, vardesc *v) { | |||
| 1033 | next(ls); | 1046 | next(ls); |
| 1034 | lua_pushvar(ls, v); /* 'v' must be on stack */ | 1047 | lua_pushvar(ls, v); /* 'v' must be on stack */ |
| 1035 | v->k = VDOT; | 1048 | v->k = VDOT; |
| 1036 | v->info = string_constant(ls->fs, checkname(ls)); | 1049 | v->info = checkname(ls); |
| 1037 | break; | 1050 | break; |
| 1038 | 1051 | ||
| 1039 | case '[': /* var_or_func_tail -> '[' exp1 ']' */ | 1052 | case '[': /* var_or_func_tail -> '[' exp1 ']' */ |
| @@ -1047,7 +1060,7 @@ static void var_or_func_tail (LexState *ls, vardesc *v) { | |||
| 1047 | case ':': /* var_or_func_tail -> ':' NAME funcparams */ | 1060 | case ':': /* var_or_func_tail -> ':' NAME funcparams */ |
| 1048 | next(ls); | 1061 | next(ls); |
| 1049 | lua_pushvar(ls, v); /* 'v' must be on stack */ | 1062 | lua_pushvar(ls, v); /* 'v' must be on stack */ |
| 1050 | code_oparg(ls, PUSHSELF, 8, string_constant(ls->fs, checkname(ls)), 1); | 1063 | code_oparg(ls, PUSHSELF, 8, checkname(ls), 1); |
| 1051 | v->k = VEXP; | 1064 | v->k = VEXP; |
| 1052 | v->info = funcparams(ls, 1); | 1065 | v->info = funcparams(ls, 1); |
| 1053 | break; | 1066 | break; |
| @@ -1082,7 +1095,7 @@ static int funcparams (LexState *ls, int slf) { | |||
| 1082 | break; | 1095 | break; |
| 1083 | 1096 | ||
| 1084 | case STRING: /* funcparams -> STRING */ | 1097 | case STRING: /* funcparams -> STRING */ |
| 1085 | code_string(ls, ls->seminfo.ts); | 1098 | code_string(ls, ls->seminfo.ts); /* must use before "next" */ |
| 1086 | next(ls); | 1099 | next(ls); |
| 1087 | break; | 1100 | break; |
| 1088 | 1101 | ||
| @@ -1138,7 +1151,7 @@ static void parlist (LexState *ls) { | |||
| 1138 | 1151 | ||
| 1139 | case NAME: /* parlist, tailparlist -> NAME [',' tailparlist] */ | 1152 | case NAME: /* parlist, tailparlist -> NAME [',' tailparlist] */ |
| 1140 | init: | 1153 | init: |
| 1141 | store_localvar(ls, checkname(ls), nparams++); | 1154 | store_localvar(ls, str_checkname(ls), nparams++); |
| 1142 | if (ls->token == ',') { | 1155 | if (ls->token == ',') { |
| 1143 | next(ls); | 1156 | next(ls); |
| 1144 | switch (ls->token) { | 1157 | switch (ls->token) { |
| @@ -1165,10 +1178,10 @@ static void parlist (LexState *ls) { | |||
| 1165 | static int localnamelist (LexState *ls) { | 1178 | static int localnamelist (LexState *ls) { |
| 1166 | /* localnamelist -> NAME {',' NAME} */ | 1179 | /* localnamelist -> NAME {',' NAME} */ |
| 1167 | int i = 1; | 1180 | int i = 1; |
| 1168 | store_localvar(ls, checkname(ls), 0); | 1181 | store_localvar(ls, str_checkname(ls), 0); |
| 1169 | while (ls->token == ',') { | 1182 | while (ls->token == ',') { |
| 1170 | next(ls); | 1183 | next(ls); |
| 1171 | store_localvar(ls, checkname(ls), i++); | 1184 | store_localvar(ls, str_checkname(ls), i++); |
| 1172 | } | 1185 | } |
| 1173 | return i; | 1186 | return i; |
| 1174 | } | 1187 | } |
| @@ -1323,7 +1336,7 @@ static void recfield (LexState *ls) { | |||
| 1323 | /* recfield -> (NAME | '['exp1']') = exp1 */ | 1336 | /* recfield -> (NAME | '['exp1']') = exp1 */ |
| 1324 | switch (ls->token) { | 1337 | switch (ls->token) { |
| 1325 | case NAME: | 1338 | case NAME: |
| 1326 | code_string(ls, checkname(ls)); | 1339 | code_constant(ls, checkname(ls)); |
| 1327 | break; | 1340 | break; |
| 1328 | 1341 | ||
| 1329 | case '[': | 1342 | case '[': |
