Added two new stack disciplines to LuaStack

This commit is contained in:
2023-04-06 20:12:03 -04:00
parent b8df2bbc89
commit 7f000bc0fd
26 changed files with 401 additions and 271 deletions

View File

@@ -27,7 +27,7 @@
// Given a table and an tnmap, return the table number of the table.
// Returns zero if the table doesn't have a table number.
//
static int get_table_number(LuaStack &MLS, LuaSlot mval, LuaSlot mtnmap) {
static int get_table_number(LuaCoreStack &MLS, LuaSlot mval, LuaSlot mtnmap) {
lua_State *L = MLS.state();
lua_pushvalue(L, mval.index());
lua_rawget(L, mtnmap.index());
@@ -40,8 +40,8 @@ static int get_table_number(LuaStack &MLS, LuaSlot mval, LuaSlot mtnmap) {
}
static bool equivalent_values(LuaStack &MLS, LuaSlot mval, LuaSlot mtnmap,
LuaStack &SLS, LuaSlot sval, LuaSlot stnmap) {
static bool equivalent_values(LuaCoreStack &MLS, LuaSlot mval, LuaSlot mtnmap,
LuaCoreStack &SLS, LuaSlot sval, LuaSlot stnmap) {
switch (MLS.xtype(mval)) {
case LUA_TBOOLEAN: {
if (SLS.type(sval) != LUA_TBOOLEAN) return false;
@@ -92,7 +92,7 @@ static bool equivalent_values(LuaStack &MLS, LuaSlot mval, LuaSlot mtnmap,
}
}
static void transmit_value(LuaStack &MLS, LuaSlot mval, LuaSlot mtnmap, StreamBuffer *sb) {
static void transmit_value(LuaCoreStack &MLS, LuaSlot mval, LuaSlot mtnmap, StreamBuffer *sb) {
switch (MLS.xtype(mval)) {
case LUA_TBOOLEAN: {
sb->write_uint8(LUA_TBOOLEAN);
@@ -189,12 +189,12 @@ static void transmit_value_debug_string(StreamBuffer *sb, eng::ostringstream &os
}
}
static bool diff_tables(LuaStack &SLS0, LuaSlot stnmap, LuaSlot stab,
LuaStack &MLS0, LuaSlot mtnmap, LuaSlot mtab,
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;
LuaStack SLS(SLS0.state(), skey, sval);
LuaStack MLS(MLS0.state(), mkey, mval, mnil);
LuaOldStack SLS(SLS0.state(), skey, sval);
LuaOldStack MLS(MLS0.state(), mkey, mval, mnil);
assert(MLS.istable(mtab));
assert(SLS.istable(stab));
MLS.set(mnil, LuaNil);
@@ -262,7 +262,7 @@ static eng::string diff_tables_debug_string(StreamBuffer *sb) {
return oss.str();
}
static void set_transmitted_value(LuaStack &LS, LuaSlot tangibles, LuaSlot ntmap, LuaSlot target, StreamBuffer *sb, const char *dbinfo, DebugCollector *dbc) {
static void set_transmitted_value(LuaCoreStack &LS, LuaSlot tangibles, LuaSlot ntmap, LuaSlot target, StreamBuffer *sb, const char *dbinfo, DebugCollector *dbc) {
int kind = sb->read_uint8();
switch (kind) {
case LUA_TBOOLEAN: {
@@ -322,9 +322,9 @@ static void set_transmitted_value(LuaStack &LS, LuaSlot tangibles, LuaSlot ntmap
}
}
static void patch_table(LuaStack &LS0, LuaSlot tangibles, LuaSlot ntmap, LuaSlot tab, StreamBuffer *sb, DebugCollector *dbc) {
static void patch_table(LuaCoreStack &LS0, LuaSlot tangibles, LuaSlot ntmap, LuaSlot tab, StreamBuffer *sb, DebugCollector *dbc) {
LuaVar key, val;
LuaStack LS(LS0.state(), key, val);
LuaOldStack 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);
@@ -341,7 +341,7 @@ static void patch_table(LuaStack &LS0, LuaSlot tangibles, LuaSlot ntmap, LuaSlot
void World::patch_numbered_tables(StreamBuffer *sb, DebugCollector *dbc) {
lua_State *L = state();
LuaVar tangibles, ntmap, tab;
LuaStack LS(L, tangibles, ntmap, tab);
LuaOldStack LS(L, tangibles, ntmap, tab);
LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawget(ntmap, LuaRegistry, "ntmap");
assert(LS.istable(tangibles));
@@ -361,8 +361,8 @@ void World::patch_numbered_tables(StreamBuffer *sb, DebugCollector *dbc) {
void World::diff_numbered_tables(lua_State *master, StreamBuffer *sb) {
lua_State *synch = state();
LuaVar sntmap, mntmap, stnmap, mtnmap, stab, mtab;
LuaStack SLS(synch, sntmap, stnmap, stab);
LuaStack MLS(master, mntmap, mtnmap, mtab);
LuaOldStack SLS(synch, sntmap, stnmap, stab);
LuaOldStack MLS(master, mntmap, mtnmap, mtab);
SLS.rawget(sntmap, LuaRegistry, "ntmap");
MLS.rawget(mntmap, LuaRegistry, "ntmap");
SLS.rawget(stnmap, LuaRegistry, "tnmap");
@@ -400,7 +400,7 @@ void World::diff_numbered_tables(lua_State *master, StreamBuffer *sb) {
void World::patch_tangible_databases(StreamBuffer *sb, DebugCollector *dbc) {
lua_State *L = state();
LuaVar tangibles, ntmap, tab;
LuaStack LS(L, tangibles, ntmap, tab);
LuaOldStack LS(L, tangibles, ntmap, tab);
LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawget(ntmap, LuaRegistry, "ntmap");
assert(LS.istable(tangibles));
@@ -420,8 +420,8 @@ void World::patch_tangible_databases(StreamBuffer *sb, DebugCollector *dbc) {
void World::diff_tangible_databases(const IdVector &basis, lua_State *master, StreamBuffer *sb) {
lua_State *synch = state();
LuaVar stnmap, mtnmap, stangibles, mtangibles, stab, mtab;
LuaStack SLS(synch, stnmap, stangibles, stab);
LuaStack MLS(master, mtnmap, mtangibles, mtab);
LuaOldStack SLS(synch, stnmap, stangibles, stab);
LuaOldStack MLS(master, mtnmap, mtangibles, mtab);
SLS.rawget(stnmap, LuaRegistry, "tnmap");
MLS.rawget(mtnmap, LuaRegistry, "tnmap");
SLS.rawget(stangibles, LuaRegistry, "tangibles");
@@ -456,7 +456,7 @@ LuaDefine(table_diffcompare, "mtnmap,mtab,stnmap,stab", "for unit testing only")
LuaArg mtnmap, mtab, mstnmap, mstab;
LuaRet dbgstring;
LuaVar tthread;
LuaStack MLS(L, mtnmap, mtab, mstnmap, mstab, dbgstring, tthread);
LuaOldStack MLS(L, mtnmap, mtab, mstnmap, mstab, dbgstring, tthread);
// Check the arguments.
MLS.checktable(mtnmap, "mtnmap");
MLS.checktable(mstnmap, "mstnmap");
@@ -471,7 +471,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;
LuaStack SLS(synch, stnmap, stab);
LuaOldStack SLS(synch, stnmap, stab);
// Call tablecmp_diff.
StreamBuffer sb;
@@ -486,7 +486,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;
LuaStack MLS(L, mtnmap, mtab, mstab, eql, eqlstr, rtab, tthread, tangibles, mntmap, key, val);
LuaOldStack MLS(L, mtnmap, mtab, mstab, eql, eqlstr, rtab, tthread, tangibles, mntmap, key, val);
// Check the arguments.
MLS.checktable(mtnmap, "mtnmap");
MLS.checktable(mtab, "mtab");
@@ -510,7 +510,7 @@ LuaDefine(table_diffapply, "mtnmap,mtab,mstab", "for unit testing only") {
lua_pushvalue(L, mstab.index());
lua_xmove(L, synch, 2);
LuaArg stnmap, stab;
LuaStack SLS(synch, stnmap, stab);
LuaOldStack SLS(synch, stnmap, stab);
// Call diff_tables and patch_tables
StreamBuffer sb;