| 1166 | } |
| 1167 | |
| 1168 | void fxLoadModulesFrom(txMachine* the, txSlot* queue, txSlot* module, txBoolean now) |
| 1169 | { |
| 1170 | txSlot* internal = mxModuleInstanceInternal(module); |
| 1171 | txID moduleID = internal->value.module.id; |
| 1172 | txSlot* realm = internal->value.module.realm; |
| 1173 | txSlot* transfer = mxModuleInstanceTransfers(module)->value.reference->next; |
| 1174 | txSlot* already = the->stack; |
| 1175 | while (transfer) { |
| 1176 | txSlot* from = mxTransferFrom(transfer); |
| 1177 | if (from->kind != XS_NULL_KIND) { |
| 1178 | txID importModuleID = XS_NO_ID; |
| 1179 | txSlot* importModule; |
| 1180 | txID status; |
| 1181 | txSlot* former = the->stack; |
| 1182 | while (former < already) { |
| 1183 | if (!c_strcmp(former->value.string, from->value.string)) { |
| 1184 | importModuleID = former->ID; |
| 1185 | break; |
| 1186 | } |
| 1187 | former++; |
| 1188 | } |
| 1189 | if (importModuleID == XS_NO_ID) { |
| 1190 | mxPushSlot(from); |
| 1191 | importModuleID = fxResolveSpecifier(the, realm, moduleID, from); |
| 1192 | the->stack->ID = importModuleID; |
| 1193 | } |
| 1194 | importModule = fxGetModule(the, realm, importModuleID, from->flag & XS_JSON_MODULE_FLAG); |
| 1195 | if (!importModule) { |
| 1196 | importModule = mxBehaviorSetProperty(the, mxOwnModules(realm)->value.reference, importModuleID, 0, XS_OWN); |
| 1197 | fxNewModule(the, realm, importModuleID, from->flag & XS_JSON_MODULE_FLAG, importModule); |
| 1198 | } |
| 1199 | from->kind = XS_REFERENCE_KIND; |
| 1200 | from->value.reference = importModule->value.reference; |
| 1201 | status = mxModuleStatus(importModule); |
| 1202 | if ((status == XS_MODULE_STATUS_NEW) || (status == XS_MODULE_STATUS_LOADED)) { |
| 1203 | fxQueueModule(the, queue, importModule); |
| 1204 | } |
| 1205 | else if (now) { |
| 1206 | if (status == XS_MODULE_STATUS_LINKING) { |
| 1207 | txSlot* slot = queue->next; |
| 1208 | while (slot) { |
| 1209 | if (slot->value.reference == importModule->value.reference) |
| 1210 | break; |
| 1211 | slot= slot->next; |
| 1212 | } |
| 1213 | if (!slot) |
| 1214 | mxTypeError("async module"); |
| 1215 | } |
| 1216 | else if (status == XS_MODULE_STATUS_ERROR) { |
| 1217 | mxPushSlot(mxModuleInstanceMeta(module)); |
| 1218 | mxPull(mxException); |
| 1219 | fxJump(the); |
| 1220 | } |
| 1221 | else if (status != XS_MODULE_STATUS_EXECUTED) { |
| 1222 | mxTypeError("async module"); |
| 1223 | } |
| 1224 | } |
| 1225 | } |
no test coverage detected