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

99
LINES

< > BotCompany Repo | #1003847 // transpileRaw - reuse creator class's (or OS's) transpiler if possible

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (12814L) is out of date.

sbool transpileRaw_silent = true;
sbool transpileRaw_useDiskCache;

ifdef DynModule
sS transpileRaw(S mainJava) {
  ret (S) call(dm_transpiler(), 'transpileRaw, mainJava, false, transpileRaw_useDiskCache);
}
endifdef

ifndef DynModule
static Class transpileRaw_trans;
sbool transpileRaw_mine = true;
static bool transpileRaw_verySilent;
sbool transpileRaw_dontCopyFromCreator;
static Lock transpileRaw_lock = lock();

static new ThreadLocal<Bool> transpileRaw_asInclude;
static new ThreadLocal<S> transpileRaw_progID;

static S transpileRaw(S mainJava) {
  ret transpileRaw(mainJava, false, transpileRaw_useDiskCache);
}

static S transpileRaw(S mainJava, bool fragment) {
  ret transpileRaw(mainJava, fragment, transpileRaw_useDiskCache);
}

static S transpileRaw(S mainJava, bool fragment, bool useDiskCache) {
  mainJava = dropTranslators(mainJava);
  if (!transpileRaw_dontCopyFromCreator)
    transpileRaw_copyFromCreator();
  lock transpileRaw_lock;
  
  File cacheFile = null;
  if (useDiskCache) {
    cacheFile = new File(javaxCodeDir(), "Transpilations/" + uniqueFileNameUsingMD5_80_v2(mainJava) + ".java");
    try answer loadTextFile(cacheFile);
  }
  
  temp transpileRaw_verySilent ? null : tempLoadingAnim("Transpiling...");
  
  transpileRaw_translator();
 
  //setOpt(transpileRaw_trans, dontPrintSource := true);
  setOpt(transpileRaw_trans, localStuffOnly := fragment);
  setOpt(transpileRaw_trans, asInclude := isTrue(transpileRaw_asInclude!));
  setOpt(transpileRaw_trans, mainSnippetID := transpileRaw_progID!);
  set(transpileRaw_trans, +mainJava);
  // TODO: setOpt(transpileRaw_trans, transpilingSnippetID := );
  set(transpileRaw_trans, +print_byThread);
  if (!transpileRaw_verySilent)
    print("Running translator " + getOpt(transpileRaw_trans, 'programID));
  callMain(transpileRaw_trans);
  //print("Ran translator " + identityHashCode(transpileRaw_trans));
  S main = cast get(transpileRaw_trans, "mainJava");
  if (useDiskCache) {
    saveTextFile(new File(cacheFile.getPath() + "x"), mainJava);
    saveTextFile(cacheFile, main);
  }
  ret main;
}

static swappable Class transpileRaw_translator() {
  if (transpileRaw_trans == null) {
    //print("Loading translator.");
    transpileRaw_trans = transpileRaw_makeTranslator();
    transpileRaw_mine = true;
    makeDependent(transpileRaw_trans);
    //print("Loaded translator: " + identityHashCode(transpileRaw_trans));
  }
  setOpt(transpileRaw_trans, "print_silent", transpileRaw_silent);
  ret transpileRaw_trans;
}

static swappable Class transpileRaw_makeTranslator() {
  ret hotwireSharingLibraries_silently(defaultJavaXTranslatorID());
}

svoid transpileRaw_copyFromCreator {
  lock transpileRaw_lock;
  if (transpileRaw_trans != null) ret;
  O c = creator();
  if (c == null) ret;
  Class trans = cast getOpt(c, 'transpileRaw_trans);
  Lock lock = cast getOpt(c, 'transpileRaw_lock);
  if (trans != null && lock != null) {
    print("Using creator's transpiler: " + getProgramID(c) + " => " + programID());
    transpileRaw_lock = lock;
    transpileRaw_trans = trans;
    transpileRaw_mine = false;
  }
}

svoid cleanMeUp_transpileRaw {
  if (transpileRaw_mine)
    cleanUp(transpileRaw_trans);
  transpileRaw_trans = null; // release proactively (it's big)
}
endifndef

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1003847
Snippet name: transpileRaw - reuse creator class's (or OS's) transpiler if possible
Eternal ID of this version: #1003847/54
Text MD5: 7c1643b640aa463c1e883044ffc6153c
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-01 20:29:05
Source code size: 3362 bytes / 99 lines
Pitched / IR pitched: No / No
Views / Downloads: 889 / 1121
Version history: 53 change(s)
Referenced in: [show references]