void fx_Boolean(txMachine* the) { if (mxResult->kind == XS_UNDEFINED_KIND) { if (mxArgc > 0) *mxResult = *mxArgv(0); fxToBoolean(the, mxResult); } else { txSlot* aBoolean = fxGetOwnInstance(the, mxResult); mxCheckBoolean(aBoolean); if (mxArgc > 0) { fxToBoolean(the, mxArgv(0)); aBoolean->next->value.boolean = mxArgv(0)->value.boolean; } } }
void fx_Boolean(txMachine* the) { txSlot* slot = fxCheckBoolean(the, mxThis); txBoolean value = 0; if (mxArgc > 0) value = fxToBoolean(the, mxArgv(0)); if (slot) slot->value.boolean = value; else { mxResult->kind = XS_BOOLEAN_KIND; mxResult->value.boolean = value; } }
txID fxFindModule(txMachine* the, txID moduleID, txSlot* slot) { char name[PATH_MAX]; char base[PATH_MAX]; txBoolean absolute, relative, search; txSlot *key, *iterator, *result; txString dot, slash; txID id; fxToStringBuffer(the, slot, name, sizeof(name)); if ((!c_strncmp(name, "./", 2)) || (!c_strncmp(name, "../", 3))) { absolute = 0; relative = (moduleID == XS_NO_ID) ? 0 : 1; search = 0; } else if ((!c_strncmp(name, "/", 1))) { absolute = 1; relative = 0; search = 0; } else { absolute = 0; relative = (moduleID == XS_NO_ID) ? 0 : 1; search = 1; } slash = c_strrchr(name, '/'); if (!slash) slash = name; dot = c_strrchr(slash, '.'); if (!dot) dot = name + c_strlen(name); if (absolute) { if (fxFindURI(the, "", name, dot, &id)) return id; } if (relative) { key = fxGetKey(the, moduleID); c_strcpy(base, key->value.key.string); if (fxFindURI(the, base, name, dot, &id)) return id; } if (search) { mxCallID(&mxModulePaths, mxID(_Symbol_iterator), 0); iterator = the->stack; for (;;) { mxCallID(iterator, mxID(_next), 0); result = the->stack; mxGetID(result, mxID(_done)); if (fxToBoolean(the, the->stack)) break; the->stack++; mxGetID(result, mxID(_value)); fxToStringBuffer(the, the->stack++, base, sizeof(base)); if (fxFindURI(the, base, name, dot, &id)) return id; } } mxReferenceError("module \"%s\" not found", name); return XS_NO_ID; }
void fx_Array_from(txMachine* the) { txSlot* list = fxNewInstance(the); txSlot* item = list; txIndex count = 0; txIndex index; txSlot* function = C_NULL; txSlot* _this = C_NULL; txSlot* resultArray; txSlot* resultSlot; if (mxArgc > 2) _this = mxArgv(2); if (mxArgc > 1) { txSlot* slot = mxArgv(1); if (slot->kind == XS_REFERENCE_KIND) { slot = slot->value.reference; if ((slot->next->kind == XS_CODE_KIND) || (slot->next->kind == XS_CALLBACK_KIND)) function = slot; } } if (mxArgc > 0) { mxPushSlot(mxArgv(0)); if (fxHasID(the, mxID(_Symbol_iterator))) { txSlot* iterator; txSlot* result; mxPushInteger(0); mxPushSlot(mxArgv(0)); fxCallID(the, mxID(_Symbol_iterator)); iterator = the->stack; { mxTry(the) { count = 0; for(;;) { mxCallID(iterator, mxID(_next), 0); result = the->stack; mxGetID(result, mxID(_done)); if (fxToBoolean(the, the->stack)) break; the->stack++; mxGetID(result, mxID(_value)); if (function) { /* ARG1 */ mxPushInteger(count); /* ARGC */ mxPushInteger(2); /* THIS */ if (_this) mxPushSlot(_this); else mxPushUndefined(); /* FUNCTION */ mxPushReference(function); fxCall(the); } item = fxNextSlotProperty(the, item, the->stack, XS_NO_ID, XS_NO_FLAG); the->stack++; count++; } } mxCatch(the) { mxCallID(iterator, mxID(_return), 0); fxJump(the); } } the->stack++; } else {