Get rid of more LuaOldStack

This commit is contained in:
2023-04-11 17:03:26 -04:00
parent f77c3864b5
commit 3fd4067969
2 changed files with 43 additions and 54 deletions

View File

@@ -192,8 +192,8 @@ static bool diff_tables(LuaCoreStack &SLS0, LuaSlot stnmap, LuaSlot stab,
LuaCoreStack &MLS0, LuaSlot mtnmap, LuaSlot mtab,
bool cmeta, StreamBuffer *sb) {
LuaVar skey, mkey, sval, mval, mnil;
LuaOldStack SLS(SLS0.state(), skey, sval);
LuaOldStack MLS(MLS0.state(), mkey, mval, mnil);
LuaExtStack SLS(SLS0.state(), skey, sval);
LuaExtStack MLS(MLS0.state(), mkey, mval, mnil);
assert(MLS.istable(mtab));
assert(SLS.istable(stab));
MLS.set(mnil, LuaNil);
@@ -237,9 +237,6 @@ static bool diff_tables(LuaCoreStack &SLS0, LuaSlot stnmap, LuaSlot stab,
}
sb->overwrite_int32(wc, nupdates);
SLS.result();
MLS.result();
return (nupdates > 0);
}
@@ -323,7 +320,7 @@ static void set_transmitted_value(LuaCoreStack &LS, LuaSlot tangibles, LuaSlot n
static void patch_table(LuaCoreStack &LS0, LuaSlot tangibles, LuaSlot ntmap, LuaSlot tab, StreamBuffer *sb, DebugCollector *dbc) {
LuaVar key, val;
LuaOldStack LS(LS0.state(), key, val);
LuaExtStack LS(LS0.state(), key, val);
int ndiffs = sb->read_int32();
for (int i = 0; i < ndiffs; i++) {
set_transmitted_value(LS, tangibles, ntmap, key, sb, "key=", dbc);
@@ -334,13 +331,12 @@ static void patch_table(LuaCoreStack &LS0, LuaSlot tangibles, LuaSlot ntmap, Lua
LS.rawset(tab, key, val);
}
}
LS.result();
}
void World::patch_numbered_tables(StreamBuffer *sb, DebugCollector *dbc) {
lua_State *L = state();
LuaVar tangibles, ntmap, tab;
LuaOldStack LS(L, tangibles, ntmap, tab);
LuaExtStack LS(L, tangibles, ntmap, tab);
LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawget(ntmap, LuaRegistry, "ntmap");
assert(LS.istable(tangibles));
@@ -354,14 +350,13 @@ void World::patch_numbered_tables(StreamBuffer *sb, DebugCollector *dbc) {
DebugHeader(dbc) << "Lua Table " << index << ":";
patch_table(LS, tangibles, ntmap, tab, sb, dbc);
}
LS.result();
}
void World::diff_numbered_tables(lua_State *master, StreamBuffer *sb) {
lua_State *synch = state();
LuaVar sntmap, mntmap, stnmap, mtnmap, stab, mtab;
LuaOldStack SLS(synch, sntmap, stnmap, stab);
LuaOldStack MLS(master, mntmap, mtnmap, mtab);
LuaExtStack SLS(synch, sntmap, stnmap, stab);
LuaExtStack MLS(master, mntmap, mtnmap, mtab);
SLS.rawget(sntmap, LuaRegistry, "ntmap");
MLS.rawget(mntmap, LuaRegistry, "ntmap");
SLS.rawget(stnmap, LuaRegistry, "tnmap");
@@ -392,14 +387,12 @@ void World::diff_numbered_tables(lua_State *master, StreamBuffer *sb) {
assert(lua_gettop(master) == m_top);
}
sb->overwrite_int32(write_count_after, nmodified);
SLS.result();
MLS.result();
}
void World::patch_tangible_databases(StreamBuffer *sb, DebugCollector *dbc) {
lua_State *L = state();
LuaVar tangibles, ntmap, tab;
LuaOldStack LS(L, tangibles, ntmap, tab);
LuaExtStack LS(L, tangibles, ntmap, tab);
LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawget(ntmap, LuaRegistry, "ntmap");
assert(LS.istable(tangibles));
@@ -413,14 +406,13 @@ void World::patch_tangible_databases(StreamBuffer *sb, DebugCollector *dbc) {
DebugHeader(dbc) << "Tangible DB " << id << ":";
patch_table(LS, tangibles, ntmap, tab, sb, dbc);
}
LS.result();
}
void World::diff_tangible_databases(const IdVector &basis, lua_State *master, StreamBuffer *sb) {
lua_State *synch = state();
LuaVar stnmap, mtnmap, stangibles, mtangibles, stab, mtab;
LuaOldStack SLS(synch, stnmap, stangibles, stab);
LuaOldStack MLS(master, mtnmap, mtangibles, mtab);
LuaExtStack SLS(synch, stnmap, stangibles, stab);
LuaExtStack MLS(master, mtnmap, mtangibles, mtab);
SLS.rawget(stnmap, LuaRegistry, "tnmap");
MLS.rawget(mtnmap, LuaRegistry, "tnmap");
SLS.rawget(stangibles, LuaRegistry, "tangibles");
@@ -447,15 +439,13 @@ void World::diff_tangible_databases(const IdVector &basis, lua_State *master, St
assert(lua_gettop(master) == m_top);
}
sb->overwrite_int32(write_count_after, nmodified);
SLS.result();
MLS.result();
}
LuaDefine(table_diffcompare, "mtnmap,mtab,stnmap,stab", "for unit testing only") {
LuaArg mtnmap, mtab, mstnmap, mstab;
LuaRet dbgstring;
LuaVar tthread;
LuaOldStack MLS(L, mtnmap, mtab, mstnmap, mstab, dbgstring, tthread);
LuaDefStack MLS(L, mtnmap, mtab, mstnmap, mstab, dbgstring, tthread);
// Check the arguments.
MLS.checktable(mtnmap, "mtnmap");
MLS.checktable(mstnmap, "mstnmap");
@@ -470,7 +460,7 @@ LuaDefine(table_diffcompare, "mtnmap,mtab,stnmap,stab", "for unit testing only")
lua_pushvalue(L, mstab.index());
lua_xmove(L, synch, 2);
LuaArg stnmap,stab;
LuaOldStack SLS(synch, stnmap, stab);
LuaDefStack SLS(synch, stnmap, stab);
// Call tablecmp_diff.
StreamBuffer sb;
@@ -485,7 +475,7 @@ LuaDefine(table_diffapply, "mtnmap,mtab,mstab", "for unit testing only") {
LuaArg mtnmap, mtab, mstab;
LuaRet eql, eqlstr, rtab;
LuaVar tthread, tangibles, mntmap, key, val;
LuaOldStack MLS(L, mtnmap, mtab, mstab, eql, eqlstr, rtab, tthread, tangibles, mntmap, key, val);
LuaDefStack MLS(L, mtnmap, mtab, mstab, eql, eqlstr, rtab, tthread, tangibles, mntmap, key, val);
// Check the arguments.
MLS.checktable(mtnmap, "mtnmap");
MLS.checktable(mtab, "mtab");
@@ -509,7 +499,7 @@ LuaDefine(table_diffapply, "mtnmap,mtab,mstab", "for unit testing only") {
lua_pushvalue(L, mstab.index());
lua_xmove(L, synch, 2);
LuaArg stnmap, stab;
LuaOldStack SLS(synch, stnmap, stab);
LuaDefStack SLS(synch, stnmap, stab);
// Call diff_tables and patch_tables
StreamBuffer sb;