Skip to content

Commit

Permalink
Make CONFIG_EXPERIMENTAL_NEW_SEQUENCE_OPERATORS mandatory
Browse files Browse the repository at this point in the history
No more "experimental" -- now IT'S THE LAW!
  • Loading branch information
GrieferAtWork committed Dec 7, 2024
1 parent 73c74b3 commit cfa3256
Show file tree
Hide file tree
Showing 24 changed files with 177 additions and 12,093 deletions.
1 change: 1 addition & 0 deletions .vs/deemon-v141.sln
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{2360741E-F
..\util\test\deemon-sequence-each-contains.dee = ..\util\test\deemon-sequence-each-contains.dee
..\util\test\deemon-sequence-each.dee = ..\util\test\deemon-sequence-each.dee
..\util\test\deemon-sequence-enumerate.dee = ..\util\test\deemon-sequence-enumerate.dee
..\util\test\deemon-sequence-math.dee = ..\util\test\deemon-sequence-math.dee
..\util\test\deemon-sequence-reversed.dee = ..\util\test\deemon-sequence-reversed.dee
..\util\test\deemon-sequence-segments.dee = ..\util\test\deemon-sequence-segments.dee
..\util\test\deemon-sequence-sorted.dee = ..\util\test\deemon-sequence-sorted.dee
Expand Down
4 changes: 0 additions & 4 deletions .vs/deemon-v141.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@
<ClInclude Include="..\src\deemon\objects\seq\smap.h" />
<ClInclude Include="..\src\deemon\objects\seq\sort-impl.c.inl" />
<ClInclude Include="..\src\deemon\objects\seq\sort.h" />
<ClInclude Include="..\src\deemon\objects\seq\subrange.h" />
<ClInclude Include="..\src\deemon\objects\seq\svec.h" />
<ClInclude Include="..\src\deemon\objects\seq\typemro.h" />
<ClInclude Include="..\src\deemon\objects\seq_functions.h" />
Expand Down Expand Up @@ -465,11 +464,8 @@
<ClCompile Include="..\src\deemon\objects\seq\simpleproxy.c" />
<ClCompile Include="..\src\deemon\objects\seq\smap.c" />
<ClCompile Include="..\src\deemon\objects\seq\sort.c" />
<ClCompile Include="..\src\deemon\objects\seq\subrange.c" />
<ClCompile Include="..\src\deemon\objects\seq\svec.c" />
<ClCompile Include="..\src\deemon\objects\seq\typemro.c" />
<ClCompile Include="..\src\deemon\objects\seq_functions.c" />
<ClCompile Include="..\src\deemon\objects\seq_mutable.c" />
<ClCompile Include="..\src\deemon\objects\set.c" />
<ClCompile Include="..\src\deemon\objects\string.c" />
<ClCompile Include="..\src\deemon\objects\super.c" />
Expand Down
12 changes: 0 additions & 12 deletions .vs/deemon-v141.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -801,9 +801,6 @@
<ClInclude Include="..\src\deemon\objects\seq\sort.h">
<Filter>src\objects\seq</Filter>
</ClInclude>
<ClInclude Include="..\src\deemon\objects\seq\subrange.h">
<Filter>src\objects\seq</Filter>
</ClInclude>
<ClInclude Include="..\src\deemon\objects\seq\svec.h">
<Filter>src\objects\seq</Filter>
</ClInclude>
Expand Down Expand Up @@ -1364,21 +1361,12 @@
<ClCompile Include="..\src\deemon\objects\seq\sort.c">
<Filter>src\objects\seq</Filter>
</ClCompile>
<ClCompile Include="..\src\deemon\objects\seq\subrange.c">
<Filter>src\objects\seq</Filter>
</ClCompile>
<ClCompile Include="..\src\deemon\objects\seq\svec.c">
<Filter>src\objects\seq</Filter>
</ClCompile>
<ClCompile Include="..\src\deemon\objects\seq\typemro.c">
<Filter>src\objects\seq</Filter>
</ClCompile>
<ClCompile Include="..\src\deemon\objects\seq_functions.c">
<Filter>src\objects</Filter>
</ClCompile>
<ClCompile Include="..\src\deemon\objects\seq_mutable.c">
<Filter>src\objects</Filter>
</ClCompile>
<ClCompile Include="..\src\deemon\objects\set.c">
<Filter>src\objects</Filter>
</ClCompile>
Expand Down
1 change: 1 addition & 0 deletions .vs/deemon-v142.sln
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{2360741E-F
..\util\test\deemon-sequence-each-contains.dee = ..\util\test\deemon-sequence-each-contains.dee
..\util\test\deemon-sequence-each.dee = ..\util\test\deemon-sequence-each.dee
..\util\test\deemon-sequence-enumerate.dee = ..\util\test\deemon-sequence-enumerate.dee
..\util\test\deemon-sequence-math.dee = ..\util\test\deemon-sequence-math.dee
..\util\test\deemon-sequence-reversed.dee = ..\util\test\deemon-sequence-reversed.dee
..\util\test\deemon-sequence-segments.dee = ..\util\test\deemon-sequence-segments.dee
..\util\test\deemon-sequence-sorted.dee = ..\util\test\deemon-sequence-sorted.dee
Expand Down
4 changes: 0 additions & 4 deletions .vs/deemon-v142.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@
<ClInclude Include="..\src\deemon\objects\seq\smap.h" />
<ClInclude Include="..\src\deemon\objects\seq\sort-impl.c.inl" />
<ClInclude Include="..\src\deemon\objects\seq\sort.h" />
<ClInclude Include="..\src\deemon\objects\seq\subrange.h" />
<ClInclude Include="..\src\deemon\objects\seq\svec.h" />
<ClInclude Include="..\src\deemon\objects\seq\typemro.h" />
<ClInclude Include="..\src\deemon\objects\seq_functions.h" />
Expand Down Expand Up @@ -465,11 +464,8 @@
<ClCompile Include="..\src\deemon\objects\seq\simpleproxy.c" />
<ClCompile Include="..\src\deemon\objects\seq\smap.c" />
<ClCompile Include="..\src\deemon\objects\seq\sort.c" />
<ClCompile Include="..\src\deemon\objects\seq\subrange.c" />
<ClCompile Include="..\src\deemon\objects\seq\svec.c" />
<ClCompile Include="..\src\deemon\objects\seq\typemro.c" />
<ClCompile Include="..\src\deemon\objects\seq_functions.c" />
<ClCompile Include="..\src\deemon\objects\seq_mutable.c" />
<ClCompile Include="..\src\deemon\objects\set.c" />
<ClCompile Include="..\src\deemon\objects\string.c" />
<ClCompile Include="..\src\deemon\objects\super.c" />
Expand Down
12 changes: 0 additions & 12 deletions .vs/deemon-v142.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -801,9 +801,6 @@
<ClInclude Include="..\src\deemon\objects\seq\sort.h">
<Filter>src\objects\seq</Filter>
</ClInclude>
<ClInclude Include="..\src\deemon\objects\seq\subrange.h">
<Filter>src\objects\seq</Filter>
</ClInclude>
<ClInclude Include="..\src\deemon\objects\seq\svec.h">
<Filter>src\objects\seq</Filter>
</ClInclude>
Expand Down Expand Up @@ -1364,21 +1361,12 @@
<ClCompile Include="..\src\deemon\objects\seq\sort.c">
<Filter>src\objects\seq</Filter>
</ClCompile>
<ClCompile Include="..\src\deemon\objects\seq\subrange.c">
<Filter>src\objects\seq</Filter>
</ClCompile>
<ClCompile Include="..\src\deemon\objects\seq\svec.c">
<Filter>src\objects\seq</Filter>
</ClCompile>
<ClCompile Include="..\src\deemon\objects\seq\typemro.c">
<Filter>src\objects\seq</Filter>
</ClCompile>
<ClCompile Include="..\src\deemon\objects\seq_functions.c">
<Filter>src\objects</Filter>
</ClCompile>
<ClCompile Include="..\src\deemon\objects\seq_mutable.c">
<Filter>src\objects</Filter>
</ClCompile>
<ClCompile Include="..\src\deemon\objects\set.c">
<Filter>src\objects</Filter>
</ClCompile>
Expand Down
177 changes: 11 additions & 166 deletions include/deemon/seq.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,146 +50,12 @@ DECL_BEGIN



/* TODO: Once `CONFIG_EXPERIMENTAL_NEW_SEQUENCE_OPERATORS' is done, re-write this documentation! */
/* NOTE: There are no `DeeSeq_Check()' macros because they wouldn't make sense.
* Being derived from `DeeSeq_Type' is _NOT_ mandatory when writing a
* sequence class. The only thing that it does do is allow usercode
* to safely query whether or not an object implements all of the standard
* sequence functions.
* Instead, a sequence object `ob' should be
* detected using `DeeType_IsSequence(Dee_TYPE(ob))'.
* The following things are required from sub-class of `Sequence':
/* The following things are required from sub-class of `Sequence':
* - Must either implement `tp_iter' or `tp_sizeob' + `tp_getitem'
* The following things are implemented by `Sequence':
* - Abstraction that automatically defines the following operators:
* - tp_iter
* - tp_sizeob
* - tp_contains
* - tp_getitem (for integer-index argument only)
* - tp_getrange (for integer-index argument only)
* - tp_eq (Lexicographic element-wise compare with other iterables)
* - tp_ne (...)
* - tp_lo
* - tp_le
* - tp_gr
* - tp_ge
* - tp_add (Concat 2 sequences)
* - tp_mul (Repeat a sequence some number of times)
* - tp_or (Repeat the left sequence, then only yield elements from right not found in the left one as well)
* - tp_and (Convert the left sequence into a set, then only yield elements from the right found in that set)
* - tp_repr (Surrounded by `{ ... }', print a comma-separated list of all elements)
* - tp_bool (Indicates if the sequence is non-empty)
* - Abstraction that automatically defines the following getsets:
* - `isempty: bool' (Read-only; same as `tp_bool', but negated)
* - `isnonempty: bool' (Read-only; same as `tp_bool')
* - `length: int' (Read-only; same as `tp_sizeob')
* - `first: Object' (Read-write; same as `tp_getitem(0)' / `tp_setitem(0)')
* - `last: Object' (Read-write; same as `tp_getitem(length - 1)' / `tp_setitem(length - 1)')
* - `each: Sequence' (Read-only; Proxy sequence for construction expressions to-be applied to each element)
* - `ids: {int...}' (Read-only; Proxy sequence for object IDs for elements)
* - `types: {Type...}' (Read-only; Proxy sequence for element types)
* - `classes: {Type...}' (Read-only; Proxy sequence for element classes)
* - `isfrozen: bool' (Read-only; returns true if the sequence is frozen)
* - `frozen: Sequence' (Read-only; returns a frozen copy of the sequence)
* - Abstraction that automatically defines the following class getsets:
* - `Iterator: Type'
* Evaluates to the internally used iterator type when `DeeObject_Iter()' would
* return it. Otherwise, accessing this field raises an `Error.AttributeError'.
* The intention here is that a sub-class defining its own iterator should override
* this field in order to return its own type.
* - Abstraction that automatically defines the following methods:
* - `front(): Object'
* - `back(): Object'
* - `reduce(combine: Callable, init?): Object'
* - Call `combine()' on two consecutive objects, reusing the result as
* the first argument in the next call; return the final sum-style value.
* NOTE: When the sequence is empty, return `none'
* - `filter(keep: Callable): Sequence'
* - Same as `(for (local x: this) if (keep(x)) x)'
* - `sum(): Object'
* - Same as `reduce((a, b) -> a + b);' or `this + ...'
* - Preferred way to concat sequences containing strings:
* - `print ["foo", "bar", "foobar"].sum(); // "foobarfoobar"'
* - `any(): bool'
* - Same as `reduce((a, b) -> a || b, false);', but stop on the first `true'.
* - Same as `this || ...'
* - `all(): bool'
* - Same as `reduce((a, b) -> a && b, true);', but stop on the first `false'.
* - Same as `this && ...'
* - `parity(): bool'
* - Same as `((#this.filter(x -> !!x)) % 2) != 0'
* - `min(key: Callable = none): Object'
* - `max(key: Callable = none): Object'
* - `count(ob: Object, key: Callable = none): int'
* - `locate(ob: Object, key: Callable = none): Object'
* - `rlocate(ob: Object, key: Callable = none): Object'
* - `locateall(ob: Object, key: Callable = none): Sequence'
* - `transform(callable transformation): Sequence'
* - Invoke `transformation()' on all items and return a sequence of all the results.
* - Same as `(for (local x: this) transformation(x));'
* - `contains(ob: Object, key: Callable = none): bool'
* - Same as the `tp_contains' operator, but allows for a key function to be used.
* - `partition(ob: Object, key: Callable = none): (Sequence, (ob), Sequence)'
* - `rpartition(ob: Object, key: Callable = none): (Sequence, (ob), Sequence)'
* - `startswith(ob: Object, key: Callable = none): bool'
* - `endswith(ob: Object, key: Callable = none): bool'
* - `find(ob: Object, key: Callable = none): int'
* - `rfind(ob: Object, key: Callable = none): int'
* - `index(ob: Object, key: Callable = none): int'
* - `rindex(ob: Object, key: Callable = none): int'
* - `join(items: Sequence): Sequence'
* - `strip(ob: Object, key: Callable = none): Sequence'
* - `lstrip(ob: Object, key: Callable = none): Sequence'
* - `rstrip(ob: Object, key: Callable = none): Sequence'
* - `split(sep: Object, key: Callable = none): Sequence'
* - `reversed(): Sequence'
* - `sorted(key: Callable = none): Sequence'
* - `segments(segsize: int): Sequence'
* - `countseq(seq: Sequence, key: Callable = none): int'
* - `containsseq(seq: Sequence, key: Callable = none): bool'
* - `partitionseq(seq: Sequence, key: Callable = none): (Sequence, Sequence, Sequence)'
* - `rpartitionseq(seq: Sequence, key: Callable = none): (Sequence, Sequence, Sequence)'
* - `startswithseq(seq: Sequence, key: Callable = none): bool'
* - `endswithseq(seq: Sequence, key: Callable = none): bool'
* - `findseq(seq: Sequence, key: Callable = none): int'
* - `rfindseq(seq: Sequence, key: Callable = none): int'
* - `indexseq(seq: Sequence, key: Callable = none): int'
* - `rindexseq(seq: Sequence, key: Callable = none): int'
* - `stripseq(items: Sequence, key: Callable = none): Sequence'
* - `lstripseq(items: Sequence, key: Callable = none): Sequence'
* - `rstripseq(items: Sequence, key: Callable = none): Sequence'
* - `splitseq(sep_seq: Sequence, key: Callable = none): Sequence'
* - ... // More exist; please consult http://localhost:8080/modules/deemon/Sequence
* Some operations (Such as `tp_add') will create instances of special objects
* that will only start invoking underlying operators when worked with:
* >> function foo() {
* >> print "In foo()";
* >> yield 10;
* >> }
* >> function bar() {
* >> print "In bar()";
* >> yield 20;
* >> }
* >>
* >> local combine = foo()+bar(); // Create a merged-sequence object
* >> // At this point, neither function has started executing, yet.
* >> for (local x: combine) {
* >> print x; // "In foo()", "10", "In bar()", "20"
* >> }
* Other operators/functions may also invoke iteration more than once.
* Which operators/functions do this is intentionally
* not revealed and is subject to change in the future.
* Code expecting certain types of sequences (or mutable sequence for that)
* should always perform an explicit cast to the desired sequence type:
* >> local a = [5, 10, 20, 30, 5];
* >> local b = a.strip(5);
* >> for (local x: b)
* >> print x; // 10 20 30
* >> print type b; // Undefined and subject to change
* >> b = [b...]; // Explicit cast to list; same as `b = list(b);'
* HINT: Instantiating `seq' as-is will yield `Dee_EmptySeq',
* which in return is re-used internally as a placeholder
* to represent an empty, general-purpose sequence. */
* Many things are implemented by `Sequence'.
* For a full list, see http://localhost:8080/modules/deemon/Sequence
*
* HINT: Instantiating `Sequence' as-is will return a copy of `Dee_EmptySeq' */
DDATDEF DeeTypeObject DeeSeq_Type; /* `Sequence from deemon' */
#define DeeSeq_Check(ob) DeeObject_Implements(ob, &DeeSeq_Type)

Expand Down Expand Up @@ -468,6 +334,12 @@ struct Dee_type_nsi {
;
};

/* Lookup the closest NSI descriptor for `tp', or return `NULL'
* if the top-most type implementing any sequence operator doesn't
* expose NSI functionality. */
DFUNDEF WUNUSED NONNULL((1)) struct Dee_type_nsi const *DCALL
DeeType_NSI(DeeTypeObject *__restrict tp); /* !!! DEPRECATED !!! */


/*****************************************************************************************/
/* */
Expand Down Expand Up @@ -527,12 +399,6 @@ DFUNDEF ATTR_CONST WUNUSED size_t DCALL
DeeSeqRange_DoClamp_n(Dee_ssize_t start, size_t size);


/* Lookup the closest NSI descriptor for `tp', or return `NULL'
* if the top-most type implementing any sequence operator doesn't
* expose NSI functionality. */
DFUNDEF WUNUSED NONNULL((1)) struct Dee_type_nsi const *DCALL
DeeType_NSI(DeeTypeObject *__restrict tp);

/* Create new range sequence objects. */
DFUNDEF WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL
DeeRange_New(DeeObject *begin, DeeObject *end, DeeObject *step);
Expand All @@ -548,27 +414,6 @@ DFUNDEF WUNUSED NONNULL((1)) DREF DeeObject *DCALL DeeSeq_Min(DeeObject *self);
DFUNDEF WUNUSED NONNULL((1)) DREF DeeObject *DCALL DeeSeq_Max(DeeObject *self);


#ifdef CONFIG_BUILDING_DEEMON
#ifndef CONFIG_EXPERIMENTAL_NEW_SEQUENCE_OPERATORS

/* @return: == -2: An error occurred.
* @return: == -1: `self < some_object'
* @return: == 0: Objects compare as equal
* @return: == 1: `self > some_object' */
INTDEF WUNUSED NONNULL((1)) int DCALL DeeSeq_CompareIV(DeeObject *lhs, DeeObject *const *rhsv, size_t rhsc); /* ITERATOR <=> VECTOR */
INTDEF WUNUSED NONNULL((1, 2)) int DCALL DeeSeq_CompareII(DeeObject *lhs, DeeObject *rhs); /* ITERATOR <=> ITERATOR */
INTDEF WUNUSED NONNULL((1, 2)) int DCALL DeeSeq_CompareIS(DeeObject *lhs, DeeObject *rhs); /* ITERATOR <=> SEQUENCE */

/* @return: == -1: An error occurred.
* @return: == 0: Sequences differ
* @return: == 1: Sequences are equal */
INTDEF WUNUSED NONNULL((1)) int DCALL DeeSeq_EqIV(DeeObject *lhs, DeeObject *const *rhsv, size_t rhsc); /* ITERATOR == VECTOR */
INTDEF WUNUSED NONNULL((1, 2)) int DCALL DeeSeq_EqII(DeeObject *lhs, DeeObject *rhs); /* ITERATOR == ITERATOR */
INTDEF WUNUSED NONNULL((1, 2)) int DCALL DeeSeq_EqIS(DeeObject *lhs, DeeObject *rhs); /* ITERATOR == SEQUENCE */
#endif /* !CONFIG_EXPERIMENTAL_NEW_SEQUENCE_OPERATORS */
#endif /* CONFIG_BUILDING_DEEMON */


/* Possible return values for `DeeType_GetSeqClass()' */
#define Dee_SEQCLASS_UNKNOWN 0 /* Never returned by `DeeType_GetSeqClass()' (used internally) */
#define Dee_SEQCLASS_NONE 1 /* Type does not inherit from "Sequence" */
Expand Down
15 changes: 0 additions & 15 deletions include/deemon/set.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,6 @@ DDATDEF DeeObject DeeSet_UniversalInstance;
#endif /* !GUARD_DEEMON_OBJECTS_SEQ_DEFAULT_SETS_C */
#define Dee_UniversalSet (&DeeSet_UniversalInstance)


#ifdef CONFIG_BUILDING_DEEMON
#ifndef CONFIG_EXPERIMENTAL_NEW_SEQUENCE_OPERATORS
INTDEF WUNUSED NONNULL((1)) DREF DeeObject *DCALL DeeSet_Invert(DeeObject *__restrict self);
INTDEF WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL DeeSet_OperatorAdd(DeeObject *lhs, DeeObject *rhs);
INTDEF WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL DeeSet_OperatorSub(DeeObject *lhs, DeeObject *rhs);
INTDEF WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL DeeSet_OperatorAnd(DeeObject *lhs, DeeObject *rhs);
INTDEF WUNUSED NONNULL((1, 2)) DREF DeeObject *DCALL DeeSet_OperatorXor(DeeObject *lhs, DeeObject *rhs);
INTDEF WUNUSED NONNULL((1, 2)) int DCALL DeeSet_IsSubSet(DeeObject *lhs, DeeObject *rhs);
INTDEF WUNUSED NONNULL((1, 2)) int DCALL DeeSet_IsTrueSubSet(DeeObject *lhs, DeeObject *rhs);
INTDEF WUNUSED NONNULL((1, 2)) int DCALL DeeSet_IsSameSet(DeeObject *lhs, DeeObject *rhs);
#endif /* !CONFIG_EXPERIMENTAL_NEW_SEQUENCE_OPERATORS */
INTDEF WUNUSED NONNULL((1, 2)) int DCALL DeeSet_IsDisjoint(DeeObject *lhs, DeeObject *rhs);
#endif /* CONFIG_BUILDING_DEEMON */

DECL_END

#endif /* !GUARD_DEEMON_SET_H */
2 changes: 1 addition & 1 deletion lib/rt/builtins.dee
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ local __objects = deemon.List {
/* 0x0189 */ deemon.Sequence.contains,
/* 0x018a */ net.socket,
/* 0x018b */ deemon.hasattr,
/* 0x018c */ none, /* TODO: SeqSubRangeIterator_Type (CONFIG_EXPERIMENTAL_NEW_SEQUENCE_OPERATORS) */
/* 0x018c */ rt.IterWithSizeAndGetItem, /* SeqSubRangeIterator_Type (lots of other types would match here also, but we can only set one) */
/* 0x018d */ none, /* DeeSocketFile_Type -- Sockets no longer implement the File protocol */
/* 0x018e */ none, /* DeeSocketFileTo_Type -- Sockets no longer implement the File protocol */
/* 0x018f */ rt.StringIterator, /* DeeWideStringIterator_Type */
Expand Down
Loading

0 comments on commit cfa3256

Please sign in to comment.