Uses 1113K of libraries. Click here for Pure Java version (7679L/43K).
1 | !7 |
2 | |
3 | set flag DynModule. // use OS transpiler |
4 | |
5 | // We are trying to add classes directly in to the module's class loader |
6 | // without any sub-class loaders |
7 | |
8 | cprint {
|
9 | transient ClassLoader cl; |
10 | |
11 | start-thread {
|
12 | cl = getClassLoader(module()); |
13 | print("My class loader: " + cl);
|
14 | print("Class loader type: " + className(cl));
|
15 | Map<S, ClassLoader> parents = cast getOpt parentMap(cl); |
16 | print("Parents: " + parents);
|
17 | |
18 | hotwireTest(); |
19 | } |
20 | |
21 | void hotwireTest ctex {
|
22 | S name = aGlobalID(); |
23 | print("Class name: " + name);
|
24 | S mcName = "main_" + name; |
25 | S src = "mainClassName " + mcName + "\n\n" |
26 | + "sclass " + name + " {\n"
|
27 | + " S name() {\n"
|
28 | + " ret " + quote("I am " + name) + ";\n"
|
29 | + " }\n" |
30 | + "}"; |
31 | print(); |
32 | printWithIndent("SRC> ", src);
|
33 | print(); |
34 | |
35 | // taken from veryQuickJava3 |
36 | new LS libs; |
37 | src = transpileRaw(src); // transpiled, with lib references |
38 | |
39 | // taken from veryQuickJava_finish |
40 | src = findTranslators2(src, libs); |
41 | S dehlibs = join(" ", libs);
|
42 | File bytecode = javaCompile_overInternalBot(src, dehlibs); |
43 | print(+bytecode); |
44 | print("Files: " + listZip(bytecode));
|
45 | |
46 | //print("Name: " + call(o, "name"));
|
47 | |
48 | /*set(cl, findClass_extension := (IF1<S, Class>) name -> {
|
49 | if (equalsOrStartsWithPlusDollar(name, mcName)) |
50 | null; |
51 | });*/ |
52 | |
53 | call(cl, "addURL", bytecode.toURI().toURL()); |
54 | |
55 | Class c = Class.forName(mcName); |
56 | print("Resolved: " + c);
|
57 | |
58 | O o = newInstance(Class.forName(mcName + "$" + name)); |
59 | print("Instance: " + o);
|
60 | print(); |
61 | O result = call(o, "name"); |
62 | print("Result of function call: " + result);
|
63 | |
64 | assertEquals("I am " + name, result);
|
65 | } |
66 | } |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1031279 |
| Snippet name: | Change module's class loader at runtime Spike [OK] |
| Eternal ID of this version: | #1031279/25 |
| Text MD5: | 6377dfec0492122847e8bb8ef4faf6ab |
| Transpilation MD5: | 4e90c0bc1435d2e9038cb811e69187ed |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX source code (Dynamic Module) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2021-06-02 18:13:10 |
| Source code size: | 1806 bytes / 66 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 417 / 661 |
| Version history: | 24 change(s) |
| Referenced in: | [show references] |