/home/travis/build/MoarVM/MoarVM/src/6model/reprs/Lexotic.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 Lexotic_this_repr; |
5 | | |
6 | | /* Invocation protocol handler. */ |
7 | 0 | static void invoke_handler(MVMThreadContext *tc, MVMObject *invokee, MVMCallsite *callsite, MVMRegister *args) { |
8 | 0 | if (IS_CONCRETE(invokee)) { |
9 | 0 | /* Get argument and set as result. Need to root invokee, as argument |
10 | 0 | * processing may box. */ |
11 | 0 | MVMROOT(tc, invokee, { |
12 | 0 | MVMObject *result; |
13 | 0 | MVMArgProcContext arg_ctx; |
14 | 0 | MVM_args_proc_init(tc, &arg_ctx, callsite, args); |
15 | 0 | result = MVM_args_get_pos_obj(tc, &arg_ctx, 0, MVM_ARG_REQUIRED).arg.o; |
16 | 0 | MVM_ASSIGN_REF(tc, &(invokee->header), ((MVMLexotic *)invokee)->body.result, result); |
17 | 0 | MVM_args_proc_cleanup(tc, &arg_ctx); |
18 | 0 | }); |
19 | 0 |
|
20 | 0 | /* Unwind to the lexotic handler. */ |
21 | 0 | { |
22 | 0 | MVMLexotic *lex = (MVMLexotic *)invokee; |
23 | 0 | MVM_exception_gotolexotic(tc, lex->body.handler_idx, lex->body.sf); |
24 | 0 | } |
25 | 0 | } |
26 | 0 | else { |
27 | 0 | MVM_exception_throw_adhoc(tc, "Cannot invoke Lexotic type object"); |
28 | 0 | } |
29 | 0 | } |
30 | | |
31 | | /* Creates a new type object of this representation, and associates it with |
32 | | * the given HOW. */ |
33 | 132 | static MVMObject * type_object_for(MVMThreadContext *tc, MVMObject *HOW) { |
34 | 132 | MVMSTable *st = MVM_gc_allocate_stable(tc, &Lexotic_this_repr, HOW); |
35 | 132 | |
36 | 132 | MVMROOT(tc, st, { |
37 | 132 | MVMObject *obj = MVM_gc_allocate_type_object(tc, st); |
38 | 132 | MVM_ASSIGN_REF(tc, &(st->header), st->WHAT, obj); |
39 | 132 | st->invoke = invoke_handler; |
40 | 132 | st->size = sizeof(MVMLexotic); |
41 | 132 | }); |
42 | 132 | |
43 | 132 | return st->WHAT; |
44 | 132 | } |
45 | | |
46 | | /* Copies the body of one object to another. */ |
47 | 0 | static void copy_to(MVMThreadContext *tc, MVMSTable *st, void *src, MVMObject *dest_root, void *dest) { |
48 | 0 | MVM_exception_throw_adhoc(tc, "Cannot copy object with representation Lexotic"); |
49 | 0 | } |
50 | | |
51 | | /* Called by the VM to mark any GCable items. */ |
52 | 0 | static void gc_mark(MVMThreadContext *tc, MVMSTable *st, void *data, MVMGCWorklist *worklist) { |
53 | 0 | MVMLexoticBody *lb = (MVMLexoticBody *)data; |
54 | 0 | MVM_gc_worklist_add(tc, worklist, &lb->sf); |
55 | 0 | MVM_gc_worklist_add(tc, worklist, &lb->result); |
56 | 0 | } |
57 | | |
58 | | static const MVMStorageSpec storage_spec = { |
59 | | MVM_STORAGE_SPEC_REFERENCE, /* inlineable */ |
60 | | 0, /* bits */ |
61 | | 0, /* align */ |
62 | | MVM_STORAGE_SPEC_BP_NONE, /* boxed_primitive */ |
63 | | 0, /* can_box */ |
64 | | 0, /* is_unsigned */ |
65 | | }; |
66 | | |
67 | | /* Gets the storage specification for this representation. */ |
68 | 0 | static const MVMStorageSpec * get_storage_spec(MVMThreadContext *tc, MVMSTable *st) { |
69 | 0 | return &storage_spec; |
70 | 0 | } |
71 | | |
72 | | /* Compose the representation. */ |
73 | 0 | static void compose(MVMThreadContext *tc, MVMSTable *st, MVMObject *info) { |
74 | 0 | /* Nothing to do for this REPR. */ |
75 | 0 | } |
76 | | |
77 | 0 | static void describe_refs(MVMThreadContext *tc, MVMHeapSnapshotState *ss, MVMSTable *st, void *data) { |
78 | 0 | MVMLexoticBody *lb = (MVMLexoticBody *)data; |
79 | 0 | MVM_profile_heap_add_collectable_rel_const_cstr(tc, ss, (MVMCollectable *)lb->sf, |
80 | 0 | "Static Frame"); |
81 | 0 | MVM_profile_heap_add_collectable_rel_const_cstr(tc, ss, (MVMCollectable *)lb->result, |
82 | 0 | "Result"); |
83 | 0 | } |
84 | | |
85 | | /* Initializes the representation. */ |
86 | 132 | const MVMREPROps * MVMLexotic_initialize(MVMThreadContext *tc) { |
87 | 132 | return &Lexotic_this_repr; |
88 | 132 | } |
89 | | |
90 | | static const MVMREPROps Lexotic_this_repr = { |
91 | | type_object_for, |
92 | | MVM_gc_allocate_object, |
93 | | NULL, /* initialize */ |
94 | | copy_to, |
95 | | MVM_REPR_DEFAULT_ATTR_FUNCS, |
96 | | MVM_REPR_DEFAULT_BOX_FUNCS, |
97 | | MVM_REPR_DEFAULT_POS_FUNCS, |
98 | | MVM_REPR_DEFAULT_ASS_FUNCS, |
99 | | MVM_REPR_DEFAULT_ELEMS, |
100 | | get_storage_spec, |
101 | | NULL, /* change_type */ |
102 | | NULL, /* serialize */ |
103 | | NULL, /* deserialize */ |
104 | | NULL, /* serialize_repr_data */ |
105 | | NULL, /* deserialize_repr_data */ |
106 | | NULL, /* deserialize_stable_size */ |
107 | | gc_mark, |
108 | | NULL, /* gc_free */ |
109 | | NULL, /* gc_cleanup */ |
110 | | NULL, /* gc_mark_repr_data */ |
111 | | NULL, /* gc_free_repr_data */ |
112 | | compose, |
113 | | NULL, /* spesh */ |
114 | | "Lexotic", /* name */ |
115 | | MVM_REPR_ID_Lexotic, |
116 | | NULL, /* unmanaged_size */ |
117 | | describe_refs, |
118 | | }; |