diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-07-07 13:27:29 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-07-07 13:27:29 -0300 |
| commit | 81dd13f4c6a70f08d83f7b7360e4e15cf79dd573 (patch) | |
| tree | b379d2c248dd57e71f9461db581c6d0cfa0f24f8 /lcode.c | |
| parent | 6a02bbe1e2f8ad1b98a077bd2aac44e776fd107c (diff) | |
| download | lua-81dd13f4c6a70f08d83f7b7360e4e15cf79dd573.tar.gz lua-81dd13f4c6a70f08d83f7b7360e4e15cf79dd573.tar.bz2 lua-81dd13f4c6a70f08d83f7b7360e4e15cf79dd573.zip | |
new way to distinguish between indexing tables in registers and
tables in upvalues (+ fixed small bug when checking conflicts in
multiple assignments)
Diffstat (limited to 'lcode.c')
| -rw-r--r-- | lcode.c | 28 |
1 files changed, 12 insertions, 16 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lcode.c,v 2.47 2010/06/30 14:11:17 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 2.48 2010/07/02 20:42:40 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 | */ |
| @@ -373,15 +373,13 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) { | |||
| 373 | break; | 373 | break; |
| 374 | } | 374 | } |
| 375 | case VINDEXED: { | 375 | case VINDEXED: { |
| 376 | OpCode op = OP_GETTABUP; /* assume 't' is in an upvalue */ | ||
| 376 | freereg(fs, e->u.ind.idx); | 377 | freereg(fs, e->u.ind.idx); |
| 377 | freereg(fs, e->u.ind.t); | 378 | if (e->u.ind.vt == VLOCAL) { /* 't' is in a register? */ |
| 378 | e->u.info = luaK_codeABC(fs, OP_GETTABLE, 0, e->u.ind.t, e->u.ind.idx); | 379 | freereg(fs, e->u.ind.t); |
| 379 | e->k = VRELOCABLE; | 380 | op = OP_GETTABLE; |
| 380 | break; | 381 | } |
| 381 | } | 382 | e->u.info = luaK_codeABC(fs, op, 0, e->u.ind.t, e->u.ind.idx); |
| 382 | case VINDEXEDUP: { | ||
| 383 | freereg(fs, e->u.ind.idx); | ||
| 384 | e->u.info = luaK_codeABC(fs, OP_GETTABUP, 0, e->u.ind.t, e->u.ind.idx); | ||
| 385 | e->k = VRELOCABLE; | 383 | e->k = VRELOCABLE; |
| 386 | break; | 384 | break; |
| 387 | } | 385 | } |
| @@ -551,13 +549,9 @@ void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) { | |||
| 551 | break; | 549 | break; |
| 552 | } | 550 | } |
| 553 | case VINDEXED: { | 551 | case VINDEXED: { |
| 552 | OpCode op = (var->u.ind.vt == VLOCAL) ? OP_SETTABLE : OP_SETTABUP; | ||
| 554 | int e = luaK_exp2RK(fs, ex); | 553 | int e = luaK_exp2RK(fs, ex); |
| 555 | luaK_codeABC(fs, OP_SETTABLE, var->u.ind.t, var->u.ind.idx, e); | 554 | luaK_codeABC(fs, op, var->u.ind.t, var->u.ind.idx, e); |
| 556 | break; | ||
| 557 | } | ||
| 558 | case VINDEXEDUP: { | ||
| 559 | int e = luaK_exp2RK(fs, ex); | ||
| 560 | luaK_codeABC(fs, OP_SETTABUP, var->u.ind.t, var->u.ind.idx, e); | ||
| 561 | break; | 555 | break; |
| 562 | } | 556 | } |
| 563 | default: { | 557 | default: { |
| @@ -705,7 +699,9 @@ void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { | |||
| 705 | lua_assert(!hasjumps(t)); | 699 | lua_assert(!hasjumps(t)); |
| 706 | t->u.ind.t = t->u.info; | 700 | t->u.ind.t = t->u.info; |
| 707 | t->u.ind.idx = luaK_exp2RK(fs, k); | 701 | t->u.ind.idx = luaK_exp2RK(fs, k); |
| 708 | t->k = (t->k == VUPVAL) ? VINDEXEDUP : VINDEXED; | 702 | t->u.ind.vt = (t->k == VUPVAL) ? VUPVAL |
| 703 | : check_exp(vkisinreg(t->k), VLOCAL); | ||
| 704 | t->k = VINDEXED; | ||
| 709 | } | 705 | } |
| 710 | 706 | ||
| 711 | 707 | ||
