コード例 #1
0
ファイル: xs6Host.c プロジェクト: kouis3940/kinomajs
void fxLoadModule(txMachine* the, txID moduleID)
{
	txArchive* archive = the->archive;
	txSlot* key = fxGetKey(the, moduleID);
 	char buffer[PATH_MAX];
	txString path = buffer;
	txString dot;
	txString* extension;
	txLoader* loader;
 	c_strcpy(path, key->value.key.string);
	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)) {
					fxResolveModule(the, moduleID, script, fxLoadLibrary(the, key->value.key.string, C_NULL), fxUnloadLibrary);
					return;
				}
				script++;
			}
		}
	}
	dot = c_strrchr(path, '.');
	for (extension = gxExtensions, loader = gxLoaders; *extension; extension++, loader++) {
		if (!c_strcmp(dot, *extension)) {
			(**loader)(the, buffer, moduleID);
			return;
		}
	}
}
コード例 #2
0
ファイル: xs6Host.c プロジェクト: dadongdong/kinomajs
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);
}
コード例 #3
0
ファイル: xs6Host.c プロジェクト: dadongdong/kinomajs
void fxLoadModuleJS(txMachine* the, txString path, txID moduleID)
{
	FskErr err = kFskErrNone;
	FskFileMapping map = NULL;
	txFileMapStream stream;
	txParser _parser;
	txParser* parser = &_parser;
	txParserJump jump;
	txScript* script = NULL;
	bailIfError(FskFileMap(path, (unsigned char**)&(stream.buffer), &(stream.size), 0, &map));
	stream.offset = 0;
	fxInitializeParser(parser, the, 32*1024, 1993);
	parser->firstJump = &jump;
	parser->path = fxNewParserSymbol(parser, path);
	if (c_setjmp(jump.jmp_buf) == 0) {
		fxParserTree(parser, &stream, fxFileMapGetter, 2, NULL);
		fxParserHoist(parser);
		fxParserBind(parser);
		script = fxParserCode(parser);
	}
	fxTerminateParser(parser);
bail:
	FskFileDisposeMap(map);
	if (err && script) {
		fxDeleteScript(script);
		script = NULL;
	}
	fxResolveModule(the, moduleID, script, NULL, NULL);
}
コード例 #4
0
ファイル: xs6Host.c プロジェクト: kouis3940/kinomajs
void fxLoadTextModule(txMachine* the, txString path, txID moduleID)
{
	#ifdef mxDebug
		txUnsigned flags = mxDebugFlag;
	#else
		txUnsigned flags = 0;
	#endif
	txScript* script = fxLoadText(the, path, flags);
	fxResolveModule(the, moduleID, script, fxLoadLibrary(the, path, C_NULL), fxUnloadLibrary);
}
コード例 #5
0
ファイル: xs6Host.c プロジェクト: dadongdong/kinomajs
void fxLoadModule(txMachine* the, txID moduleID)
{
	txArchive* archive = the->archive;
	txSlot* key = fxGetKey(the, moduleID);
	txString path = NULL;
 	char buffer[PATH_MAX];
	txString dot = NULL;
	txString* extension;
	txLoader* loader;
 	KprURLToPath(key->value.key.string, &path);
	c_strcpy(buffer, path);
	c_free(path);
	path = buffer;
	if (archive) {
		if (!c_strncmp(path, archive->base, archive->baseLength)) {
			txInteger c = archive->scriptCount, i;
			txScript* script = archive->scripts;
			path += archive->baseLength;
			#if mxWindows
			{
				char* separator = path;
				while (*separator) {
					if (*separator == '/')
						*separator = mxSeparator;
					separator++;
				}
			}
			#endif
			for (i = 0; i < c; i++) {
				if (!c_strcmp(path, script->path)) {
					fxResolveModule(the, moduleID, script, C_NULL, C_NULL);
					return;
				}
				script++;
			}
		}
	}
	dot = FskStrRChr(path, '.');
	for (extension = gxExtensions, loader = gxLoaders; *extension; extension++, loader++) {
		if (!FskStrCompare(dot, *extension)) {
			(**loader)(the, buffer, moduleID);
			break;
		}
	}
}
コード例 #6
0
ファイル: xs6Host.c プロジェクト: dadongdong/kinomajs
void fxLoadModuleJSB(txMachine* the, txString path, txID moduleID)
{
	FskErr err = kFskErrNone;
	txScript* script = NULL;
	FskFile fref = NULL;
	Atom atom;

	bailIfError(FskMemPtrNewClear(sizeof(txScript), &script));
	bailIfError(FskFileOpen(path, kFskFilePermissionReadOnly, &fref));
	bailIfError(fxLoadModuleJSBAtom(the, fref, &atom));
	bailAssert(atom.atomType == XS_ATOM_BINARY);
	
	bailIfError(fxLoadModuleJSBAtom(the, fref, &atom));
	bailAssert(atom.atomType == XS_ATOM_VERSION);
	bailIfError(FskFileRead(fref, sizeof(script->version), script->version, NULL));
	bailAssert(script->version[0] == XS_MAJOR_VERSION);
	bailAssert(script->version[1] == XS_MINOR_VERSION);
	bailAssert(script->version[2] == XS_PATCH_VERSION);
	bailAssert(script->version[3] != -1);
	
	bailIfError(fxLoadModuleJSBAtom(the, fref, &atom));
	bailAssert(atom.atomType == XS_ATOM_SYMBOLS);
	script->symbolsSize = atom.atomSize - sizeof(atom);
	bailIfError(FskMemPtrNew(script->symbolsSize, &script->symbolsBuffer));
	bailIfError(FskFileRead(fref, script->symbolsSize, script->symbolsBuffer, NULL));
	
	bailIfError(fxLoadModuleJSBAtom(the, fref, &atom));
	bailAssert(atom.atomType == XS_ATOM_CODE);
	script->codeSize = atom.atomSize - sizeof(atom);
	bailIfError(FskMemPtrNew(script->codeSize, &script->codeBuffer));
	bailIfError(FskFileRead(fref, script->codeSize, script->codeBuffer, NULL));

bail:
	if (fref)
		FskFileClose(fref);
	if (err) {
		if (script) {
			fxDeleteScript(script);
			script = NULL;
		}
	}
	fxResolveModule(the, moduleID, script, NULL, NULL);
}
コード例 #7
0
ファイル: xs6Host.c プロジェクト: kouis3940/kinomajs
void fxLoadBinaryModule(txMachine* the, txString path, txID moduleID)
{
	txScript* script = fxLoadBinary(the, path);
	txModuleData* data = fxLoadLibrary(the, path, script);
	fxResolveModule(the, moduleID, script, data, fxUnloadLibrary);
}