X-Git-Url: http://git.megacz.com/?p=nestedvm.git;a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fmips%2FClassLoader.java;fp=src%2Forg%2Fxwt%2Fmips%2FClassLoader.java;h=510d30900dbc78021deef843274fa354b83ee52a;hp=0000000000000000000000000000000000000000;hb=3eb15f58ca0911489d7d9bdc0ac2c575d27a68d8;hpb=a6ee28ca37621098ed040e6d1c4ae103934c3e97 diff --git a/src/org/xwt/mips/ClassLoader.java b/src/org/xwt/mips/ClassLoader.java new file mode 100644 index 0000000..510d309 --- /dev/null +++ b/src/org/xwt/mips/ClassLoader.java @@ -0,0 +1,44 @@ +package org.xwt.mips; + +import java.io.*; + +// FEATURE: This is just a quick hack, it is really ugly and broken + +public class ClassLoader extends java.lang.ClassLoader { + public Class loadClass(String name, boolean resolve) throws ClassNotFoundException { + Class c; + if(name.startsWith("mips.")) { + String path = name.substring(5).replace('.','/') + ".mips"; + try { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + new ClassFileCompiler(path,name,bos).go(); + bos.close(); + byte[] buf = bos.toByteArray(); + c = defineClass(name,buf,0,buf.length); + } catch(IOException e) { + throw new ClassNotFoundException(name); + } catch(Compiler.Exn e) { + throw new ClassNotFoundException(e.getMessage()); + } + } else { + c = findSystemClass(name); + } + + if(c == null) throw new ClassNotFoundException(name); + if(resolve) resolveClass(c); + return c; + } + + public Class classFromBinary(String path) throws ClassNotFoundException { + if(!path.endsWith(".mips")) throw new IllegalArgumentException("isn't a .mips"); + return loadClass("mips." + path.substring(0,path.length()-5).replace('/','.')); + } + + public Runtime runtimeFromBinary(String path) throws ClassNotFoundException, IllegalAccessException, InstantiationException { + return (Runtime) classFromBinary(path).newInstance(); + } + + public static void main(String[] args) throws Exception { + System.exit(new ClassLoader().runtimeFromBinary(args[0]).run(args)); + } +}