Skip to content

Commit 64cf467

Browse files
committed
Cleanup & a few more serialize operators
1 parent 2f60c07 commit 64cf467

File tree

17 files changed

+399
-76
lines changed

17 files changed

+399
-76
lines changed

include/deemon/serial.h

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "types.h"
2727
/**/
2828

29-
#include <hybrid/typecore.h>
29+
#include <hybrid/typecore.h> /* __UINTPTR_TYPE__ */
3030

3131
/*
3232
* Object serialization is a general-purpose API to:
@@ -57,6 +57,41 @@ DECL_BEGIN
5757
struct Dee_serial;
5858
typedef struct Dee_serial DeeSerial;
5959

60+
#if 0
61+
PRIVATE WUNUSED NONNULL((1, 2)) int DCALL
62+
myobject_serialize(MyObject *__restrict self,
63+
DeeSerial *__restrict writer,
64+
Dee_seraddr_t addr) {
65+
#define ADDROF(field) (addr + offsetof(MyObject, field))
66+
MyObject *out = DeeSerial_Addr2Mem(writer, addr, MyObject);
67+
/* ... */
68+
return 0;
69+
err:
70+
return -1;
71+
#undef ADDROF
72+
}
73+
74+
PRIVATE WUNUSED NONNULL((1, 2)) Dee_seraddr_t DCALL
75+
myobject_serialize(MyObject *__restrict self,
76+
DeeSerial *__restrict writer) {
77+
MyObject *out;
78+
size_t sizeof_self = _Dee_MallococBufsize(offsetof(MyObject, mo_vardata),
79+
self->mo_count,
80+
sizeof(MyObjectItem));
81+
Dee_seraddr_t out_addr = DeeSerial_ObjectMalloc(writer, sizeof_self, self);
82+
#define ADDROF(field) (out_addr + offsetof(MyObject, field))
83+
if unlikely(!Dee_SERADDR_ISOK(out_addr))
84+
goto err;
85+
out = DeeSerial_Addr2Mem(writer, out_addr, MyObject);
86+
out->mo_count = self->mo_count;
87+
/* ... */
88+
return out_addr;
89+
err:
90+
return Dee_SERADDR_INVALID;
91+
#undef ADDROF
92+
}
93+
#endif
94+
6095
/* TODO: "DeeSerial" can also be used to implement "deepcopy" (in a way that
6196
* solves the problem of non-GC objects being copied whilst some nested
6297
* GC object holding another reference to the original object; in the

include/deemon/util/lock.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ typedef char Dee_event_t;
181181
#define Dee_EVENT_INIT_EX(set) 0
182182
#define Dee_event_init_set(self) (void)0
183183
#define Dee_event_init(self) (void)0
184+
#define Dee_event_init_ex(self, set) (void)0
184185
#define Dee_event_cinit_set(self) (void)0
185186
#define Dee_event_cinit(self) (void)0
186187
#define Dee_event_get(self) 1
@@ -605,16 +606,17 @@ typedef struct {
605606
* 2: event has NOT been triggered, and there may be waiting threads */
606607
} Dee_event_t;
607608

608-
#define Dee_EVENT_INIT_SET { 0 }
609-
#define Dee_EVENT_INIT { 1 }
610-
#define Dee_EVENT_INIT_EX(set) { (set) ? 0 : 1 }
611-
#define Dee_event_init_set(self) (void)((self)->ev_state = 0)
612-
#define Dee_event_init(self) (void)((self)->ev_state = 1)
613-
#define Dee_event_cinit_set(self) (void)(Dee_ASSERT((self)->ev_state == 0))
614-
#define Dee_event_cinit(self) (void)(Dee_ASSERT((self)->ev_state == 0), (self)->ev_state = 1)
615-
#define Dee_event_get(self) (__hybrid_atomic_load(&(self)->ev_state, __ATOMIC_ACQUIRE) == 0)
616-
#define Dee_event_set(self) (void)Dee_event_set_ex(self)
617-
#define Dee_event_clear(self) (void)Dee_event_clear_ex(self)
609+
#define Dee_EVENT_INIT_SET { 0 }
610+
#define Dee_EVENT_INIT { 1 }
611+
#define Dee_EVENT_INIT_EX(set) { (set) ? 0 : 1 }
612+
#define Dee_event_init_set(self) (void)((self)->ev_state = 0)
613+
#define Dee_event_init(self) (void)((self)->ev_state = 1)
614+
#define Dee_event_init_ex(self, set) (void)((self)->ev_state = (set) ? 0 : 1)
615+
#define Dee_event_cinit_set(self) (void)(Dee_ASSERT((self)->ev_state == 0))
616+
#define Dee_event_cinit(self) (void)(Dee_ASSERT((self)->ev_state == 0), (self)->ev_state = 1)
617+
#define Dee_event_get(self) (__hybrid_atomic_load(&(self)->ev_state, __ATOMIC_ACQUIRE) == 0)
618+
#define Dee_event_set(self) (void)Dee_event_set_ex(self)
619+
#define Dee_event_clear(self) (void)Dee_event_clear_ex(self)
618620
#define Dee_event_set_ex(self) \
619621
(__hybrid_atomic_xch(&(self)->ev_state, 0, __ATOMIC_SEQ_CST) > 1 \
620622
? (DeeFutex_WakeAll(&(self)->ev_state), 1) \

lib/rt/gen/unpack.dee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* claim that you wrote the original software. If you use this software *
1313
* in a product, an acknowledgement (see the following) in the product *
1414
* documentation is required: *
15-
* Portions Copyright (c) 2018-2024 Griefer@Work *
15+
* Portions Copyright (c) 2018-2026 Griefer@Work *
1616
* 2. Altered source versions must be plainly marked as such, and must not be *
1717
* misrepresented as being the original software. *
1818
* 3. This notice may not be removed or altered from any source distribution. *

src/deemon/execute/modpath.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,11 +778,19 @@ extern /*IMAGE_DOS_HEADER*/ __BYTE_TYPE__ const __ImageBase[];
778778
#define _Dee_MODULE_DEXDATA_INIT_HANDLE DeeSystem_DlOpen_FAILED
779779
#endif /* !... */
780780

781+
#ifdef Dee_MODULE_DEXDATA_HAVE_LOADSTRING
782+
PRIVATE struct Dee_module_dexinfo deemon_dexinfo = {};
783+
#endif /* Dee_MODULE_DEXDATA_HAVE_LOADSTRING */
784+
781785
INTERN struct Dee_module_dexdata deemon_dexdata = {
782786
/* .mdx_module = */ &DeeModule_Deemon,
783787
/* .mdx_export = */ NULL,
784788
/* .mdx_handle = */ _Dee_MODULE_DEXDATA_INIT_HANDLE,
789+
#ifdef Dee_MODULE_DEXDATA_HAVE_LOADSTRING
790+
/* .mdx_info = */ &deemon_dexinfo,
791+
#else /* Dee_MODULE_DEXDATA_HAVE_LOADSTRING */
785792
/* .mdx_info = */ NULL,
793+
#endif /* !Dee_MODULE_DEXDATA_HAVE_LOADSTRING */
786794
/* .mdx_init = */ NULL,
787795
/* .mdx_fini = */ NULL,
788796
/* .mdx_clear = */ NULL

src/deemon/objects/object.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include <deemon/none.h>
4646
#include <deemon/object.h>
4747
#include <deemon/objmethod.h>
48+
#include <deemon/operator-hints.h>
4849
#include <deemon/seq.h>
4950
#include <deemon/serial.h>
5051
#include <deemon/set.h>
@@ -4732,15 +4733,15 @@ PUBLIC ATTR_PURE WUNUSED NONNULL((1)) size_t
47324733
} else
47334734
DeeSlab_ENUMERATE(CHECK_ALLOCATOR)
47344735
#undef CHECK_ALLOCATOR
4735-
;
4736+
{}
47364737
} else {
47374738
#define CHECK_ALLOCATOR(index, size) \
47384739
if (tp_free == &DeeObject_SlabFree##size) { \
47394740
return size * sizeof(void *); \
47404741
} else
47414742
DeeSlab_ENUMERATE(CHECK_ALLOCATOR)
47424743
#undef CHECK_ALLOCATOR
4743-
;
4744+
{}
47444745
}
47454746
#endif /* !CONFIG_NO_OBJECT_SLABS */
47464747
return 0;

src/deemon/objects/seq.c

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2495,7 +2495,7 @@ INTERN_TPCONST struct type_method tpconst seq_methods[] = {
24952495

24962496
/* TODO: dropwhile(cond:?DCallble)->?.
24972497
* Matches everything not matched by ?#takewhile:
2498-
* >> function takeafter(cond: Callble): Sequence {
2498+
* >> function dropwhile(cond: Callble): Sequence {
24992499
* >> local iter = (this as Sequence).operator iter();
25002500
* >> foreach (local item: iter) {
25012501
* >> if (!cond(item)) {
@@ -2507,6 +2507,51 @@ INTERN_TPCONST struct type_method tpconst seq_methods[] = {
25072507
* >> yield item;
25082508
* >> } */
25092509

2510+
/* TODO: groupby(key:?DCallable)->?M?O?S?O
2511+
* Apply @key to every element of @this ?. and use the return value
2512+
* as a key into a mapping that will later be returned. Every item
2513+
* of that mapping is then another sequence containing all elements
2514+
* of @this for that same key. The order of elements within these
2515+
* sub-sequences matches the order of those elements in @this.
2516+
* >> function groupby(key: Callable): {Object: {Object...}} {
2517+
* >> // Actual impl doesn't use "Dict" and returns an abstract proxy instead
2518+
* >> local result = Dict();
2519+
* >> for (local item: this as Sequence) {
2520+
* >> result.setdefault(key(item), []).append(item);
2521+
* >> }
2522+
* >> return result;
2523+
* >> } */
2524+
2525+
/* TODO: partitionby(key?:?DCallable)->?S?T2?O?S?O
2526+
* Split @this ?. into many smaller, non-empty partition. A new partition
2527+
* is started between every 2 adjacent elements of @this for which @key
2528+
* returns a different value. When @key isn't given, `x -> x` is used.
2529+
* Returns {(PartitionKey, {PartitionItem...})...}
2530+
* >> function partitionby(key: Callable): {(Object, {Object...})...} {
2531+
* >> local iter = (this as Sequence).operator iter();
2532+
* >> foreach (local item: iter) {
2533+
* >> local currentPart = [item];
2534+
* >> local currentKey = key(item);
2535+
* >> foreach (item: iter) {
2536+
* >> local newKey = key(item);
2537+
* >> if (currentKey != newKey) {
2538+
* >> yield currentPart;
2539+
* >> currentPart = [];
2540+
* >> currentKey = newKey;
2541+
* >> }
2542+
* >> currentPart.append(item);
2543+
* >> }
2544+
* >> yield (currentKey, currentPart);
2545+
* >> break;
2546+
* >> }
2547+
* >> } */
2548+
2549+
/* TODO: get(index:?Dint,def:?O=!N)->?O
2550+
* Re-purpose the old (and long-deprecated) "get" function and have
2551+
* it implement the equivalent of Mapping.get, but for Sequence (i.e.
2552+
* be a high-level wrapper around "seq_operator_trygetitem" that
2553+
* returns "def" if "index" doesn't exist or isn't bound) */
2554+
25102555
/* TODO: pairwise->?S?T2?O?O
25112556
* Yield every element of @this sequence (except for the first) as a pair (predecessor, elem):
25122557
* >> property pairwise: {(Object, Object)...} = {

src/dex/_strexec/libjit.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ enum {
6161
TOK_ASSIGN = '=',
6262
TOK_AT = '@',
6363
TOK_BACKSLASH = '\\',
64-
TOK_COLON = ':',
64+
TOK_COLON = ':',
6565
TOK_COMMA = ',',
6666
TOK_DIV = '/',
6767
TOK_DOT = '.',
@@ -136,7 +136,7 @@ enum {
136136
TOK_NEG = TOK_SUB,
137137
TOK_LOWER = TOK_LANGLE,
138138
TOK_GREATER = TOK_RANGLE,
139-
/* TOK_COLON_COLON = TOK_NAMESPACE, */
139+
/* TOK_COLON_COLON = TOK_NAMESPACE, */
140140
/* TOK_LOWER_GREATER = TOK_LOGT, */
141141
/* TOK_LANGLE_RANGLE = TOK_LOGT, */
142142
TOK_LANGLE1 = TOK_LANGLE,

0 commit comments

Comments
 (0)