diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-05-31 15:51:50 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-05-31 15:51:50 -0300 |
| commit | 616438fe9ab5e3ae7d73e9ad838e9b7bdea1ea59 (patch) | |
| tree | 78322d820e3af1ca6645ed08eaa65a8f0aa04fec /lcode.c | |
| parent | 47eda6ebd83785908ac26f8dd06dff36a7d42664 (diff) | |
| download | lua-616438fe9ab5e3ae7d73e9ad838e9b7bdea1ea59.tar.gz lua-616438fe9ab5e3ae7d73e9ad838e9b7bdea1ea59.tar.bz2 lua-616438fe9ab5e3ae7d73e9ad838e9b7bdea1ea59.zip | |
new way to use `vararg' parameters (with `...')
Diffstat (limited to 'lcode.c')
| -rw-r--r-- | lcode.c | 28 |
1 files changed, 21 insertions, 7 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lcode.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 2.2 2004/04/30 20:13:38 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 | */ |
| @@ -252,13 +252,26 @@ static int nil_constant (FuncState *fs) { | |||
| 252 | } | 252 | } |
| 253 | 253 | ||
| 254 | 254 | ||
| 255 | void luaK_setcallreturns (FuncState *fs, expdesc *e, int nresults) { | 255 | void luaK_setreturns (FuncState *fs, expdesc *e, int nresults) { |
| 256 | if (e->k == VCALL) { /* expression is an open function call? */ | 256 | if (e->k == VCALL) { /* expression is an open function call? */ |
| 257 | SETARG_C(getcode(fs, e), nresults+1); | 257 | SETARG_C(getcode(fs, e), nresults+1); |
| 258 | if (nresults == 1) { /* `regular' expression? */ | 258 | } |
| 259 | e->k = VNONRELOC; | 259 | else if (e->k == VVARARG) { |
| 260 | e->info = GETARG_A(getcode(fs, e)); | 260 | SETARG_B(getcode(fs, e), nresults+1); |
| 261 | } | 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 */ | ||
| 262 | } | 275 | } |
| 263 | } | 276 | } |
| 264 | 277 | ||
| @@ -286,8 +299,9 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) { | |||
| 286 | e->k = VRELOCABLE; | 299 | e->k = VRELOCABLE; |
| 287 | break; | 300 | break; |
| 288 | } | 301 | } |
| 302 | case VVARARG: | ||
| 289 | case VCALL: { | 303 | case VCALL: { |
| 290 | luaK_setcallreturns(fs, e, 1); | 304 | luaK_setoneret(fs, e); |
| 291 | break; | 305 | break; |
| 292 | } | 306 | } |
| 293 | default: break; /* there is one value available (somewhere) */ | 307 | default: break; /* there is one value available (somewhere) */ |
