Пример #1
0
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);
}
Пример #2
0
txScript* fxLoadBinary(txMachine* the, txString path)
{
	int error = 0;
	txScript* script = NULL;
	FILE* file = NULL;
	Atom atom;
	txByte version[4];
	script = c_malloc(sizeof(txScript));
	bailElse(script);
	c_memset(script, 0, sizeof(txScript));
	file = fopen(path, "rb");
	bailElse(file);
	fxLoadBinaryAtom(the, file, &atom);
	bailAssert(atom.atomType == XS_ATOM_BINARY);
	
	fxLoadBinaryAtom(the, file, &atom);
	bailAssert(atom.atomType == XS_ATOM_VERSION);
	bailElse(fread(script->version, sizeof(version), 1, file) == 1);	
	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);
	
	fxLoadBinaryAtom(the, file, &atom);
	bailAssert(atom.atomType == XS_ATOM_SYMBOLS);
	script->symbolsSize = atom.atomSize - sizeof(atom);
	script->symbolsBuffer = c_malloc(script->symbolsSize);
	bailElse(fread(script->symbolsBuffer, script->symbolsSize, 1, file) == 1);	
	
	fxLoadBinaryAtom(the, file, &atom);
	bailAssert(atom.atomType == XS_ATOM_CODE);
	script->codeSize = atom.atomSize - sizeof(atom);
	script->codeBuffer = c_malloc(script->codeSize);
	bailElse(fread(script->codeBuffer, script->codeSize, 1, file) == 1);
	fclose(file);
	
	return script;
bail:
	if (file)
		fclose(file);
	if (script)
		fxDeleteScript(script);
	return C_NULL;
}
Пример #3
0
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);
}
Пример #4
0
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;
}