From 3be94c4282bbe77895e952afb12a81e55c2a4391 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Thu, 23 May 2024 17:43:26 +0200 Subject: DEBUGSPEW_PARAM_COMMA(Universe* U_) --- src/intercopycontext.cpp | 6 +++--- src/lanes.cpp | 6 +++--- src/state.cpp | 16 ++++++++-------- src/state.h | 2 +- src/tools.cpp | 34 ++++++++++++++++++---------------- src/universe.cpp | 2 +- src/universe.h | 4 ++-- 7 files changed, 36 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp index 6623b16..adbb502 100644 --- a/src/intercopycontext.cpp +++ b/src/intercopycontext.cpp @@ -1165,10 +1165,10 @@ static char const* vt_names[] = { DEBUGSPEW_CODE(DebugSpewIndentScope scope); public: - OnExit(DEBUGSPEW_PARAM_COMMA(Universe* U_) lua_State* L2_) + OnExit(lua_State* L2_) : L2{ L2_ } , top_L2{ lua_gettop(L2) } - DEBUGSPEW_COMMA_PARAM(scope{ U_ }) + DEBUGSPEW_COMMA_PARAM(scope{ universe_get(L2_) }) { } @@ -1176,7 +1176,7 @@ static char const* vt_names[] = { { lua_settop(L2, top_L2); } - } onExit{ DEBUGSPEW_PARAM_COMMA(U) L2 }; + } const _onExit{ L2 }; STACK_CHECK_START_REL(L1, 0); if (lua_type_as_enum(L1, L1_i) != LuaType::TABLE) { diff --git a/src/lanes.cpp b/src/lanes.cpp index a5c9c8b..000668a 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp @@ -342,7 +342,7 @@ LUAG_FUNC(lane_new) lane->ready.count_down(); lane = nullptr; } - } onExit{ L_, _lane}; + } _onExit{ L_, _lane}; // launch the thread early, it will sync with a std::latch to parallelize OS thread warmup and L2 preparation DEBUGSPEW_CODE(DebugSpew(_U) << "lane_new: launching thread" << std::endl); // public Lanes API accepts a generic range -3/+3 @@ -497,7 +497,7 @@ LUAG_FUNC(lane_new) STACK_CHECK_RESET_REL(L_, 0); // all went well, the lane's thread can start working - onExit.success(); // L_: [fixed] lane L2: + _onExit.success(); // L_: [fixed] lane L2: // we should have the lane userdata on top of the stack STACK_CHECK(L_, 1); return 1; @@ -681,7 +681,7 @@ LUAG_FUNC(configure) STACK_CHECK(L_, 1); // Serialize calls to 'require' from now on, also in the primary state - serialize_require(DEBUGSPEW_PARAM_COMMA(_U) L_); + serialize_require(L_); // Retrieve main module interface table lua_pushvalue(L_, lua_upvalueindex(2)); // L_: settings M diff --git a/src/state.cpp b/src/state.cpp index 08ed111..7ce8db0 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -84,11 +84,11 @@ THE SOFTWARE. /* * Serialize calls to 'require', if it exists */ -void serialize_require(DEBUGSPEW_PARAM_COMMA(Universe* U_) lua_State* L_) +void serialize_require(lua_State* L_) { STACK_GROW(L_, 1); STACK_CHECK_START_REL(L_, 0); - DEBUGSPEW_CODE(DebugSpew(U_) << "serializing require()" << std::endl); + DEBUGSPEW_CODE(DebugSpew(universe_get(L_)) << "serializing require()" << std::endl); // Check 'require' is there and not already wrapped; if not, do nothing // @@ -155,7 +155,7 @@ namespace global // ################################################################################################# -static void open1lib(DEBUGSPEW_PARAM_COMMA(Universe* U_) lua_State* L_, std::string_view const& name_) +static void open1lib(lua_State* L_, std::string_view const& name_) { for (luaL_Reg const& _entry : global::sLibs) { if (name_ == _entry.name) { @@ -164,7 +164,7 @@ static void open1lib(DEBUGSPEW_PARAM_COMMA(Universe* U_) lua_State* L_, std::str break; } std::string_view const _name{ _entry.name }; - DEBUGSPEW_CODE(DebugSpew(U_) << "opening '" << _name << "' library" << std::endl); + DEBUGSPEW_CODE(DebugSpew(universe_get(L_)) << "opening '" << _name << "' library" << std::endl); STACK_CHECK_START_REL(L_, 0); // open the library as if through require(), and create a global as well if necessary (the library table is left on the stack) bool const isLanesCore{ _libfunc == require_lanes_core }; // don't want to create a global for "lanes.core" @@ -352,12 +352,12 @@ lua_State* luaG_newstate(Universe* U_, SourceState from_, char const* libs_) DEBUGSPEW_CODE(DebugSpew(U_) << "opening ALL standard libraries" << std::endl); luaL_openlibs(_L); // don't forget lanes.core for regular lane states - open1lib(DEBUGSPEW_PARAM_COMMA(U_) _L, kLanesCoreLibName); + open1lib(_L, kLanesCoreLibName); libs_ = nullptr; // done with libs } else { #if LUAJIT_FLAVOR() != 0 // building against LuaJIT headers, always open jit DEBUGSPEW_CODE(DebugSpew(U_) << "opening 'jit' library" << std::endl); - open1lib(DEBUGSPEW_PARAM_COMMA(U_) _L, LUA_JITLIBNAME); + open1lib(_L, LUA_JITLIBNAME); #endif // LUAJIT_FLAVOR() DEBUGSPEW_CODE(DebugSpew(U_) << "opening 'base' library" << std::endl); #if LUA_VERSION_NUM >= 502 @@ -385,12 +385,12 @@ lua_State* luaG_newstate(Universe* U_, SourceState from_, char const* libs_) while (isalnum(_p[_len]) || _p[_len] == '.') ++_len; // open library - open1lib(DEBUGSPEW_PARAM_COMMA(U_) _L, { _p, _len }); + open1lib(_L, { _p, _len }); } } lua_gc(_L, LUA_GCRESTART, 0); - serialize_require(DEBUGSPEW_PARAM_COMMA(U_) _L); + serialize_require(_L); // call this after the base libraries are loaded and GC is restarted // will raise an error in from_ in case of problem diff --git a/src/state.h b/src/state.h index 626a696..5334c90 100644 --- a/src/state.h +++ b/src/state.h @@ -7,7 +7,7 @@ enum class LookupMode; class Universe; -void serialize_require(DEBUGSPEW_PARAM_COMMA(Universe* U_) lua_State* L_); +void serialize_require(lua_State* L_); // ################################################################################################# diff --git a/src/tools.cpp b/src/tools.cpp index 5f12995..1d778ef 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -122,15 +122,16 @@ static constexpr int kWriterReturnCode{ 666 }; * if we already had an entry of type [o] = ..., replace the name if the new one is shorter * pops the processed object from the stack */ -static void update_lookup_entry(DEBUGSPEW_PARAM_COMMA(Universe* U_) lua_State* L_, int ctxBase_, int depth_) +static void update_lookup_entry(lua_State* L_, int ctxBase_, int depth_) { // slot 1 in the stack contains the table that receives everything we found int const _dest{ ctxBase_ }; // slot 2 contains a table that, when concatenated, produces the fully qualified name of scanned elements in the table provided at slot _i int const _fqn{ ctxBase_ + 1 }; - DEBUGSPEW_CODE(DebugSpew(U_) << "update_lookup_entry()" << std::endl); - DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U_ }); + DEBUGSPEW_CODE(Universe* const _U{ universe_get(L_) }); + DEBUGSPEW_CODE(DebugSpew(_U) << "update_lookup_entry()" << std::endl); + DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); STACK_CHECK_START_REL(L_, 0); // first, raise an error if the function is already known @@ -154,7 +155,7 @@ static void update_lookup_entry(DEBUGSPEW_PARAM_COMMA(Universe* U_) lua_State* L // Therefore, when we encounter an object for which a name was previously registered, we need to select the names // based on some sorting order so that we end up with the same name in all databases whatever order the table walk yielded if (!_prevName.empty() && (_prevName.size() < _newName.size() || lua_lessthan(L_, -2, -1))) { - DEBUGSPEW_CODE(DebugSpew(U_) << lua_typename(L_, lua_type(L_, -3)) << " '" << _newName << "' remains named '" << _prevName << "'" << std::endl); + DEBUGSPEW_CODE(DebugSpew(_U) << lua_typename(L_, lua_type(L_, -3)) << " '" << _newName << "' remains named '" << _prevName << "'" << std::endl); // the previous name is 'smaller' than the one we just generated: keep it! lua_pop(L_, 3); // L_: ... {bfc} k } else { @@ -168,7 +169,7 @@ static void update_lookup_entry(DEBUGSPEW_PARAM_COMMA(Universe* U_) lua_State* L } else { lua_remove(L_, -2); // L_: ... {bfc} k o "f.q.n" } - DEBUGSPEW_CODE(DebugSpew(U_) << lua_typename(L_, lua_type(L_, -2)) << " '" << _newName << "'" << std::endl); + DEBUGSPEW_CODE(DebugSpew(_U) << lua_typename(L_, lua_type(L_, -2)) << " '" << _newName << "'" << std::endl); // prepare the stack for database feed lua_pushvalue(L_, -1); // L_: ... {bfc} k o "f.q.n" "f.q.n" lua_pushvalue(L_, -3); // L_: ... {bfc} k o "f.q.n" "f.q.n" o @@ -188,15 +189,16 @@ static void update_lookup_entry(DEBUGSPEW_PARAM_COMMA(Universe* U_) lua_State* L // ################################################################################################# -static void populate_func_lookup_table_recur(DEBUGSPEW_PARAM_COMMA(Universe* U_) lua_State* L_, int dbIdx_, int i_, int depth_) +static void populate_func_lookup_table_recur(lua_State* L_, int dbIdx_, int i_, int depth_) { // slot dbIdx_ contains the lookup database table // slot dbIdx_ + 1 contains a table that, when concatenated, produces the fully qualified name of scanned elements in the table provided at slot i_ int const _fqn{ dbIdx_ + 1 }; // slot dbIdx_ + 2 contains a cache that stores all already visited tables to avoid infinite recursion loops int const _cache{ dbIdx_ + 2 }; - DEBUGSPEW_CODE(DebugSpew(U_) << "populate_func_lookup_table_recur()" << std::endl); - DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U_ }); + DEBUGSPEW_CODE(Universe* const _U{ universe_get(L_) }); + DEBUGSPEW_CODE(DebugSpew(_U) << "populate_func_lookup_table_recur()" << std::endl); + DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); STACK_GROW(L_, 6); // slot i_ contains a table where we search for functions (or a full userdata with a metatable) @@ -215,7 +217,7 @@ static void populate_func_lookup_table_recur(DEBUGSPEW_PARAM_COMMA(Universe* U_) lua_pop(L_, 1); // L_: ... {i_} STACK_CHECK(L_, 0); if (_visit_count > 0) { - DEBUGSPEW_CODE(DebugSpew(U_) << "already visited" << std::endl); + DEBUGSPEW_CODE(DebugSpew(_U) << "already visited" << std::endl); return; } @@ -248,11 +250,11 @@ static void populate_func_lookup_table_recur(DEBUGSPEW_PARAM_COMMA(Universe* U_) lua_pushvalue(L_, -2); // L_: ... {i_} {bfc} k {} k {} lua_rawset(L_, breadthFirstCache); // L_: ... {i_} {bfc} k {} // generate a name, and if we already had one name, keep whichever is the shorter - update_lookup_entry(DEBUGSPEW_PARAM_COMMA(U_) L_, dbIdx_, depth_); // L_: ... {i_} {bfc} k + update_lookup_entry(L_, dbIdx_, depth_); // L_: ... {i_} {bfc} k } else if (lua_isfunction(L_, -1) && (luaG_getfuncsubtype(L_, -1) != FuncSubType::Bytecode)) { // generate a name, and if we already had one name, keep whichever is the shorter // this pops the function from the stack - update_lookup_entry(DEBUGSPEW_PARAM_COMMA(U_) L_, dbIdx_, depth_); // L_: ... {i_} {bfc} k + update_lookup_entry(L_, dbIdx_, depth_); // L_: ... {i_} {bfc} k } else { lua_pop(L_, 1); // L_: ... {i_} {bfc} k } @@ -263,8 +265,8 @@ static void populate_func_lookup_table_recur(DEBUGSPEW_PARAM_COMMA(Universe* U_) lua_pushnil(L_); // L_: ... {i_} {bfc} nil while (lua_next(L_, breadthFirstCache) != 0) { // L_: ... {i_} {bfc} k {} DEBUGSPEW_CODE(std::string_view const _key{ (lua_type(L_, -2) == LUA_TSTRING) ? lua_tostringview(L_, -2) : std::string_view{ "" } }); - DEBUGSPEW_CODE(DebugSpew(U_) << "table '"<< _key <<"'" << std::endl); - DEBUGSPEW_CODE(DebugSpewIndentScope _scope2{ U_ }); + DEBUGSPEW_CODE(DebugSpew(_U) << "table '"<< _key <<"'" << std::endl); + DEBUGSPEW_CODE(DebugSpewIndentScope _scope2{ _U }); // un-visit this table in case we do need to process it lua_pushvalue(L_, -1); // L_: ... {i_} {bfc} k {} {} lua_rawget(L_, _cache); // L_: ... {i_} {bfc} k {} n @@ -281,7 +283,7 @@ static void populate_func_lookup_table_recur(DEBUGSPEW_PARAM_COMMA(Universe* U_) // push table name in fqn stack (note that concatenation will crash if name is a not string!) lua_pushvalue(L_, -2); // L_: ... {i_} {bfc} k {} k lua_rawseti(L_, _fqn, depth_); // L_: ... {i_} {bfc} k {} - populate_func_lookup_table_recur(DEBUGSPEW_PARAM_COMMA(U_) L_, dbIdx_, lua_gettop(L_), depth_); + populate_func_lookup_table_recur(L_, dbIdx_, lua_gettop(L_), depth_); lua_pop(L_, 1); // L_: ... {i_} {bfc} k STACK_CHECK(L_, 2); } @@ -330,7 +332,7 @@ void populate_func_lookup_table(lua_State* const L_, int const i_, std::string_v std::ignore = lua_pushstringview(L_, _name); // L_: {} {fqn} "name" // generate a name, and if we already had one name, keep whichever is the shorter lua_pushvalue(L_, _in_base); // L_: {} {fqn} "name" t - update_lookup_entry(DEBUGSPEW_PARAM_COMMA(_U) L_, _dbIdx, _startDepth); // L_: {} {fqn} "name" + update_lookup_entry(L_, _dbIdx, _startDepth); // L_: {} {fqn} "name" // don't forget to store the name at the bottom of the fqn stack lua_rawseti(L_, -2, ++_startDepth); // L_: {} {fqn} STACK_CHECK(L_, 2); @@ -338,7 +340,7 @@ void populate_func_lookup_table(lua_State* const L_, int const i_, std::string_v // retrieve the cache, create it if we haven't done it yet std::ignore = kLookupCacheRegKey.getSubTable(L_, 0, 0); // L_: {} {fqn} {cache} // process everything we find in that table, filling in lookup data for all functions and tables we see there - populate_func_lookup_table_recur(DEBUGSPEW_PARAM_COMMA(_U) L_, _dbIdx, _in_base, _startDepth); + populate_func_lookup_table_recur(L_, _dbIdx, _in_base, _startDepth); lua_pop(L_, 3); // L_: } else { lua_pop(L_, 1); // L_: diff --git a/src/universe.cpp b/src/universe.cpp index 0bab844..cdb3d72 100644 --- a/src/universe.cpp +++ b/src/universe.cpp @@ -262,7 +262,7 @@ void Universe::initializeKeepers(lua_State* L_) luaL_requiref(_K, LUA_LOADLIBNAME, luaopen_package, 1); // L_: settings K: package lua_pop(_K, 1); // L_: settings K: STACK_CHECK(_K, 0); - serialize_require(DEBUGSPEW_PARAM_COMMA(this) _K); + serialize_require(_K); STACK_CHECK(_K, 0); // copy package.path and package.cpath from the source state diff --git a/src/universe.h b/src/universe.h index f5327a6..97b613e 100644 --- a/src/universe.h +++ b/src/universe.h @@ -197,9 +197,9 @@ void universe_store(lua_State* L_, Universe* U_); [[nodiscard]] inline Universe* universe_get(lua_State* L_) { STACK_CHECK_START_REL(L_, 0); - Universe* const universe{ kUniverseLightRegKey.readLightUserDataValue(L_) }; + Universe* const _universe{ kUniverseLightRegKey.readLightUserDataValue(L_) }; STACK_CHECK(L_, 0); - return universe; + return _universe; } // ################################################################################################# -- cgit v1.2.3-55-g6feb