5 // FEATURE: This is just a quick hack, it is really ugly and broken
7 public class ClassLoader extends java.lang.ClassLoader {
8 public Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
10 if(name.startsWith("mips.")) {
11 String path = name.substring(5).replace('.','/') + ".mips";
13 ByteArrayOutputStream bos = new ByteArrayOutputStream();
14 new ClassFileCompiler(path,name,bos).go();
16 byte[] buf = bos.toByteArray();
17 c = defineClass(name,buf,0,buf.length);
18 } catch(IOException e) {
19 throw new ClassNotFoundException(name);
20 } catch(Compiler.Exn e) {
21 throw new ClassNotFoundException(e.getMessage());
24 c = findSystemClass(name);
27 if(c == null) throw new ClassNotFoundException(name);
28 if(resolve) resolveClass(c);
32 public Class classFromBinary(String path) throws ClassNotFoundException {
33 if(!path.endsWith(".mips")) throw new IllegalArgumentException("isn't a .mips");
34 return loadClass("mips." + path.substring(0,path.length()-5).replace('/','.'));
37 public Runtime runtimeFromBinary(String path) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
38 return (Runtime) classFromBinary(path).newInstance();
41 public static void main(String[] args) throws Exception {
42 System.exit(new ClassLoader().runtimeFromBinary(args[0]).run(args));