-
Notifications
You must be signed in to change notification settings - Fork 135
/
serializationcontext.pmc
110 lines (93 loc) · 3.69 KB
/
serializationcontext.pmc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* A serialization context is a container for a set of objects
* that exist per compilation unit and cross the compile-time /
* runtime boundary.*/
/* HEADERIZER HFILE: none */
/* HEADERIZER BEGIN: static */
/* HEADERIZER END: static */
pmclass SerializationContext auto_attrs {
/* The handle of this SC. */
ATTR STRING *handle;
/* The root set of objects that live in this SC. */
ATTR PMC *root_objects;
/* Description (probably the file name) if any. */
ATTR STRING *description;
VTABLE void init() {
PMC *root_objects = pmc_new(interp, enum_class_ResizablePMCArray);
SETATTR_SerializationContext_root_objects(interp, SELF, root_objects);
PObj_custom_mark_SET(SELF);
}
VTABLE void set_string_native(STRING *handle) {
SETATTR_SerializationContext_handle(interp, SELF, handle);
}
VTABLE void mark() {
PMC *root_objects;
STRING *handle, *description;
GETATTR_SerializationContext_root_objects(interp, SELF, root_objects);
Parrot_gc_mark_PMC_alive(INTERP, root_objects);
GETATTR_SerializationContext_handle(interp, SELF, handle);
Parrot_gc_mark_STRING_alive(INTERP, handle);
GETATTR_SerializationContext_description(interp, SELF, description);
Parrot_gc_mark_STRING_alive(INTERP, description);
}
VTABLE PMC* get_pmc_keyed_int(INTVAL idx) {
PMC *root_objects;
GETATTR_SerializationContext_root_objects(interp, SELF, root_objects);
return VTABLE_get_pmc_keyed_int(interp, root_objects, idx);
}
VTABLE PMC* get_pmc_keyed(PMC *idx) {
PMC *root_objects;
GETATTR_SerializationContext_root_objects(interp, SELF, root_objects);
return VTABLE_get_pmc_keyed(interp, root_objects, idx);
}
VTABLE void set_pmc_keyed_int(INTVAL idx, PMC *value) {
PMC *root_objects;
GETATTR_SerializationContext_root_objects(interp, SELF, root_objects);
VTABLE_set_pmc_keyed_int(interp, root_objects, idx, value);
}
VTABLE void set_pmc_keyed(PMC *idx, PMC *value) {
PMC *root_objects;
GETATTR_SerializationContext_root_objects(interp, SELF, root_objects);
VTABLE_set_pmc_keyed(interp, root_objects, idx, value);
}
METHOD INTVAL elems() {
PMC *root_objects;
INTVAL elems;
GETATTR_SerializationContext_root_objects(interp, SELF, root_objects);
elems = VTABLE_elements(interp, root_objects);
RETURN(INTVAL elems);
}
METHOD STRING* handle() {
STRING *handle;
GETATTR_SerializationContext_handle(interp, SELF, handle);
RETURN(STRING* handle);
}
METHOD set_description(STRING *description) {
SETATTR_SerializationContext_description(interp, SELF, description);
RETURN(STRING* description);
}
METHOD STRING* description() {
STRING *description;
GETATTR_SerializationContext_description(interp, SELF, description);
RETURN(STRING* description);
}
METHOD INTVAL slot_index_for(PMC *obj) {
/* This is kinda stupid, but it'll do for now. */
PMC *root_objects;
INTVAL i, count;
GETATTR_SerializationContext_root_objects(interp, SELF, root_objects);
count = VTABLE_elements(interp, root_objects);
for (i = 0; i < count; i++) {
if (VTABLE_get_pmc_keyed_int(interp, root_objects, i) == obj) {
RETURN(INTVAL i);
}
}
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Object does not exist in serialization context");
}
}
/*
* Local variables:
* c-file-style: "parrot"
* End:
* vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
*/