txBoolean fxExecute(txMachine* the, void* theStream, txGetter theGetter, txString thePath, txInteger theLine) { #ifdef mxDebug txUnsigned flags = mxProgramFlag | mxDebugFlag; #else txUnsigned flags = mxProgramFlag; #endif txParser _parser; txParser* parser = &_parser; txParserJump jump; txScript* script = NULL; fxInitializeParser(parser, the, 32*1024, 1993); parser->firstJump = &jump; if (c_setjmp(jump.jmp_buf) == 0) { if (thePath) parser->path = fxNewParserSymbol(parser, thePath); fxParserTree(parser, theStream, theGetter, flags, NULL); fxParserHoist(parser); fxParserBind(parser); script = fxParserCode(parser); } fxTerminateParser(parser); if (script) { fxRunScript(the, script, &mxGlobal, C_NULL, C_NULL, C_NULL); return 1; } return 0; }
void fxLoadTextProgram(txMachine* the, txString path) { #ifdef mxDebug txUnsigned flags = mxProgramFlag | mxDebugFlag; #else txUnsigned flags = mxProgramFlag; #endif txScript* script = fxLoadText(the, path, flags); fxRunScript(the, script, &mxGlobal, C_NULL, C_NULL, C_NULL); }
void fxRunProgram(txMachine* the, txString path) { txArchive* archive = the->archive; if (archive) { if (!c_strncmp(path, archive->base, archive->baseLength)) { txInteger c = archive->scriptCount, i; txScript* script = archive->scripts; path += archive->baseLength; for (i = 0; i < c; i++) { if (!c_strcmp(path, script->path)) { fxRunScript(the, script, &mxGlobal, C_NULL, C_NULL, C_NULL); return; } script++; } } } }
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; } }
void fxLink(txMachine* the, xsGrammar* theGrammar) { txScript* script = NULL; FskErr err = kFskErrNone; err = FskMemPtrNewClear(sizeof(txScript), &script); if (err) goto bail; err = FskMemPtrNew(theGrammar->symbolsSize, &script->symbolsBuffer); if (err) goto bail; err = FskMemPtrNew(theGrammar->codeSize, &script->codeBuffer); if (err) goto bail; FskMemCopy(script->symbolsBuffer, theGrammar->symbols, theGrammar->symbolsSize); script->symbolsSize = theGrammar->symbolsSize; FskMemCopy(script->codeBuffer, theGrammar->code, theGrammar->codeSize); script->codeSize = theGrammar->codeSize; script->callback = theGrammar->callback; fxRunScript(the, script, C_NULL, C_NULL, C_NULL, C_NULL); script = C_NULL; bail: fxDeleteScript(script); return; }
void fxNewFunction(txMachine* the, txString arguments, txInteger argumentsSize, txString body, txInteger bodySize, txFlag theFlag, txString thePath, txInteger theLine) { txNewFunctionStream stream; #ifdef mxDebug txUnsigned flags = mxProgramFlag | mxDebugFlag; #else txUnsigned flags = mxProgramFlag; #endif txParser _parser; txParser* parser = &_parser; txParserJump jump; txScript* script = NULL; stream.strings[0] = "(function"; stream.strings[1] = arguments; stream.strings[2] = "{"; stream.strings[3] = body; stream.strings[4] = "})"; stream.sizes[0] = 9; stream.sizes[1] = argumentsSize; stream.sizes[2] = 1; stream.sizes[3] = bodySize; stream.sizes[4] = 2; stream.offset = 0; stream.index = 0; fxInitializeParser(parser, the, 32*1024, 1993); parser->firstJump = &jump; if (c_setjmp(jump.jmp_buf) == 0) { if (thePath) parser->path = fxNewParserSymbol(parser, thePath); fxParserTree(parser, &stream, fxNewFunctionStreamGetter, flags, NULL); fxParserHoist(parser); fxParserBind(parser); script = fxParserCode(parser); } fxTerminateParser(parser); fxRunScript(the, script, C_NULL, C_NULL, C_NULL, C_NULL); }
void fxLoadBinaryProgram(txMachine* the, txString path) { txScript* script = fxLoadBinary(the, path); fxRunScript(the, script, &mxGlobal, C_NULL, C_NULL, C_NULL); }