aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-08-27 18:01:44 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-08-27 18:01:44 -0300
commit8332d5c8a5059b85da1adaa3f0197d0f57afae81 (patch)
tree8a2f59ff0803da3afbc7e8a409911c920d624e94 /ldo.c
parent885961be1d8e3f703b54d1d19e6c63617cd2ed24 (diff)
downloadlua-8332d5c8a5059b85da1adaa3f0197d0f57afae81.tar.gz
lua-8332d5c8a5059b85da1adaa3f0197d0f57afae81.tar.bz2
lua-8332d5c8a5059b85da1adaa3f0197d0f57afae81.zip
parser fully reentrant(!)
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/ldo.c b/ldo.c
index 2b5dfdbf..bf244c91 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 1.222 2003/08/25 19:51:54 roberto Exp roberto $ 2** $Id: ldo.c,v 1.223 2003/08/26 12:04:13 roberto Exp roberto $
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*/
@@ -429,18 +429,17 @@ int luaD_pcall (lua_State *L, Pfunc func, void *u,
429struct SParser { /* data to `f_parser' */ 429struct SParser { /* data to `f_parser' */
430 ZIO *z; 430 ZIO *z;
431 Mbuffer buff; /* buffer to be used by the scanner */ 431 Mbuffer buff; /* buffer to be used by the scanner */
432 int bin;
433 const char *name; 432 const char *name;
434}; 433};
435 434
436static void f_parser (lua_State *L, void *ud) { 435static void f_parser (lua_State *L, void *ud) {
437 struct SParser *p;
438 Proto *tf; 436 Proto *tf;
439 Closure *cl; 437 Closure *cl;
438 struct SParser *p = cast(struct SParser *, ud);
439 int c = luaZ_lookahead(p->z);
440 luaC_checkGC(L); 440 luaC_checkGC(L);
441 p = cast(struct SParser *, ud); 441 tf = (c == LUA_SIGNATURE[0]) ? luaU_undump(L, p->z, &p->buff, p->name) :
442 tf = p->bin ? luaU_undump(L, p->z, &p->buff, p->name) : 442 luaY_parser(L, p->z, &p->buff, p->name);
443 luaY_parser(L, p->z, &p->buff, p->name);
444 cl = luaF_newLclosure(L, 0, gt(L)); 443 cl = luaF_newLclosure(L, 0, gt(L));
445 cl->l.p = tf; 444 cl->l.p = tf;
446 setclvalue(L->top, cl); 445 setclvalue(L->top, cl);
@@ -448,18 +447,13 @@ static void f_parser (lua_State *L, void *ud) {
448} 447}
449 448
450 449
451int luaD_protectedparser (lua_State *L, ZIO *z, int bin, const char *name) { 450int luaD_protectedparser (lua_State *L, ZIO *z, const char *name) {
452 struct SParser p; 451 struct SParser p;
453 int status; 452 int status;
454 ptrdiff_t oldtopr = savestack(L, L->top); /* save current top */ 453 p.z = z; p.name = name;
455 p.z = z; p.bin = bin; p.name = name;
456 luaZ_initbuffer(L, &p.buff); 454 luaZ_initbuffer(L, &p.buff);
457 status = luaD_rawrunprotected(L, f_parser, &p); 455 status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc);
458 luaZ_freebuffer(L, &p.buff); 456 luaZ_freebuffer(L, &p.buff);
459 if (status != 0) { /* error? */
460 StkId oldtop = restorestack(L, oldtopr);
461 seterrorobj(L, status, oldtop);
462 }
463 return status; 457 return status;
464} 458}
465 459