Skip to content

Commit 1516bd2

Browse files
committed
Add a Serialization Context PMC. Just bare bones for now.
1 parent 97580b7 commit 1516bd2

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

build/Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ DYNOPS = $(OPS_DIR)/$(OPS)$(LOAD_EXT)
150150
PMC_SOURCES = $(PMC_DIR)/stable.pmc $(PMC_DIR)/rakudoobject.pmc \
151151
$(PMC_DIR)/repr.pmc $(PMC_DIR)/dispatchersub.pmc \
152152
$(PMC_DIR)/nqpmultisig.pmc $(PMC_DIR)/nqplexinfo.pmc \
153-
$(PMC_DIR)/nqplexpad.pmc
153+
$(PMC_DIR)/nqplexpad.pmc $(PMC_DIR)/serializationcontext.pmc
154154

155155
OPS_SOURCE = nqp.ops
156156

src/pmc/serializationcontext.pmc

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/* A serialization context is a container for a set of objects
2+
* that exist per compilation unit and cross the compile-time /
3+
* runtime boundary.*/
4+
pmclass SerializationContext auto_attrs dynpmc group nqp {
5+
/* The handle of this SC. */
6+
ATTR STRING *handle;
7+
8+
/* The set of objects that live in this SC. */
9+
ATTR PMC *root_objects;
10+
11+
VTABLE void init() {
12+
PMC *root_objects = pmc_new(interp, enum_class_ResizablePMCArray);
13+
SETATTR_SerializationContext_root_objects(interp, SELF, root_objects);
14+
PObj_custom_mark_SET(SELF);
15+
}
16+
17+
VTABLE void set_string_native(STRING *handle) {
18+
SETATTR_SerializationContext_handle(interp, SELF, handle);
19+
}
20+
21+
VTABLE void mark() {
22+
PMC *root_objects;
23+
STRING *handle;
24+
GETATTR_SerializationContext_root_objects(interp, SELF, root_objects);
25+
Parrot_gc_mark_PMC_alive(INTERP, root_objects);
26+
GETATTR_SerializationContext_handle(interp, SELF, handle);
27+
Parrot_gc_mark_STRING_alive(INTERP, handle);
28+
}
29+
30+
VTABLE PMC* get_pmc_keyed_int(INTVAL idx) {
31+
PMC *root_objects;
32+
GETATTR_SerializationContext_root_objects(interp, SELF, root_objects);
33+
return VTABLE_get_pmc_keyed_int(interp, root_objects, idx);
34+
}
35+
36+
VTABLE PMC* get_pmc_keyed(PMC *idx) {
37+
PMC *root_objects;
38+
GETATTR_SerializationContext_root_objects(interp, SELF, root_objects);
39+
return VTABLE_get_pmc_keyed(interp, root_objects, idx);
40+
}
41+
42+
VTABLE void set_pmc_keyed_int(INTVAL idx, PMC *value) {
43+
PMC *root_objects;
44+
GETATTR_SerializationContext_root_objects(interp, SELF, root_objects);
45+
VTABLE_set_pmc_keyed_int(interp, root_objects, idx, value);
46+
}
47+
48+
VTABLE void set_pmc_keyed(PMC *idx, PMC *value) {
49+
PMC *root_objects;
50+
GETATTR_SerializationContext_root_objects(interp, SELF, root_objects);
51+
VTABLE_set_pmc_keyed(interp, root_objects, idx, value);
52+
}
53+
54+
METHOD INTVAL elems() {
55+
PMC *root_objects;
56+
INTVAL elems;
57+
GETATTR_SerializationContext_root_objects(interp, SELF, root_objects);
58+
elems = VTABLE_elements(interp, root_objects);
59+
RETURN (INTVAL elems);
60+
}
61+
62+
METHOD STRING* handle() {
63+
STRING *handle;
64+
GETATTR_SerializationContext_handle(interp, SELF, handle);
65+
RETURN (STRING* handle);
66+
}
67+
}

0 commit comments

Comments
 (0)