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

85
LINES

< > BotCompany Repo | #1002424 // 759 Bot (for PHP, but not only); can also run ecj (Java compiler)

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

Download Jar. Libraryless. Click here for Pure Java version (10135L/71K).

!759

static S vmArgs = "-server";

static O trans;
static O onClear;

static Lock lock = lock();

p {
  //makeBot("The 759 Bot.");
  
  Android3 a = new Android3("The 759 Bot.");
  a.useMultiPort = false;
  a.startPort = 4898;
  makeAndroid(a);
  // run(#1007916); // Compiler Bot
}

answer {
  print("# " + s);
  lock lock;
  print("go");
  
  if "please translate *"
    ret transpile(m.unq(0), null);
    
  if "please translate snippet *" time {
    ret transpile(loadSnippet(m.unq(0)), fsI(m.unq(0)));
  }
    
  if "clear 759" {
    cleanUp(trans);
    trans = null;
    setOpt(getJavaX(), "preferCached", false);
    loadTranslator();
    pcallF(onClear);
    ret "OK, cleared & reloaded.";
  }
  
  if (startsWith(s, "ecj ", m)) try {
    ret "OK " + quote(invokeEcj($1));
  } catch e {
    ret str(getInnerException(e));
  }

  if "reboot" {
    restartVM();
    ret "OK";
  }
}

static S transpile(S mainJava, S snippetID) {
  mainJava = mainJava.replace("\r\n", "\n").replace("\r", "");
  
  assertTrue("default translator", mainJava.contains("!752") || mainJava.contains("!759") || containsRegexp(mainJava, "!7\\s"));
  
  mainJava = ("\n" + mainJava).replace("\n!752", "\n").replace("\n!759", "\n").replaceAll("\n!7\\s", "\n\n").substring(1);

  S transpiled = transpileRaw(mainJava, snippetID);  
  
  // remaining translator invocations are libraries. move to top
  new L<S> libs;
  transpiled = findTranslators2(transpiled, libs);
  if (nempty(libs))
    transpiled = "LIBS: " + join(" ", libs) + "\n" + transpiled;
  
  ret "OK " + bytesToHex(toUtf8(transpiled));
}

// assumes translator invocation has been removed
static S transpileRaw(S mainJava, S snippetID) {
  if (trans == null)
    loadTranslator();
    
  set(trans, "mainJava", mainJava);
  setOpt(trans, transpilingSnippetID := snippetID);

  callMain(trans);
  ret (S) get(trans, "mainJava");
}

static void loadTranslator() {
  trans = hotwire("#759");
}

Author comment

Began life as a copy of #1002422

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1002424
Snippet name: 759 Bot (for PHP, but not only); can also run ecj (Java compiler)
Eternal ID of this version: #1002424/14
Text MD5: 3e0f5ff9bd3bc1dbd1d3e85ba8f5d413
Transpilation MD5: 175fdd0391a96794c10aa9f1fe81c1fc
Author: stefan
Category: javax
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-12-15 20:00:12
Source code size: 2020 bytes / 85 lines
Pitched / IR pitched: No / No
Views / Downloads: 906 / 54180
Version history: 13 change(s)
Referenced in: [show references]