diff -r 9d6130cb464f -r f5c9934a252c rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java Mon May 06 11:57:29 2013 +0200 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java Mon May 06 18:06:08 2013 +0200 @@ -28,12 +28,15 @@ * @author Jaroslav Tulach */ abstract class VM extends ByteCodeToJavaScript { - protected final Bck2Brwsr.Resources resources; + protected final ClassDataCache classDataCache; + + private final Bck2Brwsr.Resources resources; private final ExportedSymbols exportedSymbols; private VM(Appendable out, Bck2Brwsr.Resources resources) { super(out); this.resources = resources; + this.classDataCache = new ClassDataCache(resources); this.exportedSymbols = new ExportedSymbols(resources); } @@ -231,10 +234,6 @@ } } - private static InputStream loadClass(Bck2Brwsr.Resources l, String name) throws IOException { - return l.get(name + ".class"); // NOI18N - } - static String toString(String name) throws IOException { StringBuilder sb = new StringBuilder(); // compile(sb, name); @@ -268,6 +267,19 @@ return "vm." + className; } + @Override + protected String accessMember(String object, String mangledName, + String[] fieldInfoName) throws IOException { + final ClassData declaringClass = + classDataCache.getClassData(fieldInfoName[0]); + if (declaringClass == null) { + return object + "['" + mangledName + "']"; + } + + // TODO + return object + "." + mangledName; + } + private static final class Standalone extends VM { private Standalone(Appendable out, Bck2Brwsr.Resources resources) { super(out, resources); @@ -322,11 +334,11 @@ @Override protected String generateClass(String className) throws IOException { - InputStream is = loadClass(resources, className); - if (is == null) { + ClassData classData = classDataCache.getClassData(className); + if (classData == null) { throw new IOException("Can't find class " + className); } - return compile(is); + return compile(classData); } @Override @@ -362,8 +374,8 @@ @Override protected String generateClass(String className) throws IOException { - InputStream is = loadClass(resources, className); - if (is == null) { + ClassData classData = classDataCache.getClassData(className); + if (classData == null) { out.append("\n").append(assignClass( className.replace('/', '_'))) .append("function() {\n return link('") @@ -374,7 +386,7 @@ return null; } - return compile(is); + return compile(classData); } @Override