/home/travis/build/MoarVM/MoarVM/src/6model/reprs/MVMCFunction.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 MVMCFunction_this_repr; |
5 | | |
6 | | /* Invocation protocol handler. */ |
7 | 4.97k | static void invoke_handler(MVMThreadContext *tc, MVMObject *invokee, MVMCallsite *callsite, MVMRegister *args) { |
8 | 4.97k | if (IS_CONCRETE(invokee)) |
9 | 4.97k | ((MVMCFunction *)invokee)->body.func(tc, callsite, args); |
10 | 4.97k | else |
11 | 0 | MVM_exception_throw_adhoc(tc, "Cannot invoke C function type object"); |
12 | 4.97k | } |
13 | | |
14 | | /* Creates a new type object of this representation, and associates it with |
15 | | * the given HOW. Also sets the invocation protocol handler in the STable. */ |
16 | 144 | static MVMObject * type_object_for(MVMThreadContext *tc, MVMObject *HOW) { |
17 | 144 | MVMSTable *st = MVM_gc_allocate_stable(tc, &MVMCFunction_this_repr, HOW); |
18 | 144 | |
19 | 144 | MVMROOT(tc, st, { |
20 | 144 | MVMObject *obj = MVM_gc_allocate_type_object(tc, st); |
21 | 144 | MVM_ASSIGN_REF(tc, &(st->header), st->WHAT, obj); |
22 | 144 | st->invoke = invoke_handler; |
23 | 144 | st->size = sizeof(MVMCFunction); |
24 | 144 | }); |
25 | 144 | |
26 | 144 | return st->WHAT; |
27 | 144 | } |
28 | | |
29 | | /* Copies the body of one object to another. */ |
30 | 0 | static void copy_to(MVMThreadContext *tc, MVMSTable *st, void *src, MVMObject *dest_root, void *dest) { |
31 | 0 | MVMCFunctionBody *src_body = (MVMCFunctionBody *)src; |
32 | 0 | MVMCFunctionBody *dest_body = (MVMCFunctionBody *)dest; |
33 | 0 | dest_body->func = src_body->func; |
34 | 0 | } |
35 | | |
36 | | |
37 | | static const MVMStorageSpec storage_spec = { |
38 | | MVM_STORAGE_SPEC_REFERENCE, /* inlineable */ |
39 | | 0, /* bits */ |
40 | | 0, /* align */ |
41 | | MVM_STORAGE_SPEC_BP_NONE, /* boxed_primitive */ |
42 | | 0, /* can_box */ |
43 | | 0, /* is_unsigned */ |
44 | | }; |
45 | | |
46 | | |
47 | | /* Gets the storage specification for this representation. */ |
48 | 0 | static const MVMStorageSpec * get_storage_spec(MVMThreadContext *tc, MVMSTable *st) { |
49 | 0 | return &storage_spec; |
50 | 0 | } |
51 | | |
52 | | /* Compose the representation. */ |
53 | 0 | static void compose(MVMThreadContext *tc, MVMSTable *st, MVMObject *info) { |
54 | 0 | /* Nothing to do for this REPR. */ |
55 | 0 | } |
56 | | |
57 | | /* Initializes the representation. */ |
58 | 144 | const MVMREPROps * MVMCFunction_initialize(MVMThreadContext *tc) { |
59 | 144 | return &MVMCFunction_this_repr; |
60 | 144 | } |
61 | | |
62 | | static const MVMREPROps MVMCFunction_this_repr = { |
63 | | type_object_for, |
64 | | MVM_gc_allocate_object, |
65 | | NULL, /* initialize */ |
66 | | copy_to, |
67 | | MVM_REPR_DEFAULT_ATTR_FUNCS, |
68 | | MVM_REPR_DEFAULT_BOX_FUNCS, |
69 | | MVM_REPR_DEFAULT_POS_FUNCS, |
70 | | MVM_REPR_DEFAULT_ASS_FUNCS, |
71 | | MVM_REPR_DEFAULT_ELEMS, |
72 | | get_storage_spec, |
73 | | NULL, /* change_type */ |
74 | | NULL, /* serialize */ |
75 | | NULL, /* deserialize */ |
76 | | NULL, /* serialize_repr_data */ |
77 | | NULL, /* deserialize_repr_data */ |
78 | | NULL, /* deserialize_stable_size */ |
79 | | NULL, /* gc_mark */ |
80 | | NULL, /* gc_free */ |
81 | | NULL, /* gc_cleanup */ |
82 | | NULL, /* gc_mark_repr_data */ |
83 | | NULL, /* gc_free_repr_data */ |
84 | | compose, |
85 | | NULL, /* spesh */ |
86 | | "MVMCFunction", /* name */ |
87 | | MVM_REPR_ID_MVMCFunction, |
88 | | NULL, /* unmanaged_size */ |
89 | | NULL, /* describe_refs */ |
90 | | }; |