Coverage Report

Created: 2018-07-03 15:31

/home/travis/build/MoarVM/MoarVM/src/6model/reprs/CPointer.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 CPointer_this_repr;
5
6
/* Creates a new type object of this representation, and associates it with
7
 * the given HOW. */
8
1
static MVMObject * type_object_for(MVMThreadContext *tc, MVMObject *HOW) {
9
1
    MVMSTable *st  = MVM_gc_allocate_stable(tc, &CPointer_this_repr, HOW);
10
1
11
1
    MVMROOT(tc, st, {
12
1
        MVMObject *obj = MVM_gc_allocate_type_object(tc, st);
13
1
        MVM_ASSIGN_REF(tc, &(st->header), st->WHAT, obj);
14
1
        st->size = sizeof(MVMCPointer);
15
1
    });
16
1
17
1
    return st->WHAT;
18
1
}
19
20
/* Compose the representation. */
21
1
static void compose(MVMThreadContext *tc, MVMSTable *st, MVMObject *info) {
22
1
}
23
24
/* Copies to the body of one object to another. */
25
0
static void copy_to(MVMThreadContext *tc, MVMSTable *st, void *src, MVMObject *dest_root, void *dest) {
26
0
    MVMCPointerBody *src_body = (MVMCPointerBody *)src;
27
0
    MVMCPointerBody *dest_body = (MVMCPointerBody *)dest;
28
0
    dest_body->ptr = src_body->ptr;
29
0
}
30
31
0
static void set_int(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void *data, MVMint64 value) {
32
0
    MVMCPointerBody *body = (MVMCPointerBody *)OBJECT_BODY(root);
33
0
#if MVM_PTR_SIZE == 4
34
    body->ptr = (void *)(MVMint32)value;
35
#else
36
0
    body->ptr = (void *)value;
37
0
#endif
38
0
}
39
40
0
static MVMint64 get_int(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void *data) {
41
0
    MVMCPointerBody *body = (MVMCPointerBody *)OBJECT_BODY(root);
42
0
#if MVM_PTR_SIZE == 4
43
    return (MVMint64)(MVMint32)body->ptr;
44
#else
45
0
    return (MVMint64)body->ptr;
46
0
#endif
47
0
}
48
49
0
static void set_uint(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void *data, MVMuint64 value) {
50
0
    MVMCPointerBody *body = (MVMCPointerBody *)OBJECT_BODY(root);
51
0
#if MVM_PTR_SIZE == 4
52
    body->ptr = (void *)(MVMuint32)value;
53
#else
54
0
    body->ptr = (void *)value;
55
0
#endif
56
0
}
57
58
0
static MVMuint64 get_uint(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void *data) {
59
0
    MVMCPointerBody *body = (MVMCPointerBody *)OBJECT_BODY(root);
60
0
#if MVM_PTR_SIZE == 4
61
    return (MVMuint64)(MVMuint32)body->ptr;
62
#else
63
0
    return (MVMuint64)body->ptr;
64
0
#endif
65
0
}
66
67
static const MVMStorageSpec storage_spec = {
68
    MVM_STORAGE_SPEC_REFERENCE,       /* inlineable */
69
    sizeof(void *) * 8,               /* bits */
70
    ALIGNOF(void *),                  /* align */
71
    MVM_STORAGE_SPEC_BP_NONE,         /* boxed_primitive */
72
    0,                                /* can_box */
73
    0,                                /* is_unsigned */
74
};
75
76
77
/* Gets the storage specification for this representation. */
78
0
static const MVMStorageSpec * get_storage_spec(MVMThreadContext *tc, MVMSTable *st) {
79
0
    return &storage_spec;
80
0
}
81
82
0
static void deserialize_stable_size(MVMThreadContext *tc, MVMSTable *st, MVMSerializationReader *reader) {
83
0
    st->size = sizeof(MVMCPointer);
84
0
}
85
86
0
static void deserialize(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void *data, MVMSerializationReader *reader) {
87
0
    MVMCPointerBody *body = (MVMCPointerBody *)data;
88
0
    MVMint64 value;
89
0
90
0
    if (reader->root.version >= 19) {
91
0
        value = MVM_serialization_read_int(tc, reader);
92
0
    } else {
93
0
        value = MVM_serialization_read_int64(tc, reader);
94
0
    }
95
0
96
0
#if MVM_PTR_SIZE == 4
97
    body->ptr = (void *)(MVMuint32)value;
98
#else
99
0
    body->ptr = (void *)value;
100
0
#endif
101
0
102
0
}
103
104
0
static void serialize(MVMThreadContext *tc, MVMSTable *st, void *data, MVMSerializationWriter *writer) {
105
0
    MVMCPointerBody *body = (MVMCPointerBody *)data;
106
0
    MVM_serialization_write_int(tc, writer,
107
0
#if MVM_PTR_SIZE == 4
108
        (MVMuint64)(MVMuint32)body->ptr
109
#else
110
0
        (MVMuint64)body->ptr
111
0
#endif
112
0
    );
113
0
}
114
115
/* Initializes the representation. */
116
144
const MVMREPROps * MVMCPointer_initialize(MVMThreadContext *tc) {
117
144
    return &CPointer_this_repr;
118
144
}
119
120
static const MVMREPROps CPointer_this_repr = {
121
    type_object_for,
122
    MVM_gc_allocate_object,
123
    NULL, /* initialize */
124
    copy_to,
125
    MVM_REPR_DEFAULT_ATTR_FUNCS,
126
    {
127
        set_int,
128
        get_int,
129
        MVM_REPR_DEFAULT_SET_NUM,
130
        MVM_REPR_DEFAULT_GET_NUM,
131
        MVM_REPR_DEFAULT_SET_STR,
132
        MVM_REPR_DEFAULT_GET_STR,
133
        set_uint,
134
        get_uint,
135
        MVM_REPR_DEFAULT_GET_BOXED_REF
136
    },    /* box_funcs */
137
    MVM_REPR_DEFAULT_POS_FUNCS,
138
    MVM_REPR_DEFAULT_ASS_FUNCS,
139
    MVM_REPR_DEFAULT_ELEMS,
140
    get_storage_spec,
141
    NULL, /* change_type */
142
    serialize, /* serialize */
143
    deserialize, /* deserialize */
144
    NULL, /* serialize_repr_data */
145
    NULL, /* deserialize_repr_data */
146
    deserialize_stable_size,
147
    NULL, /* gc_mark */
148
    NULL, /* gc_free */
149
    NULL, /* gc_cleanup */
150
    NULL, /* gc_mark_repr_data */
151
    NULL, /* gc_free_repr_data */
152
    compose,
153
    NULL, /* spesh */
154
    "CPointer", /* name */
155
    MVM_REPR_ID_MVMCPointer,
156
    NULL, /* unmanaged_size */
157
    NULL, /* describe_refs */
158
};