Skip to content

Commit

Permalink
XS linker accessor strip
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Soquet committed Jan 4, 2022
1 parent 028f951 commit 92b4571
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion xs/sources/xsProperty.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ txSlot* fxLastProperty(txMachine* the, txSlot* slot)
return slot;
}

#ifndef mxLink
txSlot* fxNextHostAccessorProperty(txMachine* the, txSlot* property, txCallback get, txCallback set, txID id, txFlag flag)
{
txSlot *getter = NULL, *setter = NULL, *home = the->stack, *slot;
Expand Down Expand Up @@ -73,7 +74,6 @@ txSlot* fxNextHostAccessorProperty(txMachine* the, txSlot* property, txCallback
return property;
}

#ifndef mxLink
txSlot* fxNextHostFunctionProperty(txMachine* the, txSlot* property, txCallback call, txInteger length, txID id, txFlag flag)
{
txSlot *function, *home = the->stack, *slot;
Expand Down
41 changes: 38 additions & 3 deletions xs/tools/xslSlot.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,13 @@ txSlot* fxNewFunctionName(txMachine* the, txSlot* instance, txID id, txIndex ind
if (linker->stripFlag)
return C_NULL;
property = mxBehaviorGetProperty(the, instance, mxID(_name), 0, XS_OWN);
if (!property)
property = fxNextSlotProperty(the, fxLastProperty(the, instance), &mxEmptyString, mxID(_name), XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
if (id) {
if (property) {
if ((property->kind != mxEmptyString.kind) || (property->value.string != mxEmptyString.value.string))
return property;
}
else
property = fxNextSlotProperty(the, fxLastProperty(the, instance), &mxEmptyString, mxID(_name), XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG);
if (id != XS_NO_ID) {
key = fxGetKey(the, (txID)id);
if (key) {
txKind kind = mxGetKeySlotKind(key);
Expand Down Expand Up @@ -558,6 +562,37 @@ txSlot* fxNewFunctionName(txMachine* the, txSlot* instance, txID id, txIndex ind
return property;
}

txSlot* fxNextHostAccessorProperty(txMachine* the, txSlot* property, txCallback get, txCallback set, txID id, txFlag flag)
{
txLinker* linker = (txLinker*)(the->context);
txSlot *getter = NULL, *setter = NULL, *home = the->stack, *slot;
if (get) {
fxNewLinkerBuilder(linker, get, 0, id);
getter = fxNewHostFunction(the, get, 0, XS_NO_ID);
slot = mxFunctionInstanceHome(getter);
slot->value.home.object = home->value.reference;
fxRenameFunction(the, getter, id, 0, XS_NO_ID, "get ");
}
if (set) {
fxNewLinkerBuilder(linker, set, 1, id);
setter = fxNewHostFunction(the, set, 1, XS_NO_ID);
slot = mxFunctionInstanceHome(setter);
slot->value.home.object = home->value.reference;
fxRenameFunction(the, setter, id, 0, XS_NO_ID, "set ");
}
property = property->next = fxNewSlot(the);
property->flag = flag;
property->ID = id;
property->kind = XS_ACCESSOR_KIND;
property->value.accessor.getter = getter;
property->value.accessor.setter = setter;
if (set)
mxPop();
if (get)
mxPop();
return property;
}

txSlot* fxNextHostFunctionProperty(txMachine* the, txSlot* property, txCallback call, txInteger length, txID id, txFlag flag)
{
property = property->next = fxNewSlot(the);
Expand Down

0 comments on commit 92b4571

Please sign in to comment.