diff options
Diffstat (limited to 'src/tools.cpp')
-rw-r--r-- | src/tools.cpp | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/src/tools.cpp b/src/tools.cpp index 98cbf27..3410f4b 100644 --- a/src/tools.cpp +++ b/src/tools.cpp | |||
@@ -72,7 +72,7 @@ void push_registry_subtable_mode(lua_State* L, RegistryUniqueKey key_, const cha | |||
72 | } | 72 | } |
73 | } | 73 | } |
74 | STACK_CHECK(L, 1); | 74 | STACK_CHECK(L, 1); |
75 | ASSERT_L(lua_istable(L, -1)); | 75 | LUA_ASSERT(L, lua_istable(L, -1)); |
76 | } | 76 | } |
77 | 77 | ||
78 | // ################################################################################################# | 78 | // ################################################################################################# |
@@ -139,7 +139,7 @@ void initialize_allocator_function(Universe* U, lua_State* L) | |||
139 | } | 139 | } |
140 | else if (lua_type(L, -1) == LUA_TSTRING) // should be "protected" | 140 | else if (lua_type(L, -1) == LUA_TSTRING) // should be "protected" |
141 | { | 141 | { |
142 | ASSERT_L(strcmp(lua_tostring(L, -1), "protected") == 0); | 142 | LUA_ASSERT(L, strcmp(lua_tostring(L, -1), "protected") == 0); |
143 | // set the original allocator to call from inside protection by the mutex | 143 | // set the original allocator to call from inside protection by the mutex |
144 | U->protected_allocator.initFrom(L); | 144 | U->protected_allocator.initFrom(L); |
145 | U->protected_allocator.installIn(L); | 145 | U->protected_allocator.installIn(L); |
@@ -290,7 +290,7 @@ static void update_lookup_entry(DEBUGSPEW_PARAM_COMMA(Universe* U) lua_State* L, | |||
290 | prevName = lua_tolstring( L, -1, &prevNameLength); // nullptr if we got nil (first encounter of this object) | 290 | prevName = lua_tolstring( L, -1, &prevNameLength); // nullptr if we got nil (first encounter of this object) |
291 | // push name in fqn stack (note that concatenation will crash if name is a not string or a number) | 291 | // push name in fqn stack (note that concatenation will crash if name is a not string or a number) |
292 | lua_pushvalue(L, -3); // ... {bfc} k o name? k | 292 | lua_pushvalue(L, -3); // ... {bfc} k o name? k |
293 | ASSERT_L(lua_type(L, -1) == LUA_TNUMBER || lua_type(L, -1) == LUA_TSTRING); | 293 | LUA_ASSERT(L, lua_type(L, -1) == LUA_TNUMBER || lua_type(L, -1) == LUA_TSTRING); |
294 | ++_depth; | 294 | ++_depth; |
295 | lua_rawseti(L, fqn, _depth); // ... {bfc} k o name? | 295 | lua_rawseti(L, fqn, _depth); // ... {bfc} k o name? |
296 | // generate name | 296 | // generate name |
@@ -329,8 +329,8 @@ static void update_lookup_entry(DEBUGSPEW_PARAM_COMMA(Universe* U) lua_State* L, | |||
329 | // prepare the stack for database feed | 329 | // prepare the stack for database feed |
330 | lua_pushvalue(L, -1); // ... {bfc} k o "f.q.n" "f.q.n" | 330 | lua_pushvalue(L, -1); // ... {bfc} k o "f.q.n" "f.q.n" |
331 | lua_pushvalue(L, -3); // ... {bfc} k o "f.q.n" "f.q.n" o | 331 | lua_pushvalue(L, -3); // ... {bfc} k o "f.q.n" "f.q.n" o |
332 | ASSERT_L(lua_rawequal(L, -1, -4)); | 332 | LUA_ASSERT(L, lua_rawequal(L, -1, -4)); |
333 | ASSERT_L(lua_rawequal(L, -2, -3)); | 333 | LUA_ASSERT(L, lua_rawequal(L, -2, -3)); |
334 | // t["f.q.n"] = o | 334 | // t["f.q.n"] = o |
335 | lua_rawset(L, dest); // ... {bfc} k o "f.q.n" | 335 | lua_rawset(L, dest); // ... {bfc} k o "f.q.n" |
336 | // t[o] = "f.q.n" | 336 | // t[o] = "f.q.n" |
@@ -387,7 +387,7 @@ static void populate_func_lookup_table_recur(DEBUGSPEW_PARAM_COMMA(Universe* U) | |||
387 | 387 | ||
388 | // this table is at breadth_first_cache index | 388 | // this table is at breadth_first_cache index |
389 | lua_newtable(L); // ... {_i} {bfc} | 389 | lua_newtable(L); // ... {_i} {bfc} |
390 | ASSERT_L( lua_gettop(L) == breadth_first_cache); | 390 | LUA_ASSERT(L, lua_gettop(L) == breadth_first_cache); |
391 | // iterate over all entries in the processed table | 391 | // iterate over all entries in the processed table |
392 | lua_pushnil(L); // ... {_i} {bfc} nil | 392 | lua_pushnil(L); // ... {_i} {bfc} nil |
393 | while( lua_next(L, _i) != 0) // ... {_i} {bfc} k v | 393 | while( lua_next(L, _i) != 0) // ... {_i} {bfc} k v |
@@ -434,7 +434,7 @@ static void populate_func_lookup_table_recur(DEBUGSPEW_PARAM_COMMA(Universe* U) | |||
434 | // un-visit this table in case we do need to process it | 434 | // un-visit this table in case we do need to process it |
435 | lua_pushvalue(L, -1); // ... {_i} {bfc} k {} {} | 435 | lua_pushvalue(L, -1); // ... {_i} {bfc} k {} {} |
436 | lua_rawget(L, cache); // ... {_i} {bfc} k {} n | 436 | lua_rawget(L, cache); // ... {_i} {bfc} k {} n |
437 | ASSERT_L(lua_type(L, -1) == LUA_TNUMBER); | 437 | LUA_ASSERT(L, lua_type(L, -1) == LUA_TNUMBER); |
438 | visit_count = lua_tointeger(L, -1) - 1; | 438 | visit_count = lua_tointeger(L, -1) - 1; |
439 | lua_pop(L, 1); // ... {_i} {bfc} k {} | 439 | lua_pop(L, 1); // ... {_i} {bfc} k {} |
440 | lua_pushvalue(L, -1); // ... {_i} {bfc} k {} {} | 440 | lua_pushvalue(L, -1); // ... {_i} {bfc} k {} {} |
@@ -481,7 +481,7 @@ void populate_func_lookup_table(lua_State* L, int i_, char const* name_) | |||
481 | STACK_CHECK_START_REL(L, 0); | 481 | STACK_CHECK_START_REL(L, 0); |
482 | LOOKUP_REGKEY.pushValue(L); // {} | 482 | LOOKUP_REGKEY.pushValue(L); // {} |
483 | STACK_CHECK(L, 1); | 483 | STACK_CHECK(L, 1); |
484 | ASSERT_L(lua_istable(L, -1)); | 484 | LUA_ASSERT(L, lua_istable(L, -1)); |
485 | if (lua_type(L, in_base) == LUA_TFUNCTION) // for example when a module is a simple function | 485 | if (lua_type(L, in_base) == LUA_TFUNCTION) // for example when a module is a simple function |
486 | { | 486 | { |
487 | name_ = name_ ? name_ : "nullptr"; | 487 | name_ = name_ ? name_ : "nullptr"; |
@@ -606,7 +606,7 @@ static constexpr RegistryUniqueKey REG_MTID{ 0x2E68F9B4751584DCull }; | |||
606 | { | 606 | { |
607 | DEBUGSPEW_CODE( Universe* const U = universe_get( L)); | 607 | DEBUGSPEW_CODE( Universe* const U = universe_get( L)); |
608 | char const* fqn; | 608 | char const* fqn; |
609 | ASSERT_L( lua_isfunction( L, i) || lua_istable( L, i)); // ... v ... | 609 | LUA_ASSERT(L, lua_isfunction( L, i) || lua_istable( L, i)); // ... v ... |
610 | STACK_CHECK_START_REL(L, 0); | 610 | STACK_CHECK_START_REL(L, 0); |
611 | STACK_GROW( L, 3); // up to 3 slots are necessary on error | 611 | STACK_GROW( L, 3); // up to 3 slots are necessary on error |
612 | if (mode_ == LookupMode::FromKeeper) | 612 | if (mode_ == LookupMode::FromKeeper) |
@@ -619,7 +619,7 @@ static constexpr RegistryUniqueKey REG_MTID{ 0x2E68F9B4751584DCull }; | |||
619 | else | 619 | else |
620 | { | 620 | { |
621 | // if this is not a sentinel, this is some user-created table we wanted to lookup | 621 | // if this is not a sentinel, this is some user-created table we wanted to lookup |
622 | ASSERT_L(nullptr == f && lua_istable(L, i)); | 622 | LUA_ASSERT(L, nullptr == f && lua_istable(L, i)); |
623 | // push anything that will convert to nullptr string | 623 | // push anything that will convert to nullptr string |
624 | lua_pushnil( L); // ... v ... nil | 624 | lua_pushnil( L); // ... v ... nil |
625 | } | 625 | } |
@@ -629,7 +629,7 @@ static constexpr RegistryUniqueKey REG_MTID{ 0x2E68F9B4751584DCull }; | |||
629 | // fetch the name from the source state's lookup table | 629 | // fetch the name from the source state's lookup table |
630 | LOOKUP_REGKEY.pushValue(L); // ... v ... {} | 630 | LOOKUP_REGKEY.pushValue(L); // ... v ... {} |
631 | STACK_CHECK( L, 1); | 631 | STACK_CHECK( L, 1); |
632 | ASSERT_L( lua_istable( L, -1)); | 632 | LUA_ASSERT(L, lua_istable( L, -1)); |
633 | lua_pushvalue( L, i); // ... v ... {} v | 633 | lua_pushvalue( L, i); // ... v ... {} v |
634 | lua_rawget( L, -2); // ... v ... {} "f.q.n" | 634 | lua_rawget( L, -2); // ... v ... {} "f.q.n" |
635 | } | 635 | } |
@@ -701,7 +701,7 @@ static constexpr RegistryUniqueKey REG_MTID{ 0x2E68F9B4751584DCull }; | |||
701 | case LookupMode::FromKeeper: | 701 | case LookupMode::FromKeeper: |
702 | LOOKUP_REGKEY.pushValue(L2); // {} | 702 | LOOKUP_REGKEY.pushValue(L2); // {} |
703 | STACK_CHECK(L2, 1); | 703 | STACK_CHECK(L2, 1); |
704 | _ASSERT_L(L1, lua_istable(L2, -1)); | 704 | LUA_ASSERT(L1, lua_istable(L2, -1)); |
705 | lua_pushlstring(L2, fqn, len); // {} "f.q.n" | 705 | lua_pushlstring(L2, fqn, len); // {} "f.q.n" |
706 | lua_rawget(L2, -2); // {} t | 706 | lua_rawget(L2, -2); // {} t |
707 | // we accept destination lookup failures in the case of transfering the Lanes body function (this will result in the source table being cloned instead) | 707 | // we accept destination lookup failures in the case of transfering the Lanes body function (this will result in the source table being cloned instead) |
@@ -754,7 +754,7 @@ static constexpr RegistryUniqueKey REG_MTID{ 0x2E68F9B4751584DCull }; | |||
754 | { | 754 | { |
755 | void const* p{ lua_topointer(L1, i) }; | 755 | void const* p{ lua_topointer(L1, i) }; |
756 | 756 | ||
757 | _ASSERT_L(L1, L2_cache_i != 0); | 757 | LUA_ASSERT(L1, L2_cache_i != 0); |
758 | STACK_GROW(L2, 3); // L2 | 758 | STACK_GROW(L2, 3); // L2 |
759 | STACK_CHECK_START_REL(L2, 0); | 759 | STACK_CHECK_START_REL(L2, 0); |
760 | 760 | ||
@@ -777,7 +777,7 @@ static constexpr RegistryUniqueKey REG_MTID{ 0x2E68F9B4751584DCull }; | |||
777 | lua_rawset(L2, L2_cache_i); // ... {} | 777 | lua_rawset(L2, L2_cache_i); // ... {} |
778 | } | 778 | } |
779 | STACK_CHECK(L2, 1); | 779 | STACK_CHECK(L2, 1); |
780 | _ASSERT_L(L1, lua_istable( L2, -1)); | 780 | LUA_ASSERT(L1, lua_istable( L2, -1)); |
781 | return !not_found_in_cache; | 781 | return !not_found_in_cache; |
782 | } | 782 | } |
783 | 783 | ||
@@ -1006,7 +1006,7 @@ void InterCopyContext::lookup_native_func() const | |||
1006 | case LookupMode::FromKeeper: | 1006 | case LookupMode::FromKeeper: |
1007 | LOOKUP_REGKEY.pushValue(L2); // {} | 1007 | LOOKUP_REGKEY.pushValue(L2); // {} |
1008 | STACK_CHECK(L2, 1); | 1008 | STACK_CHECK(L2, 1); |
1009 | _ASSERT_L(L1, lua_istable(L2, -1)); | 1009 | LUA_ASSERT(L1, lua_istable(L2, -1)); |
1010 | lua_pushlstring(L2, fqn, len); // {} "f.q.n" | 1010 | lua_pushlstring(L2, fqn, len); // {} "f.q.n" |
1011 | lua_rawget(L2, -2); // {} f | 1011 | lua_rawget(L2, -2); // {} f |
1012 | // nil means we don't know how to transfer stuff: user should do something | 1012 | // nil means we don't know how to transfer stuff: user should do something |
@@ -1104,7 +1104,7 @@ static char const* vt_names[] = | |||
1104 | 1104 | ||
1105 | void InterCopyContext::copy_func() const | 1105 | void InterCopyContext::copy_func() const |
1106 | { | 1106 | { |
1107 | _ASSERT_L(L1, L2_cache_i != 0); // ... {cache} ... p | 1107 | LUA_ASSERT(L1, L2_cache_i != 0); // ... {cache} ... p |
1108 | STACK_GROW(L1, 2); | 1108 | STACK_GROW(L1, 2); |
1109 | STACK_CHECK_START_REL(L1, 0); | 1109 | STACK_CHECK_START_REL(L1, 0); |
1110 | 1110 | ||
@@ -1158,7 +1158,7 @@ void InterCopyContext::copy_func() const | |||
1158 | { | 1158 | { |
1159 | size_t sz; | 1159 | size_t sz; |
1160 | char const* s = lua_tolstring(L1, -1, &sz); // ... b | 1160 | char const* s = lua_tolstring(L1, -1, &sz); // ... b |
1161 | _ASSERT_L(L1, s && sz); | 1161 | LUA_ASSERT(L1, s && sz); |
1162 | STACK_GROW(L2, 2); | 1162 | STACK_GROW(L2, 2); |
1163 | // Note: Line numbers seem to be taken precisely from the | 1163 | // Note: Line numbers seem to be taken precisely from the |
1164 | // original function. 'name' is not used since the chunk | 1164 | // original function. 'name' is not used since the chunk |
@@ -1238,7 +1238,7 @@ void InterCopyContext::copy_func() const | |||
1238 | // "assigns the value at the top of the stack to the upvalue and returns its name. | 1238 | // "assigns the value at the top of the stack to the upvalue and returns its name. |
1239 | // It also pops the value from the stack." | 1239 | // It also pops the value from the stack." |
1240 | 1240 | ||
1241 | _ASSERT_L(L1, rc); // not having enough slots? | 1241 | LUA_ASSERT(L1, rc); // not having enough slots? |
1242 | } | 1242 | } |
1243 | // once all upvalues have been set we are left | 1243 | // once all upvalues have been set we are left |
1244 | // with the function at the top of the stack // ... {cache} ... function | 1244 | // with the function at the top of the stack // ... {cache} ... function |
@@ -1262,7 +1262,7 @@ void InterCopyContext::copy_cached_func() const | |||
1262 | { | 1262 | { |
1263 | void* const aspointer = const_cast<void*>(lua_topointer(L1, L1_i)); | 1263 | void* const aspointer = const_cast<void*>(lua_topointer(L1, L1_i)); |
1264 | // TBD: Merge this and same code for tables | 1264 | // TBD: Merge this and same code for tables |
1265 | _ASSERT_L(L1, L2_cache_i != 0); | 1265 | LUA_ASSERT(L1, L2_cache_i != 0); |
1266 | 1266 | ||
1267 | STACK_GROW(L2, 2); | 1267 | STACK_GROW(L2, 2); |
1268 | 1268 | ||
@@ -1297,13 +1297,13 @@ void InterCopyContext::copy_cached_func() const | |||
1297 | lua_remove(L2, -2); // ... {cache} ... function | 1297 | lua_remove(L2, -2); // ... {cache} ... function |
1298 | } | 1298 | } |
1299 | STACK_CHECK(L2, 1); | 1299 | STACK_CHECK(L2, 1); |
1300 | _ASSERT_L(L1, lua_isfunction(L2, -1)); | 1300 | LUA_ASSERT(L1, lua_isfunction(L2, -1)); |
1301 | } | 1301 | } |
1302 | else // function is native/LuaJIT: no need to cache | 1302 | else // function is native/LuaJIT: no need to cache |
1303 | { | 1303 | { |
1304 | lookup_native_func(); // ... {cache} ... function | 1304 | lookup_native_func(); // ... {cache} ... function |
1305 | // if the function was in fact a lookup sentinel, we can either get a function or a table here | 1305 | // if the function was in fact a lookup sentinel, we can either get a function or a table here |
1306 | _ASSERT_L(L1, lua_isfunction(L2, -1) || lua_istable(L2, -1)); | 1306 | LUA_ASSERT(L1, lua_isfunction(L2, -1) || lua_istable(L2, -1)); |
1307 | } | 1307 | } |
1308 | } | 1308 | } |
1309 | 1309 | ||
@@ -1421,7 +1421,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
1421 | c.name = valPath ? valPath : name; | 1421 | c.name = valPath ? valPath : name; |
1422 | if (c.inter_copy_one()) | 1422 | if (c.inter_copy_one()) |
1423 | { | 1423 | { |
1424 | _ASSERT_L(L1, lua_istable( L2, -3)); | 1424 | LUA_ASSERT(L1, lua_istable( L2, -3)); |
1425 | lua_rawset(L2, -3); // add to table (pops key & val) | 1425 | lua_rawset(L2, -3); // add to table (pops key & val) |
1426 | } | 1426 | } |
1427 | else | 1427 | else |
@@ -1494,7 +1494,7 @@ static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull }; | |||
1494 | { | 1494 | { |
1495 | if (LookupMode::ToKeeper == mode) // ... u sentinel | 1495 | if (LookupMode::ToKeeper == mode) // ... u sentinel |
1496 | { | 1496 | { |
1497 | _ASSERT_L(L1, lua_tocfunction(L2, -1) == table_lookup_sentinel); | 1497 | LUA_ASSERT(L1, lua_tocfunction(L2, -1) == table_lookup_sentinel); |
1498 | // we want to create a new closure with a 'clone sentinel' function, where the upvalues are the userdata and the metatable fqn | 1498 | // we want to create a new closure with a 'clone sentinel' function, where the upvalues are the userdata and the metatable fqn |
1499 | lua_getupvalue(L2, -1, 1); // ... u sentinel fqn | 1499 | lua_getupvalue(L2, -1, 1); // ... u sentinel fqn |
1500 | lua_remove(L2, -2); // ... u fqn | 1500 | lua_remove(L2, -2); // ... u fqn |
@@ -1503,7 +1503,7 @@ static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull }; | |||
1503 | } | 1503 | } |
1504 | else // from keeper or direct // ... u mt | 1504 | else // from keeper or direct // ... u mt |
1505 | { | 1505 | { |
1506 | _ASSERT_L(L1, lua_istable(L2, -1)); | 1506 | LUA_ASSERT(L1, lua_istable(L2, -1)); |
1507 | lua_setmetatable(L2, -2); // ... u | 1507 | lua_setmetatable(L2, -2); // ... u |
1508 | } | 1508 | } |
1509 | STACK_CHECK(L2, 1); | 1509 | STACK_CHECK(L2, 1); |
@@ -1726,7 +1726,7 @@ static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull }; | |||
1726 | */ | 1726 | */ |
1727 | if (lookup_table()) | 1727 | if (lookup_table()) |
1728 | { | 1728 | { |
1729 | _ASSERT_L(L1, lua_istable(L2, -1) || (lua_tocfunction(L2, -1) == table_lookup_sentinel)); // from lookup data. can also be table_lookup_sentinel if this is a table we know | 1729 | LUA_ASSERT(L1, lua_istable(L2, -1) || (lua_tocfunction(L2, -1) == table_lookup_sentinel)); // from lookup data. can also be table_lookup_sentinel if this is a table we know |
1730 | return true; | 1730 | return true; |
1731 | } | 1731 | } |
1732 | 1732 | ||
@@ -1741,10 +1741,10 @@ static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull }; | |||
1741 | */ | 1741 | */ |
1742 | if (push_cached_table(L2, L2_cache_i, L1, L1_i)) | 1742 | if (push_cached_table(L2, L2_cache_i, L1, L1_i)) |
1743 | { | 1743 | { |
1744 | _ASSERT_L(L1, lua_istable(L2, -1)); // from cache | 1744 | LUA_ASSERT(L1, lua_istable(L2, -1)); // from cache |
1745 | return true; | 1745 | return true; |
1746 | } | 1746 | } |
1747 | _ASSERT_L(L1, lua_istable(L2, -1)); | 1747 | LUA_ASSERT(L1, lua_istable(L2, -1)); |
1748 | 1748 | ||
1749 | STACK_GROW(L1, 2); | 1749 | STACK_GROW(L1, 2); |
1750 | STACK_GROW(L2, 2); | 1750 | STACK_GROW(L2, 2); |
@@ -1907,7 +1907,7 @@ static constexpr UniqueKey CLONABLES_CACHE_KEY{ 0xD04EE018B3DEE8F5ull }; | |||
1907 | // NOTE: Both the states must be solely in the current OS thread's possession. | 1907 | // NOTE: Both the states must be solely in the current OS thread's possession. |
1908 | [[nodiscard]] InterCopyResult InterCopyContext::inter_copy(int n_) const | 1908 | [[nodiscard]] InterCopyResult InterCopyContext::inter_copy(int n_) const |
1909 | { | 1909 | { |
1910 | _ASSERT_L(L1, vt == VT::NORMAL); | 1910 | LUA_ASSERT(L1, vt == VT::NORMAL); |
1911 | 1911 | ||
1912 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "InterCopyContext::inter_copy()\n" INDENT_END)); | 1912 | DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "InterCopyContext::inter_copy()\n" INDENT_END)); |
1913 | DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U }); | 1913 | DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U }); |