~ubuntu-branches/ubuntu/vivid/nqp/vivid-proposed

« back to all changes in this revision

Viewing changes to src/pmc/serializationcontext.pmc

  • Committer: Package Import Robot
  • Author(s): Alessandro Ghedini
  • Date: 2013-11-01 12:09:18 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20131101120918-kx51sl0sxl3exsxi
Tags: 2013.10-1
* New upstream release
* Bump versioned (Build-)Depends on parrot
* Update patches
* Install new README.pod
* Fix vcs-field-not-canonical
* Do not install rubyish examples
* Do not Depends on parrot-devel anymore
* Add 07_disable-serialization-tests.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
5
 
#include "../6model/sixmodelobject.h"
6
 
static INTVAL smo_id    = 0;
7
 
 
8
 
pmclass SerializationContext auto_attrs dynpmc group nqp {
9
 
    /* The handle of this SC. */
10
 
    ATTR STRING *handle;
11
 
    
12
 
    /* The root set of objects that live in this SC. */
13
 
    ATTR PMC *root_objects;
14
 
    
15
 
    /* The root set of STables that live in this SC. */
16
 
    ATTR PMC *root_stables;
17
 
    
18
 
    /* The root set of code refs that live in this SC. */
19
 
    ATTR PMC *root_codes;
20
 
    
21
 
    /* Description (probably the file name) if any. */
22
 
    ATTR STRING *description;
23
 
    
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;
28
 
    ATTR PMC *rep_scs;
29
 
    
30
 
    VTABLE void init() {
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);
42
 
        if (!smo_id)
43
 
            smo_id = Parrot_pmc_get_type_str(interp, Parrot_str_new(interp, "SixModelObject", 0));
44
 
    }
45
 
    
46
 
    VTABLE void set_string_native(STRING *handle) {
47
 
        SET_ATTR_handle(interp, SELF, handle);
48
 
    }
49
 
 
50
 
    VTABLE void mark() {
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);
67
 
    }
68
 
    
69
 
    VTABLE PMC* get_pmc_keyed_int(INTVAL idx) {
70
 
        PMC    *root_objects;
71
 
        GET_ATTR_root_objects(interp, SELF, root_objects);
72
 
        return VTABLE_get_pmc_keyed_int(interp, root_objects, idx);
73
 
    }
74
 
    
75
 
    VTABLE PMC* get_pmc_keyed(PMC *idx) {
76
 
        PMC    *root_objects;
77
 
        GET_ATTR_root_objects(interp, SELF, root_objects);
78
 
        return VTABLE_get_pmc_keyed(interp, root_objects, idx);
79
 
    }
80
 
    
81
 
    VTABLE void set_pmc_keyed_int(INTVAL idx, PMC *value) {
82
 
        PMC    *root_objects;
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
87
 
             * for this SC. */
88
 
            if (PMC_IS_NULL(STABLE(value)->sc)) {
89
 
                PMC *root_stables;
90
 
                GET_ATTR_root_stables(interp, SELF, root_stables);
91
 
                STABLE(value)->sc = SELF;
92
 
                VTABLE_push_pmc(interp, root_stables, STABLE_PMC(value));
93
 
            }
94
 
        }
95
 
    }
96
 
    
97
 
    VTABLE void set_pmc_keyed(PMC *idx, PMC *value) {
98
 
        PMC    *root_objects;
99
 
        GET_ATTR_root_objects(interp, SELF, root_objects);
100
 
        VTABLE_set_pmc_keyed(interp, root_objects, idx, value);
101
 
    }
102
 
    
103
 
    VTABLE INTVAL elements() {
104
 
        PMC    *root_objects;
105
 
        GET_ATTR_root_objects(interp, SELF, root_objects);
106
 
        return VTABLE_elements(interp, root_objects);
107
 
    }
108
 
    
109
 
    METHOD INTVAL elems() {
110
 
        PMC    *root_objects;
111
 
        INTVAL elems;
112
 
        GET_ATTR_root_objects(interp, SELF, root_objects);
113
 
        elems = VTABLE_elements(interp, root_objects);
114
 
        RETURN (INTVAL elems);
115
 
    }
116
 
    
117
 
    METHOD STRING* handle() {
118
 
        STRING *handle;
119
 
        GET_ATTR_handle(interp, SELF, handle);
120
 
        RETURN (STRING* handle);
121
 
    }
122
 
    
123
 
    METHOD set_description(STRING *description) {
124
 
        SET_ATTR_description(interp, SELF, description);
125
 
        RETURN (STRING* description);
126
 
    }
127
 
    
128
 
    METHOD STRING* description() {
129
 
        STRING *description;
130
 
        GET_ATTR_description(interp, SELF, description);
131
 
        RETURN (STRING* description);
132
 
    }
133
 
    
134
 
    METHOD INTVAL slot_index_for(PMC *obj) {
135
 
        /* This is kinda stupid, but it'll do for now. */
136
 
        PMC    *root_objects;
137
 
        INTVAL  i, count;
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) {
142
 
                RETURN (INTVAL i);
143
 
            }
144
 
        }
145
 
        Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
146
 
            "Object does not exist in serialization context");
147
 
    }
148
 
}