|
| 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