| 1173 | } |
| 1174 | |
| 1175 | void fx_Array_from(txMachine* the) |
| 1176 | { |
| 1177 | txSlot* function = (mxArgc > 1) && !mxIsUndefined(mxArgv(1)) ? fxArgToCallback(the, 1) : C_NULL; |
| 1178 | txIndex length = 0; |
| 1179 | txSlot* iterator; |
| 1180 | txSlot* next; |
| 1181 | txSlot* value; |
| 1182 | if (mxArgc > 0) { |
| 1183 | mxPushSlot(mxArgv(0)); |
| 1184 | mxGetID(mxID(_Symbol_iterator)); |
| 1185 | if (mxIsUndefined(the->stack) || mxIsNull(the->stack)) { |
| 1186 | txIndex index = 0; |
| 1187 | mxPushSlot(mxArgv(0)); |
| 1188 | mxGetID(mxID(_length)); |
| 1189 | if (mxIsUndefined(the->stack)) |
| 1190 | length = 0; |
| 1191 | else |
| 1192 | length = fxCheckArrayLength(the, the->stack); |
| 1193 | mxPop(); |
| 1194 | fxCreateArray(the, 1, length); |
| 1195 | while (index < length) { |
| 1196 | mxPushSlot(mxArgv(0)); |
| 1197 | mxGetIndex(index); |
| 1198 | fx_Array_from_aux(the, function, the->stack, index); |
| 1199 | mxPop(); |
| 1200 | index++; |
| 1201 | } |
| 1202 | } |
| 1203 | else { |
| 1204 | fxCreateArray(the, 0, 0); |
| 1205 | mxTemporary(iterator); |
| 1206 | mxTemporary(next); |
| 1207 | fxGetIterator(the, mxArgv(0), iterator, next, 0); |
| 1208 | mxTemporary(value); |
| 1209 | length = 0; |
| 1210 | while (fxIteratorNext(the, iterator, next, value)) { |
| 1211 | mxTry(the) { |
| 1212 | fx_Array_from_aux(the, function, value, length); |
| 1213 | length++; |
| 1214 | } |
| 1215 | mxCatch(the) { |
| 1216 | fxIteratorReturn(the, iterator, 1); |
| 1217 | fxJump(the); |
| 1218 | } |
| 1219 | } |
| 1220 | mxPop(); |
| 1221 | } |
| 1222 | } |
| 1223 | else { |
| 1224 | fxCreateArray(the, 1, 0); |
| 1225 | } |
| 1226 | mxPushUnsigned(length); |
| 1227 | mxPushSlot(mxResult); |
| 1228 | mxSetID(mxID(_length)); |
| 1229 | mxPop(); |
| 1230 | } |
| 1231 | |
| 1232 | void fx_Array_from_aux(txMachine* the, txSlot* function, txSlot* value, txIndex index) |
nothing calls this directly
no test coverage detected