Scanner and parser use different tables for constants
Moreover, each function being parsed has its own table. The code is cleaner when each table is used for one specific purpose: The scanner uses its table to anchor and unify strings, mapping strings to themselves; the parser uses it to reuse constants in the code, mapping constants to their indices in the constant table. A different table for each task avoids false collisions.
This commit is contained in:
@@ -737,6 +737,7 @@ static void codeclosure (LexState *ls, expdesc *v) {
|
||||
|
||||
|
||||
static void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) {
|
||||
lua_State *L = ls->L;
|
||||
Proto *f = fs->f;
|
||||
fs->prev = ls->fs; /* linked list of funcstates */
|
||||
fs->ls = ls;
|
||||
@@ -757,8 +758,11 @@ static void open_func (LexState *ls, FuncState *fs, BlockCnt *bl) {
|
||||
fs->firstlabel = ls->dyd->label.n;
|
||||
fs->bl = NULL;
|
||||
f->source = ls->source;
|
||||
luaC_objbarrier(ls->L, f, f->source);
|
||||
luaC_objbarrier(L, f, f->source);
|
||||
f->maxstacksize = 2; /* registers 0/1 are always valid */
|
||||
fs->kcache = luaH_new(L); /* create table for function */
|
||||
sethvalue2s(L, L->top.p, fs->kcache); /* anchor it */
|
||||
luaD_inctop(L);
|
||||
enterblock(fs, bl, 0);
|
||||
}
|
||||
|
||||
@@ -780,6 +784,7 @@ static void close_func (LexState *ls) {
|
||||
luaM_shrinkvector(L, f->locvars, f->sizelocvars, fs->ndebugvars, LocVar);
|
||||
luaM_shrinkvector(L, f->upvalues, f->sizeupvalues, fs->nups, Upvaldesc);
|
||||
ls->fs = fs->prev;
|
||||
L->top.p--; /* pop kcache table */
|
||||
luaC_checkGC(L);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user