1 | !636
|
2 | !700 // ctex
|
3 |
|
4 | !include #2000470 // class _x16
|
5 |
|
6 | main {
|
7 | psvm {
|
8 | Class<?> solver = compileAndLoadMainClass(loadSnippet("#695"));
|
9 | Object case = call(solver, "parse", "#1000386");
|
10 | call(solver, "calculate", case);
|
11 | }
|
12 |
|
13 | static Object call(Object o, String method, Object... args) ctex {
|
14 | findMethod(o, method, args).invoke(o, args);
|
15 | }
|
16 |
|
17 | static Method findMethod(Object o, String method, Object[] args) {
|
18 | // TODO: go to superclasses too
|
19 | for (Method method : theClass.getMethods())
|
20 | if (method.getName().equals("main") && method.getParameterTypes().length == 1)
|
21 | return method;
|
22 | throw new RuntimeException("Method 'main' with 1 parameter not found in " + theClass.getName());
|
23 | }
|
24 |
|
25 | // compile JavaX source and load main class
|
26 | static Class<?> compileAndLoadMainClass(String src) tex {
|
27 | File srcDir = _x16.TempDirMaker_make();
|
28 | File classesDir = _x16.TempDirMaker_make();
|
29 | _x16.saveTextFile(new File(srcDir, "main.java").getPath(), src);
|
30 | new List<File> libraries;
|
31 | File transpiledDir = _x16.topLevelTranslate(srcDir, libraries);
|
32 | String javacOutput = _x16.compileJava(transpiledDir, libraries, classesDir);
|
33 | System.out.println(javacOutput);
|
34 | URL[] urls = {classesDir.toURI().toURL()};
|
35 |
|
36 | // make class loader
|
37 | URLClassLoader classLoader = new URLClassLoader(urls);
|
38 |
|
39 | // load main class
|
40 | Class<?> mainClass = classLoader.loadClass("main");
|
41 | return mainClass;
|
42 | }
|
43 | } |