Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
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 {