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; gxProperties = calloc(mxPropertyModulo, sizeof(xsSlot)); if (gxProperties) { #ifdef XSCONFIG aMachine = xsNewMachine(&anAllocation, &xsconfigGrammar, NULL); #endif #ifdef XSDOC aMachine = xsNewMachine(&anAllocation, &xsdocGrammar, NULL); #endif #ifdef XSSHORT aMachine = xsNewMachine(&anAllocation, &xsshortGrammar, NULL); #endif 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"); }
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
static FskErr makeSSLRootVM(const char *calistpath) { #ifdef KPR_CONFIG FskErr err = kFskErrNone; xsBeginHost(gShell->root); xsTry { xsCall1_noResult(xsGet(xsGlobal, xsID("FskSSL")), xsID("loadRootCerts"), xsString((xsStringValue)calistpath)); } xsCatch { err = kFskErrOperationFailed; } xsEndHost(gShell->root); return err; #else char *rootPath, *xsbPath, *xsbName; xsGrammar *grammar; FskErr err; if ((err = FskMemPtrNewClear(sizeof(FskECMAScriptRecord), &gSSLVM)) != kFskErrNone) return err; #if FSK_EMBED FskExtensionsEmbedLoad(SSL_VMNAME); FskExtensionsEmbedGrammar(SSL_VMNAME, &xsbName, &grammar); #else xsbName = "FskCore.xsb"; grammar = &FskCoreGrammar; #endif rootPath = FskEnvironmentDoApply(FskStrDoCopy("[applicationPath]")); xsbPath = FskStrDoCat(rootPath, xsbName); FskMemPtrDispose(rootPath); grammar->name = (xsStringValue)SSL_VMNAME; if ((err = loadGrammar(xsbPath, grammar)) == kFskErrNone) { if ((gSSLVM->the = xsNewMachine(&anAllocation, grammar, gSSLVM)) == NULL) err = kFskErrMemFull; FskMemPtrDispose(grammar->symbols); FskMemPtrDispose(grammar->code); } FskMemPtrDispose(xsbPath); BAIL_IF_ERR(err); xsBeginHost(gSSLVM->the); xsTry { #if !FSK_EMBED /* load Crypt and FskSSL extensions which are only needed for Fsk SSL */ xsCall3_noResult(xsGet(xsGlobal, xsID("System")), xsID("loadExtension"), xsString("Crypt"), xsString("[applicationPath]"), xsInteger(0)); xsCall3_noResult(xsGet(xsGlobal, xsID("System")), xsID("loadExtension"), xsString("FskSSL"), xsString("[applicationPath]"), xsInteger(1)); #endif xsCall1_noResult(xsGet(xsGlobal, xsID("FskSSL")), xsID("loadRootCerts"), xsString((xsStringValue)calistpath)); } xsCatch { err = kFskErrOperationFailed; } xsEndHost(gSSLVM->the); if (err == kFskErrNone) xsShareMachine(gSSLVM->the); bail: if (err != kFskErrNone) disposeSSLRootVM(); return err; #endif }