Skip to content

Commit

Permalink
Expose SeqSome in C API
Browse files Browse the repository at this point in the history
  • Loading branch information
GrieferAtWork committed Dec 20, 2024
1 parent 991398d commit 3e552c0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 64 deletions.
24 changes: 24 additions & 0 deletions include/deemon/seq.h
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,30 @@ DeeSeq_AsHeapVectorWithAllocReuseOffset2(DeeObject *__restrict self,
/*in*/ size_t offset);
#endif /* Dee_MallocUsableSize */




/************************************************************************/
/* Type for `Sequence.some' */
/************************************************************************/
typedef struct {
Dee_OBJECT_HEAD
DREF DeeObject *se_seq; /* [1..1][const] The sequence being wrapped. */
} DeeSeqSomeObject;
#define DeeSeqSome_GetSeq(self) ((DeeSeqSomeObject const *)Dee_REQUIRES_OBJECT(self))->se_seq

DDATDEF DeeTypeObject DeeSeqSome_Type;
#define DeeSeqSome_Check(self) DeeObject_InstanceOfExact(self, &DeeSeqSome_Type)
#define DeeSeqSome_CheckExact(self) DeeObject_InstanceOfExact(self, &DeeSeqSome_Type)

/* Construct a some-wrapper for `self' */
#ifdef CONFIG_BUILDING_DEEMON
INTDEF WUNUSED NONNULL((1)) DREF DeeObject *DCALL DeeSeq_Some(DeeObject *__restrict self);
#else /* CONFIG_BUILDING_DEEMON */
#define DeeSeq_Some(self) DeeObject_NewPack(&DeeSeqSome_Type, 1, self)
#endif /* !CONFIG_BUILDING_DEEMON */


DECL_END

#endif /* !GUARD_DEEMON_SEQ_H */
14 changes: 6 additions & 8 deletions src/deemon/objects/seq/each.c
Original file line number Diff line number Diff line change
Expand Up @@ -1949,7 +1949,7 @@ PRIVATE struct type_attr ss_attr = {
/* .tp_findattr_info_string_len_hash = */ NULL
};

INTERN DeeTypeObject SeqSome_Type = {
PUBLIC DeeTypeObject DeeSeqSome_Type = {
OBJECT_HEAD_INIT(&DeeType_Type),
/* .tp_name = */ "_SeqSome",
/* .tp_doc = */ DOC("(seq:?DSequence)"),
Expand Down Expand Up @@ -2020,23 +2020,21 @@ DeeSeq_Each(DeeObject *__restrict self) {
return (DREF DeeObject *)result;
}


STATIC_ASSERT(sizeof(DeeSeqSomeObject) == sizeof(SeqEachBase));
STATIC_ASSERT(offsetof(DeeSeqSomeObject, se_seq) == offsetof(SeqEachBase, se_seq));

INTERN WUNUSED NONNULL((1)) DREF DeeObject *DCALL
DeeSeq_Some(DeeObject *__restrict self) {
#if 1 /* TODO */
DREF SeqEachBase *result;
result = DeeObject_MALLOC(SeqEachBase);
if unlikely(!result)
goto done;
result->se_seq = self;
Dee_Incref(self);
DeeObject_Init(result, &SeqSome_Type);
DeeObject_Init(result, &DeeSeqSome_Type);
done:
return (DREF DeeObject *)result;
#else
(void)self;
DeeError_NOTIMPLEMENTED();
return NULL;
#endif
}


Expand Down
5 changes: 0 additions & 5 deletions src/deemon/objects/seq/each.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ typedef struct {
INTDEF DeeTypeObject SeqEach_Type;
INTDEF DeeTypeObject SeqEachOperator_Type;
INTDEF DeeTypeObject SeqEachOperatorIterator_Type;
INTDEF DeeTypeObject SeqSome_Type;
INTDEF DeeTypeObject SeqSomeOperator_Type;

#ifdef CONFIG_HAVE_SEQEACH_ATTRIBUTE_OPTIMIZATIONS
Expand Down Expand Up @@ -227,10 +226,6 @@ INTDEF WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL DeeSeqSome_CallAttrStringLe
INTDEF WUNUSED NONNULL((1)) DREF DeeObject *DCALL
DeeSeq_Each(DeeObject *__restrict self);

/* Construct a some-wrapper for `self' */
INTDEF WUNUSED NONNULL((1)) DREF DeeObject *DCALL
DeeSeq_Some(DeeObject *__restrict self);

DECL_END

#endif /* !GUARD_DEEMON_OBJECTS_SEQ_EACH_H */
63 changes: 12 additions & 51 deletions src/dex/rt/librt.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ print define_Dee_HashStr("casesplit");
print define_Dee_HashStr("classes");
print define_Dee_HashStr("combinations");
print define_Dee_HashStr("each");
print define_Dee_HashStr("some");
print define_Dee_HashStr("filter");
print define_Dee_HashStr("ubfilter");
print define_Dee_HashStr("findall");
Expand Down Expand Up @@ -1275,72 +1274,35 @@ librt_get_SeqEachCallAttrKwIterator_Type_f(size_t UNUSED(argc), DeeObject *const
}


PRIVATE WUNUSED DREF DeeObject *DCALL
librt_get_SeqSome_stub_instance(void) {
return_cached(DeeObject_GetAttrStringHash(&object_with_size_and_getitem_index, STR_AND_HASH(some)));
}
PRIVATE DeeSeqSomeObject SeqSome_stub_instance = {
OBJECT_HEAD_INIT(&DeeSeqSome_Type),
/* .se_seq = */ Dee_EmptyTuple
};

PRIVATE WUNUSED DREF DeeObject *DCALL
librt_get_SeqSomeOperator_stub_instance(void) {
DREF DeeObject *result;
result = librt_get_SeqSome_stub_instance();
if likely(result) {
DREF DeeObject *temp;
temp = DeeObject_Pos(result);
Dee_Decref(result);
result = temp;
}
return result;
return DeeObject_Pos((DeeObject *)&SeqSome_stub_instance);
}

PRIVATE WUNUSED DREF DeeObject *DCALL
librt_get_SeqSomeGetAttr_stub_instance(void) {
DREF DeeObject *result;
result = librt_get_SeqSome_stub_instance();
if likely(result) {
DREF DeeObject *temp;
temp = DeeObject_GetAttr(result, (DeeObject *)&str_Iterator);
Dee_Decref(result);
result = temp;
}
return result;
return DeeObject_GetAttr((DeeObject *)&SeqSome_stub_instance, (DeeObject *)&str_Iterator);
}

PRIVATE WUNUSED DREF DeeObject *DCALL
librt_get_SeqSomeCallAttr_stub_instance(void) {
DREF DeeObject *result;
result = librt_get_SeqSome_stub_instance();
if likely(result) {
DREF DeeObject *temp;
temp = DeeObject_CallAttr(result, (DeeObject *)&str_Iterator, 0, NULL);
Dee_Decref(result);
result = temp;
}
return result;
return DeeObject_CallAttr((DeeObject *)&SeqSome_stub_instance,
(DeeObject *)&str_Iterator, 0, NULL);
}

PRIVATE WUNUSED DREF DeeObject *DCALL
librt_get_SeqSomeCallAttrKw_stub_instance(void) {
DREF DeeObject *result;
result = librt_get_SeqSome_stub_instance();
if likely(result) {
DREF DeeObject *temp;
temp = DeeObject_CallAttrKw(result, (DeeObject *)&str_Iterator,
0,
NULL,
Dee_EmptyMapping);
Dee_Decref(result);
result = temp;
}
return result;
return DeeObject_CallAttrKw((DeeObject *)&SeqSome_stub_instance,
(DeeObject *)&str_Iterator, 0, NULL,
Dee_EmptyMapping);
}


PRIVATE WUNUSED DREF DeeObject *DCALL
librt_get_SeqSome_Type_f(size_t UNUSED(argc), DeeObject *const *UNUSED(argv)) {
return_cached(get_type_of(librt_get_SeqSome_stub_instance()));
}

PRIVATE WUNUSED DREF DeeObject *DCALL
librt_get_SeqSomeOperator_Type_f(size_t UNUSED(argc), DeeObject *const *UNUSED(argv)) {
return_cached(get_type_of(librt_get_SeqSomeOperator_stub_instance()));
Expand Down Expand Up @@ -3346,7 +3308,6 @@ PRIVATE DEFINE_CMETHOD(librt_get_SeqEachCallAttr, &librt_get_SeqEachCallAttr_Typ
PRIVATE DEFINE_CMETHOD(librt_get_SeqEachCallAttrIterator, &librt_get_SeqEachCallAttrIterator_Type_f, METHOD_FCONSTCALL);
PRIVATE DEFINE_CMETHOD(librt_get_SeqEachCallAttrKw, &librt_get_SeqEachCallAttrKw_Type_f, METHOD_FCONSTCALL);
PRIVATE DEFINE_CMETHOD(librt_get_SeqEachCallAttrKwIterator, &librt_get_SeqEachCallAttrKwIterator_Type_f, METHOD_FCONSTCALL);
PRIVATE DEFINE_CMETHOD(librt_get_SeqSome, &librt_get_SeqSome_Type_f, METHOD_FCONSTCALL);
PRIVATE DEFINE_CMETHOD(librt_get_SeqSomeOperator, &librt_get_SeqSomeOperator_Type_f, METHOD_FCONSTCALL);
PRIVATE DEFINE_CMETHOD(librt_get_SeqSomeGetAttr, &librt_get_SeqSomeGetAttr_Type_f, METHOD_FCONSTCALL);
PRIVATE DEFINE_CMETHOD(librt_get_SeqSomeCallAttr, &librt_get_SeqSomeCallAttr_Type_f, METHOD_FCONSTCALL);
Expand Down Expand Up @@ -3724,7 +3685,7 @@ PRIVATE struct dex_symbol symbols[] = {
{ "SeqEachCallAttrKwIterator", (DeeObject *)&librt_get_SeqEachCallAttrKwIterator, MODSYM_FREADONLY | MODSYM_FPROPERTY | MODSYM_FCONSTEXPR }, /* SeqEachCallAttrKwIterator_Type */

/* Seq-some wrapper types. */
{ "SeqSome", (DeeObject *)&librt_get_SeqSome, MODSYM_FREADONLY | MODSYM_FPROPERTY | MODSYM_FCONSTEXPR }, /* SeqSome_Type */
{ "SeqSome", (DeeObject *)&DeeSeqSome_Type, MODSYM_FREADONLY },
{ "SeqSomeOperator", (DeeObject *)&librt_get_SeqSomeOperator, MODSYM_FREADONLY | MODSYM_FPROPERTY | MODSYM_FCONSTEXPR }, /* SeqSomeOperator_Type */
{ "SeqSomeGetAttr", (DeeObject *)&librt_get_SeqSomeGetAttr, MODSYM_FREADONLY | MODSYM_FPROPERTY | MODSYM_FCONSTEXPR }, /* SeqSomeGetAttr_Type */
{ "SeqSomeCallAttr", (DeeObject *)&librt_get_SeqSomeCallAttr, MODSYM_FREADONLY | MODSYM_FPROPERTY | MODSYM_FCONSTEXPR }, /* SeqSomeCallAttr_Type */
Expand Down

0 comments on commit 3e552c0

Please sign in to comment.