Showing the changes to src/lcode.c (1 of 75 files). Show all
Unified · Split
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 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 $ |
| 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 | */ |
| @@ -8,6 +8,7 @@ · 2 unmodified lines | |||
| 8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
| 9 | 9 | ||
| 10 | #define lcode_c | 10 | #define lcode_c |
| 11 | #define LUA_CORE | ||
| 11 | 12 | ||
| 12 | #include "lua.h" | 13 | #include "lua.h" |
| 13 | 14 | ||
| @@ -194,7 +195,7 @@ void luaK_reserveregs (FuncState *fs, int n) { · 180 unmodified lines | |||
| 194 | 195 | ||
| 195 | 196 | ||
| 196 | static void freereg (FuncState *fs, int reg) { | 197 | static void freereg (FuncState *fs, int reg) { |
| 197 | if (reg >= fs->nactvar && reg < MAXSTACK) { | 198 | if (!ISK(reg) && reg >= fs->nactvar) { |
| 198 | fs->freereg--; | 199 | fs->freereg--; |
| 199 | lua_assert(reg == fs->freereg); | 200 | lua_assert(reg == fs->freereg); |
| 200 | } | 201 | } |
| @@ -222,7 +223,7 @@ static int addk (FuncState *fs, TValue *k, TValue *v) { · 21 unmodified lines | |||
| 222 | MAXARG_Bx, "constant table overflow"); | 223 | MAXARG_Bx, "constant table overflow"); |
| 223 | while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]); | 224 | while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]); |
| 224 | setobj(L, &f->k[fs->nk], v); | 225 | setobj(L, &f->k[fs->nk], v); |
| 225 | luaC_barrier(L, f, v); | 226 | luaC_barriert(L, f, v); |
| 226 | return fs->nk++; | 227 | return fs->nk++; |
| 227 | } | 228 | } |
| 228 | } | 229 | } |
| @@ -251,13 +252,26 @@ static int nil_constant (FuncState *fs) { · 22 unmodified lines | |||
| 251 | } | 252 | } |
| 252 | 253 | ||
| 253 | 254 | ||
| 254 | void luaK_setcallreturns (FuncState *fs, expdesc *e, int nresults) { | 255 | void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) { |
| 255 | if (e->k == VCALL) { /* expression is an open function call? */ | 256 | if (e->k == VCALL) { /* expression is an open function call? */ |
| 256 | SETARG_C(getcode(fs, e), nresults+1); | 257 | SETARG_C(getcode(fs, e), nresults+1); |
| 257 | if (nresults == 1) { /* `regular' expression? */ | 258 | } |
| 258 | e->k = VNONRELOC; | 259 | else if (e->k == VVARARG) { |
| 259 | e->info = GETARG_A(getcode(fs, e)); | 260 | SETARG_B(getcode(fs, e), nresults+1); |
| 260 | } | 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 */ | ||
| 261 | } | 275 | } |
| 262 | } | 276 | } |
| 263 | 277 | ||
| @@ -285,8 +299,9 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) { · 21 unmodified lines | |||
| 285 | e->k = VRELOCABLE; | 299 | e->k = VRELOCABLE; |
| 286 | break; | 300 | break; |
| 287 | } | 301 | } |
| 302 | case VVARARG: | ||
| 288 | case VCALL: { | 303 | case VCALL: { |
| 289 | luaK_setcallreturns(fs, e, 1); | 304 | luaK_setoneret(fs, e); |
| 290 | break; | 305 | break; |
| 291 | } | 306 | } |
| 292 | default: break; /* there is one value available (somewhere) */ | 307 | default: break; /* there is one value available (somewhere) */ |
| @@ -403,16 +418,16 @@ int luaK_exp2RK (FuncState *fs, expdesc *e) { · 110 unmodified lines | |||
| 403 | luaK_exp2val(fs, e); | 418 | luaK_exp2val(fs, e); |
| 404 | switch (e->k) { | 419 | switch (e->k) { |
| 405 | case VNIL: { | 420 | case VNIL: { |
| 406 | if (fs->nk + MAXSTACK <= MAXARG_C) { /* constant fit in argC? */ | 421 | if (fs->nk <= MAXINDEXRK) { /* constant fit in RK operand? */ |
| 407 | e->info = nil_constant(fs); | 422 | e->info = nil_constant(fs); |
| 408 | e->k = VK; | 423 | e->k = VK; |
| 409 | return e->info + MAXSTACK; | 424 | return RKASK(e->info); |
| 410 | } | 425 | } |
| 411 | else break; | 426 | else break; |
| 412 | } | 427 | } |
| 413 | case VK: { | 428 | case VK: { |
| 414 | if (e->info + MAXSTACK <= MAXARG_C) /* constant fit in argC? */ | 429 | if (e->info <= MAXINDEXRK) /* constant fit in argC? */ |
| 415 | return e->info + MAXSTACK; | 430 | return RKASK(e->info); |
| 416 | else break; | 431 | else break; |
| 417 | } | 432 | } |
| 418 | default: break; | 433 | default: break; |