/home/travis/build/MoarVM/MoarVM/src/6model/reprs/KnowHOWREPR.c
Line | Count | Source (jump to first uncovered line) |
1 | | #include "moar.h" |
2 | | |
3 | | /* This representation's function pointer table. */ |
4 | | static const MVMREPROps KnowHOWREPR_this_repr; |
5 | | |
6 | | /* Creates a new type object of this representation, and associates it with |
7 | | * the given HOW. */ |
8 | 144 | static MVMObject * type_object_for(MVMThreadContext *tc, MVMObject *HOW) { |
9 | 144 | MVMSTable *st = MVM_gc_allocate_stable(tc, &KnowHOWREPR_this_repr, HOW); |
10 | 144 | |
11 | 144 | MVMROOT(tc, st, { |
12 | 144 | MVMObject *obj = MVM_gc_allocate_type_object(tc, st); |
13 | 144 | MVM_ASSIGN_REF(tc, &(st->header), st->WHAT, obj); |
14 | 144 | st->size = sizeof(MVMKnowHOWREPR); |
15 | 144 | }); |
16 | 144 | |
17 | 144 | return st->WHAT; |
18 | 144 | } |
19 | | |
20 | | /* Initializes a new instance. */ |
21 | 5.35k | static void initialize(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void *data) { |
22 | 5.35k | MVMObject *methods, *attributes, *BOOTArray; |
23 | 5.35k | MVMObject * const BOOTHash = tc->instance->boot_types.BOOTHash; |
24 | 5.35k | |
25 | 5.35k | MVM_gc_root_temp_push(tc, (MVMCollectable **)&root); |
26 | 5.35k | |
27 | 5.35k | methods = REPR(BOOTHash)->allocate(tc, STABLE(BOOTHash)); |
28 | 5.35k | MVM_gc_root_temp_push(tc, (MVMCollectable **)&methods); |
29 | 5.35k | MVM_ASSIGN_REF(tc, &(root->header), ((MVMKnowHOWREPR *)root)->body.methods, methods); |
30 | 5.35k | |
31 | 5.35k | BOOTArray = tc->instance->boot_types.BOOTArray; |
32 | 5.35k | attributes = REPR(BOOTArray)->allocate(tc, STABLE(BOOTArray)); |
33 | 5.35k | MVM_ASSIGN_REF(tc, &(root->header), ((MVMKnowHOWREPR *)root)->body.attributes, attributes); |
34 | 5.35k | |
35 | 5.35k | MVM_gc_root_temp_pop_n(tc, 2); |
36 | 5.35k | } |
37 | | |
38 | | /* Copies the body of one object to another. */ |
39 | 0 | static void copy_to(MVMThreadContext *tc, MVMSTable *st, void *src, MVMObject *dest_root, void *dest) { |
40 | 0 | MVMKnowHOWREPRBody *src_body = (MVMKnowHOWREPRBody *)src; |
41 | 0 | MVMKnowHOWREPRBody *dest_body = (MVMKnowHOWREPRBody *)dest; |
42 | 0 | MVM_ASSIGN_REF(tc, &(dest_root->header), dest_body->methods, src_body->methods); |
43 | 0 | MVM_ASSIGN_REF(tc, &(dest_root->header), dest_body->attributes, src_body->attributes); |
44 | 0 | MVM_ASSIGN_REF(tc, &(dest_root->header), dest_body->name, src_body->name); |
45 | 0 | } |
46 | | |
47 | | static const MVMStorageSpec storage_spec = { |
48 | | MVM_STORAGE_SPEC_REFERENCE, /* inlineable */ |
49 | | 0, /* bits */ |
50 | | 0, /* align */ |
51 | | MVM_STORAGE_SPEC_BP_NONE, /* boxed_primitive */ |
52 | | 0, /* can_box */ |
53 | | 0, /* is_unsigned */ |
54 | | }; |
55 | | |
56 | | /* Gets the storage specification for this representation. */ |
57 | 9 | static const MVMStorageSpec * get_storage_spec(MVMThreadContext *tc, MVMSTable *st) { |
58 | 9 | return &storage_spec; |
59 | 9 | } |
60 | | |
61 | | /* Adds held objects to the GC worklist. */ |
62 | 706 | static void gc_mark(MVMThreadContext *tc, MVMSTable *st, void *data, MVMGCWorklist *worklist) { |
63 | 706 | MVMKnowHOWREPRBody *body = (MVMKnowHOWREPRBody *)data; |
64 | 706 | MVM_gc_worklist_add(tc, worklist, &body->methods); |
65 | 706 | MVM_gc_worklist_add(tc, worklist, &body->attributes); |
66 | 706 | MVM_gc_worklist_add(tc, worklist, &body->name); |
67 | 706 | } |
68 | | |
69 | | /* Compose the representation. */ |
70 | 0 | static void compose(MVMThreadContext *tc, MVMSTable *st, MVMObject *info) { |
71 | 0 | /* Nothing to do for this REPR. */ |
72 | 0 | } |
73 | | |
74 | | /* Set the size of the STable. */ |
75 | 0 | static void deserialize_stable_size(MVMThreadContext *tc, MVMSTable *st, MVMSerializationReader *reader) { |
76 | 0 | st->size = sizeof(MVMKnowHOWREPR); |
77 | 0 | } |
78 | | |
79 | | /* Serializes the data. */ |
80 | 7 | static void serialize(MVMThreadContext *tc, MVMSTable *st, void *data, MVMSerializationWriter *writer) { |
81 | 7 | MVMKnowHOWREPRBody *body = (MVMKnowHOWREPRBody *)data; |
82 | 7 | MVM_serialization_write_str(tc, writer, body->name); |
83 | 7 | MVM_serialization_write_ref(tc, writer, body->attributes); |
84 | 7 | MVM_serialization_write_ref(tc, writer, body->methods); |
85 | 7 | } |
86 | | |
87 | | /* Deserializes the data. */ |
88 | 1.09k | static void deserialize(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void *data, MVMSerializationReader *reader) { |
89 | 1.09k | MVMKnowHOWREPRBody *body = (MVMKnowHOWREPRBody *)data; |
90 | 1.09k | MVM_ASSIGN_REF(tc, &(root->header), body->name, MVM_serialization_read_str(tc, reader)); |
91 | 1.09k | MVM_ASSIGN_REF(tc, &(root->header), body->attributes, MVM_serialization_read_ref(tc, reader)); |
92 | 1.09k | MVM_ASSIGN_REF(tc, &(root->header), body->methods, MVM_serialization_read_ref(tc, reader)); |
93 | 1.09k | } |
94 | | |
95 | | /* Initializes the representation. */ |
96 | 144 | const MVMREPROps * MVMKnowHOWREPR_initialize(MVMThreadContext *tc) { |
97 | 144 | return &KnowHOWREPR_this_repr; |
98 | 144 | } |
99 | | |
100 | | static const MVMREPROps KnowHOWREPR_this_repr = { |
101 | | type_object_for, |
102 | | MVM_gc_allocate_object, |
103 | | initialize, |
104 | | copy_to, |
105 | | MVM_REPR_DEFAULT_ATTR_FUNCS, |
106 | | MVM_REPR_DEFAULT_BOX_FUNCS, |
107 | | MVM_REPR_DEFAULT_POS_FUNCS, |
108 | | MVM_REPR_DEFAULT_ASS_FUNCS, |
109 | | MVM_REPR_DEFAULT_ELEMS, |
110 | | get_storage_spec, |
111 | | NULL, /* change_type */ |
112 | | serialize, |
113 | | deserialize, |
114 | | NULL, /* serialize_repr_data */ |
115 | | NULL, /* deserialize_repr_data */ |
116 | | deserialize_stable_size, |
117 | | gc_mark, |
118 | | NULL, /* gc_free */ |
119 | | NULL, /* gc_cleanup */ |
120 | | NULL, /* gc_mark_repr_data */ |
121 | | NULL, /* gc_free_repr_data */ |
122 | | compose, |
123 | | NULL, /* spesh */ |
124 | | "KnowHOWREPR", /* name */ |
125 | | MVM_REPR_ID_KnowHOWREPR, |
126 | | NULL, /* unmanaged_size */ |
127 | | NULL, /* describe_refs */ |
128 | | }; |