5858 static void espStartInstrumentation (txMachine * the );
5959#endif
6060
61+ extern void * xsPreparationAndCreation (xsCreation * * creation );
62+
6163ICACHE_RAM_ATTR uint8_t espRead8 (const void * addr )
6264{
6365 const uint32_t * p = (const uint32_t * )(~3 & (uint32_t )addr );
@@ -634,45 +636,25 @@ int32_t modGetDaylightSavingsOffset(void)
634636
635637void * ESP_cloneMachine (uint32_t allocation , uint32_t stackCount , uint32_t slotCount , const char * name )
636638{
637- extern txPreparation * xsPreparation ();
638- void * result ;
639- txMachine root ;
640- txPreparation * prep = xsPreparation ();
641- txCreation creation ;
639+ xsMachine * result ;
642640 uint8_t * context [2 ];
641+ xsCreation * creationP ;
642+ void * preparation = xsPreparationAndCreation (& creationP );
643+ void * archive ;
643644
644- if ((prep -> version [0 ] != XS_MAJOR_VERSION ) || (prep -> version [1 ] != XS_MINOR_VERSION ) || (prep -> version [2 ] != XS_PATCH_VERSION ))
645- modLog ("version mismatch" );
646-
647- creation = prep -> creation ;
648-
649- root .preparation = prep ;
650645#if MODDEF_XS_MODS
651- root . archive = installModules (prep );
652- gHasMods = root . archive != NULL ;
646+ archive = installModules (prep );
647+ gHasMods = NULL != archive ;
653648#else
654- root . archive = NULL ;
649+ archive = NULL ;
655650#endif
656- root .keyArray = prep -> keys ;
657- root .keyCount = prep -> keyCount + prep -> creation .keyCount ;
658- root .keyIndex = prep -> keyCount ;
659- root .nameModulo = prep -> nameModulo ;
660- root .nameTable = prep -> names ;
661- root .symbolModulo = prep -> symbolModulo ;
662- root .symbolTable = prep -> symbols ;
663-
664- root .stack = & prep -> stack [0 ];
665- root .stackBottom = & prep -> stack [0 ];
666- root .stackTop = & prep -> stack [prep -> stackCount ];
667-
668- root .firstHeap = & prep -> heap [0 ];
669- root .freeHeap = & prep -> heap [prep -> heapCount - 1 ];
670- root .aliasCount = prep -> aliasCount ;
671651
672652 if (0 == allocation )
673- allocation = creation . staticSize ;
653+ allocation = creationP -> staticSize ;
674654
675655 if (allocation ) {
656+ xsCreation creation = * creationP ;
657+
676658 if (stackCount )
677659 creation .stackCount = stackCount ;
678660
@@ -686,22 +668,20 @@ void *ESP_cloneMachine(uint32_t allocation, uint32_t stackCount, uint32_t slotCo
686668 }
687669 context [1 ] = context [0 ] + allocation ;
688670
689- result = fxCloneMachine (& creation , & root , name ? (txString )name : "main" , context );
671+ result = xsPrepareMachine (& creation , preparation , name ? (txString )name : "main" , context , archive );
690672 if (NULL == result ) {
691673 if (context [0 ])
692674 c_free (context [0 ]);
693675 return NULL ;
694676 }
695-
696- ((txMachine * )result )-> context = NULL ;
697677 }
698678 else {
699- result = fxCloneMachine ( & prep -> creation , & root , "main" , NULL );
679+ result = xsPrepareMachine ( NULL , preparation , "main" , NULL , archive );
700680 if (NULL == result )
701681 return NULL ;
702682 }
703683
704- (( txMachine * ) result ) -> preparation = prep ;
684+ xsSetContext ( result , NULL ) ;
705685
706686#ifdef mxInstrument
707687 espStartInstrumentation (result );
@@ -728,8 +708,7 @@ void setStepDone(xsMachine *the)
728708
729709void mc_setup (xsMachine * the )
730710{
731- extern txPreparation * xsPreparation ();
732- txPreparation * preparation = xsPreparation ();
711+ txPreparation * preparation = xsPreparationAndCreation (NULL );
733712 txInteger scriptCount = preparation -> scriptCount ;
734713 txScript * script = preparation -> scripts ;
735714
@@ -1057,12 +1036,10 @@ void fxMarkHost(txMachine* the, txMarkRoot markRoot)
10571036
10581037txScript * fxParseScript (txMachine * the , void * stream , txGetter getter , txUnsigned flags )
10591038{
1060- extern txPreparation * xsPreparation ();
10611039 txParser _parser ;
10621040 txParser * parser = & _parser ;
10631041 txParserJump jump ;
10641042 txScript * script = NULL ;
1065- txPreparation * prep = xsPreparation ();
10661043 fxInitializeParser (parser , the , the -> parserBufferSize , the -> parserTableModulo );
10671044 parser -> firstJump = & jump ;
10681045 if (c_setjmp (jump .jmp_buf ) == 0 ) {
0 commit comments