1
/* A serialization context is a container for a set of objects
2
* that exist per compilation unit and cross the compile-time /
5
#include "../6model/sixmodelobject.h"
6
static INTVAL smo_id = 0;
8
pmclass SerializationContext auto_attrs dynpmc group nqp {
9
/* The handle of this SC. */
12
/* The root set of objects that live in this SC. */
13
ATTR PMC *root_objects;
15
/* The root set of STables that live in this SC. */
16
ATTR PMC *root_stables;
18
/* The root set of code refs that live in this SC. */
21
/* Description (probably the file name) if any. */
22
ATTR STRING *description;
24
/* Repossession info. The following RIA and RPA have matching indexes, each
25
* representing the integer of an object in our root set along with the SC
26
* that the object was originally from. */
27
ATTR PMC *rep_indexes;
31
PMC *root_objects = Parrot_pmc_new(interp, enum_class_ResizablePMCArray);
32
PMC *root_stables = Parrot_pmc_new(interp, enum_class_ResizablePMCArray);
33
PMC *root_codes = Parrot_pmc_new(interp, enum_class_ResizablePMCArray);
34
PMC *rep_indexes = Parrot_pmc_new(interp, enum_class_ResizableIntegerArray);
35
PMC *rep_scs = Parrot_pmc_new(interp, enum_class_ResizablePMCArray);
36
SET_ATTR_root_objects(interp, SELF, root_objects);
37
SET_ATTR_root_stables(interp, SELF, root_stables);
38
SET_ATTR_root_codes(interp, SELF, root_codes);
39
SET_ATTR_rep_indexes(interp, SELF, rep_indexes);
40
SET_ATTR_rep_scs(interp, SELF, rep_scs);
41
PObj_custom_mark_SET(SELF);
43
smo_id = Parrot_pmc_get_type_str(interp, Parrot_str_new(interp, "SixModelObject", 0));
46
VTABLE void set_string_native(STRING *handle) {
47
SET_ATTR_handle(interp, SELF, handle);
51
PMC *root_objects, *root_stables, *root_codes, *rep_indexes, *rep_scs;
52
STRING *handle, *description;
53
GET_ATTR_root_objects(interp, SELF, root_objects);
54
Parrot_gc_mark_PMC_alive(INTERP, root_objects);
55
GET_ATTR_root_stables(interp, SELF, root_stables);
56
Parrot_gc_mark_PMC_alive(INTERP, root_stables);
57
GET_ATTR_root_codes(interp, SELF, root_codes);
58
Parrot_gc_mark_PMC_alive(INTERP, root_codes);
59
GET_ATTR_handle(interp, SELF, handle);
60
Parrot_gc_mark_STRING_alive(INTERP, handle);
61
GET_ATTR_description(interp, SELF, description);
62
Parrot_gc_mark_STRING_alive(INTERP, description);
63
GET_ATTR_rep_indexes(interp, SELF, rep_indexes);
64
Parrot_gc_mark_PMC_alive(INTERP, rep_indexes);
65
GET_ATTR_rep_scs(interp, SELF, rep_scs);
66
Parrot_gc_mark_PMC_alive(INTERP, rep_scs);
69
VTABLE PMC* get_pmc_keyed_int(INTVAL idx) {
71
GET_ATTR_root_objects(interp, SELF, root_objects);
72
return VTABLE_get_pmc_keyed_int(interp, root_objects, idx);
75
VTABLE PMC* get_pmc_keyed(PMC *idx) {
77
GET_ATTR_root_objects(interp, SELF, root_objects);
78
return VTABLE_get_pmc_keyed(interp, root_objects, idx);
81
VTABLE void set_pmc_keyed_int(INTVAL idx, PMC *value) {
83
GET_ATTR_root_objects(interp, SELF, root_objects);
84
VTABLE_set_pmc_keyed_int(interp, root_objects, idx, value);
85
if (value->vtable->base_type == smo_id) {
86
/* Check if the STable is already owned; if not, take it
88
if (PMC_IS_NULL(STABLE(value)->sc)) {
90
GET_ATTR_root_stables(interp, SELF, root_stables);
91
STABLE(value)->sc = SELF;
92
VTABLE_push_pmc(interp, root_stables, STABLE_PMC(value));
97
VTABLE void set_pmc_keyed(PMC *idx, PMC *value) {
99
GET_ATTR_root_objects(interp, SELF, root_objects);
100
VTABLE_set_pmc_keyed(interp, root_objects, idx, value);
103
VTABLE INTVAL elements() {
105
GET_ATTR_root_objects(interp, SELF, root_objects);
106
return VTABLE_elements(interp, root_objects);
109
METHOD INTVAL elems() {
112
GET_ATTR_root_objects(interp, SELF, root_objects);
113
elems = VTABLE_elements(interp, root_objects);
114
RETURN (INTVAL elems);
117
METHOD STRING* handle() {
119
GET_ATTR_handle(interp, SELF, handle);
120
RETURN (STRING* handle);
123
METHOD set_description(STRING *description) {
124
SET_ATTR_description(interp, SELF, description);
125
RETURN (STRING* description);
128
METHOD STRING* description() {
130
GET_ATTR_description(interp, SELF, description);
131
RETURN (STRING* description);
134
METHOD INTVAL slot_index_for(PMC *obj) {
135
/* This is kinda stupid, but it'll do for now. */
138
GET_ATTR_root_objects(interp, SELF, root_objects);
139
count = VTABLE_elements(interp, root_objects);
140
for (i = 0; i < count; i++) {
141
if (VTABLE_get_pmc_keyed_int(interp, root_objects, i) == obj) {
145
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
146
"Object does not exist in serialization context");