Skip to content

Commit d0ced9a

Browse files
phoddiemkellner
authored andcommitted
a little more on xsPreparation
1 parent 965539f commit d0ced9a

File tree

3 files changed

+20
-43
lines changed

3 files changed

+20
-43
lines changed

tools/tool.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
*/
2020

2121
#include "xsPlatform.h"
22-
#include "xsAll.h"
2322
#include "xs.h"
2423
#include "mc.xs.h"
2524

xs/platforms/esp/xsHost.c

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
static void espStartInstrumentation(txMachine* the);
5959
#endif
6060

61+
extern void* xsPreparationAndCreation(xsCreation **creation);
62+
6163
ICACHE_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

635637
void *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

729709
void 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

10581037
txScript* 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) {

xs/tools/xsl.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,8 @@ int main(int argc, char* argv[])
323323
fprintf(file, "#ifdef __cplusplus\n");
324324
fprintf(file, "extern \"C\" {\n");
325325
fprintf(file, "#endif\n");
326-
fprintf(file, "mxExport void* xsPreparation();\n\n");
326+
fprintf(file, "#define xsPreparation() xsPreparationAndCreation(NULL)\n");
327+
fprintf(file, "mxExport void* xsPreparationAndCreation(xsCreation **creation);\n\n");
327328
script = linker->firstScript;
328329
while (script) {
329330
fxWriteScriptExterns(script, file);
@@ -484,8 +485,8 @@ int main(int argc, char* argv[])
484485
fprintf(file, ", 0x%.2X", linker->symbolsChecksum[argi]);
485486
fprintf(file, " }\n");
486487
fprintf(file, "};\n");
487-
fprintf(file, "void* xsPreparation() { return (void*)&gxPreparation; }\n\n");
488-
488+
fprintf(file, "void* xsPreparationAndCreation(xsCreation **creation) { if (creation) *creation = (xsCreation *)&gxPreparation.creation; return (void*)&gxPreparation; }\n\n");
489+
489490
if (linker->stripping)
490491
fxStripDefaults(linker, file);
491492
else

0 commit comments

Comments
 (0)