Exemple #1
0
void fxLoadModuleXML(txMachine* the, txString path, txID moduleID)
{
	FskFileMapping map = NULL;
	txFileMapStream fileMapStream;
	txStringStream stringStream;
	txScript* script = NULL;
	
	mxTry(the) {
		fxBeginHost(the);
		xsThrowIfFskErr(FskFileMap(path, &fileMapStream.buffer, &fileMapStream.size, 0, &map));
		fileMapStream.offset = 0;
		mxPushInteger(0);
		mxPushInteger(0);
		mxPushInteger(0);
		mxPushInteger(0);
		mxPushInteger(3);
		fxParse(the, &fileMapStream, fxFileMapGetter, path, 1, xsSourceFlag | xsDebugFlag);
		fxCallID(the, fxID(the, "generate"));
		fxToString(the, the->stack);
		stringStream.slot = the->stack;
		stringStream.size = c_strlen(stringStream.slot->value.string);
		stringStream.offset = 0;
		script = fxParseScript(the, &stringStream, fxStringGetter, mxDebugFlag);
		fxEndHost(the);
	}
	mxCatch(the) {
		break;
	}
	FskFileDisposeMap(map);
	fxResolveModule(the, moduleID, script, NULL, NULL);
}
Exemple #2
0
void fx_Function(txMachine* the)
{
    txInteger c, i;
    txStringStream stream;

    c = mxArgc;
    i = 0;
    mxPushStringC("(function anonymous(");
    while (c > 1) {
        fxToString(the, mxArgv(i));
        fxConcatString(the, the->stack, mxArgv(i));
        if (c > 2)
            fxConcatStringC(the, the->stack, ", ");
        c--;
        i++;
    }
    fxConcatStringC(the, the->stack, "){");
    if (c > 0) {
        fxToString(the, mxArgv(i));
        fxConcatString(the, the->stack, mxArgv(i));
    }
    fxConcatStringC(the, the->stack, "})");
    stream.slot = the->stack;
    stream.offset = 0;
    stream.size = c_strlen(the->stack->value.string);
    fxRunScript(the, fxParseScript(the, &stream, fxStringGetter, mxProgramFlag), C_NULL, C_NULL, C_NULL, C_NULL);
    if (mxTarget->kind == XS_UNDEFINED_KIND)
        mxPullSlot(mxResult);
    else {
        txSlot* from = fxGetInstance(the, the->stack++);
        txSlot* to = fxGetInstance(the, mxThis);
        txSlot* fromProperty;
        txSlot* toProperty;
        to->next->value.code = from->next->value.code;
        fromProperty = mxFunctionInstancePrototype(from);
        toProperty = mxFunctionInstancePrototype(to);
        *toProperty = *fromProperty;
        fromProperty = mxFunctionInstanceInfo(from);
        toProperty = mxFunctionInstanceInfo(to);
        *toProperty = *fromProperty;
    }
}
Exemple #3
0
void fx_Function(txMachine* the)
{	
	txSlot* aFunction;
	txInteger aCount, anIndex, aFileIndex, aLineIndex;
	txFlag aFlag;
	txSlot* aSlot;
	txStringStream aStream;
	txByte* aCode;
	txSlot* aProperty;
	
	if (mxResult->kind == XS_UNDEFINED_KIND) {
		mxPush(mxFunctionPrototype);
		aFunction = fxNewFunctionInstance(the);
		*mxResult = *(the->stack++);
	}
	else
		aFunction = fxGetOwnInstance(the, mxResult);
	mxCheckFunction(aFunction);

	aCount = mxArgc;
	anIndex = 0;
	aFileIndex = aCount - 2;
	aLineIndex = aCount - 1;
	aFlag = XS_NO_FLAG;
	if ((aCount >= 4) && (mxArgv(aLineIndex)->kind == XS_INTEGER_KIND)) {
		aCount -= 2;
		aFlag |= XS_DEBUG_FLAG;
	}
	aSlot = fxGetInstance(the, mxThis);
	if (aSlot && (aSlot->flag & XS_SANDBOX_FLAG))
		aFlag |= XS_SANDBOX_FLAG;
	else
		aFlag |= the->frame->next->flag & XS_SANDBOX_FLAG;
	
	mxZeroSlot(--the->stack);
	fxCopyStringC(the, the->stack, "(");
	while (aCount > 1) {
		fxToString(the, mxArgv(anIndex));
		fxConcatString(the, the->stack, mxArgv(anIndex));
		if (aCount > 2)
			fxConcatStringC(the, the->stack, ", ");
		aCount--;
		anIndex++;
	}
	fxConcatStringC(the, the->stack, "){");
	if (aCount > 0) {
		fxToString(the, mxArgv(anIndex));
		fxConcatString(the, the->stack, mxArgv(anIndex));
	}
	fxConcatStringC(the, the->stack, "}");
		
	aStream.slot = the->stack;
	aStream.offset = 0;
	aStream.size = c_strlen(the->stack->value.string);
#ifdef mxDebug
	if (aFlag & XS_DEBUG_FLAG) 
		aCode = fxParseScript(the, &aStream, fxStringGetter, 
				fxNewFile(the, mxArgv(aFileIndex)), mxArgv(aLineIndex)->value.integer, 
				aFlag, C_NULL);
	else
#endif
		aCode = fxParseScript(the, &aStream, fxStringGetter, C_NULL, 0, 
				aFlag, C_NULL);
	
	aFunction->next->value.code = aCode;
	
	aProperty = fxSetProperty(the, aFunction, the->bodyID, C_NULL);
	aProperty->flag = XS_DONT_DELETE_FLAG | XS_DONT_ENUM_FLAG | XS_DONT_SET_FLAG;
	aProperty->value.string = mxArgv(anIndex)->value.string;
	aProperty->kind = mxArgv(anIndex)->kind;
	the->stack++;
}