Skip to content
Permalink
Browse files
Third argument to __index handlers?
The original table triggering the MT call chain

Originally 6d84cd88d6c74289b1eaad4f94beb840ce16f945

Signed-off-by: Karel Tuma <kat@lua.cz>
  • Loading branch information
katlogic committed Feb 27, 2016
1 parent 5adbd89 commit 22b7bab
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
@@ -135,6 +135,7 @@ static TValue *mmcall(lua_State *L, ASMFunction cont, cTValue *mo,
cTValue *lj_meta_tget(lua_State *L, cTValue *o, cTValue *k)
{
int loop;
cTValue *origo = o;
for (loop = 0; loop < LJ_MAX_IDXCHAIN; loop++) {
cTValue *mo;
if (LJ_LIKELY(tvistab(o))) {
@@ -149,6 +150,7 @@ cTValue *lj_meta_tget(lua_State *L, cTValue *o, cTValue *k)
}
if (tvisfunc(mo)) {
L->top = mmcall(L, lj_cont_ra, mo, o, k);
copyTV(L, L->top+2, origo);
return NULL; /* Trigger metamethod call. */
}
o = mo;
@@ -1301,6 +1301,10 @@ TRef lj_record_idx(jit_State *J, RecordIndex *ix)
IRType1 rbguard;
cTValue *oldv;

/* Remember original table before overwriting it. */
ix->otab = ix->tab;
ix->otabv = ix->tabv;

while (!tref_istab(ix->tab)) { /* Handle non-table lookup. */
/* Never call raw lj_record_idx() on non-table. */
lua_assert(ix->idxchain != 0);
@@ -1322,7 +1326,9 @@ TRef lj_record_idx(jit_State *J, RecordIndex *ix)
lj_record_call(J, func, 3); /* mobj(tab, key, val) */
return 0;
} else {
lj_record_call(J, func, 2); /* res = mobj(tab, key) */
base[3] = ix->otab;
copyTV(J->L, tv+3, &ix->otabv);
lj_record_call(J, func, 3); /* res = mobj(tab, key, origtab) */
return 0; /* No result yet. */
}
}
@@ -12,12 +12,14 @@
#if LJ_HASJIT
/* Context for recording an indexed load/store. */
typedef struct RecordIndex {
TValue otabv; /* Original runtime value of table (or indexed object). */
TValue tabv; /* Runtime value of table (or indexed object). */
TValue keyv; /* Runtime value of key. */
TValue valv; /* Runtime value of stored value. */
TValue mobjv; /* Runtime value of metamethod object. */
GCtab *mtv; /* Runtime value of metatable object. */
cTValue *oldv; /* Runtime value of previously stored value. */
TRef otab; /* Original table (or indexed object) reference. */
TRef tab; /* Table (or indexed object) reference. */
TRef key; /* Key reference. */
TRef val; /* Value reference for a store or 0 for a load. */
@@ -931,13 +931,13 @@ static void build_subroutines(BuildCtx *ctx)
| ins_next
|
|3: // Call __index metamethod.
| // BASE = base, L->top = new base, stack = cont/func/t/k
| // BASE = base, L->top = new base, stack = cont/func/t/k/origt
| mov RA, L:RB->top
| mov [RA-12], PC // [cont|PC]
| lea PC, [RA+FRAME_CONT]
| sub PC, BASE
| mov LFUNC:RB, [RA-8] // Guaranteed to be a function here.
| mov NARGS:RD, 2+1 // 2 args for func(t, k).
| mov NARGS:RD, 3+1 // 2 args for func(t, k).
| jmp ->vm_call_dispatch_f
|
|->vmeta_tgetr:

0 comments on commit 22b7bab

Please sign in to comment.