/home/travis/build/MoarVM/MoarVM/src/6model/reprs/MVMContinuation.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 MVMContinuation_this_repr; |
5 | | |
6 | | /* Creates a new type object of this representation, and associates it with |
7 | | * the given HOW. Also sets the invocation protocol handler in the STable. */ |
8 | 144 | static MVMObject * type_object_for(MVMThreadContext *tc, MVMObject *HOW) { |
9 | 144 | MVMSTable *st = MVM_gc_allocate_stable(tc, &MVMContinuation_this_repr, HOW); |
10 | 144 | |
11 | 144 | MVMROOT(tc, st, { |
12 | 144 | MVMObject *obj = MVM_gc_allocate_type_object(tc, st); |
13 | 144 | MVM_ASSIGN_REF(tc, &(st->header), st->WHAT, obj); |
14 | 144 | st->size = sizeof(MVMContinuation); |
15 | 144 | }); |
16 | 144 | |
17 | 144 | return st->WHAT; |
18 | 144 | } |
19 | | |
20 | | /* Copies the body of one object to another. */ |
21 | 0 | static void copy_to(MVMThreadContext *tc, MVMSTable *st, void *src, MVMObject *dest_root, void *dest) { |
22 | 0 | MVM_panic(MVM_exitcode_NYI, "MVMContinuation copy_to NYI"); |
23 | 0 | } |
24 | | |
25 | | /* Adds held objects to the GC worklist. */ |
26 | 0 | static void gc_mark(MVMThreadContext *tc, MVMSTable *st, void *data, MVMGCWorklist *worklist) { |
27 | 0 | MVMContinuationBody *body = (MVMContinuationBody *)data; |
28 | 0 | MVM_gc_worklist_add(tc, worklist, &body->top); |
29 | 0 | MVM_gc_worklist_add(tc, worklist, &body->root); |
30 | 0 | if (body->active_handlers) { |
31 | 0 | MVMActiveHandler *cur_ah = body->active_handlers; |
32 | 0 | while (cur_ah != NULL) { |
33 | 0 | MVM_gc_worklist_add(tc, worklist, &cur_ah->ex_obj); |
34 | 0 | MVM_gc_worklist_add(tc, worklist, &cur_ah->frame); |
35 | 0 | cur_ah = cur_ah->next_handler; |
36 | 0 | } |
37 | 0 | } |
38 | 0 | if (body->prof_cont) { |
39 | 0 | MVMuint64 i; |
40 | 0 | for (i = 0; i < body->prof_cont->num_sfs; i++) |
41 | 0 | MVM_gc_worklist_add(tc, worklist, &(body->prof_cont->sfs[i])); |
42 | 0 | } |
43 | 0 | } |
44 | | |
45 | | /* Called by the VM in order to free memory associated with this object. */ |
46 | 0 | static void gc_free(MVMThreadContext *tc, MVMObject *obj) { |
47 | 0 | MVMContinuation *ctx = (MVMContinuation *)obj; |
48 | 0 | if (ctx->body.active_handlers) { |
49 | 0 | MVMActiveHandler *cur_ah = ctx->body.active_handlers; |
50 | 0 | while (cur_ah != NULL) { |
51 | 0 | MVMActiveHandler *next_ah = cur_ah->next_handler; |
52 | 0 | MVM_free(cur_ah); |
53 | 0 | cur_ah = next_ah; |
54 | 0 | } |
55 | 0 | } |
56 | 0 | if (ctx->body.prof_cont) |
57 | 0 | MVM_free(ctx->body.prof_cont); |
58 | 0 | } |
59 | | |
60 | | static const MVMStorageSpec storage_spec = { |
61 | | MVM_STORAGE_SPEC_REFERENCE, /* inlineable */ |
62 | | 0, /* bits */ |
63 | | 0, /* align */ |
64 | | MVM_STORAGE_SPEC_BP_NONE, /* boxed_primitive */ |
65 | | 0, /* can_box */ |
66 | | 0, /* is_unsigned */ |
67 | | }; |
68 | | |
69 | | /* Gets the storage specification for this representation. */ |
70 | 0 | static const MVMStorageSpec * get_storage_spec(MVMThreadContext *tc, MVMSTable *st) { |
71 | 0 | return &storage_spec; |
72 | 0 | } |
73 | | |
74 | | /* Compose the representation. */ |
75 | 0 | static void compose(MVMThreadContext *tc, MVMSTable *st, MVMObject *info) { |
76 | 0 | /* Nothing to do for this REPR. */ |
77 | 0 | } |
78 | | |
79 | | /* Initializes the representation. */ |
80 | 144 | const MVMREPROps * MVMContinuation_initialize(MVMThreadContext *tc) { |
81 | 144 | return &MVMContinuation_this_repr; |
82 | 144 | } |
83 | | |
84 | | static const MVMREPROps MVMContinuation_this_repr = { |
85 | | type_object_for, |
86 | | MVM_gc_allocate_object, |
87 | | NULL, /* initialize */ |
88 | | copy_to, |
89 | | MVM_REPR_DEFAULT_ATTR_FUNCS, |
90 | | MVM_REPR_DEFAULT_BOX_FUNCS, |
91 | | MVM_REPR_DEFAULT_POS_FUNCS, |
92 | | MVM_REPR_DEFAULT_ASS_FUNCS, |
93 | | NULL, /* elems */ |
94 | | get_storage_spec, |
95 | | NULL, /* change_type */ |
96 | | NULL, /* serialize */ |
97 | | NULL, /* deserialize */ |
98 | | NULL, /* serialize_repr_data */ |
99 | | NULL, /* deserialize_repr_data */ |
100 | | NULL, /* deserialize_stable_size */ |
101 | | gc_mark, |
102 | | gc_free, |
103 | | NULL, /* gc_cleanup */ |
104 | | NULL, /* gc_mark_repr_data */ |
105 | | NULL, /* gc_free_repr_data */ |
106 | | compose, |
107 | | NULL, /* spesh */ |
108 | | "MVMContinuation", /* name */ |
109 | | MVM_REPR_ID_MVMContinuation, |
110 | | NULL, /* unmanaged_size */ |
111 | | NULL, /* describe_refs */ |
112 | | }; |