Skip to content

Commit 965539f

Browse files
Patrick Soquetmkellner
authored andcommitted
XS: xsPrepareMachine - REBUILD ALL FROM SCRATCH
1 parent 2817dbd commit 965539f

File tree

7 files changed

+45
-66
lines changed

7 files changed

+45
-66
lines changed

build/simulator/screen.c

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ struct sxWorker {
5858
};
5959

6060
extern void fxAbortCallback(void *info);
61-
extern txPreparation* xsPreparation();
6261

6362
static void fxScreenIdle(txScreen* screen);
6463
static void fxScreenInvoke(txScreen* screen, char* message, int size);
@@ -225,42 +224,11 @@ void fxScreenInvoke(txScreen* screen, char* buffer, int size)
225224

226225
void fxScreenLaunch(txScreen* screen)
227226
{
228-
txPreparation* preparation = xsPreparation();
229-
txMachine _root;
230-
txMachine* root = &_root;
231-
if (!preparation) {
232-
return;
233-
}
234-
if ((preparation->version[0] != XS_MAJOR_VERSION) || (preparation->version[1] != XS_MINOR_VERSION) || (preparation->version[2] != XS_PATCH_VERSION)) {
235-
//info = [NSString stringWithFormat:@"Require version %d.%d.%d", XS_MAJOR_VERSION, XS_MINOR_VERSION, XS_PATCH_VERSION];
236-
return;
237-
}
238-
239-
root->preparation = preparation;
240-
if (screen->archive)
241-
root->archive = fxMapArchive(preparation, screen->archive, screen->archive, 4 * 1024, fxArchiveRead, fxArchiveWrite);
242-
else
243-
root->archive = NULL;
244-
root->keyArray = preparation->keys;
245-
root->keyCount = (txID)preparation->keyCount + (txID)preparation->creation.keyCount;
246-
root->keyIndex = (txID)preparation->keyCount;
247-
root->nameModulo = preparation->nameModulo;
248-
root->nameTable = preparation->names;
249-
root->symbolModulo = preparation->symbolModulo;
250-
root->symbolTable = preparation->symbols;
251-
252-
root->stack = &preparation->stack[0];
253-
root->stackBottom = &preparation->stack[0];
254-
root->stackTop = &preparation->stack[preparation->stackCount];
255-
256-
root->firstHeap = &preparation->heap[0];
257-
root->freeHeap = &preparation->heap[preparation->heapCount - 1];
258-
root->aliasCount = (txID)preparation->aliasCount;
259-
260-
screen->machine = fxCloneMachine(&preparation->creation, root, "mc", screen);
261-
if (!screen->machine) {
262-
return;
263-
}
227+
void* preparation = xsPreparation();
228+
void* archive = (screen->archive) ? fxMapArchive(preparation, screen->archive, screen->archive, 4 * 1024, fxArchiveRead, fxArchiveWrite) : NULL;
229+
screen->machine = fxPrepareMachine(NULL, preparation, "mc", screen, archive);
230+
if (!screen->machine)
231+
return;
264232
((txMachine*)(screen->machine))->host = screen;
265233
screen->idle = fxScreenIdle;
266234
screen->invoke = fxScreenInvoke;

modules/piu/PC/piuService.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
#include "pthread.h"
3333
#endif
3434

35-
extern txPreparation* xsPreparation();
36-
3735
typedef struct ServiceThreadStruct ServiceThreadRecord, *ServiceThread;
3836
typedef struct ServiceEventStruct ServiceEventRecord, *ServiceEvent;
3937
typedef struct ServiceMessageStruct ServiceMessageRecord, *ServiceMessage;

tools/tool.c

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "xsAll.h"
2323
#include "xs.h"
2424
#include "mc.xs.h"
25-
extern txPreparation* xsPreparation();
2625

2726
#if mxWindows
2827
#include <direct.h>
@@ -58,30 +57,9 @@ void fxAbort(xsMachine* the)
5857

5958
int main(int argc, char* argv[])
6059
{
61-
static txMachine root;
6260
int error = 0;
63-
txMachine* machine = &root;
64-
txPreparation* preparation = xsPreparation();
65-
66-
c_memset(machine, 0, sizeof(txMachine));
67-
machine->preparation = preparation;
68-
machine->keyArray = preparation->keys;
69-
machine->keyCount = (txID)preparation->keyCount + (txID)preparation->creation.keyCount;
70-
machine->keyIndex = (txID)preparation->keyCount;
71-
machine->nameModulo = preparation->nameModulo;
72-
machine->nameTable = preparation->names;
73-
machine->symbolModulo = preparation->symbolModulo;
74-
machine->symbolTable = preparation->symbols;
75-
76-
machine->stack = &preparation->stack[0];
77-
machine->stackBottom = &preparation->stack[0];
78-
machine->stackTop = &preparation->stack[preparation->stackCount];
79-
80-
machine->firstHeap = &preparation->heap[0];
81-
machine->freeHeap = &preparation->heap[preparation->heapCount - 1];
82-
machine->aliasCount = (txID)preparation->aliasCount;
8361

84-
machine = fxCloneMachine(&preparation->creation, machine, "tool", NULL);
62+
xsMachine* machine = fxPrepareMachine(NULL, xsPreparation(), "tool", NULL, NULL);
8563

8664
xsBeginHost(machine);
8765
{

xs/includes/xs.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,9 +1131,12 @@ struct xsCreationRecord {
11311131
#define xsDeleteMachine(_THE) \
11321132
fxDeleteMachine(_THE)
11331133

1134-
#define xsCloneMachine(_ALLOCATION,_MACHINE,_NAME,_CONTEXT) \
1135-
fxCloneMachine(_ALLOCATION, _MACHINE, _NAME, _CONTEXT)
1134+
#define xsCloneMachine(_CREATION,_MACHINE,_NAME,_CONTEXT) \
1135+
fxCloneMachine(_CREATION, _MACHINE, _NAME, _CONTEXT)
11361136

1137+
#define xsPrepareMachine(_CREATION,_PREPARATION,_NAME, _CONTEXT, _ARCHIVE) \
1138+
fxPrepareMachine(_CREATION, _PREPARATION, _NAME, _CONTEXT, _ARCHIVE)
1139+
11371140
#define xsShareMachine(_THE) \
11381141
fxShareMachine(_THE)
11391142

@@ -1336,6 +1339,7 @@ mxImport void fxReport(xsMachine*, xsStringValue, ...);
13361339
mxImport xsMachine* fxCreateMachine(xsCreation*, xsStringValue, void*);
13371340
mxImport void fxDeleteMachine(xsMachine*);
13381341
mxImport xsMachine* fxCloneMachine(xsCreation*, xsMachine*, xsStringValue, void*);
1342+
mxImport xsMachine* fxPrepareMachine(xsCreation*, void*, xsStringValue, void*, void*);
13391343
mxImport void fxShareMachine(xsMachine*);
13401344

13411345
mxImport xsMachine* fxBeginHost(xsMachine*);

xs/sources/xsAPI.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,6 +1627,36 @@ txMachine* fxCloneMachine(txCreation* theCreation, txMachine* theMachine, txStri
16271627
return the;
16281628
}
16291629

1630+
txMachine* fxPrepareMachine(txCreation* creation, txPreparation* preparation, txString name, void* context, void* archive)
1631+
{
1632+
txMachine _root;
1633+
txMachine* root = &_root;
1634+
if ((preparation->version[0] != XS_MAJOR_VERSION) || (preparation->version[1] != XS_MINOR_VERSION) || (preparation->version[2] != XS_PATCH_VERSION))
1635+
return C_NULL;
1636+
c_memset(root, 0, sizeof(txMachine));
1637+
root->preparation = preparation;
1638+
root->archive = archive;
1639+
root->keyArray = preparation->keys;
1640+
root->keyCount = (txID)preparation->keyCount + (txID)preparation->creation.keyCount;
1641+
root->keyIndex = (txID)preparation->keyCount;
1642+
root->nameModulo = preparation->nameModulo;
1643+
root->nameTable = preparation->names;
1644+
root->symbolModulo = preparation->symbolModulo;
1645+
root->symbolTable = preparation->symbols;
1646+
1647+
root->stack = &preparation->stack[0];
1648+
root->stackBottom = &preparation->stack[0];
1649+
root->stackTop = &preparation->stack[preparation->stackCount];
1650+
1651+
root->firstHeap = &preparation->heap[0];
1652+
root->freeHeap = &preparation->heap[preparation->heapCount - 1];
1653+
root->aliasCount = (txID)preparation->aliasCount;
1654+
1655+
if (!creation)
1656+
creation = &preparation->creation;
1657+
return fxCloneMachine(creation, root, name, context);
1658+
}
1659+
16301660
void fxShareMachine(txMachine* the)
16311661
{
16321662
if (!(the->shared)) {

xs/sources/xsAll.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ mxExport const txByte gxNoCode[] ICACHE_FLASH_ATTR;
556556
mxExport txMachine* fxCreateMachine(txCreation* theCreation, txString theName, void* theContext);
557557
mxExport void fxDeleteMachine(txMachine*);
558558
mxExport txMachine* fxCloneMachine(txCreation* theCreation, txMachine* theMachine, txString theName, void* theContext);
559+
mxExport txMachine* fxPrepareMachine(txCreation* creation, txPreparation* preparation, txString name, void* context, void* archive);
559560
mxExport void fxShareMachine(txMachine* the);
560561

561562
mxExport txMachine* fxBeginHost(txMachine*);

xs/tools/xsl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ 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");
326327
script = linker->firstScript;
327328
while (script) {
328329
fxWriteScriptExterns(script, file);
@@ -386,7 +387,6 @@ int main(int argc, char* argv[])
386387
fprintf(file, "#define mxScriptsCount %d\n", linker->scriptCount);
387388
fprintf(file, "static const txScript gxScripts[mxScriptsCount];\n");
388389
fprintf(file, "static const txPreparation gxPreparation;\n\n");
389-
fprintf(file, "mxExport txPreparation* xsPreparation();\n\n");
390390

391391
if (linker->stripping) {
392392
fprintf(file, "static void fxDeadStrip(txMachine* the) { mxUnknownError(\"dead strip\"); }\n\n");
@@ -484,7 +484,7 @@ int main(int argc, char* argv[])
484484
fprintf(file, ", 0x%.2X", linker->symbolsChecksum[argi]);
485485
fprintf(file, " }\n");
486486
fprintf(file, "};\n");
487-
fprintf(file, "txPreparation* xsPreparation() { return (txPreparation*)&gxPreparation; }\n\n");
487+
fprintf(file, "void* xsPreparation() { return (void*)&gxPreparation; }\n\n");
488488

489489
if (linker->stripping)
490490
fxStripDefaults(linker, file);

0 commit comments

Comments
 (0)