// (make-vm thunk-sexp import-spec-sexp . name) => #<vm> Object scheme::makeVmEx(VM* theVM, int argc, const Object* argv) { DeclareProcedureName("make-vm"); checkArgumentLengthBetween(2, 3); argumentCheckPair(0, thunkSexp); argumentCheckPair(1, importSpecSexp); VMFactory factory; const int INITIAL_STACK_SIZE = 5000; const bool isProfilerON = false; VM* vm = factory.create(INITIAL_STACK_SIZE, isProfilerON); vm->setValueString(UC("%loadpath"), Object::False); // todo not false vm->setValueString(UC("%verbose"), Object::False); vm->setValueString(UC("*command-line-args*"), Pair::list1("./test/stack-trace2.scm")); vm->setValueString(UC("%vm-import-spec"), importSpecSexp); vm->setValueString(UC("%vm-thunk"), thunkSexp); if (argc == 3) { argumentAsString(2, vmName); vm->setName(vmName->data()); } return Object::makeVM(vm); }
MOSHEXPORT int mosh_main(int argc, char *argv[]) #endif { // call this before any allocation. mosh_init(); ucs4char opt; int optionIndex = 0; bool isTestOption = false; bool isCompileString = false; bool isProfilerOn = false; bool isR6RSBatchMode = true; bool disableAcc = false; bool verbose = false; bool cleanAcc = false; bool isDebugExpand = false; // show the result of psyntax expansion. #ifdef WITH_NMOSH_DEFAULTS bool invokeApplet = false; bool enablePreload = false; bool isGuruMode = false; #endif ucs4char* initFile = NULL; ucs4char* loadPath = NULL; static struct optionU long_options[] = { {UC("loadpath"), optional_argument, 0, 'L'}, {UC("help"), 0, 0, 'h'}, {UC("disable-acc"), 0, 0, 'd'}, {UC("clean-acc"), 0, 0, 'C'}, {UC("verbose"), 0, 0, 'a'}, #ifdef WITH_NMOSH_DEFAULTS {UC("preload"), 0, 0, 'R'}, {UC("applet"), 0, 0, 'T'}, {UC("guru-mode"), 0, 0, 'G'}, #endif {0, 0, 0, 0} }; ucs4char** argvU = getCommandLine(argc, argv); #ifdef WITH_NMOSH_DEFAULTS #define NMOSH_APPEND_OPTIONS "RT" #else #define NMOSH_APPEND_OPTIONS #endif while ((opt = getopt_longU(argc, argvU, UC("htvpVcl:5rze" NMOSH_APPEND_OPTIONS), long_options, &optionIndex)) != -1) { switch (opt) { case 'h': showUsage(); break; case 'd': disableAcc = true; break; case 'l': initFile = optargU; break; case 'L': loadPath = optargU; break; case 'b': isR6RSBatchMode = true; break; case 'v': showVersion(); break; case 'V': showVersion(); break; case 't': isTestOption = true; break; case 'p': isProfilerOn = true; break; case 'c': isCompileString = true; break; case 'a': verbose = true; break; case 'C': cleanAcc = true; disableAcc = true; break; case 'e': isDebugExpand = true; break; case '5': isR6RSBatchMode = false; break; #ifdef WITH_NMOSH_DEFAULTS case 'R': enablePreload = true; break; case 'T': invokeApplet = true; break; case 'G': isGuruMode = true; break; #endif default: fprintf(stderr, "invalid option %c", opt); showUsage(); exit(EXIT_FAILURE); } } if (isProfilerOn && argc == optindU) { fprintf(stderr, "[file] not specified\n"); showUsage(); exit(EXIT_FAILURE); } // for Shell mode. // VM(=parent) ignores SIGINT, but child use default handler. (See %fork) // signal(SIGINT, SIG_IGN); #if defined(_WIN32) || defined(MONA) #else signal(SIGPIPE, SIG_IGN); #endif VMFactory factory; const int INITIAL_STACK_SIZE = 10000; // N.B. // We store the VM instance in thread specific storage. // Used for storing yylex and re2c which has only global interfaces. theVM = factory.create(INITIAL_STACK_SIZE, isProfilerOn); if (!setCurrentVM(theVM)) { fprintf(stderr, "fatal vm specific failure\n"); exit(-1); } theVM->setValueString(UC("*command-line-args*"), argsToList(argc, optindU, argvU)); #ifdef WITH_NMOSH_DEFAULTS theVM->setValueString(UC("%get-stack-trace-obj"),Object::makeCProcedure(internalGetStackTraceObj)); theVM->setValueString(UC("%get-nmosh-dbg-image"),Object::makeCProcedure(internalGetNmoshDbgImage)); theVM->setValueString(UC("%invoke-applet"),Object::makeBool(invokeApplet)); theVM->setValueString(UC("%nmosh-guru-mode"),Object::makeBool(isGuruMode)); theVM->setValueString(UC("%nmosh-preload-mode"),Object::makeBool(enablePreload)); #ifdef WITH_NMOSH_PORTABLE theVM->setValueString(UC("%nmosh-portable-mode"),Object::makeBool(1)); #else theVM->setValueString(UC("%nmosh-portable-mode"),Object::makeBool(0)); #endif #ifdef WITH_NMOSH_PREFIXLESS theVM->setValueString(UC("%nmosh-prefixless-mode"),Object::makeBool(1)); #else theVM->setValueString(UC("%nmosh-prefixless-mode"),Object::makeBool(0)); #endif #ifdef WITH_PRELOAD_CORE theVM->setValueString(UC("%nmosh-preload-core"),Object::makeBool(1)); #else theVM->setValueString(UC("%nmosh-preload-core"),Object::makeBool(0)); #endif #else // WITH_NMOSH_DEFAULTS theVM->setValueString(UC("%nmosh-portable-mode"),Object::makeBool(0)); theVM->setValueString(UC("%nmosh-prefixless-mode"),Object::makeBool(0)); #endif// WITH_NMOSH_DEFAULTS if (isTestOption) { theVM->loadFileWithGuard(UC("all-tests.scm")); // } else if (isCompileString) { // ucs4string text // const Object port = Object::makeStringInputPort((const uint8_t*)argvU[optindU], strlen(argv[optindU])); // bool errorOccured = false; // const Object code = port.toTextualInputPort()->getDatum(errorOccured); // if (errorOccured) { // callLexicalViolationImmidiaImmediately(theVM, "read", port.toTextualInputPort()->error()); // } else { // const Object compiled = theVM->compile(code); // theVM->currentOutputPort().toTextualOutputPort()->display(compiled); // } } else if (isR6RSBatchMode) { if (NULL == loadPath) { theVM->setValueString(UC("%loadpath"), Object::False); } else { theVM->setValueString(UC("%loadpath"), Object::makeString(loadPath)); } theVM->setValueString(UC("%verbose"), Object::makeBool(verbose)); theVM->setValueString(UC("%disable-acc"), Object::makeBool(disableAcc)); theVM->setValueString(UC("%clean-acc"), Object::makeBool(cleanAcc)); activateR6RSMode(theVM, isDebugExpand); } else if (optindU < argc) { theVM->setValueString(UC("debug-expand"), Object::makeBool(isDebugExpand)); theVM->loadFileWithGuard(Object::makeString(argvU[optindU]).toString()->data()); } else { showUsage(); } #ifdef ENABLE_PROFILER if (isProfilerOn) { const Object result = theVM->getProfileResult(); theVM->callClosureByName(Symbol::intern(UC("show-profile")), result); } #endif theVM->flushAllPorts(); // N.B. // static destructor will be called. // this means that static member *can be freed*. // Don't rely on static initializer and destructor on multithreads. // See Symbol::symbols for more detailed information. exit(EXIT_SUCCESS); }
virtual void SetUp() { mosh_init(); VMFactory factory; theVM_ = factory.create(1000, false); setCurrentVM(theVM_); }