History

Lua 5.1-work1

Lua Team committed 22 years ago

Commit 4014ed71 parent ad2eda775 files · +2140 −2612Browse files

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

Unified · Split

src/lcode.c+28−13
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lcode.c,v 2.1 2003/12/10 12:13:36 roberto Exp $
2+** $Id: lcode.c,v 2.6 2004/08/24 20:09:11 roberto Exp $
33 ** Code generator for Lua
44 ** See Copyright Notice in lua.h
55 */
@@ -8,6 +8,7 @@ · 2 unmodified lines
88 #include <stdlib.h>
99
1010 #define lcode_c
11+#define LUA_CORE
1112
1213 #include "lua.h"
1314
@@ -194,7 +195,7 @@ void luaK_reserveregs (FuncState *fs, int n) { · 180 unmodified lines
194195
195196
196197 static void freereg (FuncState *fs, int reg) {
197− if (reg >= fs->nactvar && reg < MAXSTACK) {
198+ if (!ISK(reg) && reg >= fs->nactvar) {
198199 fs->freereg--;
199200 lua_assert(reg == fs->freereg);
200201 }
@@ -222,7 +223,7 @@ static int addk (FuncState *fs, TValue *k, TValue *v) { · 21 unmodified lines
222223 MAXARG_Bx, "constant table overflow");
223224 while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
224225 setobj(L, &f->k[fs->nk], v);
225− luaC_barrier(L, f, v);
226+ luaC_barriert(L, f, v);
226227 return fs->nk++;
227228 }
228229 }
@@ -251,13 +252,26 @@ static int nil_constant (FuncState *fs) { · 22 unmodified lines
251252 }
252253
253254
254−void luaK_setcallreturns (FuncState *fs, expdesc *e, int nresults) {
255+void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) {
255256 if (e->k == VCALL) { /* expression is an open function call? */
256257 SETARG_C(getcode(fs, e), nresults+1);
257− if (nresults == 1) { /* `regular' expression? */
258− e->k = VNONRELOC;
259− e->info = GETARG_A(getcode(fs, e));
260− }
258+ }
259+ else if (e->k == VVARARG) {
260+ SETARG_B(getcode(fs, e), nresults+1);
261+ SETARG_A(getcode(fs, e), fs->freereg);
262+ luaK_reserveregs(fs, 1);
263+ }
264+}
265+
266+
267+void luaK_setoneret (FuncState *fs, expdesc *e) {
268+ if (e->k == VCALL) { /* expression is an open function call? */
269+ e->k = VNONRELOC;
270+ e->info = GETARG_A(getcode(fs, e));
271+ }
272+ else if (e->k == VVARARG) {
273+ SETARG_B(getcode(fs, e), 2);
274+ e->k = VRELOCABLE; /* can relocate its simple result */
261275 }
262276 }
263277
@@ -285,8 +299,9 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) { · 21 unmodified lines
285299 e->k = VRELOCABLE;
286300 break;
287301 }
302+ case VVARARG:
288303 case VCALL: {
289− luaK_setcallreturns(fs, e, 1);
304+ luaK_setoneret(fs, e);
290305 break;
291306 }
292307 default: break; /* there is one value available (somewhere) */
@@ -403,16 +418,16 @@ int luaK_exp2RK (FuncState *fs, expdesc *e) { · 110 unmodified lines
403418 luaK_exp2val(fs, e);
404419 switch (e->k) {
405420 case VNIL: {
406− if (fs->nk + MAXSTACK <= MAXARG_C) { /* constant fit in argC? */
421+ if (fs->nk <= MAXINDEXRK) { /* constant fit in RK operand? */
407422 e->info = nil_constant(fs);
408423 e->k = VK;
409− return e->info + MAXSTACK;
424+ return RKASK(e->info);
410425 }
411426 else break;
412427 }
413428 case VK: {
414− if (e->info + MAXSTACK <= MAXARG_C) /* constant fit in argC? */
415− return e->info + MAXSTACK;
429+ if (e->info <= MAXINDEXRK) /* constant fit in argC? */
430+ return RKASK(e->info);
416431 else break;
417432 }
418433 default: break;