Skip to content

Commit cce66db

Browse files
committed
Start chasing chains of outer contexts, serializing along the chain rather than just the immediate one. No deserialization of the chaining just yet.
1 parent 20ef680 commit cce66db

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

src/6model/serialization.c

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#define STABLES_TABLE_ENTRY_SIZE 8
2525
#define OBJECTS_TABLE_ENTRY_SIZE 16
2626
#define CLOSURES_TABLE_ENTRY_SIZE 24
27-
#define CONTEXTS_TABLE_ENTRY_SIZE 12
27+
#define CONTEXTS_TABLE_ENTRY_SIZE 16
2828
#define REPOS_TABLE_ENTRY_SIZE 16
2929

3030
/* Some guesses. */
@@ -312,23 +312,19 @@ static PMC * closure_to_static_code_ref(PARROT_INTERP, PMC *closure, INTVAL fata
312312
}
313313
}
314314

315-
/* Takes a closure, that is to be serialized. Checks if it has an outer that is
316-
* of interest, and if so sets it up to be serialized. */
317-
Parrot_Int4 get_serialized_outer_context_idx(PARROT_INTERP, SerializationWriter *writer, PMC *closure) {
318-
PMC *outer_ctx = PARROT_SUB(closure)->outer_ctx;
319-
PMC *ctx_sc = VTABLE_getprop(interp, outer_ctx, Parrot_str_new_constant(interp, "SC"));
320-
if (!PMC_IS_NULL(VTABLE_getprop(interp, closure, Parrot_str_new_constant(interp, "COMPILER_STUB")))) {
321-
return 0;
322-
}
315+
/* Takes an outer context that is potentially to be serialized. Checks if it
316+
* is of interest, and if so sets it up to be serialized. */
317+
static Parrot_Int4 get_serialized_context_idx(PARROT_INTERP, SerializationWriter *writer, PMC *ctx) {
318+
PMC *ctx_sc = VTABLE_getprop(interp, ctx, Parrot_str_new_constant(interp, "SC"));
323319
if (PMC_IS_NULL(ctx_sc)) {
324320
/* Make sure we should chase a level down. */
325-
if (PMC_IS_NULL(closure_to_static_code_ref(interp, PARROT_CALLCONTEXT(outer_ctx)->current_sub, 0))) {
321+
if (PMC_IS_NULL(closure_to_static_code_ref(interp, PARROT_CALLCONTEXT(ctx)->current_sub, 0))) {
326322
return 0;
327323
}
328324
else {
329325
INTVAL idx = VTABLE_elements(interp, writer->contexts_list);
330-
VTABLE_set_pmc_keyed_int(interp, writer->contexts_list, idx, outer_ctx);
331-
VTABLE_setprop(interp, outer_ctx, Parrot_str_new_constant(interp, "SC"), writer->root.sc);
326+
VTABLE_set_pmc_keyed_int(interp, writer->contexts_list, idx, ctx);
327+
VTABLE_setprop(interp, ctx, Parrot_str_new_constant(interp, "SC"), writer->root.sc);
332328
return (Parrot_Int4)idx + 1;
333329
}
334330
}
@@ -339,13 +335,21 @@ Parrot_Int4 get_serialized_outer_context_idx(PARROT_INTERP, SerializationWriter
339335
"Serialization Error: reference to context outside of SC");
340336
c = VTABLE_elements(interp, writer->contexts_list);
341337
for (i = 0; i < c; i++)
342-
if (VTABLE_get_pmc_keyed_int(interp, writer->contexts_list, i) == outer_ctx)
338+
if (VTABLE_get_pmc_keyed_int(interp, writer->contexts_list, i) == ctx)
343339
return (Parrot_Int4)i + 1;
344340
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
345341
"Serialization Error: could not locate outer context in current SC");
346342
}
347343
}
348344

345+
/* Takes a closure, that is to be serialized. Checks if it has an outer that is
346+
* of interest, and if so sets it up to be serialized. */
347+
static Parrot_Int4 get_serialized_outer_context_idx(PARROT_INTERP, SerializationWriter *writer, PMC *closure) {
348+
if (!PMC_IS_NULL(VTABLE_getprop(interp, closure, Parrot_str_new_constant(interp, "COMPILER_STUB"))))
349+
return 0;
350+
return get_serialized_context_idx(interp, writer, PARROT_SUB(closure)->outer_ctx);
351+
}
352+
349353
/* Takes a closure that needs to be serialized. Makes an entry in the closures
350354
* table for it. Also adds it to this SC's code refs set and tags it with the
351355
* current SC. */
@@ -773,6 +777,14 @@ static void serialize_context(PARROT_INTERP, SerializationWriter *writer, PMC *c
773777
write_int32(writer->root.contexts_table, offset + 4, static_idx);
774778
write_int32(writer->root.contexts_table, offset + 8, writer->contexts_data_offset);
775779

780+
/* See if there's any relevant outer context, and if so set it up to
781+
* be serialized. */
782+
if (!PMC_IS_NULL(PARROT_CALLCONTEXT(ctx)->outer_ctx))
783+
write_int32(writer->root.contexts_table, offset + 12,
784+
get_serialized_context_idx(interp, writer, PARROT_CALLCONTEXT(ctx)->outer_ctx));
785+
else
786+
write_int32(writer->root.contexts_table, offset + 12, 0);
787+
776788
/* Increment count of stables in the table. */
777789
writer->root.num_contexts++;
778790

0 commit comments

Comments
 (0)