Beispiel #1
0
void KprHostDispose(void* it)
{
	KprHost self = it;
	FskInstrumentedItemSendMessageNormal(self, kprInstrumentedContentDeleteMachine, self->first);
	xsDeleteMachine(self->first->the);
	KprContainerDispose(it);
}
Beispiel #2
0
static void
disposeSSLVM(FskECMAScript vm)
{
	if (vm->the != NULL)
		xsDeleteMachine(vm->the);
#ifdef KPR_CONFIG
#else
	if (vm->name != NULL)
		FskMemPtrDispose(vm->name);
#endif
	FskMemPtrDispose(vm);
}
Beispiel #3
0
static void
disposeSSLRootVM()
{
#ifdef KPR_CONFIG
#else
	if (gSSLVM != NULL) {
		if (gSSLVM->the != NULL)
			xsDeleteMachine(gSSLVM->the);
		FskMemPtrDisposeAt(&gSSLVM);
	}
#endif
}
Beispiel #4
0
int main(int argc, char* argv[]) 
{
	xsAllocation anAllocation = {
		2048 * 1024, /* initialChunkSize */
		512 * 1024, /* incrementalChunkSize */
		1000 * 1000, /* initialHeapCount */	
		50 * 1000, /* incrementalHeapCount */
		1024, /* stackCount */
		8192, /* symbolCount */
		1993 /* symbolModulo */
	};
	xsMachine* aMachine;
	int argi;
	int result = 1;

	for (argi = 0; argi < argc; argi++){
		result = strncmp(argv[argi], "--help", strlen("--help"));
		if(!result) {
			printHelp();
			exit(0);
		}
	}
	
	result = 1;

	gxProperties = calloc(mxPropertyModulo, sizeof(xsSlot));
	if (gxProperties) {
		aMachine = xsNewMachine(&anAllocation, &kprconfigGrammar, NULL);
		if (aMachine) {
			xsBeginHost(aMachine);
			{
				xsTry {
					xsResult = xsNewInstanceOf(xsArrayPrototype);
					for (argi = 0; argi < argc; argi++)
						xsSet(xsResult, argi, xsString(argv[argi]));
					(void)xsCall1(xsGlobal, xsID("main"), xsResult);
					result = 0;
				}
				xsCatch {
					char* aMessage = xsToString(xsGet(xsException, xsID("message")));
					fprintf(stderr, "### %s\n", aMessage);
				}
			}
			xsEndHost(aMachine);
			xsDeleteMachine(aMachine);
		}
		else
			fprintf(stderr, "### Cannot allocate machine!\n");
	}
Beispiel #5
0
static void KprServicesLoop(void* theParameter)
{
	xsAllocation allocation = {
		1100000,		// 700 * 1024,
		32 * 1024,
		70000,			// 62000,
		4096,
		2048,
		16000,
		1993
	};
	FskErr err = kFskErrNone;
	KprService service = gServices;
	FskThread thread = FskThreadGetCurrent();
	gServiceMachine = xsAliasMachine(&allocation, gShell->root, "services", gShell);
	bailIfNULL(gServiceMachine);

	while (service) {
		if (service->flags & kprServicesThread) {
			FskInstrumentedTypePrintfNormal(&KprServiceInstrumentation, "Starting %s", service->id);
			(*service->start)(service, thread, gServiceMachine);
		}
		service = service->next;
	}
	FskThreadInitializationComplete(thread);
	while (!gServicesThreadQuitting)
		FskThreadRunloopCycle(-1);
	service = gServices;
	while (service) {
		if (service->flags & kprServicesThread) {
			FskInstrumentedTypePrintfNormal(&KprServiceInstrumentation, "Stopping %s", service->id);
			(*service->stop)(service);
		}
		service = service->next;
	}
bail:
	if (gServiceMachine) {
		xsDeleteMachine(gServiceMachine);
		gServiceMachine = NULL;
	}
	return;
}
Beispiel #6
0
int main(int argc, char* argv[])
{
    xsAllocation anAllocation = {
        2048 * 1024, /* initialChunkSize */
        512 * 1024, /* incrementalChunkSize */
        1000 * 1000, /* initialHeapCount */
        50 * 1000, /* incrementalHeapCount */
        64 * 1024, /* stackCount */
        4096, /* symbolCount */
        1993 /* symbolModulo */
    };
    xsMachine* aMachine;
    int argi;
    int result = 1;

    aMachine = xsNewMachine(&anAllocation, &kpr2jsGrammar, NULL);
    if (aMachine) {
        xsBeginHost(aMachine);
        {
            xsTry {
                xsResult = xsNewInstanceOf(xsArrayPrototype);
                for (argi = 0; argi < argc; argi++)
                    xsSet(xsResult, argi, xsString(argv[argi]));
                (void)xsCall1(xsGlobal, xsID("main"), xsResult);
                result = 0;
            }
            xsCatch {
                char* aMessage = xsToString(xsGet(xsException, xsID("message")));
                if (*aMessage)
                    fprintf(stderr, "### %s\n", aMessage);
                else
                    fprintf(stderr, "### XML error(s)\n");
            }
        }
        xsEndHost(aMachine);
        xsDeleteMachine(aMachine);
    }
    else
Beispiel #7
0
int main(int argc, char* argv[]) 
{
	xsCreation creation_mc = {
		25*1024,	/* initial chunk size */
		2048,		/* incremental chunk size */
		50*1024/16,	/* initial heap count	-- will be calculated later */
		128,		/* incremental heap count	-- wasting 16 bytes / allocation */
		650,		/* stack count */
		2048+1024,	/* key count */
		97,		/* name modulo */
		127,		/* symbol modulo */
	};
	xsCreation creation_tool = {
		128 * 1024 * 1024, 	/* initialChunkSize */
		16 * 1024 * 1024, 	/* incrementalChunkSize */
		8 * 1024 * 1024, 		/* initialHeapCount */
		1 * 1024 * 1024, 		/* incrementalHeapCount */
		4096, 		/* stackCount */
		4096*3, 		/* keyCount */
		1993, 		/* nameModulo */
		127 		/* symbolModulo */
	};
	xsCreation* creation = &creation_tool;
	int error = 0;
	int argi = 1;
	void* archive = NULL;
	xsBooleanValue program = 0;
	xsBooleanValue xsbug = 0;
	xsMachine* machine;
	char path[PATH_MAX];
	char modulePath[PATH_MAX];
	xsStringValue extension;
	xsStringValue slash;
	xsStringValue name;
	int size;
	if (argi < argc) {
		if (!strcmp(argv[argi], "-a")) {
			argi++;
			if (argi < argc) {
                if (realpath(argv[argi], path)) {
                	archive = fxMapArchive(path, NULL);
                    if (!archive) {
                        fprintf(stderr, "# invalid archive: %s\n", path);
                        return 1;
                    }
                    if (strstr(path, "mc.xsa")) {
                  		creation = &creation_mc;
                    }
                }
				else {
					fprintf(stderr, "# archive not found: %s\n", argv[argi]);
					return 1;
				}
				argi++;
			}
		}
	}
	while (argi < argc) {
		if (!strcmp(argv[argi], "-p")) {
			program = 1;
			argi++;
		}
		else if (!strcmp(argv[argi], "-x")) {
			xsbug = 1;
			argi++;
		}
		else
			break;
	}
	gargc = argc;
	gargi = argi;
	gargv = argv;
	machine = xsCreateMachine(creation, archive, "xsr6", NULL);
	xsBeginHost(machine);
	{
		xsVars(2);
		{
			xsTry {
				xsVar(0) = xsNewInstanceOf(xsObjectPrototype);
				if (xsbug)
					xsVar(1) = xsNewHostFunction(console_log_xsbug, 0);
				else
					xsVar(1) = xsNewHostFunction(console_log, 0);
				xsSet(xsVar(0), xsID("log"), xsVar(1));
				xsSet(xsGlobal, xsID("console"), xsVar(0));

				xsVar(0) = xsNewHostObject(weakTest);
				xsVar(1) = xsNewHostConstructor(WeakTest, 1, xsVar(0));
				xsSet(xsGlobal, xsID("WeakTest"), xsVar(1));
				xsVar(1) = xsNewHostFunction(gc, 0);
				xsSet(xsGlobal, xsID("gc"), xsVar(1));

				xsResult = xsModulePaths();
				if (archive) {
					slash = strrchr(path, mxSeparator);
					if (slash) {
						*(slash + 1) = 0;
						xsCall1(xsResult, xsID("add"), xsString(path));
					}
				}
				realpath(argv[0], modulePath);
				slash = strrchr(modulePath, mxSeparator);
				if (slash) {
					strcpy(slash + 1, "modules");
					size = c_strlen(modulePath);
					modulePath[size++] = mxSeparator;
					modulePath[size] = 0;
					xsCall1(xsResult, xsID("add"), xsString(modulePath));
				}

				if (argi == argc) {
					fprintf(stderr, "# no module, no program\n");
					error = 1;
				}	
				else if (program) {
					xsVar(0) = xsNewHostFunction(print, 0);
					xsSet(xsGlobal, xsID("print"), xsVar(0));
					//xsStartProfiling();
					while (argi < argc) {
						if (argv[argi][0] != '-') {
							xsElseError(realpath(argv[argi], path));
							strcpy(modulePath, path);
							slash = strrchr(modulePath, mxSeparator);
							*(slash + 1) = 0;
							xsCall1(xsResult, xsID("add"), xsString(modulePath));
							strcat(modulePath, "modules/");
							xsCall1(xsResult, xsID("add"), xsString(modulePath));
							fxRunProgram(the, path);
						}
						argi++;
					}
					fxRunLoop(the);
					//xsStopProfiling();
				}
				else {
					xsVar(0) = xsNewInstanceOf(xsObjectPrototype);
					xsVar(1) = xsNewHostFunction(process_cwd, 0);
					xsSet(xsVar(0), xsID("cwd"), xsVar(1));
				#ifdef mxDebug
					xsSet(xsVar(0), xsID("debug"), xsTrue);
				#else
					xsSet(xsVar(0), xsID("debug"), xsFalse);
				#endif
					xsVar(1) = xsNewHostFunction(process_execArgv, 0);
					xsSet(xsVar(0), xsID("execArgv"), xsVar(1));
					xsVar(1) = xsNewHostFunction(process_getenv, 0);
					xsSet(xsVar(0), xsID("getenv"), xsVar(1));
					xsVar(1) = xsNewHostFunction(process_then, 1);
					xsSet(xsVar(0), xsID("then"), xsVar(1));
					xsSet(xsVar(0), xsID("platform"), xsString("darwin"));
					xsSet(xsGlobal, xsID("process"), xsVar(0));
		
					strcpy(path, argv[argi]);
					slash = strrchr(path, mxSeparator);
					if (slash) {
						*slash = 0;
						realpath(path, modulePath);
						size = c_strlen(modulePath);
						modulePath[size++] = mxSeparator;
						modulePath[size] = 0;
						xsCall1(xsResult, xsID("add"), xsString(modulePath));
						strcat(modulePath, "modules");
						size = c_strlen(modulePath);
						modulePath[size++] = mxSeparator;
						modulePath[size] = 0;
						xsCall1(xsResult, xsID("add"), xsString(modulePath));
						name = slash + 1;
					
					}
					else {
						realpath(".", modulePath);
						size = c_strlen(modulePath);
						modulePath[size++] = mxSeparator;
						modulePath[size] = 0;
						xsCall1(xsResult, xsID("add"), xsString(modulePath));
						strcat(modulePath, "modules");
						size = c_strlen(modulePath);
						modulePath[size++] = mxSeparator;
						modulePath[size] = 0;
						xsCall1(xsResult, xsID("add"), xsString(modulePath));
						name = path;
					}
					extension = strrchr(name, '.');
					if (extension)
						*extension = 0;
					//xsStartProfiling();
					fxRunModule(the, name);
					//xsStopProfiling();
				}
			}
			xsCatch {
				xsStringValue message = xsToString(xsException);
				fprintf(stderr, "### %s\n", message);
				error = 1;
			}
		}
	}
	xsEndHost(the);
	xsDeleteMachine(machine);
	fxUnmapArchive(archive);
	if (!error && process_then_parameters) {
	#if mxWindows
		error =_spawnvp(_P_WAIT, process_then_parameters[0], process_then_parameters);
		if (error < 0)
			fprintf(stderr, "### Cannot execute %s!\n", process_then_parameters[0]);
	#else
		execvp(process_then_parameters[0], process_then_parameters);
	#endif
	}
	return error;
}