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

16
LINES

< > BotCompany Repo | #1000598 // isSafeCompilable function - checks if code is JavaX-compilable to bytecode using only safe translators

JavaX fragment (include)

// requires class _javax

static boolean isSafeCompilable(String src) {
  File srcDir = _javax.TempDirMaker_make();
  File classesDir = _javax.TempDirMaker_make();
  _javax.saveTextFile(new File(srcDir, "main.java").getPath(), src);
  new List<File> libraries;
  _javax.safeTranslate = true;
  File transpiledDir = _javax.topLevelTranslate(srcDir, libraries);
  try {
    _javax.compileJava(transpiledDir, libraries, classesDir);
  } catch (RuntimeException e) { // TODO: check if it's actually a compile fail, not any other error
    return false;
  }
  return true;
}

Author comment

Began life as a copy of #1000590

download  show line numbers  debug dex  old transpilations   

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

Comments [hide]

ID Author/Program Comment Date
676 #1000610 Edit suggestion:
!636
!629

main {
static Object androidContext;
static String programID;

public static void main(String[] args) throws Exception {
// requires class _javax

static boolean isSafeCompilable(String src) {
File srcDir = _javax.TempDirMaker_make();
File classesDir = _javax.TempDirMaker_make();
_javax.saveTextFile(new File(srcDir, "main.java").getPath(), src);
new List<File> libraries;
_javax.safeTranslate = true;
File transpiledDir = _javax.topLevelTranslate(srcDir, libraries);
try {
_javax.compileJava(transpiledDir, libraries, classesDir);
} catch (RuntimeException e) { // TODO: check if it's actually a compile fail, not any other error
return false;
}
return true;
}

}}
2015-08-19 06:55:52  delete 
674 #1000604 (pitcher) 2015-08-18 00:07:22

add comment

Snippet ID: #1000598
Snippet name: isSafeCompilable function - checks if code is JavaX-compilable to bytecode using only safe translators
Eternal ID of this version: #1000598/1
Text MD5: 23e96e9d0047aa6d1b244a3f0ecc9d90
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-08-15 17:01:13
Source code size: 586 bytes / 16 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 958 / 1140
Referenced in: #1002427 - Accellerating 629 (SPIKE)
#1006654 - Standard functions list 2 (LIVE, continuation of #761)
#3000382 - Answer for ferdie (>> t = 1, f = 0)