aboutsummaryrefslogtreecommitdiff
path: root/lcode.c
diff options
context:
space:
mode:
Diffstat (limited to 'lcode.c')
-rw-r--r--lcode.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/lcode.c b/lcode.c
index b8ba2a98..ca4e884f 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 2.24 2005/12/22 16:19:56 roberto Exp roberto $ 2** $Id: lcode.c,v 2.25 2006/03/21 19:28:49 roberto Exp roberto $
3** Code generator for Lua 3** Code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -221,24 +221,28 @@ static void freeexp (FuncState *fs, expdesc *e) {
221} 221}
222 222
223 223
224static int addk (FuncState *fs, TValue *k, TValue *v) { 224static int addk (FuncState *fs, TValue *key, TValue *v) {
225 lua_State *L = fs->L; 225 lua_State *L = fs->L;
226 TValue *idx = luaH_set(L, fs->h, k); 226 TValue *idx = luaH_set(L, fs->h, key);
227 Proto *f = fs->f; 227 Proto *f = fs->f;
228 int oldsize = f->sizek; 228 int k;
229 if (ttisnumber(idx)) { 229 if (ttisnumber(idx)) {
230 lua_assert(luaO_rawequalObj(&fs->f->k[cast_int(nvalue(idx))], v)); 230 lua_Number n = nvalue(idx);
231 return cast_int(nvalue(idx)); 231 lua_number2int(k, n);
232 lua_assert(luaO_rawequalObj(&f->k[k], v));
232 } 233 }
233 else { /* constant not found; create a new entry */ 234 else { /* constant not found; create a new entry */
234 setnvalue(idx, cast_num(fs->nk)); 235 int oldsize = f->sizek;
235 luaM_growvector(L, f->k, fs->nk, f->sizek, TValue, 236 k = fs->nk;
236 MAXARG_Bx, "constant table overflow"); 237 setnvalue(idx, cast_num(k));
238 luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Bx,
239 "constant table overflow");
237 while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]); 240 while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
238 setobj(L, &f->k[fs->nk], v); 241 setobj(L, &f->k[k], v);
242 fs->nk++;
239 luaC_barrier(L, f, v); 243 luaC_barrier(L, f, v);
240 return fs->nk++;
241 } 244 }
245 return k;
242} 246}
243 247
244 248