Coverage Report

Created: 2017-04-15 07:07

/home/travis/build/MoarVM/MoarVM/src/6model/reprconv.c
Line
Count
Source (jump to first uncovered line)
1
#include "moar.h"
2
3
/* Representation function convenience accessors. Could potentially be made into
4
 * macros in the future, but hopefully the compiler is smart enough to inline
5
 * them anyway. */
6
7
4.72k
void MVM_repr_init(MVMThreadContext *tc, MVMObject *obj) {
8
4.72k
    if (REPR(obj)->initialize)
9
2.86k
        REPR(obj)->initialize(tc, STABLE(obj), obj, OBJECT_BODY(obj));
10
4.72k
}
11
12
3.12M
MVMObject * MVM_repr_alloc_init(MVMThreadContext *tc, MVMObject *type) {
13
3.12M
    MVMObject *obj = REPR(type)->allocate(tc, STABLE(type));
14
3.12M
15
3.12M
    if (REPR(obj)->initialize) {
16
13.4k
        MVMROOT(tc, obj, {
17
13.4k
            REPR(obj)->initialize(tc, STABLE(obj), obj, OBJECT_BODY(obj));
18
13.4k
        });
19
13.4k
    }
20
3.12M
21
3.12M
    return obj;
22
3.12M
}
23
24
26.4k
MVMObject * MVM_repr_clone(MVMThreadContext *tc, MVMObject *obj) {
25
26.4k
    MVMObject *res;
26
26.4k
    if (IS_CONCRETE(obj)) {
27
26.4k
        MVM_gc_root_temp_push(tc, (MVMCollectable **)&obj);
28
26.4k
        res = REPR(obj)->allocate(tc, STABLE(obj));
29
26.4k
        MVM_gc_root_temp_push(tc, (MVMCollectable **)&res);
30
26.4k
        REPR(obj)->copy_to(tc, STABLE(obj), OBJECT_BODY(obj), res, OBJECT_BODY(res));
31
26.4k
        MVM_gc_root_temp_pop_n(tc, 2);
32
2
    } else {
33
2
        res = obj;
34
2
    }
35
26.4k
    return res;
36
26.4k
}
37
38
1.31k
void MVM_repr_compose(MVMThreadContext *tc, MVMObject *type, MVMObject *obj) {
39
1.31k
    REPR(type)->compose(tc, STABLE(type), obj);
40
1.31k
}
41
42
20.5k
MVM_PUBLIC void MVM_repr_pos_set_elems(MVMThreadContext *tc, MVMObject *obj, MVMint64 elems) {
43
20.5k
    REPR(obj)->pos_funcs.set_elems(tc, STABLE(obj), obj,
44
20.5k
        OBJECT_BODY(obj), elems);
45
20.5k
}
46
47
131
static void populate_indices_array(MVMThreadContext *tc, MVMObject *arr, MVMint64 *elems) {
48
131
    MVMint64 i;
49
131
    *elems = MVM_repr_elems(tc, arr);
50
131
    if (*elems > tc->num_multi_dim_indices)
51
122
        tc->multi_dim_indices = MVM_realloc(tc->multi_dim_indices,
52
122
            *elems * sizeof(MVMint64));
53
364
    for (i = 0; i < *elems; i++)
54
233
        tc->multi_dim_indices[i] = MVM_repr_at_pos_i(tc, arr, i);
55
131
}
56
57
28
void MVM_repr_set_dimensions(MVMThreadContext *tc, MVMObject *obj, MVMObject *dims) {
58
28
    if (IS_CONCRETE(obj)) {
59
28
        MVMint64 num_dims;
60
28
        populate_indices_array(tc, dims, &num_dims);
61
28
        REPR(obj)->pos_funcs.set_dimensions(tc, STABLE(obj), obj,
62
28
            OBJECT_BODY(obj), num_dims, tc->multi_dim_indices);
63
28
    }
64
0
    else {
65
0
        MVM_exception_throw_adhoc(tc, "Cannot set dimensions on a type object");
66
0
    }
67
28
}
68
69
57.0k
MVM_PUBLIC void MVM_repr_pos_splice(MVMThreadContext *tc, MVMObject *obj, MVMObject *replacement, MVMint64 offset, MVMint64 count) {
70
57.0k
    REPR(obj)->pos_funcs.splice(tc, STABLE(obj), obj,
71
57.0k
        OBJECT_BODY(obj), replacement,
72
57.0k
        offset, count);
73
57.0k
}
74
75
7
MVM_PUBLIC MVMint64 MVM_repr_exists_pos(MVMThreadContext *tc, MVMObject *obj, MVMint64 index) {
76
7
    MVMint64 elems = REPR(obj)->elems(tc, STABLE(obj), obj, OBJECT_BODY(obj));
77
7
    if (index < 0)
78
3
        index += elems;
79
6
    return index >= 0 && index < elems && !MVM_is_null(tc, MVM_repr_at_pos_o(tc, obj, index));
80
7
}
81
82
253k
MVMint64 MVM_repr_at_pos_i(MVMThreadContext *tc, MVMObject *obj, MVMint64 idx) {
83
253k
    MVMRegister value;
84
253k
    REPR(obj)->pos_funcs.at_pos(tc, STABLE(obj), obj, OBJECT_BODY(obj),
85
253k
        idx, &value, MVM_reg_int64);
86
253k
    return value.i64;
87
253k
}
88
89
1
MVMnum64 MVM_repr_at_pos_n(MVMThreadContext *tc, MVMObject *obj, MVMint64 idx) {
90
1
    MVMRegister value;
91
1
    REPR(obj)->pos_funcs.at_pos(tc, STABLE(obj), obj, OBJECT_BODY(obj),
92
1
        idx, &value, MVM_reg_num64);
93
1
    return value.n64;
94
1
}
95
96
55.9k
MVMString * MVM_repr_at_pos_s(MVMThreadContext *tc, MVMObject *obj, MVMint64 idx) {
97
55.9k
    MVMRegister value;
98
55.9k
    REPR(obj)->pos_funcs.at_pos(tc, STABLE(obj), obj, OBJECT_BODY(obj),
99
55.9k
        idx, &value, MVM_reg_str);
100
55.9k
    return value.s;
101
55.9k
}
102
103
3.13M
MVMObject * MVM_repr_at_pos_o(MVMThreadContext *tc, MVMObject *obj, MVMint64 idx) {
104
3.13M
    if (IS_CONCRETE(obj)) {
105
3.13M
            MVMRegister value;
106
3.13M
            REPR(obj)->pos_funcs.at_pos(tc, STABLE(obj), obj, OBJECT_BODY(obj),
107
3.13M
                                        idx, &value, MVM_reg_obj);
108
3.13M
            return value.o;
109
3.13M
    }
110
0
    return NULL;
111
3.13M
}
112
113
53
static void at_pos_multidim(MVMThreadContext *tc, MVMObject *obj, MVMObject *indices, MVMRegister *value, MVMuint16 kind) {
114
53
    MVMint64 num_indices;
115
53
    populate_indices_array(tc, indices, &num_indices);
116
53
    REPR(obj)->pos_funcs.at_pos_multidim(tc, STABLE(obj), obj,
117
53
        OBJECT_BODY(obj), num_indices, tc->multi_dim_indices, value, kind);
118
53
}
119
120
10
MVMint64 MVM_repr_at_pos_multidim_i(MVMThreadContext *tc, MVMObject *obj, MVMObject *indices) {
121
10
    MVMRegister r;
122
10
    at_pos_multidim(tc, obj, indices, &r, MVM_reg_int64);
123
10
    return r.i64;
124
10
}
125
126
3
MVMnum64 MVM_repr_at_pos_multidim_n(MVMThreadContext *tc, MVMObject *obj, MVMObject *indices) {
127
3
    MVMRegister r;
128
3
    at_pos_multidim(tc, obj, indices, &r, MVM_reg_num64);
129
3
    return r.n64;
130
3
}
131
132
3
MVMString * MVM_repr_at_pos_multidim_s(MVMThreadContext *tc, MVMObject *obj, MVMObject *indices) {
133
3
    MVMRegister r;
134
3
    at_pos_multidim(tc, obj, indices, &r, MVM_reg_str);
135
3
    return r.s;
136
3
}
137
138
37
MVMObject * MVM_repr_at_pos_multidim_o(MVMThreadContext *tc, MVMObject *obj, MVMObject *indices) {
139
37
    MVMRegister r;
140
37
    at_pos_multidim(tc, obj, indices, &r, MVM_reg_obj);
141
37
    return r.o;
142
37
}
143
144
14
static void at_pos_2d(MVMThreadContext *tc, MVMObject *obj, MVMint64 idx1, MVMint64 idx2, MVMRegister *value, MVMuint16 kind) {
145
14
    MVMint64 c_indices[2] = { idx1, idx2 };
146
14
    REPR(obj)->pos_funcs.at_pos_multidim(tc, STABLE(obj), obj,
147
14
        OBJECT_BODY(obj), 2, c_indices, value, kind);
148
14
}
149
150
1
MVMint64 MVM_repr_at_pos_2d_i(MVMThreadContext *tc, MVMObject *obj, MVMint64 idx1, MVMint64 idx2) {
151
1
    MVMRegister r;
152
1
    at_pos_2d(tc, obj, idx1, idx2, &r, MVM_reg_int64);
153
1
    return r.i64;
154
1
}
155
156
1
MVMnum64 MVM_repr_at_pos_2d_n(MVMThreadContext *tc, MVMObject *obj, MVMint64 idx1, MVMint64 idx2) {
157
1
    MVMRegister r;
158
1
    at_pos_2d(tc, obj, idx1, idx2, &r, MVM_reg_num64);
159
1
    return r.n64;
160
1
}
161
162
1
MVMString * MVM_repr_at_pos_2d_s(MVMThreadContext *tc, MVMObject *obj, MVMint64 idx1, MVMint64 idx2) {
163
1
    MVMRegister r;
164
1
    at_pos_2d(tc, obj, idx1, idx2, &r, MVM_reg_str);
165
1
    return r.s;
166
1
}
167
168
11
MVMObject * MVM_repr_at_pos_2d_o(MVMThreadContext *tc, MVMObject *obj, MVMint64 idx1, MVMint64 idx2) {
169
11
    MVMRegister r;
170
11
    at_pos_2d(tc, obj, idx1, idx2, &r, MVM_reg_obj);
171
11
    return r.o;
172
11
}
173
174
15
static void at_pos_3d(MVMThreadContext *tc, MVMObject *obj, MVMint64 idx1, MVMint64 idx2, MVMint64 idx3, MVMRegister *value, MVMuint16 kind) {
175
15
    MVMint64 c_indices[3] = { idx1, idx2, idx3 };
176
15
    REPR(obj)->pos_funcs.at_pos_multidim(tc, STABLE(obj), obj,
177
15
        OBJECT_BODY(obj), 3, c_indices, value, kind);
178
15
}
179
180
9
MVMint64 MVM_repr_at_pos_3d_i(MVMThreadContext *tc, MVMObject *obj, MVMint64 idx1, MVMint64 idx2, MVMint64 idx3) {
181
9
    MVMRegister r;
182
9
    at_pos_3d(tc, obj, idx1, idx2, idx3, &r, MVM_reg_int64);
183
9
    return r.i64;
184
9
}
185
186
2
MVMnum64 MVM_repr_at_pos_3d_n(MVMThreadContext *tc, MVMObject *obj, MVMint64 idx1, MVMint64 idx2, MVMint64 idx3) {
187
2
    MVMRegister r;
188
2
    at_pos_3d(tc, obj, idx1, idx2, idx3, &r, MVM_reg_num64);
189
2
    return r.n64;
190
2
}
191
192
2
MVMString * MVM_repr_at_pos_3d_s(MVMThreadContext *tc, MVMObject *obj, MVMint64 idx1, MVMint64 idx2, MVMint64 idx3) {
193
2
    MVMRegister r;
194
2
    at_pos_3d(tc, obj, idx1, idx2, idx3, &r, MVM_reg_str);
195
2
    return r.s;
196
2
}
197
198
2
MVMObject * MVM_repr_at_pos_3d_o(MVMThreadContext *tc, MVMObject *obj, MVMint64 idx1, MVMint64 idx2, MVMint64 idx3) {
199
2
    MVMRegister r;
200
2
    at_pos_3d(tc, obj, idx1, idx2, idx3, &r, MVM_reg_obj);
201
2
    return r.o;
202
2
}
203
204
562k
void MVM_repr_bind_pos_i(MVMThreadContext *tc, MVMObject *obj, MVMint64 idx, MVMint64 value) {
205
562k
    MVMRegister val;
206
562k
    val.i64 = value;
207
562k
    REPR(obj)->pos_funcs.bind_pos(tc, STABLE(obj), obj, OBJECT_BODY(obj),
208
562k
        idx, val, MVM_reg_int64);
209
562k
}
210
211
1
void MVM_repr_bind_pos_n(MVMThreadContext *tc, MVMObject *obj, MVMint64 idx, MVMnum64 value) {
212
1
    MVMRegister val;
213
1
    val.n64 = value;
214
1
    REPR(obj)->pos_funcs.bind_pos(tc, STABLE(obj), obj, OBJECT_BODY(obj),
215
1
        idx, val, MVM_reg_num64);
216
1
}
217
218
139k
void MVM_repr_bind_pos_s(MVMThreadContext *tc, MVMObject *obj, MVMint64 idx, MVMString *value) {
219
139k
    MVMRegister val;
220
139k
    val.s = value;
221
139k
    REPR(obj)->pos_funcs.bind_pos(tc, STABLE(obj), obj, OBJECT_BODY(obj),
222
139k
        idx, val, MVM_reg_str);
223
139k
}
224
225
51.3k
void MVM_repr_bind_pos_o(MVMThreadContext *tc, MVMObject *obj, MVMint64 idx, MVMObject *value) {
226
51.3k
    MVMRegister val;
227
51.3k
    val.o = value;
228
51.3k
    REPR(obj)->pos_funcs.bind_pos(tc, STABLE(obj), obj, OBJECT_BODY(obj),
229
51.3k
        idx, val, MVM_reg_obj);
230
51.3k
}
231
232
50
static void bind_pos_multidim(MVMThreadContext *tc, MVMObject *obj, MVMObject *indices, MVMRegister value, MVMuint16 kind) {
233
50
    MVMint64 num_indices;
234
50
    populate_indices_array(tc, indices, &num_indices);
235
50
    REPR(obj)->pos_funcs.bind_pos_multidim(tc, STABLE(obj), obj,
236
50
        OBJECT_BODY(obj), num_indices, tc->multi_dim_indices, value, kind);
237
50
}
238
239
10
void MVM_repr_bind_pos_multidim_i(MVMThreadContext *tc, MVMObject *obj, MVMObject *indices, MVMint64 value) {
240
10
    MVMRegister r;
241
10
    r.i64 = value;
242
10
    bind_pos_multidim(tc, obj, indices, r, MVM_reg_int64);
243
10
}
244
2
void MVM_repr_bind_pos_multidim_n(MVMThreadContext *tc, MVMObject *obj, MVMObject *indices, MVMnum64 value) {
245
2
    MVMRegister r;
246
2
    r.n64 = value;
247
2
    bind_pos_multidim(tc, obj, indices, r, MVM_reg_num64);
248
2
}
249
2
void MVM_repr_bind_pos_multidim_s(MVMThreadContext *tc, MVMObject *obj, MVMObject *indices, MVMString *value) {
250
2
    MVMRegister r;
251
2
    r.s = value;
252
2
    bind_pos_multidim(tc, obj, indices, r, MVM_reg_str);
253
2
}
254
36
void MVM_repr_bind_pos_multidim_o(MVMThreadContext *tc, MVMObject *obj, MVMObject *indices, MVMObject *value) {
255
36
    MVMRegister r;
256
36
    r.o = value;
257
36
    bind_pos_multidim(tc, obj, indices, r, MVM_reg_obj);
258
36
}
259
260
14
static void bind_pos_2d(MVMThreadContext *tc, MVMObject *obj, MVMint64 idx1, MVMint64 idx2, MVMRegister value, MVMuint16 kind) {
261
14
    MVMint64 c_indices[2] = { idx1, idx2 };
262
14
    REPR(obj)->pos_funcs.bind_pos_multidim(tc, STABLE(obj), obj,
263
14
        OBJECT_BODY(obj), 2, c_indices, value, kind);
264
14
}
265
266
1
void MVM_repr_bind_pos_2d_i(MVMThreadContext *tc, MVMObject *obj, MVMint64 idx1, MVMint64 idx2, MVMint64 value) {
267
1
    MVMRegister r;
268
1
    r.i64 = value;
269
1
    bind_pos_2d(tc, obj, idx1, idx2, r, MVM_reg_int64);
270
1
}
271
1
void MVM_repr_bind_pos_2d_n(MVMThreadContext *tc, MVMObject *obj, MVMint64 idx1, MVMint64 idx2, MVMnum64 value) {
272
1
    MVMRegister r;
273
1
    r.n64 = value;
274
1
    bind_pos_2d(tc, obj, idx1, idx2, r, MVM_reg_num64);
275
1
}
276
1
void MVM_repr_bind_pos_2d_s(MVMThreadContext *tc, MVMObject *obj, MVMint64 idx1, MVMint64 idx2, MVMString *value) {
277
1
    MVMRegister r;
278
1
    r.s = value;
279
1
    bind_pos_2d(tc, obj, idx1, idx2, r, MVM_reg_str);
280
1
}
281
11
void MVM_repr_bind_pos_2d_o(MVMThreadContext *tc, MVMObject *obj, MVMint64 idx1, MVMint64 idx2, MVMObject *value) {
282
11
    MVMRegister r;
283
11
    r.o = value;
284
11
    bind_pos_2d(tc, obj, idx1, idx2, r, MVM_reg_obj);
285
11
}
286
287
12
static void bind_pos_3d(MVMThreadContext *tc, MVMObject *obj, MVMint64 idx1, MVMint64 idx2, MVMint64 idx3, MVMRegister value, MVMuint16 kind) {
288
12
    MVMint64 c_indices[3] = { idx1, idx2, idx3 };
289
12
    REPR(obj)->pos_funcs.bind_pos_multidim(tc, STABLE(obj), obj,
290
12
        OBJECT_BODY(obj), 3, c_indices, value, kind);
291
12
}
292
293
9
void MVM_repr_bind_pos_3d_i(MVMThreadContext *tc, MVMObject *obj, MVMint64 idx1, MVMint64 idx2, MVMint64 idx3, MVMint64 value) {
294
9
    MVMRegister r;
295
9
    r.i64 = value;
296
9
    bind_pos_3d(tc, obj, idx1, idx2, idx3, r, MVM_reg_int64);
297
9
}
298
1
void MVM_repr_bind_pos_3d_n(MVMThreadContext *tc, MVMObject *obj, MVMint64 idx1, MVMint64 idx2, MVMint64 idx3, MVMnum64 value) {
299
1
    MVMRegister r;
300
1
    r.n64 = value;
301
1
    bind_pos_3d(tc, obj, idx1, idx2, idx3, r, MVM_reg_num64);
302
1
}
303
1
void MVM_repr_bind_pos_3d_s(MVMThreadContext *tc, MVMObject *obj, MVMint64 idx1, MVMint64 idx2, MVMint64 idx3, MVMString *value) {
304
1
    MVMRegister r;
305
1
    r.s = value;
306
1
    bind_pos_3d(tc, obj, idx1, idx2, idx3, r, MVM_reg_str);
307
1
}
308
1
void MVM_repr_bind_pos_3d_o(MVMThreadContext *tc, MVMObject *obj, MVMint64 idx1, MVMint64 idx2, MVMint64 idx3, MVMObject *value) {
309
1
    MVMRegister r;
310
1
    r.o = value;
311
1
    bind_pos_3d(tc, obj, idx1, idx2, idx3, r, MVM_reg_obj);
312
1
}
313
314
854k
void MVM_repr_push_i(MVMThreadContext *tc, MVMObject *obj, MVMint64 pushee) {
315
854k
    MVMRegister value;
316
854k
    value.i64 = pushee;
317
854k
    REPR(obj)->pos_funcs.push(tc, STABLE(obj), obj, OBJECT_BODY(obj),
318
854k
        value, MVM_reg_int64);
319
854k
}
320
321
0
void MVM_repr_push_n(MVMThreadContext *tc, MVMObject *obj, MVMnum64 pushee) {
322
0
    MVMRegister value;
323
0
    value.n64 = pushee;
324
0
    REPR(obj)->pos_funcs.push(tc, STABLE(obj), obj, OBJECT_BODY(obj),
325
0
        value, MVM_reg_num64);
326
0
}
327
328
18.2k
void MVM_repr_push_s(MVMThreadContext *tc, MVMObject *obj, MVMString *pushee) {
329
18.2k
    MVMRegister value;
330
18.2k
    value.s = pushee;
331
18.2k
    REPR(obj)->pos_funcs.push(tc, STABLE(obj), obj, OBJECT_BODY(obj),
332
18.2k
        value, MVM_reg_str);
333
18.2k
}
334
335
889k
void MVM_repr_push_o(MVMThreadContext *tc, MVMObject *obj, MVMObject *pushee) {
336
889k
    MVMRegister value;
337
889k
    value.o = pushee;
338
889k
    REPR(obj)->pos_funcs.push(tc, STABLE(obj), obj, OBJECT_BODY(obj),
339
889k
        value, MVM_reg_obj);
340
889k
}
341
342
0
void MVM_repr_unshift_i(MVMThreadContext *tc, MVMObject *obj, MVMint64 unshiftee) {
343
0
    MVMRegister value;
344
0
    value.i64 = unshiftee;
345
0
    REPR(obj)->pos_funcs.unshift(tc, STABLE(obj), obj, OBJECT_BODY(obj),
346
0
        value, MVM_reg_int64);
347
0
}
348
349
0
void MVM_repr_unshift_n(MVMThreadContext *tc, MVMObject *obj, MVMnum64 unshiftee) {
350
0
    MVMRegister value;
351
0
    value.n64 = unshiftee;
352
0
    REPR(obj)->pos_funcs.unshift(tc, STABLE(obj), obj, OBJECT_BODY(obj),
353
0
        value, MVM_reg_num64);
354
0
}
355
356
0
void MVM_repr_unshift_s(MVMThreadContext *tc, MVMObject *obj, MVMString *unshiftee) {
357
0
    MVMRegister value;
358
0
    value.s = unshiftee;
359
0
    REPR(obj)->pos_funcs.unshift(tc, STABLE(obj), obj, OBJECT_BODY(obj),
360
0
        value, MVM_reg_str);
361
0
}
362
363
9.34k
void MVM_repr_unshift_o(MVMThreadContext *tc, MVMObject *obj, MVMObject *unshiftee) {
364
9.34k
    MVMRegister value;
365
9.34k
    value.o = unshiftee;
366
9.34k
    REPR(obj)->pos_funcs.unshift(tc, STABLE(obj), obj, OBJECT_BODY(obj),
367
9.34k
        value, MVM_reg_obj);
368
9.34k
}
369
370
22.9k
MVMint64 MVM_repr_pop_i(MVMThreadContext *tc, MVMObject *obj) {
371
22.9k
    MVMRegister value;
372
22.9k
    REPR(obj)->pos_funcs.pop(tc, STABLE(obj), obj, OBJECT_BODY(obj),
373
22.9k
        &value, MVM_reg_int64);
374
22.9k
    return value.i64;
375
22.9k
}
376
377
0
MVMnum64 MVM_repr_pop_n(MVMThreadContext *tc, MVMObject *obj) {
378
0
    MVMRegister value;
379
0
    REPR(obj)->pos_funcs.pop(tc, STABLE(obj), obj, OBJECT_BODY(obj),
380
0
        &value, MVM_reg_num64);
381
0
    return value.n64;
382
0
}
383
384
0
MVMString * MVM_repr_pop_s(MVMThreadContext *tc, MVMObject *obj) {
385
0
    MVMRegister value;
386
0
    REPR(obj)->pos_funcs.pop(tc, STABLE(obj), obj, OBJECT_BODY(obj),
387
0
        &value, MVM_reg_str);
388
0
    return value.s;
389
0
}
390
391
26.4k
MVMObject * MVM_repr_pop_o(MVMThreadContext *tc, MVMObject *obj) {
392
26.4k
    MVMRegister value;
393
26.4k
    REPR(obj)->pos_funcs.pop(tc, STABLE(obj), obj, OBJECT_BODY(obj),
394
26.4k
        &value, MVM_reg_obj);
395
26.4k
    return value.o;
396
26.4k
}
397
398
0
MVMint64 MVM_repr_shift_i(MVMThreadContext *tc, MVMObject *obj) {
399
0
    MVMRegister value;
400
0
    REPR(obj)->pos_funcs.shift(tc, STABLE(obj), obj, OBJECT_BODY(obj),
401
0
        &value, MVM_reg_int64);
402
0
    return value.i64;
403
0
}
404
405
0
MVMnum64 MVM_repr_shift_n(MVMThreadContext *tc, MVMObject *obj) {
406
0
    MVMRegister value;
407
0
    REPR(obj)->pos_funcs.shift(tc, STABLE(obj), obj, OBJECT_BODY(obj),
408
0
        &value, MVM_reg_num64);
409
0
    return value.n64;
410
0
}
411
412
0
MVMString * MVM_repr_shift_s(MVMThreadContext *tc, MVMObject *obj) {
413
0
    MVMRegister value;
414
0
    REPR(obj)->pos_funcs.shift(tc, STABLE(obj), obj, OBJECT_BODY(obj),
415
0
        &value, MVM_reg_str);
416
0
    return value.s;
417
0
}
418
419
599k
MVMObject * MVM_repr_shift_o(MVMThreadContext *tc, MVMObject *obj) {
420
599k
    MVMRegister value;
421
599k
    REPR(obj)->pos_funcs.shift(tc, STABLE(obj), obj, OBJECT_BODY(obj),
422
599k
        &value, MVM_reg_obj);
423
599k
    return value.o;
424
599k
}
425
426
0
MVMint64 MVM_repr_at_key_i(MVMThreadContext *tc, MVMObject *obj, MVMString *key) {
427
0
    MVMRegister value;
428
0
    REPR(obj)->ass_funcs.at_key(tc, STABLE(obj), obj, OBJECT_BODY(obj),
429
0
                                (MVMObject *)key, &value, MVM_reg_int64);
430
0
    return value.i64;
431
0
}
432
433
0
MVMnum64 MVM_repr_at_key_n(MVMThreadContext *tc, MVMObject *obj, MVMString *key) {
434
0
    MVMRegister value;
435
0
    REPR(obj)->ass_funcs.at_key(tc, STABLE(obj), obj, OBJECT_BODY(obj),
436
0
                                (MVMObject *)key, &value, MVM_reg_num64);
437
0
    return value.n64;
438
0
}
439
440
0
MVMString * MVM_repr_at_key_s(MVMThreadContext *tc, MVMObject *obj, MVMString *key) {
441
0
    MVMRegister value;
442
0
    REPR(obj)->ass_funcs.at_key(tc, STABLE(obj), obj, OBJECT_BODY(obj),
443
0
                                (MVMObject *)key, &value, MVM_reg_str);
444
0
    return value.s;
445
0
}
446
447
8.27M
MVMObject * MVM_repr_at_key_o(MVMThreadContext *tc, MVMObject *obj, MVMString *key) {
448
8.27M
    if (IS_CONCRETE(obj)) {
449
8.27M
        MVMRegister value;
450
8.27M
        REPR(obj)->ass_funcs.at_key(tc, STABLE(obj), obj, OBJECT_BODY(obj),
451
8.27M
                                    (MVMObject *)key, &value, MVM_reg_obj);
452
8.27M
        return value.o;
453
8.27M
    }
454
91
    return NULL;
455
8.27M
}
456
457
0
void MVM_repr_bind_key_i(MVMThreadContext *tc, MVMObject *obj, MVMString *key, MVMint64 val) {
458
0
    MVMRegister value;
459
0
    value.i64 = val;
460
0
    REPR(obj)->ass_funcs.bind_key(tc, STABLE(obj), obj, OBJECT_BODY(obj),
461
0
        (MVMObject *)key, value, MVM_reg_int64);
462
0
}
463
464
0
void MVM_repr_bind_key_n(MVMThreadContext *tc, MVMObject *obj, MVMString *key, MVMnum64 val) {
465
0
    MVMRegister value;
466
0
    value.n64 = val;
467
0
    REPR(obj)->ass_funcs.bind_key(tc, STABLE(obj), obj, OBJECT_BODY(obj),
468
0
        (MVMObject *)key, value, MVM_reg_num64);
469
0
}
470
471
0
void MVM_repr_bind_key_s(MVMThreadContext *tc, MVMObject *obj, MVMString *key, MVMString *val) {
472
0
    MVMRegister value;
473
0
    value.s = val;
474
0
    REPR(obj)->ass_funcs.bind_key(tc, STABLE(obj), obj, OBJECT_BODY(obj),
475
0
        (MVMObject *)key, value, MVM_reg_str);
476
0
}
477
478
930k
void MVM_repr_bind_key_o(MVMThreadContext *tc, MVMObject *obj, MVMString *key, MVMObject *val) {
479
930k
    MVMRegister value;
480
930k
    value.o = val;
481
930k
    REPR(obj)->ass_funcs.bind_key(tc, STABLE(obj), obj, OBJECT_BODY(obj),
482
930k
        (MVMObject *)key, value, MVM_reg_obj);
483
930k
}
484
485
80.2k
MVMint64 MVM_repr_exists_key(MVMThreadContext *tc, MVMObject *obj, MVMString *key) {
486
80.2k
    return REPR(obj)->ass_funcs.exists_key(tc, STABLE(obj), obj,
487
80.2k
        OBJECT_BODY(obj), (MVMObject *)key);
488
80.2k
}
489
490
22.4k
void MVM_repr_delete_key(MVMThreadContext *tc, MVMObject *obj, MVMString *key) {
491
22.4k
    REPR(obj)->ass_funcs.delete_key(tc, STABLE(obj), obj,
492
22.4k
        OBJECT_BODY(obj), (MVMObject *)key);
493
22.4k
}
494
495
3.16M
MVMuint64 MVM_repr_elems(MVMThreadContext *tc, MVMObject *obj) {
496
3.16M
    return REPR(obj)->elems(tc, STABLE(obj), obj, OBJECT_BODY(obj));
497
3.16M
}
498
499
10
MVMObject * MVM_repr_dimensions(MVMThreadContext *tc, MVMObject *obj) {
500
10
    if (IS_CONCRETE(obj)) {
501
9
        MVMint64 num_dims, i;
502
9
        MVMint64 *dims;
503
9
        MVMObject *result = MVM_repr_alloc_init(tc, tc->instance->boot_types.BOOTIntArray);
504
9
        REPR(obj)->pos_funcs.dimensions(tc, STABLE(obj), obj, OBJECT_BODY(obj),
505
9
            &num_dims, &dims);
506
23
        for (i = 0; i < num_dims; i++)
507
14
            MVM_repr_bind_pos_i(tc, result, i, dims[i]);
508
9
        return result;
509
9
    }
510
1
    else {
511
1
        MVM_exception_throw_adhoc(tc, "Cannot get dimensions of a type object");
512
1
    }
513
10
}
514
515
9
MVMint64 MVM_repr_num_dimensions(MVMThreadContext *tc, MVMObject *obj) {
516
9
    if (IS_CONCRETE(obj)) {
517
8
        MVMint64 num_dims;
518
8
        MVMint64 *_;
519
8
        REPR(obj)->pos_funcs.dimensions(tc, STABLE(obj), obj, OBJECT_BODY(obj),
520
8
            &num_dims, &_);
521
8
        return num_dims;
522
8
    }
523
1
    else {
524
1
        MVM_exception_throw_adhoc(tc, "Cannot get number of dimensions of a type object");
525
1
    }
526
9
}
527
528
370k
MVMint64 MVM_repr_get_int(MVMThreadContext *tc, MVMObject *obj) {
529
370k
    if (!IS_CONCRETE(obj))
530
0
        MVM_exception_throw_adhoc(tc, "Cannot unbox a type object (%s) to int.", STABLE(obj)->debug_name);
531
370k
    return REPR(obj)->box_funcs.get_int(tc, STABLE(obj), obj, OBJECT_BODY(obj));
532
370k
}
533
534
5
MVMnum64 MVM_repr_get_num(MVMThreadContext *tc, MVMObject *obj) {
535
5
    if (!IS_CONCRETE(obj))
536
0
        MVM_exception_throw_adhoc(tc, "Cannot unbox a type object (%s) to a num.", STABLE(obj)->debug_name);
537
5
    return REPR(obj)->box_funcs.get_num(tc, STABLE(obj), obj, OBJECT_BODY(obj));
538
5
}
539
540
1.39M
MVMString * MVM_repr_get_str(MVMThreadContext *tc, MVMObject *obj) {
541
1.39M
    if (!IS_CONCRETE(obj))
542
0
        MVM_exception_throw_adhoc(tc, "Cannot unbox a type object (%s) to a str.", STABLE(obj)->debug_name);
543
1.39M
    return REPR(obj)->box_funcs.get_str(tc, STABLE(obj), obj, OBJECT_BODY(obj));
544
1.39M
}
545
546
0
MVMuint64 MVM_repr_get_uint(MVMThreadContext *tc, MVMObject *obj) {
547
0
    if (!IS_CONCRETE(obj))
548
0
        MVM_exception_throw_adhoc(tc, "Cannot unbox a type object (%s) to an unsigned int.", STABLE(obj)->debug_name);
549
0
    return REPR(obj)->box_funcs.get_uint(tc, STABLE(obj), obj, OBJECT_BODY(obj));
550
0
}
551
552
699k
void MVM_repr_set_int(MVMThreadContext *tc, MVMObject *obj, MVMint64 val) {
553
699k
    REPR(obj)->box_funcs.set_int(tc, STABLE(obj), obj, OBJECT_BODY(obj), val);
554
699k
}
555
556
175k
void MVM_repr_set_num(MVMThreadContext *tc, MVMObject *obj, MVMnum64 val) {
557
175k
    REPR(obj)->box_funcs.set_num(tc, STABLE(obj), obj, OBJECT_BODY(obj), val);
558
175k
}
559
560
261k
void MVM_repr_set_str(MVMThreadContext *tc, MVMObject *obj, MVMString *val) {
561
261k
    REPR(obj)->box_funcs.set_str(tc, STABLE(obj), obj, OBJECT_BODY(obj), val);
562
261k
}
563
564
0
void MVM_repr_set_uint(MVMThreadContext *tc, MVMObject *obj, MVMuint64 val) {
565
0
    REPR(obj)->box_funcs.set_uint(tc, STABLE(obj), obj, OBJECT_BODY(obj), val);
566
0
}
567
568
1.92M
MVMObject * MVM_repr_box_int(MVMThreadContext *tc, MVMObject *type, MVMint64 val) {
569
1.92M
    MVMObject *res;
570
1.92M
    res = MVM_intcache_get(tc, type, val);
571
1.92M
    if (res == 0) {
572
697k
        res = MVM_repr_alloc_init(tc, type);
573
697k
        MVM_repr_set_int(tc, res, val);
574
697k
    }
575
1.92M
    return res;
576
1.92M
}
577
578
10
MVMObject * MVM_repr_box_num(MVMThreadContext *tc, MVMObject *type, MVMnum64 val) {
579
10
    MVMObject *res = MVM_repr_alloc_init(tc, type);
580
10
    MVM_repr_set_num(tc, res, val);
581
10
    return res;
582
10
}
583
584
33.6k
MVMObject * MVM_repr_box_str(MVMThreadContext *tc, MVMObject *type, MVMString *val) {
585
33.6k
    MVMObject *res;
586
33.6k
    MVMROOT(tc, val, {
587
33.6k
        res = MVM_repr_alloc_init(tc, type);
588
33.6k
        MVM_repr_set_str(tc, res, val);
589
33.6k
    });
590
33.6k
    return res;
591
33.6k
}
592
593
0
MVMObject * MVM_repr_box_uint(MVMThreadContext *tc, MVMObject *type, MVMuint64 val) {
594
0
    MVMObject *res = MVM_repr_alloc_init(tc, type);
595
0
    MVM_repr_set_uint(tc, res, val);
596
0
    return res;
597
0
}
598
599
MVM_PUBLIC MVMint64 MVM_repr_get_attr_i(MVMThreadContext *tc, MVMObject *object, MVMObject *type,
600
66.2k
                                           MVMString *name, MVMint16 hint) {
601
66.2k
    MVMRegister result_reg;
602
66.2k
    if (!IS_CONCRETE(object))
603
0
        MVM_exception_throw_adhoc(tc, "Cannot look up attributes in a %s type object", STABLE(object)->debug_name);
604
66.2k
    REPR(object)->attr_funcs.get_attribute(tc,
605
66.2k
            STABLE(object), object, OBJECT_BODY(object),
606
66.2k
            type, name,
607
66.2k
            hint, &result_reg, MVM_reg_int64);
608
66.2k
    return result_reg.i64;
609
66.2k
}
610
611
MVM_PUBLIC MVMnum64 MVM_repr_get_attr_n(MVMThreadContext *tc, MVMObject *object, MVMObject *type,
612
1
                                           MVMString *name, MVMint16 hint) {
613
1
    MVMRegister result_reg;
614
1
    if (!IS_CONCRETE(object))
615
0
        MVM_exception_throw_adhoc(tc, "Cannot look up attributes in a %s type object", STABLE(object)->debug_name);
616
1
    REPR(object)->attr_funcs.get_attribute(tc,
617
1
            STABLE(object), object, OBJECT_BODY(object),
618
1
            type, name,
619
1
            hint, &result_reg, MVM_reg_num64);
620
1
    return result_reg.n64;
621
1
}
622
623
MVM_PUBLIC MVMString * MVM_repr_get_attr_s(MVMThreadContext *tc, MVMObject *object, MVMObject *type,
624
299k
                                           MVMString *name, MVMint16 hint) {
625
299k
    MVMRegister result_reg;
626
299k
    if (!IS_CONCRETE(object))
627
0
        MVM_exception_throw_adhoc(tc, "Cannot look up attributes in a %s type object", STABLE(object)->debug_name);
628
299k
    REPR(object)->attr_funcs.get_attribute(tc,
629
299k
            STABLE(object), object, OBJECT_BODY(object),
630
299k
            type, name,
631
299k
            hint, &result_reg, MVM_reg_str);
632
299k
    return result_reg.s;
633
299k
}
634
635
MVM_PUBLIC MVMObject * MVM_repr_get_attr_o(MVMThreadContext *tc, MVMObject *object, MVMObject *type,
636
254k
                                           MVMString *name, MVMint16 hint) {
637
254k
    MVMRegister result_reg;
638
254k
    if (!IS_CONCRETE(object))
639
0
        MVM_exception_throw_adhoc(tc, "Cannot look up attributes in a %s type object", STABLE(object)->debug_name);
640
254k
    REPR(object)->attr_funcs.get_attribute(tc,
641
254k
            STABLE(object), object, OBJECT_BODY(object),
642
254k
            type, name,
643
254k
            hint, &result_reg, MVM_reg_obj);
644
254k
    return result_reg.o;
645
254k
}
646
647
648
MVM_PUBLIC void MVM_repr_bind_attr_inso(MVMThreadContext *tc, MVMObject *object, MVMObject *type,
649
1.06M
                                           MVMString *name, MVMint16 hint, MVMRegister value_reg, MVMuint16 kind) {
650
1.06M
    if (!IS_CONCRETE(object))
651
0
        MVM_exception_throw_adhoc(tc, "Cannot bind attributes in a %s type object", STABLE(object)->debug_name);
652
1.06M
    REPR(object)->attr_funcs.bind_attribute(tc,
653
1.06M
            STABLE(object), object, OBJECT_BODY(object),
654
1.06M
            type, name,
655
1.06M
            hint, value_reg, kind);
656
1.06M
    MVM_SC_WB_OBJ(tc, object);
657
1.06M
}
658
659
MVM_PUBLIC MVMint64 MVM_repr_attribute_inited(MVMThreadContext *tc, MVMObject *obj, MVMObject *type,
660
0
                                              MVMString *name) {
661
0
    if (!IS_CONCRETE(obj))
662
0
        MVM_exception_throw_adhoc(tc, "Cannot look up attributes in a %s type object", STABLE(obj)->debug_name);
663
0
    return REPR(obj)->attr_funcs.is_attribute_initialized(tc,
664
0
        STABLE(obj), OBJECT_BODY(obj),
665
0
        type, name, MVM_NO_HINT);
666
0
}
667
668
0
MVM_PUBLIC MVMint64    MVM_repr_compare_repr_id(MVMThreadContext *tc, MVMObject *object, MVMuint32 REPRId) {
669
0
    return object && REPR(object)->ID == REPRId ? 1 : 0;
670
0
}
671
672
0
MVM_PUBLIC MVMint64    MVM_repr_hint_for(MVMThreadContext *tc, MVMObject *object, MVMString *attrname) {
673
0
    return REPR(object)->attr_funcs.hint_for(tc, STABLE(object), object, attrname);
674
0
}