| 755 | } |
| 756 | |
| 757 | void fxSortArrayItems(txMachine* the, txSlot* function, txSlot* array, txNumber LENGTH, txSlot* target) |
| 758 | { |
| 759 | txBoolean flag = mxThis->value.reference != target->value.reference; |
| 760 | txSlot* instance = C_NULL; |
| 761 | txIndex index; |
| 762 | txSlot* item; |
| 763 | txIndex length; |
| 764 | txIndex size; |
| 765 | again: |
| 766 | if (!array) { |
| 767 | LENGTH = fxGetArrayLength(the, mxThis); |
| 768 | if (LENGTH > 0xFFFFFFFF) |
| 769 | mxRangeError("array overflow"); |
| 770 | mxPush(mxArrayPrototype); |
| 771 | instance = fxNewArrayInstance(the); |
| 772 | array = instance->next; |
| 773 | item = array; |
| 774 | index = 0; |
| 775 | while (index < LENGTH) { |
| 776 | mxPushSlot(mxThis); |
| 777 | if (flag || fxHasIndex(the, index)) { |
| 778 | item->next = fxNewSlot(the); |
| 779 | item = item->next; |
| 780 | array->value.array.length++; |
| 781 | mxPushSlot(mxThis); |
| 782 | mxGetIndex(index); |
| 783 | mxPullSlot(item); |
| 784 | } |
| 785 | index++; |
| 786 | } |
| 787 | fxCacheArray(the, instance); |
| 788 | } |
| 789 | length = array->value.array.length; |
| 790 | size = mxArraySize(array); |
| 791 | /* like GCC qsort */ |
| 792 | #define CHECK \ |
| 793 | if (size != mxArraySize(array)) { \ |
| 794 | array = C_NULL; \ |
| 795 | goto again; \ |
| 796 | } |
| 797 | #define COMPARE(INDEX) \ |
| 798 | fxCompareArrayItem(the, function, array, INDEX) |
| 799 | #define COPY \ |
| 800 | to->next = from->next; \ |
| 801 | to->ID = from->ID; \ |
| 802 | to->kind = from->kind; \ |
| 803 | to->value = from->value |
| 804 | #define MOVE(FROM,TO) \ |
| 805 | from = array->value.array.address + (FROM); \ |
| 806 | to = array->value.array.address + (TO); \ |
| 807 | COPY |
| 808 | #define PUSH(INDEX) \ |
| 809 | from = array->value.array.address + (INDEX); \ |
| 810 | mxPushUndefined(); \ |
| 811 | to = the->stack; \ |
| 812 | COPY |
| 813 | #define PULL(INDEX) \ |
| 814 | from = the->stack++; \ |
no test coverage detected