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); }
void fx_Date_prototype_toPrimitive(txMachine* the) { if (mxThis->kind == XS_REFERENCE_KIND) { txInteger hint = ((mxArgc > 0) && (c_strcmp(fxToString(the, mxArgv(0)), "number") == 0)) ? XS_NUMBER_HINT : XS_STRING_HINT; if (hint == XS_STRING_HINT) { mxPushInteger(0); mxPushSlot(mxThis); fxCallID(the, mxID(_toString)); if (mxIsReference(the->stack)) { the->stack++; mxPushInteger(0); mxPushSlot(mxThis); fxCallID(the, mxID(_valueOf)); } } else { mxPushInteger(0); mxPushSlot(mxThis); fxCallID(the, mxID(_valueOf)); if (mxIsReference(the->stack)) { the->stack++; mxPushInteger(0); mxPushSlot(mxThis); fxCallID(the, mxID(_toString)); } } if (mxIsReference(the->stack)) { if (hint == XS_STRING_HINT) mxTypeError("Cannot coerce object to string"); else mxTypeError("Cannot coerce object to number"); } mxResult->kind = the->stack->kind; mxResult->value = the->stack->value; the->stack++; } else { mxResult->kind = mxThis->kind; mxResult->value = mxThis->value; } }
void fxToPrimitive(txMachine* the, txSlot* theSlot, txInteger theHint) { if (theSlot->kind == XS_REFERENCE_KIND) { fxBeginHost(the); if (theHint == XS_NO_HINT) mxPushString(mxDefaultString.value.string); else if (theHint == XS_NUMBER_HINT) mxPushString(mxNumberString.value.string); else mxPushString(mxStringString.value.string); mxPushInteger(1); mxPushSlot(theSlot); fxCallID(the, mxID(_Symbol_toPrimitive)); theSlot->kind = the->stack->kind; theSlot->value = the->stack->value; the->stack++; fxEndHost(the); } }
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 {
void fxIncludeScript(txParser* parser, txString string) { txBoolean done = 0; char* base = NULL; char name[PATH_MAX]; char* slash = NULL; char* dot = NULL; char* extension = NULL; char* url = NULL; char* path = NULL; FskFileInfo fileInfo; FskFileMapping map= NULL; txFileMapStream fileMapStream; txStringStream stringStream; txMachine* the = parser->console; fxBeginHost(the); { mxTry(the) { xsThrowIfFskErr(KprPathToURL(parser->path->string, &base)); FskStrCopy(name, string); slash = FskStrRChr(name, '/'); if (!slash) slash = name; dot = FskStrRChr(slash, '.'); if (dot) extension = dot; else extension = name + FskStrLen(name); if (!dot) FskStrCopy(extension, ".js"); if (!FskStrCompare(extension, ".js")) { xsThrowIfFskErr(KprURLMerge(base, name, &url)); xsThrowIfFskErr(KprURLToPath(url, &path)); if (kFskErrNone == FskFileGetFileInfo(path, &fileInfo)) { xsThrowIfFskErr(FskFileMap(path, (unsigned char**)&(fileMapStream.buffer), &(fileMapStream.size), 0, &map)); fileMapStream.offset = 0; fxIncludeTree(parser, &fileMapStream, fxFileMapGetter, parser->flags, path); done = 1; FskFileDisposeMap(map); map = NULL; } FskMemPtrDisposeAt(&path); FskMemPtrDisposeAt(&url); } if (!dot) FskStrCopy(extension, ".xml"); if (!FskStrCompare(extension, ".xml")) { xsThrowIfFskErr(KprURLMerge(base, name, &url)); xsThrowIfFskErr(KprURLToPath(url, &path)); if (kFskErrNone == FskFileGetFileInfo(path, &fileInfo)) { 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; fxIncludeTree(parser, &stringStream, fxStringGetter, parser->flags, path); done = 1; FskFileDisposeMap(map); map = NULL; } FskMemPtrDisposeAt(&path); FskMemPtrDisposeAt(&url); } FskMemPtrDispose(base); } mxCatch(the) { FskFileDisposeMap(map); FskMemPtrDispose(path); FskMemPtrDispose(url); FskMemPtrDispose(base); break; } } fxEndHost(the); if (!done) fxReportParserError(parser, "include file not found: %s", string); }