!7 sbool usePrimaryPort = true; static new Flag taken; static Android3 android; static Lock lock = lock(); p { if (usePrimaryPort) android = androidAtPrecisePort(preSpunVMPort(), "A pre-spun VM.", mc()); if (android != null) print("Using primary port!"); else { print("Using regular port."); android = makeAndroid3("A pre-spun VM."); } hideVM(); taken.waitUntilUp(); } static S answer(S s, L history) { lock lock; new Matches m; if (match3("please start program *", s, m)) { final S progID = formatSnippetID(unquote(m.m[0])); return startIt(progID, ""); } if (match3("please start program * with arguments *", s, m)) { final S progID = formatSnippetID(unquote(m.m[0])); final S args = unquote(m.m[1]); return startIt(progID, args); } if (match3("are you free to start a program?", s)) ret !taken.isUp() ? "Yes." : "No."; ret null; } static S startIt(final S progID, S args) { lock lock; if (taken.isUp()) ret "Sorry, not free anymore."; taken.raise(); // Remove my injection (without cleanup) so program becomes first injection synchronized(javax()) { L injections = (L) get(javax(), 'injectable_programsInjected); injections.remove(0); } final S[] splitArgs = toStringArray(codeTokensOnly(javaTok(args))); // yeah this is bad... thread { Class c = hotwire(progID); callMain(c, splitArgs); } thread { setConsoleTitle(snippetTitle(progID)); } if (android != null) { android.dispose(); android = null; } if (usePreSpunVMs()) startPreSpunVM(); // Start another one unhideVM(); ret "OK."; }