Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

74
LINES

< > BotCompany Repo | #1001361 // Pre-spun VM (still not perfect)

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (7032L/49K/165K).

!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<S> 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.";
}

download  show line numbers  debug dex  old transpilations   

Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, dhtvkmknsjym, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1001361
Snippet name: Pre-spun VM (still not perfect)
Eternal ID of this version: #1001361/15
Text MD5: 5f6797051379a31edb9b8602b41d5985
Transpilation MD5: 02649ab22edfc896da60eb29ea481a35
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-11-17 04:04:24
Source code size: 1726 bytes / 74 lines
Pitched / IR pitched: No / No
Views / Downloads: 603 / 1864
Version history: 14 change(s)
Referenced in: [show references]