History

Lua 5.2.0-rc1

Lua Team committed 14 years ago

Commit d74d0e51 parent 8203bab51 files · +1861 −1136Browse files

Showing the changes to src/lcode.c (1 of 51 files). Show all

Unified · Split

src/lcode.c+12−10
@@ -1,5 +1,5 @@
1/*1/*
2** $Id: lcode.c,v 2.56 2011/05/31 18:27:56 roberto Exp $2** $Id: lcode.c,v 2.60 2011/08/30 16:26:41 roberto Exp $
3** Code generator for Lua3** Code generator for Lua
4** See Copyright Notice in lua.h4** See Copyright Notice in lua.h
5*/5*/
@@ -44,8 +44,8 @@ void luaK_nil (FuncState *fs, int from, int n) { · 38 unmodified lines
44 int pl = pfrom + GETARG_B(*previous);44 int pl = pfrom + GETARG_B(*previous);
45 if ((pfrom <= from && from <= pl + 1) ||45 if ((pfrom <= from && from <= pl + 1) ||
46 (from <= pfrom && pfrom <= l + 1)) { /* can connect both? */46 (from <= pfrom && pfrom <= l + 1)) { /* can connect both? */
47 if (pfrom < from) from = pfrom; /* from = min(from, pfrom) */ 47 if (pfrom < from) from = pfrom; /* from = min(from, pfrom) */
48 if (pl > l) l = pl; /* l = max(l, pl) */ 48 if (pl > l) l = pl; /* l = max(l, pl) */
49 SETARG_A(*previous, from);49 SETARG_A(*previous, from);
50 SETARG_B(*previous, l - from);50 SETARG_B(*previous, l - from);
51 return;51 return;
@@ -213,11 +213,11 @@ static int luaK_code (FuncState *fs, Instruction i) { · 161 unmodified lines
213 Proto *f = fs->f;213 Proto *f = fs->f;
214 dischargejpc(fs); /* `pc' will change */214 dischargejpc(fs); /* `pc' will change */
215 /* put new instruction in code array */215 /* put new instruction in code array */
216 luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction,216 luaM_growvector(fs->ls->L, f->code, fs->pc, f->sizecode, Instruction,
217 MAX_INT, "opcodes");217 MAX_INT, "opcodes");
218 f->code[fs->pc] = i;218 f->code[fs->pc] = i;
219 /* save corresponding line information */219 /* save corresponding line information */
220 luaM_growvector(fs->L, f->lineinfo, fs->pc, f->sizelineinfo, int,220 luaM_growvector(fs->ls->L, f->lineinfo, fs->pc, f->sizelineinfo, int,
221 MAX_INT, "opcodes");221 MAX_INT, "opcodes");
222 f->lineinfo[fs->pc] = fs->ls->lastline;222 f->lineinfo[fs->pc] = fs->ls->lastline;
223 return fs->pc++;223 return fs->pc++;
@@ -289,7 +289,7 @@ static void freeexp (FuncState *fs, expdesc *e) { · 65 unmodified lines
289 289
290 290
291static int addk (FuncState *fs, TValue *key, TValue *v) {291static int addk (FuncState *fs, TValue *key, TValue *v) {
292 lua_State *L = fs->L;292 lua_State *L = fs->ls->L;
293 TValue *idx = luaH_set(L, fs->h, key);293 TValue *idx = luaH_set(L, fs->h, key);
294 Proto *f = fs->f;294 Proto *f = fs->f;
295 int k, oldsize;295 int k, oldsize;
@@ -304,6 +304,8 @@ static int addk (FuncState *fs, TValue *key, TValue *v) { · 8 unmodified lines
304 /* constant not found; create a new entry */304 /* constant not found; create a new entry */
305 oldsize = f->sizek;305 oldsize = f->sizek;
306 k = fs->nk;306 k = fs->nk;
307 /* numerical value does not need GC barrier;
308 table has no metatable, so it does not need to invalidate cache */
307 setnvalue(idx, cast_num(k));309 setnvalue(idx, cast_num(k));
308 luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, "constants");310 luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, "constants");
309 while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);311 while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
@@ -316,14 +318,14 @@ static int addk (FuncState *fs, TValue *key, TValue *v) { · 6 unmodified lines
316 318
317int luaK_stringK (FuncState *fs, TString *s) {319int luaK_stringK (FuncState *fs, TString *s) {
318 TValue o;320 TValue o;
319 setsvalue(fs->L, &o, s);321 setsvalue(fs->ls->L, &o, s);
320 return addk(fs, &o, &o);322 return addk(fs, &o, &o);
321}323}
322 324
323 325
324int luaK_numberK (FuncState *fs, lua_Number r) {326int luaK_numberK (FuncState *fs, lua_Number r) {
325 int n;327 int n;
326 lua_State *L = fs->L;328 lua_State *L = fs->ls->L;
327 TValue o;329 TValue o;
328 setnvalue(&o, r);330 setnvalue(&o, r);
329 if (r == 0 || luai_numisnan(NULL, r)) { /* handle -0 and NaN */331 if (r == 0 || luai_numisnan(NULL, r)) { /* handle -0 and NaN */
@@ -350,7 +352,7 @@ static int nilK (FuncState *fs) { · 20 unmodified lines
350 TValue k, v;352 TValue k, v;
351 setnilvalue(&v);353 setnilvalue(&v);
352 /* cannot use nil as key; instead use table itself to represent nil */354 /* cannot use nil as key; instead use table itself to represent nil */
353 sethvalue(fs->L, &k, fs->h);355 sethvalue(fs->ls->L, &k, fs->h);
354 return addk(fs, &k, &v);356 return addk(fs, &k, &v);
355}357}
356 358
@@ -641,7 +643,7 @@ void luaK_goiftrue (FuncState *fs, expdesc *e) { · 284 unmodified lines
641}643}
642 644
643 645
644static void luaK_goiffalse (FuncState *fs, expdesc *e) {646void luaK_goiffalse (FuncState *fs, expdesc *e) {
645 int pc; /* pc of last jump */647 int pc; /* pc of last jump */
646 luaK_dischargevars(fs, e);648 luaK_dischargevars(fs, e);
647 switch (e->k) {649 switch (e->k) {