Coverage Report

Created: 2018-07-03 15:31

/home/travis/build/MoarVM/MoarVM/src/6model/reprs/P6str.c
Line
Count
Source
1
#include "moar.h"
2
3
/* This representation's function pointer table. */
4
static const MVMREPROps P6str_this_repr;
5
6
/* Creates a new type object of this representation, and associates it with
7
 * the given HOW. */
8
149
static MVMObject * type_object_for(MVMThreadContext *tc, MVMObject *HOW) {
9
149
    MVMSTable *st  = MVM_gc_allocate_stable(tc, &P6str_this_repr, HOW);
10
149
11
149
    MVMROOT(tc, st, {
12
149
        MVMObject *obj = MVM_gc_allocate_type_object(tc, st);
13
149
        MVM_ASSIGN_REF(tc, &(st->header), st->WHAT, obj);
14
149
        st->size = sizeof(MVMP6str);
15
149
    });
16
149
17
149
    return st->WHAT;
18
149
}
19
20
/* Copies the body of one object to another. */
21
1
static void copy_to(MVMThreadContext *tc, MVMSTable *st, void *src, MVMObject *dest_root, void *dest) {
22
1
    MVMP6strBody *src_body  = (MVMP6strBody *)src;
23
1
    MVMP6strBody *dest_body = (MVMP6strBody *)dest;
24
1
    MVM_ASSIGN_REF(tc, &(dest_root->header), dest_body->value, src_body->value);
25
1
}
26
27
3.99M
static void set_str(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void *data, MVMString *value) {
28
3.99M
    MVM_ASSIGN_REF(tc, &(root->header), ((MVMP6strBody *)data)->value, value);
29
3.99M
}
30
31
6.94M
static MVMString * get_str(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void *data) {
32
6.94M
    return ((MVMP6strBody *)data)->value;
33
6.94M
}
34
35
static const MVMStorageSpec storage_spec = {
36
    MVM_STORAGE_SPEC_INLINED, /* inlineable */
37
    sizeof(MVMString*) * 8,   /* bits */
38
    ALIGNOF(void *),               /* align */
39
    MVM_STORAGE_SPEC_BP_STR,       /* boxed_primitive */
40
    MVM_STORAGE_SPEC_CAN_BOX_STR,  /* can_box */
41
    0,                          /* is_unsigned */
42
};
43
44
/* Gets the storage specification for this representation. */
45
2.77M
static const MVMStorageSpec * get_storage_spec(MVMThreadContext *tc, MVMSTable *st) {
46
2.77M
    return &storage_spec;
47
2.77M
}
48
49
/* Compose the representation. */
50
5
static void compose(MVMThreadContext *tc, MVMSTable *st, MVMObject *info) {
51
5
}
52
53
/* Called by the VM to mark any GCable items. */
54
1.35M
static void gc_mark(MVMThreadContext *tc, MVMSTable *st, void *data, MVMGCWorklist *worklist) {
55
1.35M
    MVM_gc_worklist_add(tc, worklist, &((MVMP6strBody *)data)->value);
56
1.35M
}
57
58
/* Set the size of the STable. */
59
144
static void deserialize_stable_size(MVMThreadContext *tc, MVMSTable *st, MVMSerializationReader *reader) {
60
144
    st->size = sizeof(MVMP6str);
61
144
}
62
63
4
static void deserialize(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void *data, MVMSerializationReader *reader) {
64
4
    MVM_ASSIGN_REF(tc, &(root->header), ((MVMP6strBody *)data)->value,
65
4
        MVM_serialization_read_str(tc, reader));
66
4
}
67
68
4
static void serialize(MVMThreadContext *tc, MVMSTable *st, void *data, MVMSerializationWriter *writer) {
69
4
    MVM_serialization_write_str(tc, writer, ((MVMP6strBody *)data)->value);
70
4
}
71
72
/* Initializes the representation. */
73
144
const MVMREPROps * MVMP6str_initialize(MVMThreadContext *tc) {
74
144
    return &P6str_this_repr;
75
144
}
76
77
static const MVMREPROps P6str_this_repr = {
78
    type_object_for,
79
    MVM_gc_allocate_object,
80
    NULL, /* initialize */
81
    copy_to,
82
    MVM_REPR_DEFAULT_ATTR_FUNCS,
83
    {
84
        MVM_REPR_DEFAULT_SET_INT,
85
        MVM_REPR_DEFAULT_GET_INT,
86
        MVM_REPR_DEFAULT_SET_NUM,
87
        MVM_REPR_DEFAULT_GET_NUM,
88
        set_str,
89
        get_str,
90
        MVM_REPR_DEFAULT_SET_UINT,
91
        MVM_REPR_DEFAULT_GET_UINT,
92
        MVM_REPR_DEFAULT_GET_BOXED_REF
93
    },    /* box_funcs */
94
    MVM_REPR_DEFAULT_POS_FUNCS,
95
    MVM_REPR_DEFAULT_ASS_FUNCS,
96
    MVM_REPR_DEFAULT_ELEMS,
97
    get_storage_spec,
98
    NULL, /* change_type */
99
    serialize,
100
    deserialize, /* deserialize */
101
    NULL, /* serialize_repr_data */
102
    NULL, /* deserialize_repr_data */
103
    deserialize_stable_size,
104
    gc_mark,
105
    NULL, /* gc_free */
106
    NULL, /* gc_cleanup */
107
    NULL, /* gc_mark_repr_data */
108
    NULL, /* gc_free_repr_data */
109
    compose,
110
    NULL, /* spesh */
111
    "P6str", /* name */
112
    MVM_REPR_ID_P6str,
113
    NULL, /* unmanaged_size */
114
    NULL, /* describe_refs */
115
};