Coverage Report

Created: 2017-04-15 07:07

/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
130
static MVMObject * type_object_for(MVMThreadContext *tc, MVMObject *HOW) {
9
130
    MVMSTable *st  = MVM_gc_allocate_stable(tc, &KnowHOWREPR_this_repr, HOW);
10
130
11
130
    MVMROOT(tc, st, {
12
130
        MVMObject *obj = MVM_gc_allocate_type_object(tc, st);
13
130
        MVM_ASSIGN_REF(tc, &(st->header), st->WHAT, obj);
14
130
        st->size = sizeof(MVMKnowHOWREPR);
15
130
    });
16
130
17
130
    return st->WHAT;
18
130
}
19
20
/* Initializes a new instance. */
21
4.95k
static void initialize(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void *data) {
22
4.95k
    MVMObject *methods, *attributes, *BOOTArray;
23
4.95k
    MVMObject * const BOOTHash  = tc->instance->boot_types.BOOTHash;
24
4.95k
25
4.95k
    MVM_gc_root_temp_push(tc, (MVMCollectable **)&root);
26
4.95k
27
4.95k
    methods = REPR(BOOTHash)->allocate(tc, STABLE(BOOTHash));
28
4.95k
    MVM_gc_root_temp_push(tc, (MVMCollectable **)&methods);
29
4.95k
    MVM_ASSIGN_REF(tc, &(root->header), ((MVMKnowHOWREPR *)root)->body.methods, methods);
30
4.95k
31
4.95k
    BOOTArray  = tc->instance->boot_types.BOOTArray;
32
4.95k
    attributes = REPR(BOOTArray)->allocate(tc, STABLE(BOOTArray));
33
4.95k
    MVM_ASSIGN_REF(tc, &(root->header), ((MVMKnowHOWREPR *)root)->body.attributes, attributes);
34
4.95k
35
4.95k
    MVM_gc_root_temp_pop_n(tc, 2);
36
4.95k
}
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
572
static void gc_mark(MVMThreadContext *tc, MVMSTable *st, void *data, MVMGCWorklist *worklist) {
63
572
    MVMKnowHOWREPRBody *body = (MVMKnowHOWREPRBody *)data;
64
572
    MVM_gc_worklist_add(tc, worklist, &body->methods);
65
572
    MVM_gc_worklist_add(tc, worklist, &body->attributes);
66
572
    MVM_gc_worklist_add(tc, worklist, &body->name);
67
572
}
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
6
static void serialize(MVMThreadContext *tc, MVMSTable *st, void *data, MVMSerializationWriter *writer) {
81
6
    MVMKnowHOWREPRBody *body = (MVMKnowHOWREPRBody *)data;
82
6
    MVM_serialization_write_str(tc, writer, body->name);
83
6
    MVM_serialization_write_ref(tc, writer, body->attributes);
84
6
    MVM_serialization_write_ref(tc, writer, body->methods);
85
6
}
86
87
/* Deserializes the data. */
88
991
static void deserialize(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void *data, MVMSerializationReader *reader) {
89
991
    MVMKnowHOWREPRBody *body = (MVMKnowHOWREPRBody *)data;
90
991
    MVM_ASSIGN_REF(tc, &(root->header), body->name, MVM_serialization_read_str(tc, reader));
91
991
    MVM_ASSIGN_REF(tc, &(root->header), body->attributes, MVM_serialization_read_ref(tc, reader));
92
991
    MVM_ASSIGN_REF(tc, &(root->header), body->methods, MVM_serialization_read_ref(tc, reader));
93
991
}
94
95
/* Initializes the representation. */
96
130
const MVMREPROps * MVMKnowHOWREPR_initialize(MVMThreadContext *tc) {
97
130
    return &KnowHOWREPR_this_repr;
98
130
}
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
};