Coverage Report

Created: 2018-07-03 15:31

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