Skip to content

Commit

Permalink
Give SCs an extra slot set for code refs.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Feb 4, 2012
1 parent bd58479 commit cac5607
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/6model/serialization_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ INTVAL SC_find_object_idx(PARROT_INTERP, PMC *sc, PMC *obj) {
"Object does not exist in serialization context");
}

/* Given an SC, looks up the index of a code ref that is in its root set. */
INTVAL SC_find_code_idx(PARROT_INTERP, PMC *sc, PMC *obj) {
PMC *to_search;
INTVAL i, count;
GETATTR_SerializationContext_root_codes(interp, sc, to_search);
count = VTABLE_elements(interp, to_search);
for (i = 0; i < count; i++)
if (VTABLE_get_pmc_keyed_int(interp, to_search, i) == obj)
return i;
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Code ref does not exist in serialization context");
}

/* Given an SC and an index, fetch the STable stored there. */
PMC * SC_get_stable(PARROT_INTERP, PMC *sc, INTVAL idx) {
PMC *stables;
Expand All @@ -91,3 +104,13 @@ PMC * SC_get_object(PARROT_INTERP, PMC *sc, INTVAL idx) {
"No object at index %d", idx);
return VTABLE_get_pmc_keyed_int(interp, objects, idx);
}

/* Given an SC and an index, fetch the code ref stored there. */
PMC * SC_get_code(PARROT_INTERP, PMC *sc, INTVAL idx) {
PMC *codes;
GETATTR_SerializationContext_root_codes(interp, sc, codes);
if (idx >= VTABLE_elements(interp, codes))
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"No code ref at index %d", idx);
return VTABLE_get_pmc_keyed_int(interp, codes, idx);
}
2 changes: 2 additions & 0 deletions src/6model/serialization_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ PMC * SC_get_sc(PARROT_INTERP, STRING *handle);
void SC_set_sc(PARROT_INTERP, STRING *handle, PMC *sc);
INTVAL SC_find_stable_idx(PARROT_INTERP, PMC *sc, PMC *st);
INTVAL SC_find_object_idx(PARROT_INTERP, PMC *sc, PMC *st);
INTVAL SC_find_code_idx(PARROT_INTERP, PMC *sc, PMC *st);
STRING * SC_get_handle(PARROT_INTERP, PMC *sc);
STRING * SC_get_description(PARROT_INTERP, PMC *sc);
PMC * SC_get_stable(PARROT_INTERP, PMC *sc, INTVAL idx);
PMC * SC_get_object(PARROT_INTERP, PMC *sc, INTVAL idx);
PMC * SC_get_code(PARROT_INTERP, PMC *sc, INTVAL idx);
#endif
9 changes: 8 additions & 1 deletion src/pmc/serializationcontext.pmc
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@ pmclass SerializationContext auto_attrs dynpmc group nqp {
/* The root set of STables that live in this SC. */
ATTR PMC *root_stables;

/* The root set of code refs that live in this SC. */
ATTR PMC *root_codes;

/* Description (probably the file name) if any. */
ATTR STRING *description;

VTABLE void init() {
PMC *root_objects = Parrot_pmc_new(interp, enum_class_ResizablePMCArray);
PMC *root_stables = Parrot_pmc_new(interp, enum_class_ResizablePMCArray);
PMC *root_codes = Parrot_pmc_new(interp, enum_class_ResizablePMCArray);
SET_ATTR_root_objects(interp, SELF, root_objects);
SET_ATTR_root_stables(interp, SELF, root_stables);
SET_ATTR_root_codes(interp, SELF, root_codes);
PObj_custom_mark_SET(SELF);
if (!smo_id)
smo_id = Parrot_pmc_get_type_str(interp, Parrot_str_new(interp, "SixModelObject", 0));
Expand All @@ -33,12 +38,14 @@ pmclass SerializationContext auto_attrs dynpmc group nqp {
}

VTABLE void mark() {
PMC *root_objects, *root_stables;
PMC *root_objects, *root_stables, *root_codes;
STRING *handle, *description;
GET_ATTR_root_objects(interp, SELF, root_objects);
Parrot_gc_mark_PMC_alive(INTERP, root_objects);
GET_ATTR_root_stables(interp, SELF, root_stables);
Parrot_gc_mark_PMC_alive(INTERP, root_stables);
GET_ATTR_root_codes(interp, SELF, root_codes);
Parrot_gc_mark_PMC_alive(INTERP, root_codes);
GET_ATTR_handle(interp, SELF, handle);
Parrot_gc_mark_STRING_alive(INTERP, handle);
GET_ATTR_description(interp, SELF, description);
Expand Down

0 comments on commit cac5607

Please sign in to comment.