Skip to content

Commit

Permalink
Merge branch 'XS11.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Soquet committed Jan 2, 2022
2 parents a2e7ad4 + 3ef6c22 commit 03d3211
Show file tree
Hide file tree
Showing 46 changed files with 3,358 additions and 2,517 deletions.
2,470 changes: 1,438 additions & 1,032 deletions documentation/xs/XS Conformance.md

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions examples/js/compartments/separate-modules/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ import increment from "increment";
function test() {
trace("app " + increment() + "\n");
}
const modules = {
increment: new StaticModuleRecord({ archive:"increment" }),
mod: new StaticModuleRecord({ archive:"mod" }),
};
let compartment = new Compartment({}, {}, {
let compartment = new Compartment({}, {
increment: "/increment.xsb",
mod: "/mod.xsb",
}, {
resolveHook(specifier, refererSpecifier) {
return specifier;
},
loadNowHook(specifier) {
return modules[specifier];
}
});
let modNS = compartment.importNow("mod");
Expand Down
12 changes: 6 additions & 6 deletions examples/js/compartments/shared-modules/main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as increment from "increment";
import increment from "increment";
function test() {
trace("app " + increment.default() + "\n");
trace("app " + increment() + "\n");
}
const modules = {
mod: new StaticModuleRecord({ archive:"mod" }),
};
let compartment = new Compartment({}, { increment }, {
let compartment = new Compartment({}, {
increment: "/increment.xsb",
mod: "/mod.xsb",
}, {
resolveHook(specifier, refererSpecifier) {
return specifier;
},
Expand Down
2 changes: 1 addition & 1 deletion modules/commodetto/commodettoBMPOut.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/

import Bitmap from "commodetto/Bitmap";
import PixelsOut from "PixelsOut";
import PixelsOut from "commodetto/PixelsOut";
import File from "file";

export default class BMPOut extends PixelsOut {
Expand Down
4 changes: 2 additions & 2 deletions modules/piu/MC/piuMC.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import parseRLE from "commodetto/parseRLE";
import Poco from "commodetto/Poco";
import Resource from "Resource";

import {} from "All";
export * from "All";
import {} from "piu/All";
export * from "piu/All";

export class CLUT extends Resource {
constructor(path) {
Expand Down
2 changes: 1 addition & 1 deletion modules/piu/PC/Common/piuPC.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
*/

import {} from "All";
import {} from "piu/All";

global.__jsx__ = function(Tag, attributes) @ "Piu__jsx__"

Expand Down
2 changes: 1 addition & 1 deletion xs/makefiles/lin/xst.mk
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ C_OPTIONS += \
ifeq ($(GOAL),debug)
C_OPTIONS += -g -O0 -Wall -Wextra -Wno-missing-field-initializers -Wno-unused-parameter
else
C_OPTIONS += -O3
C_OPTIONS += -DmxMultipleThreads=1 -O3
endif

LIBRARIES = -ldl -lm -lpthread -latomic
Expand Down
3 changes: 1 addition & 2 deletions xs/makefiles/mac/xst.mk
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ C_OPTIONS = \
-DmxRun=1 \
-DmxSloppy=1 \
-DmxSnapshot=1 \
-DmxRegExpUnicodePropertyEscapes=1 \
-I$(INC_DIR) \
-I$(PLT_DIR) \
-I$(SRC_DIR) \
Expand All @@ -65,7 +64,7 @@ endif
ifeq ($(GOAL),debug)
C_OPTIONS += -g -O0 -Wall -Wextra -Wno-missing-field-initializers -Wno-unused-parameter
else
C_OPTIONS += -O3
C_OPTIONS += -DmxMultipleThreads=1 -O3
endif

LIBRARIES = -framework CoreServices
Expand Down
1 change: 1 addition & 0 deletions xs/makefiles/win/xst.mak
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ C_OPTIONS = $(C_OPTIONS) \
/Z7
!ELSE
C_OPTIONS = $(C_OPTIONS) \
/D mxMultipleThreads=1 \
/D NDEBUG \
/Fp$(TMP_DIR_RLS)\ \
/O2 \
Expand Down
121 changes: 37 additions & 84 deletions xs/platforms/esp/xsHost.c
Original file line number Diff line number Diff line change
Expand Up @@ -1011,8 +1011,7 @@ static uint8_t *findMod(txMachine *the, char *name, int *modSize)
if (!aName)
break;
if (0 == c_strncmp(name, aName, nameLen)) {
if (0 == c_strcmp(".xsb", aName + nameLen))
return findNthAtom(FOURCC('C', 'O', 'D', 'E'), index, mods, modsSize, modSize);
return findNthAtom(FOURCC('C', 'O', 'D', 'E'), index, mods, modsSize, modSize);
}
}

Expand All @@ -1029,14 +1028,14 @@ static txBoolean fxFindScript(txMachine* the, txSlot* realm, txString path, txID
uint8_t *mod;
int modSize;

mod = findMod(the, path + preparation->baseLength, &modSize);
mod = findMod(the, path, &modSize);
if (mod) {
*id = fxNewNameC(the, path);
return 1;
}
#endif
while (c > 0) {
if (!c_strcmp(path + preparation->baseLength, script->path)) {
if (!c_strcmp(path, script->path)) {
*id = fxNewNameC(the, path);
return 1;
}
Expand All @@ -1048,40 +1047,23 @@ static txBoolean fxFindScript(txMachine* the, txSlot* realm, txString path, txID

txID fxFindModule(txMachine* the, txSlot* realm, txID moduleID, txSlot* slot)
{
txPreparation* preparation = the->preparation;
#if MODDEF_XS_TEST
char extension[5] = "";
#endif
char name[PATH_MAX];
char path[PATH_MAX];
txBoolean absolute = 0, relative = 0, search = 0;
char buffer[PATH_MAX];
txInteger dot = 0;
txString slash;
txString path;
txID id;

fxToStringBuffer(the, slot, name, sizeof(name) - preparation->baseLength - 4);
// #if MODDEF_XS_MODS
// if (findMod(the, name, NULL)) {
// c_strcpy(path, "/");
// c_strcat(path, name);
// c_strcat(path, ".xsb");
// return fxNewNameC(the, path);
// }
// #endif
//
if (!c_strncmp(name, "/", 1)) {
absolute = 1;
}
else if (!c_strncmp(name, "./", 2)) {
dot = 1;
relative = 1;
}
else if (!c_strncmp(name, "../", 3)) {
dot = 2;
relative = 1;
}
else {
search = 1;
fxToStringBuffer(the, slot, name, sizeof(name));
if (name[0] == '.') {
if (name[1] == '/') {
dot = 1;
}
else if ((name[1] == '.') && (name[2] == '/')) {
dot = 2;
}
}
slash = c_strrchr(name, '/');
if (!slash)
Expand All @@ -1093,69 +1075,41 @@ txID fxFindModule(txMachine* the, txSlot* realm, txID moduleID, txSlot* slot)
#endif
*slash = 0;
}
if (absolute) {
c_strcpy(path, preparation->base);
c_strcat(path, name + 1);
c_strcat(path, ".xsb");
if (fxFindScript(the, realm, path, &id)) {
// fxReport(the, "ABSOLUTE %s\n", path);
return id;
}
}
if (relative && (moduleID != XS_NO_ID)) {
if (dot) {
if (moduleID == XS_NO_ID)
return XS_NO_ID;
buffer[0] = '/';
path = buffer + 1;
c_strcpy(path, fxGetKeyName(the, moduleID));
slash = c_strrchr(path, '/');
slash = c_strrchr(buffer, '/');
if (!slash)
return XS_NO_ID;
if (dot == 0)
slash++;
else if (dot == 2) {
if (dot == 2) {
*slash = 0;
slash = c_strrchr(path, '/');
slash = c_strrchr(buffer, '/');
if (!slash)
return XS_NO_ID;
}
if (!c_strncmp(path, preparation->base, preparation->baseLength)) {
*slash = 0;
c_strcat(path, name + dot);
c_strcat(path, ".xsb");
if (fxFindScript(the, realm, path, &id)) {
// fxReport(the, "RELATIVE %s\n", path);
return id;
}
}
#if MODDEF_XS_TEST
if (!c_strncmp(path, "xsbug://", 8)) {
*slash = 0;
c_strcat(path, name + dot);
c_strcat(path, extension);
return fxNewNameC(the, path);
}
#endif
*slash = 0;
c_strcat(buffer, name + dot);
}
if (search) {
c_strcpy(path, preparation->base);
c_strcat(path, name);
c_strcat(path, ".xsb");
if (fxFindScript(the, realm, path, &id)) {
// fxReport(the, "SEARCH %s\n", path);
return id;
}
else
path = name;
if (fxFindScript(the, realm, path, &id))
return id;
#if MODDEF_XS_TEST
if (!c_strncmp(name, "xsbug://", 8)) {
c_strcpy(path, name);
c_strcat(path, extension);
return fxNewNameC(the, path);
}
#endif
if (!c_strncmp(path, "xsbug://", 8)) {
c_strcat(path, extension);
return fxNewNameC(the, path);
}
#endif
return XS_NO_ID;
}

void fxLoadModule(txMachine* the, txSlot* realm, txID moduleID)
void fxLoadModule(txMachine* the, txSlot* module, txID moduleID)
{
txPreparation* preparation = the->preparation;
txString path = fxGetKeyName(the, moduleID) + preparation->baseLength;
txString path = fxGetKeyName(the, moduleID);
txInteger c = preparation->scriptCount;
txScript* script = preparation->scripts;
#if MODDEF_XS_MODS
Expand All @@ -1173,30 +1127,29 @@ void fxLoadModule(txMachine* the, txSlot* realm, txID moduleID)
aScript.codeSize = modSize;
aScript.hostsBuffer = NULL;
aScript.hostsSize = 0;
aScript.path = path - preparation->baseLength;
aScript.path = path;
aScript.version[0] = XS_MAJOR_VERSION;
aScript.version[1] = XS_MINOR_VERSION;
aScript.version[2] = XS_PATCH_VERSION;
aScript.version[3] = 0;

fxResolveModule(the, realm, moduleID, &aScript, C_NULL, C_NULL);
fxResolveModule(the, module, moduleID, &aScript, C_NULL, C_NULL);
return;
}
#endif

while (c > 0) {
if (!c_strcmp(path, script->path)) {
fxResolveModule(the, realm, moduleID, script, C_NULL, C_NULL);
fxResolveModule(the, module, moduleID, script, C_NULL, C_NULL);
return;
}
c--;
script++;
}

#if MODDEF_XS_TEST
path -= preparation->baseLength;
if (!c_strncmp(path, "xsbug://", 8))
fxDebugImport(the, realm, path);
fxDebugImport(the, module, path);
#endif
}

Expand Down
33 changes: 18 additions & 15 deletions xs/sources/xsAPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,10 +625,7 @@ txSlot* fxNewHostFunction(txMachine* the, txCallback theCallback, txInteger theL
gxDefaults.newFunctionLength(the, instance, theLength);

/* NAME */
if (name != XS_NO_ID)
fxRenameFunction(the, instance, name, 0, XS_NO_ID, C_NULL);
else if (gxDefaults.newFunctionName)
property = gxDefaults.newFunctionName(the, instance, XS_NO_ID, 0, XS_NO_ID, C_NULL);
fxRenameFunction(the, instance, name, 0, XS_NO_ID, C_NULL);

return instance;
}
Expand Down Expand Up @@ -1468,6 +1465,7 @@ txMachine* fxCreateMachine(txCreation* theCreation, txString theName, void* theC
fxBuildMapSet(the);
fxBuildModule(the);

mxPushUndefined();
mxPush(mxObjectPrototype);
#ifdef mxLink
slot = fxLastProperty(the, fxNewObjectInstance(the));
Expand All @@ -1487,6 +1485,8 @@ txMachine* fxCreateMachine(txCreation* theCreation, txString theName, void* theC
fxNewInstance(the);
fxNewInstance(the);
mxPushUndefined();
fxNewEnvironmentInstance(the, C_NULL);
mxPushUndefined();
mxPushUndefined();
mxPushUndefined();
mxPushUndefined();
Expand Down Expand Up @@ -1580,6 +1580,9 @@ void fxDeleteMachine(txMachine* the)
fxDeleteMachinePlatform(the);
fxFree(the);
c_free(the);

if (gxDefaults.terminateSharedCluster)
gxDefaults.terminateSharedCluster();
}

txMachine* fxCloneMachine(txCreation* theCreation, txMachine* theMachine, txString theName, void* theContext)
Expand Down Expand Up @@ -1671,30 +1674,30 @@ txMachine* fxCloneMachine(txCreation* theCreation, txMachine* theMachine, txStri

the->stackPrototypes = theMachine->stackTop;

mxPushUndefined();
mxPush(theMachine->stackTop[-1 - mxGlobalStackIndex]);
slot = fxLastProperty(the, fxNewObjectInstance(the));
slot = fxNextSlotProperty(the, slot, the->stack, mxID(_global), XS_DONT_ENUM_FLAG);
slot = fxNextSlotProperty(the, slot, the->stack, mxID(_globalThis), XS_DONT_ENUM_FLAG);
mxGlobal.value = the->stack->value;
mxGlobal.kind = the->stack->kind;
// mxPush(theMachine->stackTop[-1 - mxHostsStackIndex]); //@@
fxNewInstance(the);

mxPush(theMachine->stackTop[-1 - mxProgramStackIndex]); //@@

fxNewInstance(the);
mxPushUndefined();
mxPushUndefined();
mxPushUndefined();
mxPushUndefined();
mxModuleInstanceInternal(mxProgram.value.reference)->value.module.realm = slot = fxNewRealmInstance(the);

slot = fxLastProperty(the, fxNewEnvironmentInstance(the, C_NULL));
sharedSlot = theMachine->stackTop[-1 - mxExceptionStackIndex].value.reference->next->next; //@@
slot = fxLastProperty(the, mxRealmClosures(slot)->value.reference);
while (sharedSlot) {
slot = slot->next = fxDuplicateSlot(the, sharedSlot);
sharedSlot = sharedSlot->next;
}
mxPushUndefined();
mxPushUndefined();
mxPushUndefined();
mxPushUndefined();
mxModuleInstanceInternal(mxProgram.value.reference)->value.module.realm = fxNewRealmInstance(the);
mxPop();

the->sharedModules = theMachine->stackTop[-1 - mxProgramStackIndex].value.reference->next; //@@

the->collectFlag = XS_COLLECTING_FLAG;

Expand Down Expand Up @@ -2033,7 +2036,7 @@ void* fxGetArchiveCode(txMachine* the, txString path, txSize* size)
while (p < q) {
// PATH
atomSize = c_read32be(p);
if (!c_strcmp(path + preparation->baseLength, (txString)(p + sizeof(Atom)))) {
if (!c_strcmp(path, (txString)(p + sizeof(Atom)))) {
p += atomSize;
atomSize = c_read32be(p);
*size = atomSize - sizeof(Atom);
Expand Down
Loading

0 comments on commit 03d3211

Please sign in to comment.