Showing the changes to java (2 of 2 files). Show all
Unified · Split
| @@ -21,6 +21,9 @@ include "math.m"; · 20 unmodified lines | ||
| 21 | 21 | include "hash.m"; |
| 22 | 22 | hash: Hash; |
| 23 | 23 | |
| 24 | +include "sh.m"; | |
| 25 | + sh: Sh; | |
| 26 | + | |
| 24 | 27 | include "loader.m"; |
| 25 | 28 | include "classloader.m"; |
| 26 | 29 | ld: Loader; |
| @@ -83,6 +86,9 @@ debug: int = 0; · 56 unmodified lines | ||
| 83 | 86 | verbose: int = 0; |
| 84 | 87 | errors: int = 0; |
| 85 | 88 | |
| 89 | +autotranslate := 0; | |
| 90 | +sysautotranslate := 0; | |
| 91 | + | |
| 86 | 92 | # for generating ClassLoader exceptions use |
| 87 | 93 | # the following con's. They will be turned |
| 88 | 94 | # into a corresponding Java Exception by |
| @@ -1841,6 +1847,47 @@ Class.clone(c: self ref Class, o: ref Object): ref Object · 1752 unmodified lines | ||
| 1841 | 1847 | # Class private methods. |
| 1842 | 1848 | # |
| 1843 | 1849 | |
| 1850 | +# | |
| 1851 | +# Autotranslation | |
| 1852 | +# | |
| 1853 | +classfilepath(path: string): string | |
| 1854 | +{ | |
| 1855 | + extlen := len ".dis"; | |
| 1856 | + if (len path <= extlen) | |
| 1857 | + return ""; | |
| 1858 | + return path[:len path - extlen] + ".class"; | |
| 1859 | +} | |
| 1860 | +needtranslate(disfilepath: string, classfilepath: string): int | |
| 1861 | +{ | |
| 1862 | + (derr, ddir) := sys->stat(disfilepath); | |
| 1863 | + if (derr < 0) | |
| 1864 | + return 1; | |
| 1865 | + (cerr, cdir) := sys->stat(classfilepath); | |
| 1866 | + if (cerr < 0) | |
| 1867 | + return 0; | |
| 1868 | + | |
| 1869 | + return ddir.mtime < cdir.mtime; | |
| 1870 | +} | |
| 1871 | +translate(path: string) | |
| 1872 | +{ | |
| 1873 | + classfilepath := classfilepath(path); | |
| 1874 | + if (sys->open(classfilepath, Sys->OREAD) == nil) | |
| 1875 | + return; | |
| 1876 | + if (!needtranslate(path, classfilepath)) | |
| 1877 | + return; | |
| 1878 | + | |
| 1879 | + if (sh == nil) { | |
| 1880 | + sh = load Sh Sh->PATH; | |
| 1881 | + if (sh == nil) | |
| 1882 | + error(sys->sprint("could not load %s: %r", Sh->PATH)); | |
| 1883 | + } | |
| 1884 | + | |
| 1885 | + trace(JVERBOSE, sys->sprint("Autotranslate: calling j2d for %s", classfilepath)); | |
| 1886 | + result := sh->run(nil, "java/j2d" :: "-g" :: "-o" :: path :: classfilepath :: nil); | |
| 1887 | + if (result != "") | |
| 1888 | + loaderror(classformat, result + ": " + path); | |
| 1889 | +} | |
| 1890 | + | |
| 1844 | 1891 | # |
| 1845 | 1892 | # Load a class file. |
| 1846 | 1893 | # |
| @@ -1848,12 +1895,16 @@ Class.loadclass(c: self ref Class) · 1 unmodified line | ||
| 1848 | 1895 | { |
| 1849 | 1896 | c.encoding = encodename(c.name); |
| 1850 | 1897 | f := c.encoding + ".dis"; |
| 1898 | + if (autotranslate) | |
| 1899 | + translate(f); | |
| 1851 | 1900 | m := load Nilmod f; |
| 1852 | 1901 | if (m == nil) { |
| 1853 | 1902 | e := sys->sprint("%r"); |
| 1854 | 1903 | if (!matches(e, EXIST)) |
| 1855 | 1904 | error(f + ": " + e); |
| 1856 | 1905 | f = ROOT + f; |
| 1906 | + if (autotranslate) | |
| 1907 | + translate(f); | |
| 1857 | 1908 | m = load Nilmod f; |
| 1858 | 1909 | if (m == nil) { |
| 1859 | 1910 | e = sys->sprint("%r"); |
| @@ -3495,8 +3546,9 @@ setflags( flags : list of (string,int) ) · 1635 unmodified lines | ||
| 3495 | 3546 | { |
| 3496 | 3547 | if ( flags == nil ) return; |
| 3497 | 3548 | |
| 3498 | − for((f,v):=hd flags; flags != nil; flags = tl flags ) | |
| 3549 | + for(; flags != nil; flags = tl flags ) | |
| 3499 | 3550 | { |
| 3551 | + (f, v) := hd flags; | |
| 3500 | 3552 | case (f) |
| 3501 | 3553 | { |
| 3502 | 3554 | "debug" => loadtrace(); |
| @@ -3504,6 +3556,7 @@ setflags( flags : list of (string,int) ) · 1 unmodified line | ||
| 3504 | 3556 | "verbose" => loadtrace(); |
| 3505 | 3557 | jtrace->level = JVERBOSE; |
| 3506 | 3558 | "warn" => warn = v; |
| 3559 | + "autotranslate" => autotranslate = 1; | |
| 3507 | 3560 | } |
| 3508 | 3561 | } |
| 3509 | 3562 | } |
| @@ -98,6 +98,8 @@ processargs( argv : list of string ) : (list of (string,int), list of string) · 97 unmodified lines | ||
| 98 | 98 | 'v' => opts = ("verbose",1)::opts; |
| 99 | 99 | 'd' => opts = ("debug",1)::opts; |
| 100 | 100 | 'w' => opts = ("warn",1)::opts; |
| 101 | + 'a' => opts = ("autotranslate",1)::opts; | |
| 102 | + 's' => opts = ("sysautotranslate",1)::opts; | |
| 101 | 103 | 'i' => showinfo(); #exits |
| 102 | 104 | 'h' => showhelp(jvmcmd); #exits |
| 103 | 105 | * => mesg(sys->sprint( "error: %c is an invalid option\n", flags[x] )); |
| @@ -130,7 +132,8 @@ showinfo() · 26 unmodified lines | ||
| 130 | 132 | showhelp(cmd:string) |
| 131 | 133 | { |
| 132 | 134 | mesg(sys->sprint( "usage:\t%s [-vdwih] classname classargs", cmd )); |
| 133 | − mesg(sys->sprint( "\tv=verbose; d=debug; w=warnings; i=version; h=help" )); | |
| 135 | + mesg(sys->sprint( "\tv=verbose; d=debug; w=warnings; i=version; \n" + | |
| 136 | + "\ta=autotranslate; s=autotranslate system classes; h=help" )); | |
| 134 | 137 | exit; |
| 135 | 138 | } |
| 136 | 139 | |