Internal tag for iterators

This commit is contained in:
Petri Häkkinen 2023-11-07 11:43:53 +02:00
parent 09840f8f32
commit bdc142e948
5 changed files with 17 additions and 13 deletions

View file

@ -71,7 +71,7 @@ bool forgLoopTableIter(lua_State* L, Table* h, int index, TValue* ra)
if (!ttisnil(e))
{
setpvalue(ra + 2, reinterpret_cast<void*>(uintptr_t(index + 1)));
setpvalue(ra + 2, reinterpret_cast<void*>(uintptr_t(index + 1)), LU_TAG_ITERATOR);
setnvalue(ra + 3, double(index + 1));
setobj2s(L, ra + 4, e);
@ -90,7 +90,7 @@ bool forgLoopTableIter(lua_State* L, Table* h, int index, TValue* ra)
if (!ttisnil(gval(n)))
{
setpvalue(ra + 2, reinterpret_cast<void*>(uintptr_t(index + 1)));
setpvalue(ra + 2, reinterpret_cast<void*>(uintptr_t(index + 1)), LU_TAG_ITERATOR);
getnodekey(L, ra + 3, n);
setobj(L, ra + 4, gval(n));
@ -115,7 +115,7 @@ bool forgLoopNodeIter(lua_State* L, Table* h, int index, TValue* ra)
if (!ttisnil(gval(n)))
{
setpvalue(ra + 2, reinterpret_cast<void*>(uintptr_t(index + 1)));
setpvalue(ra + 2, reinterpret_cast<void*>(uintptr_t(index + 1)), LU_TAG_ITERATOR);
getnodekey(L, ra + 3, n);
setobj(L, ra + 4, gval(n));
@ -765,7 +765,7 @@ const Instruction* executeFORGPREP(lua_State* L, const Instruction* pc, StkId ba
{
// set up registers for builtin iteration
setobj2s(L, ra + 1, ra);
setpvalue(ra + 2, reinterpret_cast<void*>(uintptr_t(0)));
setpvalue(ra + 2, reinterpret_cast<void*>(uintptr_t(0)), LU_TAG_ITERATOR);
setnilvalue(ra);
}
else

View file

@ -682,8 +682,7 @@ void lua_pushboolean(lua_State* L, int b)
void lua_pushlightuserdatatagged(lua_State* L, void* p, int tag)
{
api_check(L, unsigned(tag) < LUA_LUTAG_LIMIT);
setpvalue(L->top, p);
L->top->extra[0] = tag;
setpvalue(L->top, p, tag);
api_incr_top(L);
}

View file

@ -82,6 +82,10 @@ typedef struct lua_TValue
#define lightuserdatatag(o) check_exp(ttislightuserdata(o), (o)->extra[0])
// Internal tags used by the VM
#define LU_TAG_ITERATOR LUA_UTAG_LIMIT
#define LU_TAG_COUNT (LUA_UTAG_LIMIT+1)
/*
** for internal debug only
*/
@ -122,10 +126,11 @@ typedef struct lua_TValue
}
#endif
#define setpvalue(obj, x) \
#define setpvalue(obj, x, tag) \
{ \
TValue* i_o = (obj); \
i_o->value.p = (x); \
i_o->extra[0] = (tag); \
i_o->tt = LUA_TLIGHTUSERDATA; \
}

View file

@ -197,7 +197,7 @@ typedef struct global_State
struct Table* mt[LUA_T_COUNT]; // metatables for basic types
TString* ttname[LUA_T_COUNT]; // names for basic types
TString* tmname[TM_N]; // array with tag-method names
TString* lightuserdataname[LUA_LUTAG_LIMIT]; // names for tagged lightuserdata
TString* lightuserdataname[LU_TAG_COUNT]; // names for tagged lightuserdata
TValue pseudotemp; // storage for temporary values used in pseudo2addr

View file

@ -2302,7 +2302,7 @@ reentry:
{
// set up registers for builtin iteration
setobj2s(L, ra + 1, ra);
setpvalue(ra + 2, reinterpret_cast<void*>(uintptr_t(0)));
setpvalue(ra + 2, reinterpret_cast<void*>(uintptr_t(0)), LU_TAG_ITERATOR);
setnilvalue(ra);
}
else
@ -2354,7 +2354,7 @@ reentry:
if (!ttisnil(e))
{
setpvalue(ra + 2, reinterpret_cast<void*>(uintptr_t(index + 1)));
setpvalue(ra + 2, reinterpret_cast<void*>(uintptr_t(index + 1)), LU_TAG_ITERATOR);
setnvalue(ra + 3, double(index + 1));
setobj2s(L, ra + 4, e);
@ -2375,7 +2375,7 @@ reentry:
if (!ttisnil(gval(n)))
{
setpvalue(ra + 2, reinterpret_cast<void*>(uintptr_t(index + 1)));
setpvalue(ra + 2, reinterpret_cast<void*>(uintptr_t(index + 1)), LU_TAG_ITERATOR);
getnodekey(L, ra + 3, n);
setobj2s(L, ra + 4, gval(n));
@ -2427,7 +2427,7 @@ reentry:
{
setnilvalue(ra);
// ra+1 is already the table
setpvalue(ra + 2, reinterpret_cast<void*>(uintptr_t(0)));
setpvalue(ra + 2, reinterpret_cast<void*>(uintptr_t(0)), LU_TAG_ITERATOR);
}
else if (!ttisfunction(ra))
{
@ -2456,7 +2456,7 @@ reentry:
{
setnilvalue(ra);
// ra+1 is already the table
setpvalue(ra + 2, reinterpret_cast<void*>(uintptr_t(0)));
setpvalue(ra + 2, reinterpret_cast<void*>(uintptr_t(0)), LU_TAG_ITERATOR);
}
else if (!ttisfunction(ra))
{