Skip to content

Commit

Permalink
Make getitemnr operator virtual
Browse files Browse the repository at this point in the history
  • Loading branch information
GrieferAtWork committed Jun 2, 2024
1 parent 3be18e1 commit e3e6cc0
Show file tree
Hide file tree
Showing 9 changed files with 559 additions and 676 deletions.
9 changes: 0 additions & 9 deletions include/deemon/cached-dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,6 @@ DDATDEF DeeTypeObject DeeCachedDict_Type;
DFUNDEF WUNUSED NONNULL((1)) DREF DeeObject *DCALL DeeCachedDict_New(DeeObject *__restrict mapping);
DFUNDEF WUNUSED NONNULL((1)) DREF DeeObject *DCALL DeeCachedDict_NewInherited(/*inherit(on_success)*/ DREF DeeObject *__restrict mapping);

#ifdef CONFIG_BUILDING_DEEMON
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeCachedDict_GetItemNR(DeeCachedDictObject *self, DeeObject *key);
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeCachedDict_GetItemNRStringHash(DeeCachedDictObject *__restrict self, char const *__restrict key, Dee_hash_t hash);
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeCachedDict_GetItemNRStringLenHash(DeeCachedDictObject *__restrict self, char const *__restrict key, size_t keylen, Dee_hash_t hash);
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeCachedDict_TryGetItemNR(DeeCachedDictObject *self, DeeObject *key);
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeCachedDict_TryGetItemNRStringHash(DeeCachedDictObject *self, char const *__restrict key, Dee_hash_t hash);
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeCachedDict_TryGetItemNRStringLenHash(DeeCachedDictObject *self, char const *__restrict key, size_t keylen, Dee_hash_t hash);
#endif /* CONFIG_BUILDING_DEEMON */

/* Hash iteration helpers. */
#define DeeCachedDict_HashSt(self, hash) ((hash) & (self)->cd_mask)
#define DeeCachedDict_HashNx(hs, perturb) (void)((hs) = ((hs) << 2) + (hs) + (perturb) + 1, (perturb) >>= 5) /* This `5' is tunable. */
Expand Down
29 changes: 1 addition & 28 deletions include/deemon/kwds.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,19 +371,6 @@ DeeKwdsMapping_New(/*Kwds*/ DeeObject *kwds,
DFUNDEF NONNULL((1)) void DCALL
DeeKwdsMapping_Decref(DREF /*KwdsMapping*/ DeeObject *__restrict self);

#ifdef CONFIG_BUILDING_DEEMON
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeKwdsMapping_GetItemNR(DeeKwdsMappingObject *self, /*string*/ DeeObject *name);
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeKwdsMapping_GetItemNRStringHash(DeeKwdsMappingObject *__restrict self, char const *__restrict name, Dee_hash_t hash);
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeKwdsMapping_GetItemNRStringLenHash(DeeKwdsMappingObject *__restrict self, char const *__restrict name, size_t namelen, Dee_hash_t hash);
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeKwdsMapping_TryGetItemNR(DeeKwdsMappingObject *self, /*string*/ DeeObject *name);
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeKwdsMapping_TryGetItemNRStringHash(DeeKwdsMappingObject *__restrict self, char const *__restrict name, Dee_hash_t hash);
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeKwdsMapping_TryGetItemNRStringLenHash(DeeKwdsMappingObject *__restrict self, char const *__restrict name, size_t namelen, Dee_hash_t hash);
#define DeeKwdsMapping_GetItemNRString(self, name) DeeKwdsMapping_GetItemNRStringHash(self, name, Dee_HashStr(name))
#define DeeKwdsMapping_GetItemNRStringLen(self, name, namelen) DeeKwdsMapping_GetItemNRStringLenHash(self, name, namelen, Dee_HashPtr(name, namelen))
#define DeeKwdsMapping_TryGetItemNRString(self, name) DeeKwdsMapping_TryGetItemNRStringHash(self, name, Dee_HashStr(name))
#define DeeKwdsMapping_TryGetItemNRStringLen(self, name, namelen) DeeKwdsMapping_TryGetItemNRStringLenHash(self, name, namelen, Dee_HashPtr(name, namelen))
#endif /* CONFIG_BUILDING_DEEMON */


/* Construct/access keyword arguments passed to a function as a
* high-level {string: Object}-like mapping that is bound to the
Expand Down Expand Up @@ -654,19 +641,11 @@ DFUNDEF DeeTypeObject DeeBlackListKwds_Type;

/* Helper functions & RT optimization bindings. */
#ifdef CONFIG_BUILDING_DEEMON
INTDEF WUNUSED NONNULL((1, 2)) bool DCALL DeeBlackListKwds_IsBlackListed(DeeBlackListKwdsObject *self, DeeObject *__restrict name);
INTDEF WUNUSED NONNULL((1, 2)) bool DCALL DeeBlackListKwds_IsBlackListed(DeeBlackListKwdsObject *__restrict self, /*string*/ DeeObject *__restrict name);
INTDEF WUNUSED NONNULL((1, 2)) bool DCALL DeeBlackListKwds_IsBlackListedStringHash(DeeBlackListKwdsObject *__restrict self, char const *__restrict name, Dee_hash_t hash);
INTDEF WUNUSED NONNULL((1, 2)) bool DCALL DeeBlackListKwds_IsBlackListedStringLenHash(DeeBlackListKwdsObject *__restrict self, char const *__restrict name, size_t namelen, Dee_hash_t hash);
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeBlackListKwds_GetItemNR(DeeBlackListKwdsObject *self, DeeObject *__restrict name);
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeBlackListKwds_GetItemNRStringHash(DeeBlackListKwdsObject *__restrict self, char const *__restrict name, Dee_hash_t hash);
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeBlackListKwds_GetItemNRStringLenHash(DeeBlackListKwdsObject *__restrict self, char const *__restrict name, size_t namelen, Dee_hash_t hash);
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeBlackListKwds_TryGetItemNR(DeeBlackListKwdsObject *self, DeeObject *__restrict name);
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeBlackListKwds_TryGetItemNRStringHash(DeeBlackListKwdsObject *__restrict self, char const *__restrict name, Dee_hash_t hash);
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeBlackListKwds_TryGetItemNRStringLenHash(DeeBlackListKwdsObject *__restrict self, char const *__restrict name, size_t namelen, Dee_hash_t hash);
#define DeeBlackListKwds_IsBlackListedString(self, name) DeeBlackListKwds_IsBlackListedStringHash(self, name, Dee_HashStr(name))
#define DeeBlackListKwds_IsBlackListedStringLen(self, name, namelen) DeeBlackListKwds_IsBlackListedStringLenHash(self, name, namelen, Dee_HashPtr(name, namelen))
#define DeeBlackListKwds_GetItemNRString(self, name) DeeBlackListKwds_GetItemNRStringHash(self, name, Dee_HashStr(name))
#define DeeBlackListKwds_GetItemNRStringLen(self, name, namelen) DeeBlackListKwds_GetItemNRStringLenHash(self, name, namelen, Dee_HashPtr(name, namelen))
#endif /* CONFIG_BUILDING_DEEMON */

/* Construct a new mapping for keywords that follows the black-listing scheme.
Expand Down Expand Up @@ -749,12 +728,6 @@ DDATDEF DeeTypeObject DeeBlackListKw_Type;
INTDEF WUNUSED NONNULL((1, 2)) bool DCALL DeeBlackListKw_IsBlackListed(DeeBlackListKwObject *self, /*string*/ DeeObject *name);
INTDEF WUNUSED NONNULL((1, 2)) bool DCALL DeeBlackListKw_IsBlackListedStringHash(DeeBlackListKwObject *__restrict self, char const *__restrict name, Dee_hash_t hash);
INTDEF WUNUSED NONNULL((1, 2)) bool DCALL DeeBlackListKw_IsBlackListedStringLenHash(DeeBlackListKwObject *__restrict self, char const *__restrict name, size_t namelen, Dee_hash_t hash);
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeBlackListKw_GetItemNR(DeeBlackListKwObject *self, /*string*/ DeeObject *name);
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeBlackListKw_GetItemNRStringHash(DeeBlackListKwObject *__restrict self, char const *__restrict name, Dee_hash_t hash);
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeBlackListKw_GetItemNRStringLenHash(DeeBlackListKwObject *__restrict self, char const *__restrict name, size_t namelen, Dee_hash_t hash);
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeBlackListKw_TryGetItemNR(DeeBlackListKwObject *self, /*string*/ DeeObject *name);
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeBlackListKw_TryGetItemNRStringHash(DeeBlackListKwObject *__restrict self, char const *__restrict name, Dee_hash_t hash);
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeBlackListKw_TryGetItemNRStringLenHash(DeeBlackListKwObject *__restrict self, char const *__restrict name, size_t namelen, Dee_hash_t hash);
#define DeeBlackListKw_IsBlackListedString(self, name) DeeBlackListKw_IsBlackListedStringHash(self, name, Dee_HashStr(name))
#define DeeBlackListKw_IsBlackListedStringLen(self, name, namelen) DeeBlackListKw_IsBlackListedStringLenHash(self, name, namelen, Dee_HashPtr(name, namelen))
#endif /* CONFIG_BUILDING_DEEMON */
Expand Down
18 changes: 14 additions & 4 deletions include/deemon/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -2111,18 +2111,22 @@ struct Dee_type_seq {
WUNUSED_T NONNULL_T((1, 2)) int (DCALL *tp_bounditem_string_len_hash)(DeeObject *self, char const *key, size_t keylen, Dee_hash_t hash);
WUNUSED_T NONNULL_T((1, 2)) int (DCALL *tp_hasitem_string_len_hash)(DeeObject *self, char const *key, size_t keylen, Dee_hash_t hash);

#if 0 /* TODO: Do this to allow DEX modules to extend `DeeKw_GetItemNR()' */
/* All of the following are *always* and *unconditionally* implemented
* when the associated type has the "tp_features & TF_KW" flag set,
* with the exception of `DeeKwds_Type', which has that flag, but does
* not implement these operators. */
* not implement these operators.
*
* NOTE: Even when these operators are defined, the operator above will
* NOT auto-substitute themselves with these (even though that
* would be possible), reason being that the amount of runtime
* overhead would be too great for those few types that define
* these operators. */
WUNUSED_T NONNULL_T((1, 2)) DeeObject *(DCALL *tp_getitemnr)(DeeObject *__restrict self, /*string*/ DeeObject *__restrict name);
WUNUSED_T NONNULL_T((1, 2)) DeeObject *(DCALL *tp_getitemnr_string_hash)(DeeObject *__restrict self, char const *__restrict name, Dee_hash_t hash);
WUNUSED_T NONNULL_T((1, 2)) DeeObject *(DCALL *tp_getitemnr_string_len_hash)(DeeObject *__restrict self, char const *__restrict name, size_t namelen, Dee_hash_t hash);
WUNUSED_T NONNULL_T((1, 2)) DeeObject *(DCALL *tp_trygetitemnr)(DeeObject *__restrict self, /*string*/ DeeObject *name);
WUNUSED_T NONNULL_T((1, 2)) DeeObject *(DCALL *tp_trygetitemnr)(DeeObject *__restrict self, /*string*/ DeeObject *__restrict name);
WUNUSED_T NONNULL_T((1, 2)) DeeObject *(DCALL *tp_trygetitemnr_string_hash)(DeeObject *__restrict self, char const *__restrict name, Dee_hash_t hash);
WUNUSED_T NONNULL_T((1, 2)) DeeObject *(DCALL *tp_trygetitemnr_string_len_hash)(DeeObject *__restrict self, char const *__restrict name, size_t namelen, Dee_hash_t hash);
#endif

/* [0..1][owned][lock(WRITE_ONCE)]
* Internal cache for how sequence functions are implemented for this type. */
Expand Down Expand Up @@ -2526,6 +2530,12 @@ PRIVATE struct type_seq myob_seq = {
/* .tp_setitem_string_len_hash = */ (int (DCALL *)(DeeObject *, char const *, size_t, Dee_hash_t, DeeObject *))&myob_setitem_string_len_hash,
/* .tp_bounditem_string_len_hash = */ (int (DCALL *)(DeeObject *, char const *, size_t, Dee_hash_t))&myob_bounditem_string_len_hash,
/* .tp_hasitem_string_len_hash = */ (int (DCALL *)(DeeObject *, char const *, size_t, Dee_hash_t))&myob_hasitem_string_len_hash,
/* .tp_getitemnr = */ (DeeObject *(DCALL *)(DeeObject *__restrict, /*string*/ DeeObject *__restrict))NULL,
/* .tp_getitemnr_string_hash = */ (DeeObject *(DCALL *)(DeeObject *__restrict, char const *__restrict, Dee_hash_t))NULL,
/* .tp_getitemnr_string_len_hash = */ (DeeObject *(DCALL *)(DeeObject *__restrict, char const *__restrict, size_t, Dee_hash_t))NULL,
/* .tp_trygetitemnr = */ (DeeObject *(DCALL *)(DeeObject *__restrict, /*string*/ DeeObject *__restrict))NULL,
/* .tp_trygetitemnr_string_hash = */ (DeeObject *(DCALL *)(DeeObject *__restrict, char const *__restrict, Dee_hash_t))NULL,
/* .tp_trygetitemnr_string_len_hash = */ (DeeObject *(DCALL *)(DeeObject *__restrict, char const *__restrict, size_t, Dee_hash_t))NULL,
};
#endif

Expand Down
15 changes: 0 additions & 15 deletions include/deemon/rodict.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,6 @@ DDATDEF DeeObject DeeRoDict_EmptyInstance;
#define Dee_EmptyRoDict (&DeeRoDict_EmptyInstance)
#endif /* !GUARD_DEEMON_OBJECTS_RODICT_C */



#ifdef CONFIG_BUILDING_DEEMON
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeRoDict_GetItemNR(DeeRoDictObject *self, DeeObject *key);
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeRoDict_GetItemNRStringHash(DeeRoDictObject *__restrict self, char const *__restrict key, Dee_hash_t hash);
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeRoDict_GetItemNRStringLenHash(DeeRoDictObject *__restrict self, char const *__restrict key, size_t keylen, Dee_hash_t hash);
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeRoDict_TryGetItemNR(DeeRoDictObject *self, DeeObject *key);
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeRoDict_TryGetItemNRStringHash(DeeRoDictObject *self, char const *__restrict key, Dee_hash_t hash);
INTDEF WUNUSED NONNULL((1, 2)) DeeObject *DCALL DeeRoDict_TryGetItemNRStringLenHash(DeeRoDictObject *self, char const *__restrict key, size_t keylen, Dee_hash_t hash);
#define DeeRoDict_GetItemNRString(self, key) DeeRoDict_GetItemNRStringHash(self, key, Dee_HashStr(key))
#define DeeRoDict_GetItemNRStringLen(self, key, keylen) DeeRoDict_GetItemNRStringLenHash(self, key, keylen, Dee_HashPtr(key, keylen))
#define DeeRoDict_TryGetItemNRString(self, key) DeeRoDict_TryGetItemNRStringHash(self, key, Dee_HashStr(key))
#define DeeRoDict_TryGetItemNRStringLen(self, key, keylen) DeeRoDict_TryGetItemNRStringLenHash(self, key, keylen, Dee_HashPtr(key, keylen))
#endif /* !CONFIG_BUILDING_DEEMON */

/* Hash-iteration control. */
#define DeeRoDict_HashSt(self, hash) ((hash) & (self)->rd_mask)
#define DeeRoDict_HashNx(hs, perturb) (void)((hs) = ((hs) << 2) + (hs) + (perturb) + 1, (perturb) >>= 5) /* This `5' is tunable. */
Expand Down
Loading

0 comments on commit e3e6cc0

Please sign in to comment.