diff options
Diffstat (limited to 'src/keeper.cpp')
| -rw-r--r-- | src/keeper.cpp | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/src/keeper.cpp b/src/keeper.cpp index 2e13de3..4af0d86 100644 --- a/src/keeper.cpp +++ b/src/keeper.cpp | |||
| @@ -77,7 +77,7 @@ class KeyUD final | |||
| 77 | 77 | ||
| 78 | // a fifo full userdata has one uservalue, the table that holds the actual fifo contents | 78 | // a fifo full userdata has one uservalue, the table that holds the actual fifo contents |
| 79 | [[nodiscard]] | 79 | [[nodiscard]] |
| 80 | static void* operator new([[maybe_unused]] size_t size_, KeeperState L_) noexcept { return luaG_newuserdatauv<KeyUD>(L_, UserValueCount{ 1 }); } | 80 | static void* operator new([[maybe_unused]] size_t size_, KeeperState L_) noexcept { return luaW_newuserdatauv<KeyUD>(L_, UserValueCount{ 1 }); } |
| 81 | // always embedded somewhere else or "in-place constructed" as a full userdata | 81 | // always embedded somewhere else or "in-place constructed" as a full userdata |
| 82 | // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception | 82 | // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception |
| 83 | static void operator delete([[maybe_unused]] void* p_, [[maybe_unused]] KeeperState L_) { LUA_ASSERT(L_, !"should never be called"); } | 83 | static void operator delete([[maybe_unused]] void* p_, [[maybe_unused]] KeeperState L_) { LUA_ASSERT(L_, !"should never be called"); } |
| @@ -146,7 +146,7 @@ KeyUD* KeyUD::Create(KeeperState const K_) | |||
| 146 | [[nodiscard]] | 146 | [[nodiscard]] |
| 147 | KeyUD* KeyUD::GetPtr(KeeperState const K_, StackIndex const idx_) | 147 | KeyUD* KeyUD::GetPtr(KeeperState const K_, StackIndex const idx_) |
| 148 | { | 148 | { |
| 149 | return luaG_tofulluserdata<KeyUD>(K_, idx_); | 149 | return luaW_tofulluserdata<KeyUD>(K_, idx_); |
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | // ################################################################################################# | 152 | // ################################################################################################# |
| @@ -236,7 +236,7 @@ int KeyUD::pop(KeeperState const K_, int const minCount_, int const maxCount_) | |||
| 236 | // replaces it by its uservalue on the stack (the table holding the fifo values) | 236 | // replaces it by its uservalue on the stack (the table holding the fifo values) |
| 237 | void KeyUD::prepareAccess(KeeperState const K_, StackIndex const idx_) const | 237 | void KeyUD::prepareAccess(KeeperState const K_, StackIndex const idx_) const |
| 238 | { | 238 | { |
| 239 | StackIndex const _idx{ luaG_absindex(K_, idx_) }; | 239 | StackIndex const _idx{ luaW_absindex(K_, idx_) }; |
| 240 | LUA_ASSERT(K_, KeyUD::GetPtr(K_, idx_) == this); | 240 | LUA_ASSERT(K_, KeyUD::GetPtr(K_, idx_) == this); |
| 241 | // we can replace the key userdata in the stack without fear of it being GCed, there are other references around | 241 | // we can replace the key userdata in the stack without fear of it being GCed, there are other references around |
| 242 | lua_getiuservalue(K_, _idx, kContentsTableIndex); | 242 | lua_getiuservalue(K_, _idx, kContentsTableIndex); |
| @@ -250,7 +250,7 @@ void KeyUD::prepareAccess(KeeperState const K_, StackIndex const idx_) const | |||
| 250 | [[nodiscard]] | 250 | [[nodiscard]] |
| 251 | bool KeyUD::push(KeeperState const K_, int const count_, bool const enforceLimit_) | 251 | bool KeyUD::push(KeeperState const K_, int const count_, bool const enforceLimit_) |
| 252 | { | 252 | { |
| 253 | StackIndex const _fifoIdx{ luaG_absindex(K_, StackIndex{ -1 - count_ }) }; | 253 | StackIndex const _fifoIdx{ luaW_absindex(K_, StackIndex{ -1 - count_ }) }; |
| 254 | LUA_ASSERT(K_, KeyUD::GetPtr(K_, _fifoIdx) == this); // K_: this val... | 254 | LUA_ASSERT(K_, KeyUD::GetPtr(K_, _fifoIdx) == this); // K_: this val... |
| 255 | if (enforceLimit_ && (limit >= 0) && (count + count_ > limit)) { // not enough room | 255 | if (enforceLimit_ && (limit >= 0) && (count + count_ > limit)) { // not enough room |
| 256 | return false; | 256 | return false; |
| @@ -274,16 +274,16 @@ bool KeyUD::push(KeeperState const K_, int const count_, bool const enforceLimit | |||
| 274 | void KeyUD::pushFillStatus(KeeperState const K_) const | 274 | void KeyUD::pushFillStatus(KeeperState const K_) const |
| 275 | { | 275 | { |
| 276 | if (limit < 0) { | 276 | if (limit < 0) { |
| 277 | luaG_pushstring(K_, kUnder); | 277 | luaW_pushstring(K_, kUnder); |
| 278 | return; | 278 | return; |
| 279 | } | 279 | } |
| 280 | int const _delta{ limit - count }; | 280 | int const _delta{ limit - count }; |
| 281 | if (_delta < 0) { | 281 | if (_delta < 0) { |
| 282 | luaG_pushstring(K_, kOver); | 282 | luaW_pushstring(K_, kOver); |
| 283 | } else if (_delta > 0) { | 283 | } else if (_delta > 0) { |
| 284 | luaG_pushstring(K_, kUnder); | 284 | luaW_pushstring(K_, kUnder); |
| 285 | } else { | 285 | } else { |
| 286 | luaG_pushstring(K_, kExact); | 286 | luaW_pushstring(K_, kExact); |
| 287 | } | 287 | } |
| 288 | } | 288 | } |
| 289 | 289 | ||
| @@ -294,7 +294,7 @@ void KeyUD::PushFillStatus(KeeperState const K_, KeyUD const* const key_) | |||
| 294 | if (key_) { | 294 | if (key_) { |
| 295 | key_->pushFillStatus(K_); // _K: ... <fill status> | 295 | key_->pushFillStatus(K_); // _K: ... <fill status> |
| 296 | } else { | 296 | } else { |
| 297 | luaG_pushstring(K_, KeyUD::kUnder); // _K: ... "under" | 297 | luaW_pushstring(K_, KeyUD::kUnder); // _K: ... "under" |
| 298 | } | 298 | } |
| 299 | } | 299 | } |
| 300 | 300 | ||
| @@ -330,10 +330,10 @@ static void PushKeysDB(KeeperState const K_, StackIndex const idx_) | |||
| 330 | { | 330 | { |
| 331 | STACK_GROW(K_, 5); | 331 | STACK_GROW(K_, 5); |
| 332 | STACK_CHECK_START_REL(K_, 0); | 332 | STACK_CHECK_START_REL(K_, 0); |
| 333 | StackIndex const _absidx{ luaG_absindex(K_, idx_) }; | 333 | StackIndex const _absidx{ luaW_absindex(K_, idx_) }; |
| 334 | kLindasRegKey.pushValue(K_); // K_: ... LindasDB | 334 | kLindasRegKey.pushValue(K_); // K_: ... LindasDB |
| 335 | lua_pushvalue(K_, _absidx); // K_: ... LindasDB linda | 335 | lua_pushvalue(K_, _absidx); // K_: ... LindasDB linda |
| 336 | if (luaG_rawget(K_, StackIndex{ -2 }) == LuaType::NIL) { // K_: ... LindasDB KeysDB | 336 | if (luaW_rawget(K_, StackIndex{ -2 }) == LuaType::NIL) { // K_: ... LindasDB KeysDB |
| 337 | lua_pop(K_, 1); // K_: ... LindasDB | 337 | lua_pop(K_, 1); // K_: ... LindasDB |
| 338 | // add a new KeysDB table for this linda | 338 | // add a new KeysDB table for this linda |
| 339 | lua_newtable(K_); // K_: ... LindasDB KeysDB | 339 | lua_newtable(K_); // K_: ... LindasDB KeysDB |
| @@ -390,7 +390,7 @@ int keepercall_count(lua_State* const L_) | |||
| 390 | case 2: // _K: linda key | 390 | case 2: // _K: linda key |
| 391 | PushKeysDB(_K, StackIndex{ 1 }); // _K: linda key KeysDB | 391 | PushKeysDB(_K, StackIndex{ 1 }); // _K: linda key KeysDB |
| 392 | lua_replace(_K, 1); // _K: KeysDB key | 392 | lua_replace(_K, 1); // _K: KeysDB key |
| 393 | if (luaG_rawget(_K, StackIndex{ -2 }) == LuaType::NIL) { // the key is unknown // _K: KeysDB KeyUD|nil | 393 | if (luaW_rawget(_K, StackIndex{ -2 }) == LuaType::NIL) { // the key is unknown // _K: KeysDB KeyUD|nil |
| 394 | lua_remove(_K, -2); // _K: nil | 394 | lua_remove(_K, -2); // _K: nil |
| 395 | } else { // the key is known // _K: KeysDB KeyUD | 395 | } else { // the key is known // _K: KeysDB KeyUD |
| 396 | KeyUD* const _key{ KeyUD::GetPtr(_K, kIdxTop) }; | 396 | KeyUD* const _key{ KeyUD::GetPtr(_K, kIdxTop) }; |
| @@ -503,7 +503,7 @@ int keepercall_limit(lua_State* const L_) | |||
| 503 | if (_key && _key->limit >= 0) { | 503 | if (_key && _key->limit >= 0) { |
| 504 | lua_pushinteger(_K, _key->limit); // _K: limit | 504 | lua_pushinteger(_K, _key->limit); // _K: limit |
| 505 | } else { // if the key doesn't exist, it is unlimited by default | 505 | } else { // if the key doesn't exist, it is unlimited by default |
| 506 | luaG_pushstring(_K, "unlimited"); // _K: "unlimited" | 506 | luaW_pushstring(_K, "unlimited"); // _K: "unlimited" |
| 507 | } | 507 | } |
| 508 | // return a single value: the limit of the key | 508 | // return a single value: the limit of the key |
| 509 | } else { | 509 | } else { |
| @@ -617,7 +617,7 @@ int keepercall_restrict(lua_State* const L_) | |||
| 617 | if (_reading) { | 617 | if (_reading) { |
| 618 | return LindaRestrict::None; | 618 | return LindaRestrict::None; |
| 619 | } | 619 | } |
| 620 | std::string_view const _val{ luaG_tostring(_K, StackIndex{ 3 }) }; | 620 | std::string_view const _val{ luaW_tostring(_K, StackIndex{ 3 }) }; |
| 621 | if (_val == "set/get") { | 621 | if (_val == "set/get") { |
| 622 | return LindaRestrict::SetGet; | 622 | return LindaRestrict::SetGet; |
| 623 | } | 623 | } |
| @@ -649,7 +649,7 @@ int keepercall_restrict(lua_State* const L_) | |||
| 649 | lua_settop(_K, 0); // _K: | 649 | lua_settop(_K, 0); // _K: |
| 650 | auto const _prevRstrct{ _key ? _key->restrict : LindaRestrict::None }; | 650 | auto const _prevRstrct{ _key ? _key->restrict : LindaRestrict::None }; |
| 651 | // return a single value: the restrict mode of the key | 651 | // return a single value: the restrict mode of the key |
| 652 | luaG_pushstring(_K, _encodeRestrict(_prevRstrct)); // _K: _previous | 652 | luaW_pushstring(_K, _encodeRestrict(_prevRstrct)); // _K: _previous |
| 653 | } else { | 653 | } else { |
| 654 | if (_key == nullptr) { // _K: KeysDB key nil | 654 | if (_key == nullptr) { // _K: KeysDB key nil |
| 655 | lua_pop(_K, 1); // _K: KeysDB key | 655 | lua_pop(_K, 1); // _K: KeysDB key |
| @@ -661,7 +661,7 @@ int keepercall_restrict(lua_State* const L_) | |||
| 661 | // return true if we decide that blocked threads waiting to write on that key should be awakened | 661 | // return true if we decide that blocked threads waiting to write on that key should be awakened |
| 662 | // this is the case if we detect the key was full but it is no longer the case | 662 | // this is the case if we detect the key was full but it is no longer the case |
| 663 | LindaRestrict const _previous{ _key->changeRestrict(_rstrct) }; | 663 | LindaRestrict const _previous{ _key->changeRestrict(_rstrct) }; |
| 664 | luaG_pushstring(_K, _encodeRestrict(_previous)); // _K: _previous | 664 | luaW_pushstring(_K, _encodeRestrict(_previous)); // _K: _previous |
| 665 | } | 665 | } |
| 666 | STACK_CHECK(_K, 1); | 666 | STACK_CHECK(_K, 1); |
| 667 | return 1; | 667 | return 1; |
| @@ -680,7 +680,7 @@ int keepercall_send(lua_State* const L_) | |||
| 680 | PushKeysDB(_K, StackIndex{ 1 }); // _K: linda key val... KeysDB | 680 | PushKeysDB(_K, StackIndex{ 1 }); // _K: linda key val... KeysDB |
| 681 | // get the fifo associated to this key in this linda, create it if it doesn't exist | 681 | // get the fifo associated to this key in this linda, create it if it doesn't exist |
| 682 | lua_pushvalue(_K, 2); // _K: linda key val... KeysDB key | 682 | lua_pushvalue(_K, 2); // _K: linda key val... KeysDB key |
| 683 | if (luaG_rawget(_K, StackIndex{ -2 }) == LuaType::NIL) { // _K: linda key val... KeysDB KeyUD|nil | 683 | if (luaW_rawget(_K, StackIndex{ -2 }) == LuaType::NIL) { // _K: linda key val... KeysDB KeyUD|nil |
| 684 | lua_pop(_K, 1); // _K: linda key val... KeysDB | 684 | lua_pop(_K, 1); // _K: linda key val... KeysDB |
| 685 | std::ignore = KeyUD::Create(KeeperState{ _K }); // _K: linda key val... KeysDB KeyUD | 685 | std::ignore = KeyUD::Create(KeeperState{ _K }); // _K: linda key val... KeysDB KeyUD |
| 686 | // KeysDB[key] = KeyUD | 686 | // KeysDB[key] = KeyUD |
| @@ -863,7 +863,7 @@ int Keeper::PushLindaStorage(Linda& linda_, DestState const L_) | |||
| 863 | STACK_CHECK_START_REL(_K, 0); | 863 | STACK_CHECK_START_REL(_K, 0); |
| 864 | kLindasRegKey.pushValue(_K); // _K: LindasDB L_: | 864 | kLindasRegKey.pushValue(_K); // _K: LindasDB L_: |
| 865 | lua_pushlightuserdata(_K, &linda_); // _K: LindasDB linda L_: | 865 | lua_pushlightuserdata(_K, &linda_); // _K: LindasDB linda L_: |
| 866 | LuaType const _type{ luaG_rawget(_K, StackIndex{ -2 }) }; // _K: LindasDB KeysDB L_: | 866 | LuaType const _type{ luaW_rawget(_K, StackIndex{ -2 }) }; // _K: LindasDB KeysDB L_: |
| 867 | lua_remove(_K, -2); // _K: KeysDB L_: | 867 | lua_remove(_K, -2); // _K: KeysDB L_: |
| 868 | if (_type != LuaType::TABLE) { // possible if we didn't send anything through that linda | 868 | if (_type != LuaType::TABLE) { // possible if we didn't send anything through that linda |
| 869 | lua_pop(_K, 1); // _K: L_: | 869 | lua_pop(_K, 1); // _K: L_: |
| @@ -900,20 +900,20 @@ int Keeper::PushLindaStorage(Linda& linda_, DestState const L_) | |||
| 900 | if (_key->limit >= 0) { | 900 | if (_key->limit >= 0) { |
| 901 | lua_pushinteger(L_, _key->limit); // _K: KeysDB key L_: out key keyout fifo limit | 901 | lua_pushinteger(L_, _key->limit); // _K: KeysDB key L_: out key keyout fifo limit |
| 902 | } else { | 902 | } else { |
| 903 | luaG_pushstring(L_, "unlimited"); // _K: KeysDB key L_: out key keyout fifo limit | 903 | luaW_pushstring(L_, "unlimited"); // _K: KeysDB key L_: out key keyout fifo limit |
| 904 | } | 904 | } |
| 905 | STACK_CHECK(L_, 5); | 905 | STACK_CHECK(L_, 5); |
| 906 | lua_setfield(L_, -3, "limit"); // _K: KeysDB key L_: out key keyout fifo | 906 | lua_setfield(L_, -3, "limit"); // _K: KeysDB key L_: out key keyout fifo |
| 907 | // keyout.restrict | 907 | // keyout.restrict |
| 908 | switch (_key->restrict) { | 908 | switch (_key->restrict) { |
| 909 | case LindaRestrict::None: | 909 | case LindaRestrict::None: |
| 910 | luaG_pushstring(L_, "none"); // _K: KeysDB key L_: out key keyout fifo restrict | 910 | luaW_pushstring(L_, "none"); // _K: KeysDB key L_: out key keyout fifo restrict |
| 911 | break; | 911 | break; |
| 912 | case LindaRestrict::SetGet: | 912 | case LindaRestrict::SetGet: |
| 913 | luaG_pushstring(L_, "set/get"); // _K: KeysDB key L_: out key keyout fifo restrict | 913 | luaW_pushstring(L_, "set/get"); // _K: KeysDB key L_: out key keyout fifo restrict |
| 914 | break; | 914 | break; |
| 915 | case LindaRestrict::SendReceive: | 915 | case LindaRestrict::SendReceive: |
| 916 | luaG_pushstring(L_, "send/receive"); // _K: KeysDB key L_: out key keyout fifo restrict | 916 | luaW_pushstring(L_, "send/receive"); // _K: KeysDB key L_: out key keyout fifo restrict |
| 917 | break; | 917 | break; |
| 918 | } | 918 | } |
| 919 | STACK_CHECK(L_, 5); | 919 | STACK_CHECK(L_, 5); |
| @@ -1090,7 +1090,7 @@ void Keepers::initialize(Universe& U_, lua_State* L_, size_t const nbKeepers_, i | |||
| 1090 | keeper_.K = _K; | 1090 | keeper_.K = _K; |
| 1091 | 1091 | ||
| 1092 | // Give a name to the state | 1092 | // Give a name to the state |
| 1093 | luaG_pushstring(_K, "Keeper #%d", i_ + 1); // L_: settings _K: "Keeper #n" | 1093 | luaW_pushstring(_K, "Keeper #%d", i_ + 1); // L_: settings _K: "Keeper #n" |
| 1094 | if constexpr (HAVE_DECODA_SUPPORT()) { | 1094 | if constexpr (HAVE_DECODA_SUPPORT()) { |
| 1095 | lua_pushvalue(_K, -1); // _K: "Keeper #n" Keeper #n" | 1095 | lua_pushvalue(_K, -1); // _K: "Keeper #n" Keeper #n" |
| 1096 | lua_setglobal(_K, "decoda_name"); // L_: settings _K: "Keeper #n" | 1096 | lua_setglobal(_K, "decoda_name"); // L_: settings _K: "Keeper #n" |
| @@ -1112,9 +1112,9 @@ void Keepers::initialize(Universe& U_, lua_State* L_, size_t const nbKeepers_, i | |||
| 1112 | STACK_CHECK(_K, 0); | 1112 | STACK_CHECK(_K, 0); |
| 1113 | 1113 | ||
| 1114 | // copy package.path and package.cpath from the source state | 1114 | // copy package.path and package.cpath from the source state |
| 1115 | if (luaG_getmodule(L, LUA_LOADLIBNAME) != LuaType::NIL) { // L_: settings package _K: | 1115 | if (luaW_getmodule(L, LUA_LOADLIBNAME) != LuaType::NIL) { // L_: settings package _K: |
| 1116 | // when copying with mode LookupMode::ToKeeper, error message is pushed at the top of the stack, not raised immediately | 1116 | // when copying with mode LookupMode::ToKeeper, error message is pushed at the top of the stack, not raised immediately |
| 1117 | InterCopyContext _c{ U, DestState{ _K.value() }, SourceState{ L }, {}, SourceIndex{ luaG_absindex(L, kIdxTop).value() }, {}, LookupMode::ToKeeper, {} }; | 1117 | InterCopyContext _c{ U, DestState{ _K.value() }, SourceState{ L }, {}, SourceIndex{ luaW_absindex(L, kIdxTop).value() }, {}, LookupMode::ToKeeper, {} }; |
| 1118 | if (_c.interCopyPackage() != InterCopyResult::Success) { // L_: settings ... error_msg _K: | 1118 | if (_c.interCopyPackage() != InterCopyResult::Success) { // L_: settings ... error_msg _K: |
| 1119 | // if something went wrong, the error message is at the top of the stack | 1119 | // if something went wrong, the error message is at the top of the stack |
| 1120 | lua_remove(L, -2); // L_: settings error_msg | 1120 | lua_remove(L, -2); // L_: settings error_msg |
