diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2006-06-22 13:12:59 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2006-06-22 13:12:59 -0300 |
| commit | ee41bc03ab0af1b1d0c4a90e172b05cda3dac38f (patch) | |
| tree | fc2ac2bea24400ec815be94ba916b41f6f8cd104 /lcode.c | |
| parent | 98194db4295726069137d13b8d24fca8cbf892b6 (diff) | |
| download | lua-github-ee41bc03ab0af1b1d0c4a90e172b05cda3dac38f.tar.gz | |
details
Diffstat (limited to 'lcode.c')
| -rw-r--r-- | lcode.c | 26 |
1 files changed, 15 insertions, 11 deletions
@@ -1,5 +1,5 @@ /* -** $Id: lcode.c,v 2.24 2005/12/22 16:19:56 roberto Exp roberto $ +** $Id: lcode.c,v 2.25 2006/03/21 19:28:49 roberto Exp roberto $ ** Code generator for Lua ** See Copyright Notice in lua.h */ @@ -221,24 +221,28 @@ static void freeexp (FuncState *fs, expdesc *e) { } -static int addk (FuncState *fs, TValue *k, TValue *v) { +static int addk (FuncState *fs, TValue *key, TValue *v) { lua_State *L = fs->L; - TValue *idx = luaH_set(L, fs->h, k); + TValue *idx = luaH_set(L, fs->h, key); Proto *f = fs->f; - int oldsize = f->sizek; + int k; if (ttisnumber(idx)) { - lua_assert(luaO_rawequalObj(&fs->f->k[cast_int(nvalue(idx))], v)); - return cast_int(nvalue(idx)); + lua_Number n = nvalue(idx); + lua_number2int(k, n); + lua_assert(luaO_rawequalObj(&f->k[k], v)); } else { /* constant not found; create a new entry */ - setnvalue(idx, cast_num(fs->nk)); - luaM_growvector(L, f->k, fs->nk, f->sizek, TValue, - MAXARG_Bx, "constant table overflow"); + int oldsize = f->sizek; + k = fs->nk; + setnvalue(idx, cast_num(k)); + luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Bx, + "constant table overflow"); while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]); - setobj(L, &f->k[fs->nk], v); + setobj(L, &f->k[k], v); + fs->nk++; luaC_barrier(L, f, v); - return fs->nk++; } + return k; } |
