24
24
#define STABLES_TABLE_ENTRY_SIZE 8
25
25
#define OBJECTS_TABLE_ENTRY_SIZE 16
26
26
#define CLOSURES_TABLE_ENTRY_SIZE 24
27
- #define CONTEXTS_TABLE_ENTRY_SIZE 12
27
+ #define CONTEXTS_TABLE_ENTRY_SIZE 16
28
28
#define REPOS_TABLE_ENTRY_SIZE 16
29
29
30
30
/* Some guesses. */
@@ -312,23 +312,19 @@ static PMC * closure_to_static_code_ref(PARROT_INTERP, PMC *closure, INTVAL fata
312
312
}
313
313
}
314
314
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" ));
323
319
if (PMC_IS_NULL (ctx_sc )) {
324
320
/* 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 ))) {
326
322
return 0 ;
327
323
}
328
324
else {
329
325
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 );
332
328
return (Parrot_Int4 )idx + 1 ;
333
329
}
334
330
}
@@ -339,13 +335,21 @@ Parrot_Int4 get_serialized_outer_context_idx(PARROT_INTERP, SerializationWriter
339
335
"Serialization Error: reference to context outside of SC" );
340
336
c = VTABLE_elements (interp , writer -> contexts_list );
341
337
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 )
343
339
return (Parrot_Int4 )i + 1 ;
344
340
Parrot_ex_throw_from_c_args (interp , NULL , EXCEPTION_INVALID_OPERATION ,
345
341
"Serialization Error: could not locate outer context in current SC" );
346
342
}
347
343
}
348
344
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
+
349
353
/* Takes a closure that needs to be serialized. Makes an entry in the closures
350
354
* table for it. Also adds it to this SC's code refs set and tags it with the
351
355
* current SC. */
@@ -773,6 +777,14 @@ static void serialize_context(PARROT_INTERP, SerializationWriter *writer, PMC *c
773
777
write_int32 (writer -> root .contexts_table , offset + 4 , static_idx );
774
778
write_int32 (writer -> root .contexts_table , offset + 8 , writer -> contexts_data_offset );
775
779
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
+
776
788
/* Increment count of stables in the table. */
777
789
writer -> root .num_contexts ++ ;
778
790
0 commit comments