diff options
Diffstat (limited to 'apps/plugins/lua/lparser.c')
-rw-r--r-- | apps/plugins/lua/lparser.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/apps/plugins/lua/lparser.c b/apps/plugins/lua/lparser.c index d002e96b86..bb08c51c0b 100644 --- a/apps/plugins/lua/lparser.c +++ b/apps/plugins/lua/lparser.c | |||
@@ -344,6 +344,11 @@ static void open_func (LexState *ls, FuncState *fs) { | |||
344 | fs->bl = NULL; | 344 | fs->bl = NULL; |
345 | f->source = ls->source; | 345 | f->source = ls->source; |
346 | f->maxstacksize = 2; /* registers 0/1 are always valid */ | 346 | f->maxstacksize = 2; /* registers 0/1 are always valid */ |
347 | #ifdef LUA_OPTIMIZE_DEBUG | ||
348 | fs->lastline = 0; | ||
349 | fs->lastlineOffset = 0; | ||
350 | fs->lineinfoLastPC = -1; | ||
351 | #endif | ||
347 | fs->h = luaH_new(L, 0, 0); | 352 | fs->h = luaH_new(L, 0, 0); |
348 | /* anchor table of constants and prototype (to avoid being collected) */ | 353 | /* anchor table of constants and prototype (to avoid being collected) */ |
349 | sethvalue2s(L, L->top, fs->h); | 354 | sethvalue2s(L, L->top, fs->h); |
@@ -361,8 +366,14 @@ static void close_func (LexState *ls) { | |||
361 | luaK_ret(fs, 0, 0); /* final return */ | 366 | luaK_ret(fs, 0, 0); /* final return */ |
362 | luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction); | 367 | luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction); |
363 | f->sizecode = fs->pc; | 368 | f->sizecode = fs->pc; |
369 | #ifdef LUA_OPTIMIZE_DEBUG | ||
370 | f->packedlineinfo[fs->lastlineOffset+1]=0; | ||
371 | luaM_reallocvector(L, f->packedlineinfo, f->sizelineinfo, | ||
372 | fs->lastlineOffset+2, unsigned char); | ||
373 | #else | ||
364 | luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int); | 374 | luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int); |
365 | f->sizelineinfo = fs->pc; | 375 | f->sizelineinfo = fs->pc; |
376 | #endif | ||
366 | luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue); | 377 | luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue); |
367 | f->sizek = fs->nk; | 378 | f->sizek = fs->nk; |
368 | luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *); | 379 | luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *); |
@@ -379,6 +390,23 @@ static void close_func (LexState *ls) { | |||
379 | L->top -= 2; /* remove table and prototype from the stack */ | 390 | L->top -= 2; /* remove table and prototype from the stack */ |
380 | } | 391 | } |
381 | 392 | ||
393 | #ifdef LUA_OPTIMIZE_DEBUG | ||
394 | static void compile_stripdebug(lua_State *L, Proto *f) { | ||
395 | int level; | ||
396 | #ifdef LUA_OPTIMIZE_DEBUG_USER | ||
397 | lua_pushlightuserdata(L, &luaG_stripdebug); | ||
398 | lua_gettable(L, LUA_REGISTRYINDEX); | ||
399 | level = lua_isnil(L, -1) ? LUA_OPTIMIZE_DEBUG : lua_tointeger(L, -1); | ||
400 | lua_pop(L, 1); | ||
401 | #else | ||
402 | level = LUA_OPTIMIZE_DEBUG; | ||
403 | #endif | ||
404 | |||
405 | if (level > 1) { | ||
406 | luaG_stripdebug(L, f, level, 16); | ||
407 | } | ||
408 | } | ||
409 | #endif | ||
382 | 410 | ||
383 | Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { | 411 | Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { |
384 | struct LexState lexstate; | 412 | struct LexState lexstate; |
@@ -395,6 +423,9 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { | |||
395 | check(&lexstate, TK_EOS); | 423 | check(&lexstate, TK_EOS); |
396 | close_func(&lexstate); | 424 | close_func(&lexstate); |
397 | L->top--; /* remove 'name' from stack */ | 425 | L->top--; /* remove 'name' from stack */ |
426 | #ifdef LUA_OPTIMIZE_DEBUG | ||
427 | compile_stripdebug(L, funcstate.f); | ||
428 | #endif | ||
398 | lua_assert(funcstate.prev == NULL); | 429 | lua_assert(funcstate.prev == NULL); |
399 | lua_assert(funcstate.f->nups == 0); | 430 | lua_assert(funcstate.f->nups == 0); |
400 | lua_assert(lexstate.fs == NULL); | 431 | lua_assert(lexstate.fs == NULL); |
@@ -402,7 +433,6 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { | |||
402 | } | 433 | } |
403 | 434 | ||
404 | 435 | ||
405 | |||
406 | /*============================================================*/ | 436 | /*============================================================*/ |
407 | /* GRAMMAR RULES */ | 437 | /* GRAMMAR RULES */ |
408 | /*============================================================*/ | 438 | /*============================================================*/ |