Skip to content

Commit

Permalink
Make most map operators virtual
Browse files Browse the repository at this point in the history
  • Loading branch information
GrieferAtWork committed Nov 25, 2024
1 parent df3e400 commit a49a5a9
Show file tree
Hide file tree
Showing 10 changed files with 2,339 additions and 1,245 deletions.
893 changes: 11 additions & 882 deletions src/deemon/objects/map.c

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions src/deemon/objects/seq.c
Original file line number Diff line number Diff line change
Expand Up @@ -4432,6 +4432,21 @@ INTERN_TPCONST struct type_method tpconst seq_methods[] = {
"}"),


/* TODO: Sequence operators as member functions:
* >> __getitem__(index:?Dint)->
* >> __delitem__(index:?Dint)
* >> __setitem__(index:?Dint,value)
* >> ...
*
* Using these, user-code can write:
* >> Sequence.__getitem__(ob, 42);
* instead of (and needing to create a super-proxy):
* >> (ob as Sequence)[42];
*
* NOTE: The compiler should also be able to automatically
* optimize the second version into the first. */


/* Old function names/deprecated functions. */
TYPE_METHOD("transform", &seq_map,
"(mapper:?DCallable)->?DSequence\n"
Expand Down
22 changes: 11 additions & 11 deletions src/deemon/objects/seq/default-api-methods.c
Original file line number Diff line number Diff line change
Expand Up @@ -4951,7 +4951,7 @@ DeeSet_DefaultRemoveWithMapTryGetItemAndMapDelItem(DeeObject *self, DeeObject *k
DREF DeeObject *map_key_and_value[2];
if unlikely(DeeObject_Unpack(key, 2, map_key_and_value))
goto err;
current_value = DeeObject_TryGetItem(self, map_key_and_value[0]); /* TODO: DeeMap_OperatorTryGetItem */
current_value = DeeMap_OperatorTryGetItem(self, map_key_and_value[0]);
if unlikely(!current_value)
goto err_map_key_and_value;
if (current_value == ITER_DONE) {
Expand All @@ -4965,7 +4965,7 @@ DeeSet_DefaultRemoveWithMapTryGetItemAndMapDelItem(DeeObject *self, DeeObject *k
Dee_Decref(current_value);
if unlikely(temp == Dee_COMPARE_ERR)
goto err_map_key;
temp = DeeObject_DelItem(self, map_key_and_value[0]); /* TODO: DeeMap_OperatorDelItem */
temp = DeeMap_OperatorDelItem(self, map_key_and_value[0]);
Dee_Decref(map_key_and_value[0]);
if unlikely(temp)
goto err;
Expand Down Expand Up @@ -7239,7 +7239,7 @@ default_map_get(DeeObject *self, size_t argc, DeeObject *const *argv) {
DeeObject *key, *def = Dee_None;
if (DeeArg_Unpack(argc, argv, "o|o:get", &key, &def))
goto err;
result = DeeObject_TryGetItem(self, key); /* TODO: Only use this when "self is Mapping"; else, must treat as ?S?T2?O?O and search for first item where `key == self[i].first' -- DeeMap_OperatorTryGetItem() */
result = DeeMap_OperatorTryGetItem(self, key);
if (result == ITER_DONE) {
Dee_Incref(def);
result = def;
Expand Down Expand Up @@ -7399,23 +7399,23 @@ default_map_popitem(DeeObject *self, size_t argc, DeeObject *const *argv) {
return NULL;
}

INTERN WUNUSED NONNULL((1)) DREF DeeObject *DCALL
default_map_keys(DeeObject *self) {
INTERN WUNUSED NONNULL((1)) DREF DeeObject *
(DCALL default_map_keys)(DeeObject *self) {
return DeeMap_InvokeKeys(self);
}

INTERN WUNUSED NONNULL((1)) DREF DeeObject *DCALL
default_map_values(DeeObject *self) {
INTERN WUNUSED NONNULL((1)) DREF DeeObject *
(DCALL default_map_values)(DeeObject *self) {
return DeeMap_InvokeValues(self);
}

INTERN WUNUSED NONNULL((1)) DREF DeeObject *DCALL
default_map_iterkeys(DeeObject *self) {
INTERN WUNUSED NONNULL((1)) DREF DeeObject *
(DCALL default_map_iterkeys)(DeeObject *self) {
return DeeMap_InvokeIterKeys(self);
}

INTERN WUNUSED NONNULL((1)) DREF DeeObject *DCALL
default_map_itervalues(DeeObject *self) {
INTERN WUNUSED NONNULL((1)) DREF DeeObject *
(DCALL default_map_itervalues)(DeeObject *self) {
return DeeMap_InvokeIterValues(self);
}

Expand Down
Loading

0 comments on commit a49a5a9

Please sign in to comment.