diff --git a/include/deemon/seq.h b/include/deemon/seq.h index 782075eeb..cfb8bab72 100644 --- a/include/deemon/seq.h +++ b/include/deemon/seq.h @@ -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 */ diff --git a/src/deemon/objects/seq/each.c b/src/deemon/objects/seq/each.c index d39a67756..ec69b99b1 100644 --- a/src/deemon/objects/seq/each.c +++ b/src/deemon/objects/seq/each.c @@ -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)"), @@ -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 } diff --git a/src/deemon/objects/seq/each.h b/src/deemon/objects/seq/each.h index 746285f19..7ce538013 100644 --- a/src/deemon/objects/seq/each.h +++ b/src/deemon/objects/seq/each.h @@ -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 @@ -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 */ diff --git a/src/dex/rt/librt.c b/src/dex/rt/librt.c index daa698ad1..417ba0833 100644 --- a/src/dex/rt/librt.c +++ b/src/dex/rt/librt.c @@ -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"); @@ -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())); @@ -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); @@ -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 */