Skip to content

Commit

Permalink
XS profile ID by function definition
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Soquet committed Oct 28, 2022
1 parent dc70fe7 commit 29a2fad
Show file tree
Hide file tree
Showing 29 changed files with 185 additions and 87 deletions.
12 changes: 6 additions & 6 deletions xs/includes/xs.h
Original file line number Diff line number Diff line change
Expand Up @@ -916,11 +916,11 @@ struct xsHostBuilderRecord {
fxPop())

#define xsNewHostFunction(_CALLBACK,_LENGTH) \
(fxNewHostFunction(the, _CALLBACK, _LENGTH, xsNoID), \
(fxNewHostFunction(the, _CALLBACK, _LENGTH, xsNoID, xsNoID), \
fxPop())

#define xsNewHostFunctionObject(_CALLBACK,_LENGTH, _NAME) \
(fxNewHostFunction(the, _CALLBACK, _LENGTH, _NAME), \
(fxNewHostFunction(the, _CALLBACK, _LENGTH, _NAME, xsNoID), \
fxPop())

#define xsNewHostInstance(_PROTOTYPE) \
Expand Down Expand Up @@ -1197,7 +1197,7 @@ struct xsCreationRecord {
};

#define xsCreateMachine(_CREATION,_NAME,_CONTEXT) \
fxCreateMachine(_CREATION, _NAME, _CONTEXT)
fxCreateMachine(_CREATION, _NAME, _CONTEXT, xsNoID)

#define xsDeleteMachine(_THE) \
fxDeleteMachine(_THE)
Expand Down Expand Up @@ -1251,7 +1251,7 @@ struct xsCreationRecord {
} while(1)

enum {
xsNoID = -1,
xsNoID = 0,
xsDefault = 0,
xsDontDelete = 2,
xsDontEnum = 4,
Expand Down Expand Up @@ -1373,7 +1373,7 @@ mxImport void fxArrayCacheItem(xsMachine*, xsSlot*, xsSlot*);

mxImport void fxBuildHosts(xsMachine*, xsIntegerValue, xsHostBuilder*);
mxImport void fxNewHostConstructor(xsMachine*, xsCallback, xsIntegerValue, xsIntegerValue);
mxImport void fxNewHostFunction(xsMachine*, xsCallback, xsIntegerValue, xsIntegerValue);
mxImport void fxNewHostFunction(xsMachine*, xsCallback, xsIntegerValue, xsIntegerValue, xsIntegerValue);
mxImport void fxNewHostInstance(xsMachine*);
mxImport xsSlot* fxNewHostObject(xsMachine*, xsDestructor);
mxImport xsIntegerValue fxGetHostBufferLength(xsMachine*, xsSlot*);
Expand Down Expand Up @@ -1430,7 +1430,7 @@ mxImport void fxBubble(xsMachine*, xsIntegerValue, void*, xsIntegerValue, xsStri
mxImport void fxDebugger(xsMachine*, xsStringValue, xsIntegerValue);
mxImport void fxReport(xsMachine*, xsStringValue, ...);

mxImport xsMachine* fxCreateMachine(xsCreation*, xsStringValue, void*);
mxImport xsMachine* fxCreateMachine(xsCreation*, xsStringValue, void*, xsIdentifier);
mxImport void fxDeleteMachine(xsMachine*);
mxImport xsMachine* fxCloneMachine(xsCreation*, xsMachine*, xsStringValue, void*);
mxImport xsMachine* fxPrepareMachine(xsCreation*, void*, xsStringValue, void*, void*);
Expand Down
16 changes: 9 additions & 7 deletions xs/sources/xsAPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ void fxBuildHosts(txMachine* the, txInteger c, const txHostFunctionBuilder* buil
the->stack->value.hostFunction.profileID = the->profileID;
the->profileID++;
#else
fxNewHostFunction(the, builder->callback, builder->length, builder->id);
fxNewHostFunction(the, builder->callback, builder->length, builder->id, XS_NO_ID);
#endif
}
else
Expand All @@ -570,7 +570,7 @@ txSlot* fxNewHostConstructor(txMachine* the, txCallback theCallback, txInteger t

fxToInstance(the, the->stack);
aStack = the->stack;
instance = fxNewHostFunction(the, theCallback, theLength, name);
instance = fxNewHostFunction(the, theCallback, theLength, name, XS_NO_ID);
instance->flag |= XS_CAN_CONSTRUCT_FLAG;
property = fxLastProperty(the, instance);
fxNextSlotProperty(the, property, aStack, mxID(_prototype), XS_GET_ONLY);
Expand All @@ -583,7 +583,7 @@ txSlot* fxNewHostConstructor(txMachine* the, txCallback theCallback, txInteger t
return instance;
}

txSlot* fxNewHostFunction(txMachine* the, txCallback theCallback, txInteger theLength, txInteger name)
txSlot* fxNewHostFunction(txMachine* the, txCallback theCallback, txInteger theLength, txInteger name, txInteger profileID)
{
txSlot* instance;
txSlot* property;
Expand All @@ -606,8 +606,10 @@ txSlot* fxNewHostFunction(txMachine* the, txCallback theCallback, txInteger theL

/* HOME */
property = property->next = fxNewSlot(the);
property->ID = the->profileID;
the->profileID++;
if (profileID != XS_NO_ID)
property->ID = profileID;
else
property->ID = fxGenerateProfileID(the);
property->flag = XS_INTERNAL_FLAG;
property->kind = XS_HOME_KIND;
property->value.home.object = C_NULL;
Expand Down Expand Up @@ -1344,7 +1346,7 @@ void fxDebugger(txMachine* the, txString thePath, txInteger theLine)

const txByte gxNoCode[3] ICACHE_FLASH_ATTR = { XS_CODE_BEGIN_STRICT, 0, XS_CODE_END };

txMachine* fxCreateMachine(txCreation* theCreation, txString theName, void* theContext)
txMachine* fxCreateMachine(txCreation* theCreation, txString theName, void* theContext, txID profileID)
{
txMachine* the = (txMachine* )c_calloc(sizeof(txMachine), 1);
if (the) {
Expand All @@ -1371,7 +1373,7 @@ txMachine* fxCreateMachine(txCreation* theCreation, txString theName, void* theC
#ifdef mxDebug
the->name = theName;
#endif
the->profileID = 2;
the->profileID = (profileID != XS_NO_ID) ? profileID : mxBaseProfileID;
fxAllocate(the, theCreation);

c_memset(the->nameTable, 0, the->nameModulo * sizeof(txSlot *));
Expand Down
33 changes: 30 additions & 3 deletions xs/sources/xsAll.h
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ mxExport void fxArrayCacheItem(txMachine*, txSlot*, txSlot*);

mxExport void fxBuildHosts(txMachine*, txInteger, const txHostFunctionBuilder*);
mxExport txSlot* fxNewHostConstructor(txMachine*, txCallback, txInteger, txInteger);
mxExport txSlot* fxNewHostFunction(txMachine*, txCallback, txInteger, txInteger);
mxExport txSlot* fxNewHostFunction(txMachine*, txCallback, txInteger, txInteger, txInteger);
mxExport txSlot* fxNewHostInstance(txMachine* the);
mxExport txSlot* fxNewHostObject(txMachine*, txDestructor);
mxExport txInteger fxGetHostBufferLength(txMachine* the, txSlot* slot);
Expand Down Expand Up @@ -648,7 +648,7 @@ mxExport void fxThrowMessage(txMachine* the, txString thePath, txInteger theLine
mxExport void fxDebugger(txMachine* the, txString thePath, txInteger theLine);

mxExport const txByte gxNoCode[] ICACHE_FLASH_ATTR;
mxExport txMachine* fxCreateMachine(txCreation* theCreation, txString theName, void* theContext);
mxExport txMachine* fxCreateMachine(txCreation* theCreation, txString theName, void* theContext, txID profileID);
mxExport void fxDeleteMachine(txMachine*);
mxExport txMachine* fxCloneMachine(txCreation* theCreation, txMachine* theMachine, txString theName, void* theContext);
mxExport txMachine* fxPrepareMachine(txCreation* creation, txPreparation* preparation, txString name, void* context, void* archive);
Expand Down Expand Up @@ -2697,9 +2697,36 @@ extern txSlot* fxBuildHostFunction(txMachine* the, txCallback theCallback, txInt
#else
#define mxCallback(CALLBACK) CALLBACK
#define fxBuildHostConstructor(THE, CALLBACK, LENGTH, NAME) fxNewHostConstructor(THE, CALLBACK, LENGTH, NAME)
#define fxBuildHostFunction(THE, CALLBACK, LENGTH, NAME) fxNewHostFunction(THE, CALLBACK, LENGTH, NAME)
#define fxBuildHostFunction(THE, CALLBACK, LENGTH, NAME) fxNewHostFunction(THE, CALLBACK, LENGTH, NAME, XS_NO_ID)
#endif

enum {
mxHostProfileID,
mxGarbageCollectorProfileID,
mx_Promise_prototype_finallyAuxProfileID,
mx_Promise_prototype_finallyReturnProfileID,
mx_Promise_prototype_finallyThrowProfileID,
mx_Proxy_revokeProfileID,
mxAsyncGeneratorRejectAwaitProfileID,
mxAsyncGeneratorRejectYieldProfileID,
mxAsyncGeneratorResolveAwaitProfileID,
mxAsyncGeneratorResolveYieldProfileID,
mxAsyncFromSyncIteratorDoneProfileID,
mxCombinePromisesCallbackProfileID,
mxExecuteModulesFulfilledProfileID,
mxExecuteModulesRejectedProfileID,
mxExecuteVirtualModuleSourceProfileID,
mxExecuteVirtualModuleSourceImportProfileID,
mxLoadModulesFulfilledProfileID,
mxLoadModulesRejectedProfileID,
mxNewPromiseCapabilityCallbackProfileID,
mxRejectAwaitProfileID,
mxRejectPromiseProfileID,
mxResolveAwaitProfileID,
mxResolvePromiseProfileID,
mxBaseProfileID
};

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions xs/sources/xsArray.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ void fxBuildArray(txMachine* the)
txSlot* property;
txSlot* unscopable;

fxNewHostFunction(the, mxCallback(fxArrayLengthGetter), 0, XS_NO_ID);
fxNewHostFunction(the, mxCallback(fxArrayLengthSetter), 1, XS_NO_ID);
fxNewHostFunction(the, mxCallback(fxArrayLengthGetter), 0, XS_NO_ID, XS_NO_ID);
fxNewHostFunction(the, mxCallback(fxArrayLengthSetter), 1, XS_NO_ID, XS_NO_ID);
mxPushUndefined();
the->stack->flag = XS_DONT_DELETE_FLAG;
the->stack->kind = XS_ACCESSOR_KIND;
Expand Down
14 changes: 14 additions & 0 deletions xs/sources/xsCode.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ txScript* fxParserCode(txParser* parser)
case XS_CODE_SET_SUPER:
case XS_CODE_SET_VARIABLE:
case XS_CODE_SYMBOL:
case XS_CODE_PROFILE:
size += 1 + sizeof(txID);
break;

Expand Down Expand Up @@ -444,6 +445,9 @@ txScript* fxParserCode(txParser* parser)
symbol->usage++;
size += 1 + sizeof(txID);
break;
case XS_CODE_PROFILE:
size += 1 + sizeof(txID);
break;

case XS_CODE_CONST_CLOSURE_1:
case XS_CODE_CONST_LOCAL_1:
Expand Down Expand Up @@ -648,6 +652,10 @@ txScript* fxParserCode(txParser* parser)
id = XS_NO_ID;
mxEncodeID(p, id);
break;
case XS_CODE_PROFILE:
id = fxGenerateProfileID(parser->console);
mxEncodeID(p, id);
break;

case XS_CODE_ARGUMENT:
case XS_CODE_ARGUMENTS:
Expand Down Expand Up @@ -3179,6 +3187,8 @@ void fxFunctionNodeCode(void* it, void* param)
fxCoderAddSymbol(param, 1, XS_CODE_FUNCTION, name);
else
fxCoderAddSymbol(param, 1, XS_CODE_CONSTRUCTOR_FUNCTION, name);
if (coder->parser->flags & mxDebugFlag)
fxCoderAddByte(param, 0, XS_CODE_PROFILE);
fxCoderAddBranch(param, 0, XS_CODE_CODE_1, target);
if (self->flags & mxFieldFlag)
fxCoderAddIndex(param, 0, XS_CODE_BEGIN_STRICT_FIELD, fxCoderCountParameters(coder, self->params));
Expand Down Expand Up @@ -3519,6 +3529,8 @@ void fxModuleNodeCode(void* it, void* param)
}
if (count) {
fxCoderAddSymbol(param, 1, XS_CODE_FUNCTION, name);
if (coder->parser->flags & mxDebugFlag)
fxCoderAddByte(param, 0, XS_CODE_PROFILE);
fxCoderAddBranch(param, 0, XS_CODE_CODE_1, target);
fxCoderAddIndex(param, 0, XS_CODE_BEGIN_STRICT, 0);
coder->path = C_NULL;
Expand Down Expand Up @@ -3557,6 +3569,8 @@ void fxModuleNodeCode(void* it, void* param)
fxCoderAddSymbol(param, 1, XS_CODE_ASYNC_FUNCTION, name);
else
fxCoderAddSymbol(param, 1, XS_CODE_FUNCTION, name);
if (coder->parser->flags & mxDebugFlag)
fxCoderAddByte(param, 0, XS_CODE_PROFILE);
fxCoderAddBranch(param, 0, XS_CODE_CODE_1, target);
fxCoderAddIndex(param, 0, XS_CODE_BEGIN_STRICT, 0);
coder->path = C_NULL;
Expand Down
10 changes: 8 additions & 2 deletions xs/sources/xsCommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ const txString gxCodeNames[XS_CODE_COUNT] = {
/* XS_CODE_VOID */ "void",
/* XS_CODE_WITH */ "with",
/* XS_CODE_WITHOUT */ "without",
/* XS_CODE_YIELD */ "yield"
/* XS_CODE_YIELD */ "yield",
/* XS_CODE_PROFILE */ "profile"
};

const txS1 gxCodeSizes[XS_CODE_COUNT] ICACHE_FLASH_ATTR = {
Expand Down Expand Up @@ -516,7 +517,12 @@ const txS1 gxCodeSizes[XS_CODE_COUNT] ICACHE_FLASH_ATTR = {
1 /* XS_CODE_VOID */,
1 /* XS_CODE_WITH */,
1 /* XS_CODE_WITHOUT */,
1 /* XS_CODE_YIELD */
1 /* XS_CODE_YIELD */,
#ifdef mx32bitID
5 /* XS_CODE_PROFILE */
#else
3 /* XS_CODE_PROFILE */
#endif
};

#if mxUseDefaultCStackLimit
Expand Down
2 changes: 2 additions & 0 deletions xs/sources/xsCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ enum {
XS_CODE_WITH,
XS_CODE_WITHOUT,
XS_CODE_YIELD,
XS_CODE_PROFILE,
XS_CODE_COUNT
};

Expand Down Expand Up @@ -453,6 +454,7 @@ txFlag fxStringToIndex(void* dtoa, txString theString, txIndex* theIndex);

/* ? */
mxExport char* fxCStackLimit();
mxExport txID fxGenerateProfileID(void* console);
mxExport void fxGenerateTag(void* console, txString buffer, txInteger bufferSize, txString path);
mxExport void fxVReport(void* console, txString theFormat, c_va_list theArguments);
mxExport void fxVReportError(void* console, txString thePath, txInteger theLine, txString theFormat, c_va_list theArguments);
Expand Down
4 changes: 2 additions & 2 deletions xs/sources/xsDataView.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ void fxBuildDataView(txMachine* the)
mxDataViewConstructor = *the->stack;
mxPop();

fxNewHostFunction(the, mxCallback(fxTypedArrayGetter), 0, XS_NO_ID);
fxNewHostFunction(the, mxCallback(fxTypedArraySetter), 1, XS_NO_ID);
fxNewHostFunction(the, mxCallback(fxTypedArrayGetter), 0, XS_NO_ID, XS_NO_ID);
fxNewHostFunction(the, mxCallback(fxTypedArraySetter), 1, XS_NO_ID, XS_NO_ID);
mxPushUndefined();
the->stack->flag = XS_DONT_DELETE_FLAG;
the->stack->kind = XS_ACCESSOR_KIND;
Expand Down
8 changes: 8 additions & 0 deletions xs/sources/xsDebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -2191,6 +2191,14 @@ void fxReportWarning(txMachine* the, txString thePath, txInteger theLine, txStri
#endif
}

txID fxGenerateProfileID(void* console)
{
txMachine* the = console;
txID id = the->profileID;
the->profileID++;
return id;
}

void fxGenerateTag(void* console, txString buffer, txInteger bufferSize, txString path)
{
txMachine* the = console;
Expand Down
6 changes: 2 additions & 4 deletions xs/sources/xsFunction.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ txSlot* fxNewFunctionInstance(txMachine* the, txID name)

/* HOME */
property = property->next = fxNewSlot(the);
property->ID = the->profileID;
the->profileID++;
property->flag = XS_INTERNAL_FLAG;
property->kind = XS_HOME_KIND;
property->value.home.object = C_NULL;
Expand Down Expand Up @@ -633,13 +631,13 @@ txSlot* fxNewAsyncInstance(txMachine* the)
mxPop();
mxPop();

function = fxNewHostFunction(the, fxResolveAwait, 1, XS_NO_ID);
function = fxNewHostFunction(the, fxResolveAwait, 1, XS_NO_ID, mxResolveAwaitProfileID);
home = mxFunctionInstanceHome(function);
home->value.home.object = instance;
property = fxNextSlotProperty(the, property, the->stack, XS_NO_ID, XS_INTERNAL_FLAG);
mxPop();

function = fxNewHostFunction(the, fxRejectAwait, 1, XS_NO_ID);
function = fxNewHostFunction(the, fxRejectAwait, 1, XS_NO_ID, mxRejectAwaitProfileID);
home = mxFunctionInstanceHome(function);
home->value.home.object = instance;
property = fxNextSlotProperty(the, property, the->stack, XS_NO_ID, XS_INTERNAL_FLAG);
Expand Down
10 changes: 5 additions & 5 deletions xs/sources/xsGenerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,25 +543,25 @@ txSlot* fxNewAsyncGeneratorInstance(txMachine* the)
property->value.list.first = C_NULL;
property->value.list.last = C_NULL;

function = fxNewHostFunction(the, fxAsyncGeneratorResolveAwait, 1, XS_NO_ID);
function = fxNewHostFunction(the, fxAsyncGeneratorResolveAwait, 1, XS_NO_ID, mxAsyncGeneratorResolveAwaitProfileID);
home = mxFunctionInstanceHome(function);
home->value.home.object = instance;
property = fxNextSlotProperty(the, property, the->stack, XS_NO_ID, XS_INTERNAL_FLAG);
mxPop();

function = fxNewHostFunction(the, fxAsyncGeneratorRejectAwait, 1, XS_NO_ID);
function = fxNewHostFunction(the, fxAsyncGeneratorRejectAwait, 1, XS_NO_ID, mxAsyncGeneratorRejectAwaitProfileID);
home = mxFunctionInstanceHome(function);
home->value.home.object = instance;
property = fxNextSlotProperty(the, property, the->stack, XS_NO_ID, XS_INTERNAL_FLAG);
mxPop();

function = fxNewHostFunction(the, fxAsyncGeneratorResolveYield, 1, XS_NO_ID);
function = fxNewHostFunction(the, fxAsyncGeneratorResolveYield, 1, XS_NO_ID, mxAsyncGeneratorResolveYieldProfileID);
home = mxFunctionInstanceHome(function);
home->value.home.object = instance;
property = fxNextSlotProperty(the, property, the->stack, XS_NO_ID, XS_INTERNAL_FLAG);
mxPop();

function = fxNewHostFunction(the, fxAsyncGeneratorRejectYield, 1, XS_NO_ID);
function = fxNewHostFunction(the, fxAsyncGeneratorRejectYield, 1, XS_NO_ID, mxAsyncGeneratorRejectYieldProfileID);
home = mxFunctionInstanceHome(function);
home->value.home.object = instance;
property = fxNextSlotProperty(the, property, the->stack, XS_NO_ID, XS_INTERNAL_FLAG);
Expand Down Expand Up @@ -751,7 +751,7 @@ txSlot* fxNewAsyncFromSyncIteratorInstance(txMachine* the)
slot = fxNextSlotProperty(the, slot, the->stack, XS_NO_ID, XS_INTERNAL_FLAG);
mxPop();

function = fxNewHostFunction(the, fxAsyncFromSyncIteratorDone, 1, XS_NO_ID);
function = fxNewHostFunction(the, fxAsyncFromSyncIteratorDone, 1, XS_NO_ID, mxAsyncFromSyncIteratorDoneProfileID);
home = mxFunctionInstanceHome(function);
home->value.home.object = instance;
slot = fxNextSlotProperty(the, slot, the->stack, XS_NO_ID, XS_INTERNAL_FLAG);
Expand Down
2 changes: 1 addition & 1 deletion xs/sources/xsGlobal.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void fxBuildGlobal(txMachine* the)
fxNewHostConstructor(the, mxCallback(fx_Enumerator), 0, XS_NO_ID);
mxPull(mxEnumeratorFunction);

fxNewHostFunction(the, mxCallback(fxThrowTypeError), 0, XS_NO_ID);
fxNewHostFunction(the, mxCallback(fxThrowTypeError), 0, XS_NO_ID, XS_NO_ID);
mxThrowTypeErrorFunction = *the->stack;
slot = the->stack->value.reference;
slot->flag |= XS_DONT_PATCH_FLAG;
Expand Down
2 changes: 1 addition & 1 deletion xs/sources/xsLockdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
void fxSetHostFunctionProperty(txMachine* the, txSlot* property, txCallback call, txInteger length, txID id)
{
txSlot* home = the->stack;
txSlot* function = fxNewHostFunction(the, call, length, id);
txSlot* function = fxNewHostFunction(the, call, length, id, XS_NO_ID);
txSlot* slot = mxFunctionInstanceHome(function);
slot->value.home.object = home->value.reference;
property->kind = the->stack->kind;
Expand Down
Loading

0 comments on commit 29a2fad

Please sign in to comment.