Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
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);
}
Ejemplo n.º 3
0
txScript* fxParseScript(txMachine* the, void* stream, txGetter getter, txUnsigned flags)
{	
	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) {
		fxParserTree(parser, stream, getter, flags, NULL);
		fxParserHoist(parser);
		fxParserBind(parser);
		script = fxParserCode(parser);
	}
	fxTerminateParser(parser);
	return script;
}
Ejemplo n.º 4
0
txScript* fxLoadText(txMachine* the, txString path, txUnsigned flags)
{
	txParser _parser;
	txParser* parser = &_parser;
	txParserJump jump;
	FILE* file = NULL;
	txString name = NULL;
	char buffer[PATH_MAX];
	char map[PATH_MAX];
	txScript* script = NULL;
	fxInitializeParser(parser, the);
	parser->firstJump = &jump;
	if (c_setjmp(jump.jmp_buf) == 0) {
		parser->path = fxNewParserSymbol(parser, path);
		file = fopen(path, "r");
		mxParserThrowElse(file);
		fxParserTree(parser, file, (txGetter)fgetc, flags, &name);
		fclose(file);
		file = NULL;
		if (name) {
			fxMergePath(path, name, buffer);
			mxParserThrowElse(realpath(buffer, map));
			parser->path = fxNewParserSymbol(parser, map);
			file = fopen(map, "r");
			mxParserThrowElse(file);
			fxParserSourceMap(parser, file, (txGetter)fgetc, flags, &name);
			fclose(file);
			file = NULL;
			fxMergePath(map, name, buffer);
			mxParserThrowElse(realpath(buffer, map));
			parser->path = fxNewParserSymbol(parser, map);
		}
		fxParserHoist(parser);
		fxParserBind(parser);
		script = fxParserCode(parser);
	}
	if (file)
		fclose(file);
	fxTerminateParser(parser);
	return script;
}
Ejemplo n.º 5
0
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);
}