Coverage Report

Created: 2018-06-21 18:56

/home/travis/build/MoarVM/MoarVM/src/6model/reprs/CStr.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 CStr_this_repr;
5
6
/* Creates a new type object of this representation, and associates it with
7
 * the given HOW. */
8
0
static MVMObject * type_object_for(MVMThreadContext *tc, MVMObject *HOW) {
9
0
    MVMSTable *st  = MVM_gc_allocate_stable(tc, &CStr_this_repr, HOW);
10
0
11
0
    MVMROOT(tc, st, {
12
0
        MVMObject *obj = MVM_gc_allocate_type_object(tc, st);
13
0
        MVM_ASSIGN_REF(tc, &(st->header), st->WHAT, obj);
14
0
        st->size = sizeof(MVMCStr);
15
0
    });
16
0
17
0
    return st->WHAT;
18
0
}
19
20
/* Compose the representation. */
21
0
static void compose(MVMThreadContext *tc, MVMSTable *st, MVMObject *info) {
22
0
    /* TODO: move encoding stuff into here */
23
0
}
24
25
/* Copies to the body of one object to another. */
26
0
static void copy_to(MVMThreadContext *tc, MVMSTable *st, void *src, MVMObject *dest_root, void *dest) {
27
0
    MVMCPointerBody *src_body = (MVMCPointerBody *)src;
28
0
    MVMCPointerBody *dest_body = (MVMCPointerBody *)dest;
29
0
    dest_body->ptr = src_body->ptr;
30
0
}
31
32
0
static void set_str(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void *data, MVMString *value) {
33
0
    MVMCStrBody *body = (MVMCStrBody *)data;
34
0
    MVM_ASSIGN_REF(tc, &(root->header), body->orig, value);
35
0
    body->cstr = MVM_string_utf8_encode_C_string(tc, value);
36
0
}
37
38
0
static MVMString * get_str(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void *data) {
39
0
    MVMCStrBody *body = (MVMCStrBody *)data;
40
0
    return body->orig;
41
0
}
42
43
static const MVMStorageSpec storage_spec = {
44
    MVM_STORAGE_SPEC_REFERENCE,       /* inlineable */
45
    sizeof(void *) * 8,               /* bits */
46
    ALIGNOF(void *),                  /* align */
47
    MVM_STORAGE_SPEC_BP_STR,          /* boxed_primitive */
48
    MVM_STORAGE_SPEC_CAN_BOX_STR,     /* can_box */
49
    0,                                /* is_unsigned */
50
};
51
52
53
/* Gets the storage specification for this representation. */
54
0
static const MVMStorageSpec * get_storage_spec(MVMThreadContext *tc, MVMSTable *st) {
55
0
    return &storage_spec;
56
0
}
57
58
0
static void gc_mark(MVMThreadContext *tc, MVMSTable *st, void *data, MVMGCWorklist *worklist) {
59
0
    MVMCStrBody *body = (MVMCStrBody *)data;
60
0
    MVM_gc_worklist_add(tc, worklist, &body->orig);
61
0
}
62
63
0
static void gc_free(MVMThreadContext *tc, MVMObject *obj) {
64
0
    MVMCStr *cstr = (MVMCStr *)obj;
65
0
    if (obj && cstr->body.cstr)
66
0
        MVM_free(cstr->body.cstr);
67
0
}
68
69
0
static void deserialize_stable_size(MVMThreadContext *tc, MVMSTable *st, MVMSerializationReader *reader) {
70
0
    st->size = sizeof(MVMCStr);
71
0
}
72
73
/* Initializes the representation. */
74
144
const MVMREPROps * MVMCStr_initialize(MVMThreadContext *tc) {
75
144
    return &CStr_this_repr;
76
144
}
77
78
static const MVMREPROps CStr_this_repr = {
79
    type_object_for,
80
    MVM_gc_allocate_object,
81
    NULL, /* initialize */
82
    copy_to,
83
    MVM_REPR_DEFAULT_ATTR_FUNCS,
84
    {
85
        MVM_REPR_DEFAULT_SET_INT,
86
        MVM_REPR_DEFAULT_GET_INT,
87
        MVM_REPR_DEFAULT_SET_NUM,
88
        MVM_REPR_DEFAULT_GET_NUM,
89
        set_str,
90
        get_str,
91
        MVM_REPR_DEFAULT_SET_UINT,
92
        MVM_REPR_DEFAULT_GET_UINT,
93
        MVM_REPR_DEFAULT_GET_BOXED_REF
94
    },    /* box_funcs */
95
    MVM_REPR_DEFAULT_POS_FUNCS,
96
    MVM_REPR_DEFAULT_ASS_FUNCS,
97
    MVM_REPR_DEFAULT_ELEMS,
98
    get_storage_spec,
99
    NULL, /* change_type */
100
    NULL, /* serialize */
101
    NULL, /* deserialize */
102
    NULL, /* serialize_repr_data */
103
    NULL, /* deserialize_repr_data */
104
    deserialize_stable_size,
105
    gc_mark,
106
    gc_free,
107
    NULL, /* gc_cleanup */
108
    NULL, /* gc_mark_repr_data */
109
    NULL, /* gc_free_repr_data */
110
    compose,
111
    NULL, /* spesh */
112
    "CStr", /* name */
113
    MVM_REPR_ID_MVMCStr,
114
    NULL, /* unmanaged_size */
115
    NULL, /* describe_refs */
116
};