@@ -289,27 +289,37 @@ extern void optscriptInstallProcs (EsObject *dict,
289
289
}
290
290
291
291
static EsObject * optscript_CorkIndex_sym = es_nil ;
292
+ static ptrArray * corkIndexStack ;
292
293
extern void optscriptSetup (OptVM * vm , EsObject * dict , int corkIndex )
293
294
{
295
+ if (es_null (optscript_CorkIndex_sym ))
296
+ optscript_CorkIndex_sym = es_symbol_intern ("." );
297
+ if (corkIndexStack == NULL )
298
+ corkIndexStack = ptrArrayNew ((ptrArrayDeleteFunc )es_object_unref );
299
+
300
+ /* Push the last '.' to corkIndexStack. */
301
+ EsObject * last = es_false ;
302
+ opt_dict_known_and_get (dict , optscript_CorkIndex_sym , & last );
303
+ ptrArrayAdd (corkIndexStack , es_object_ref (last ));
304
+
294
305
if (corkIndex != CORK_NIL )
295
306
{
296
- static EsObject * corkIndex_sym = es_nil ;
297
- if (es_null (corkIndex_sym ))
298
- corkIndex_sym = es_symbol_intern ("." );
299
307
EsObject * corkIndex_val = es_integer_new (corkIndex );
300
- opt_dict_def (dict , corkIndex_sym , corkIndex_val );
308
+ opt_dict_def (dict , optscript_CorkIndex_sym , corkIndex_val );
301
309
es_object_unref (corkIndex_val );
302
- optscript_CorkIndex_sym = corkIndex_sym ;
303
310
}
304
311
}
305
312
306
313
extern void optscriptTeardown (OptVM * vm , EsObject * dict )
307
314
{
308
- if (!es_null (optscript_CorkIndex_sym ))
309
- {
315
+ if (opt_dict_known_and_get (dict , optscript_CorkIndex_sym , NULL ))
310
316
opt_dict_undef (dict , optscript_CorkIndex_sym );
311
- optscript_CorkIndex_sym = es_nil ;
312
- }
317
+
318
+ /* Pop the last '.'. */
319
+ EsObject * index = ptrArrayLast (corkIndexStack );
320
+ if (!es_object_equal (index , es_false ))
321
+ opt_dict_def (dict , optscript_CorkIndex_sym , index );
322
+ ptrArrayDeleteLast (corkIndexStack );
313
323
}
314
324
315
325
extern EsObject * optscriptRead (OptVM * vm , const char * src , size_t len )
0 commit comments