!636 !700 // ctex !include #2000470 // class _x16 main { psvm { Class solver = compileAndLoadMainClass(loadSnippet("#695")); Object case = call(solver, "parse", "#1000386"); call(solver, "calculate", case); } static Object call(Object o, String method, Object... args) ctex { findMethod(o, method, args).invoke(o, args); } static Method findMethod(Object o, String method, Object[] args) { // TODO: go to superclasses too for (Method method : theClass.getMethods()) if (method.getName().equals("main") && method.getParameterTypes().length == 1) return method; throw new RuntimeException("Method 'main' with 1 parameter not found in " + theClass.getName()); } // compile JavaX source and load main class static Class compileAndLoadMainClass(String src) tex { File srcDir = _x16.TempDirMaker_make(); File classesDir = _x16.TempDirMaker_make(); _x16.saveTextFile(new File(srcDir, "main.java").getPath(), src); new List libraries; File transpiledDir = _x16.topLevelTranslate(srcDir, libraries); String javacOutput = _x16.compileJava(transpiledDir, libraries, classesDir); System.out.println(javacOutput); URL[] urls = {classesDir.toURI().toURL()}; // make class loader URLClassLoader classLoader = new URLClassLoader(urls); // load main class Class mainClass = classLoader.loadClass("main"); return mainClass; } }