Skip to content

Commit

Permalink
Add some missing v100 compatibility functions
Browse files Browse the repository at this point in the history
  • Loading branch information
GrieferAtWork committed Dec 15, 2024
1 parent 64d9c1f commit 6bc5799
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 38 deletions.
33 changes: 26 additions & 7 deletions src/deemon/objects/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -3617,6 +3617,16 @@ seq_popfront(DeeObject *self, size_t argc, DeeObject *const *argv);
INTDEF WUNUSED NONNULL((1)) DREF DeeObject *DCALL /* From `seq.c' */
seq_popback(DeeObject *self, size_t argc, DeeObject *const *argv);

#ifndef CONFIG_NO_DEEMON_100_COMPAT
INTDEF WUNUSED NONNULL((1)) DREF DeeObject *DCALL
seq_binsert(DeeObject *self, size_t argc, DeeObject *const *argv, DeeObject *kw);
INTDEF WUNUSED NONNULL((1)) DREF DeeObject *DCALL
seq_distinct(DeeObject *self, size_t argc, DeeObject *const *argv, DeeObject *kw);


#endif /* !CONFIG_NO_DEEMON_100_COMPAT */


PRIVATE struct type_method tpconst list_methods[] = {
TYPE_METHOD_HINTREF(seq_extend),
TYPE_METHOD_HINTREF(seq_resize),
Expand Down Expand Up @@ -3654,13 +3664,17 @@ PRIVATE struct type_method tpconst list_methods[] = {
TYPE_METHOD_F("reserve", &list_reserve, METHOD_FNOREFESCAPE,
"(size:?Dint)\n"
"Reserve (preallocate) memory for @size items\n"
"Failures to pre-allocate memory are silently ignored, in which case ?#allocated will remain unchanged\n"
"If @size is lower than the currently ?#allocated size, the function becomes a no-op"),
"Failures to pre-allocate memory are silently ignored, "
/**/ "in which case ?#allocated will remain unchanged\n"
"If @size is lower than the currently ?#allocated size, "
/**/ "the function becomes a no-op"),
TYPE_METHOD_F("shrink", &list_shrink, METHOD_FNOREFESCAPE,
"()\n"
"Release any pre-allocated, but unused memory, setting ?#allocated to the length of @this List"),
"Release any pre-allocated, but unused memory, setting "
/**/ "?#allocated to the length of @this List"),

/* Deprecated aliases / functions. */
#ifndef CONFIG_NO_DEEMON_100_COMPAT
TYPE_KWMETHOD_F("remove_if", &DeeMH_seq_removeif, METHOD_FNOREFESCAPE,
"(should:?DCallable,start=!0,end:?Dint=!A!Dint!PSIZE_MAX)->?Dint\n"
"Deprecated alias for ?#removeif"),
Expand All @@ -3685,11 +3699,16 @@ PRIVATE struct type_method tpconst list_methods[] = {
TYPE_METHOD_F("shrink_to_fit", &list_shrink, METHOD_FNOREFESCAPE,
"()\n"
"Deprecated alias for ?#shrink"),
/* TODO: DEE_METHODDEF_v100("sorted_insert", member(&_deelist_sorted_insert), DEE_DOC_AUTO),
* TODO: DEE_METHODDEF_v100("fill", member(&_deelist_fill), DEE_DOC_AUTO),
* TODO: DEE_METHODDEF_v100("unique", member(&_deelist_unique), DEE_DOC_AUTO),
* TODO: DEE_METHODDEF_CONST_v100("tounique", member(&_deelist_tounique), DEE_DOC_AUTO),

TYPE_KWMETHOD("sorted_insert", &seq_binsert,
"(item,start=!0,end:?Dint=!A!Dint!PSIZE_MAX)\n"
"Deprecated alias for ?Abinsert?DSequence present only in ?."),
TYPE_KWMETHOD("tounique", &seq_distinct,
"(key?:?DCallable)->?DSet\n"
"Deprecated alias for ?Adistinct?DSequence present only in ?."),
/* TODO: DEE_METHODDEF_v100("unique", member(&_deelist_unique), DEE_DOC_AUTO),
* TODO: DEE_METHODDEF_CONST_v100("extend_unique", member(&_deelist_extend_unique), DEE_DOC_AUTO), */
#endif /* !CONFIG_NO_DEEMON_100_COMPAT */
TYPE_METHOD_END
};

Expand Down
25 changes: 21 additions & 4 deletions src/deemon/objects/seq.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,12 @@ seq_unpack(DeeObject *self, size_t argc, DeeObject *const *argv) {
return NULL;
}

PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL
#ifdef CONFIG_NO_DEEMON_100_COMPAT
PRIVATE
#else /* CONFIG_NO_DEEMON_100_COMPAT */
INTERN /* Needed for alias `List.unique' */
#endif /* !CONFIG_NO_DEEMON_100_COMPAT */
WUNUSED NONNULL((1)) DREF DeeObject *DCALL
seq_distinct(DeeObject *self, size_t argc, DeeObject *const *argv, DeeObject *kw) {
DREF DistinctSetWithKey *result;
DeeObject *key = NULL;
Expand Down Expand Up @@ -762,7 +767,12 @@ seq_blocateall(DeeObject *self, size_t argc, DeeObject *const *argv, DeeObject *
return NULL;
}

PRIVATE WUNUSED NONNULL((1)) DREF DeeObject *DCALL
#ifdef CONFIG_NO_DEEMON_100_COMPAT
PRIVATE
#else /* CONFIG_NO_DEEMON_100_COMPAT */
INTERN /* Needed for alias `List.sorted_insert' */
#endif /* !CONFIG_NO_DEEMON_100_COMPAT */
WUNUSED NONNULL((1)) DREF DeeObject *DCALL
seq_binsert(DeeObject *self, size_t argc, DeeObject *const *argv, DeeObject *kw) {
DeeObject *item;
size_t index, start = 0, end = (size_t)-1;
Expand Down Expand Up @@ -1576,6 +1586,13 @@ INTERN_TPCONST struct type_method tpconst seq_methods[] = {
/**/ "}"
"}"),

/* TODO: locatefirst: "(pred:?DCallable,start=!0,end:?Dint=!A!Dint!PSIZE_MAX,def=!N)->?X2?O?Q!Adef]\n"
* "Locate and return the first element such that ${pred(elem)} is true, or @def when no such element exists"
* XXX: Check if it's possible to just replace "Sequence.locate" with this */
/* TODO: locatelast: "(pred:?DCallable,start=!0,end:?Dint=!A!Dint!PSIZE_MAX,def=!N)->?X2?O?Q!Adef]\n"
* "Locate and return the last element such that ${pred(elem)} is true, or @def when no such element exists"
* XXX: Check if it's possible to just replace "Sequence.rlocate" with this */

/* TODO: findall: "(item,start=!0,end:?Dint=!A!Dint!PSIZE_MAX,key:?DCallable=!N)->?S?Dint"
* > Find not just the first, but all indices of @item */
/* TODO: findallseq(seq: Sequence, start: int = 0, end: int = -1, key: Callable = none): {int...} */
Expand Down Expand Up @@ -1934,9 +1951,9 @@ INTERN_TPCONST struct type_method tpconst seq_methods[] = {
/**/ "return [:##(this as Sequence)].operator iter();\n"
/**/ "\n"
/**/ "// When indices can be unbound (enumerate bound indices)\n"
/**/ "return (() -> {\n"
/**/ "return (() -\\> {\n"
/**/ " local keys = [];\n"
/**/ " Sequence.enumerate(this, (key, ...) -> {\n"
/**/ " Sequence.enumerate(this, (key, ...) -\\> {\n"
/**/ " keys.append(key);\n"
/**/ " });\n"
/**/ " return keys;\n"
Expand Down
28 changes: 1 addition & 27 deletions src/deemon/objects/seq/svec.c
Original file line number Diff line number Diff line change
Expand Up @@ -941,32 +941,6 @@ svec_iter(SharedVector *__restrict self) {
return result;
}

#ifndef __OPTIMIZE_SIZE__
PRIVATE WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL
svec_contains(SharedVector *self, DeeObject *other) {
size_t index;
int temp;
SharedVector_LockRead(self);
for (index = 0; index < self->sv_length; ++index) {
DREF DeeObject *item;
item = self->sv_vector[index];
Dee_Incref(item);
SharedVector_LockEndRead(self);
temp = DeeObject_TryCompareEq(other, item);
Dee_Decref(item);
if unlikely(temp == Dee_COMPARE_ERR)
goto err;
if (temp == 0)
return_true;
SharedVector_LockRead(self);
}
SharedVector_LockEndRead(self);
return_false;
err:
return NULL;
}
#endif /* !__OPTIMIZE_SIZE__ */

PRIVATE WUNUSED NONNULL((1)) size_t DCALL
svec_size(SharedVector *__restrict self) {
ASSERT(self->sv_length != (size_t)-1);
Expand Down Expand Up @@ -1201,7 +1175,7 @@ PRIVATE struct type_method_hint tpconst svec_method_hints[] = {
PRIVATE struct type_seq svec_seq = {
/* .tp_iter = */ (DREF DeeObject *(DCALL *)(DeeObject *__restrict))&svec_iter,
/* .tp_sizeob = */ NULL,
/* .tp_contains = */ NULL_IF_Os((DREF DeeObject *(DCALL *)(DeeObject *, DeeObject *))&svec_contains),
/* .tp_contains = */ NULL,
/* .tp_getitem = */ NULL,
/* .tp_delitem = */ NULL,
/* .tp_setitem = */ NULL,
Expand Down

0 comments on commit 6bc5799

Please sign in to comment.