# HG changeset patch # User Jaroslav Tulach # Date 1348830077 -7200 # Node ID 57e370fa2456b8d7df0b369386f4295b189002d0 # Parent 95330dd02c47fe441647606d29e64024e743edbf# Parent f30e2afc8ddb4e0d8d4adb2afb0a0b98fda3f6c5 Merge of default branch that properly computes names of methods now diff -r 95330dd02c47 -r 57e370fa2456 vm/pom.xml --- a/vm/pom.xml Fri Sep 28 07:43:53 2012 +0200 +++ b/vm/pom.xml Fri Sep 28 13:01:17 2012 +0200 @@ -50,6 +50,7 @@ org.apache.maven.plugins maven-jar-plugin + 2.4 diff -r 95330dd02c47 -r 57e370fa2456 vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Fri Sep 28 07:43:53 2012 +0200 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Fri Sep 28 13:01:17 2012 +0200 @@ -90,25 +90,25 @@ final String className = jc.getName().getInternalName().replace('/', '_'); out.append("\nfunction ").append(className); out.append("() {"); - for (Method m : jc.getMethods()) { - if (!m.isStatic()) { - compiler.generateMethodReference(m); - } - } for (Variable v : jc.getVariables()) { if (!v.isStatic()) { out.append("\n this." + v.getName() + " = 0;"); } } - out.append("\n this.$instOf_").append(className).append(" = true;"); - for (ClassName superInterface : jc.getInterfaces()) { - out.append("\n this.$instOf_").append(superInterface.getInternalName().replace('/', '_')).append(" = true;"); - } out.append("\n}"); ClassName sc = jc.getSuperClass(); if (sc != null) { out.append("\n").append(className) - .append(".prototype = new ").append(sc.getInternalName().replace('/', '_')); + .append(".prototype = new ").append(sc.getInternalName().replace('/', '_')).append(';'); + } + for (Method m : jc.getMethods()) { + if (!m.isStatic() && !m.isPrivate() && !m.getName().contains("")) { + compiler.generateMethodReference("\n" + className + ".prototype.", m); + } + } + out.append("\n" + className + ".prototype.$instOf_").append(className).append(" = true;"); + for (ClassName superInterface : jc.getInterfaces()) { + out.append("\n" + className + ".prototype.$instOf_").append(superInterface.getInternalName().replace('/', '_')).append(" = true;"); } for (String init : toInitilize) { out.append("\n").append(init).append("();"); @@ -152,9 +152,9 @@ out.append("}"); } - private void generateMethodReference(Method m) throws IOException { + private void generateMethodReference(String prefix, Method m) throws IOException { final String name = findMethodName(m); - out.append("\n this.").append(name).append(" = ") + out.append(prefix).append(name).append(" = ") .append(jc.getName().getInternalName().replace('/', '_')) .append('_').append(name).append(";"); } @@ -588,9 +588,13 @@ case bc_checkcast: { int indx = readIntArg(byteCodes, i); CPClassInfo ci = jc.getConstantPool().getClass(indx); - out.append("if(stack[stack.length - 1].$instOf_") - .append(ci.getClassName().getInternalName().replace('/', '_')) - .append(" != 1) throw {};"); // XXX proper exception + final String type = ci.getClassName().getType(); + if (!type.startsWith("[")) { + // no way to check arrays right now + out.append("if(stack[stack.length - 1].$instOf_") + .append(type.replace('/', '_')) + .append(" != 1) throw {};"); // XXX proper exception + } i += 2; break; } @@ -605,13 +609,13 @@ } } - out.append(" /*"); + out.append(" //"); for (int j = prev; j <= i; j++) { out.append(" "); final int cc = (byteCodes[j] + 256) % 256; out.append(Integer.toString(cc)); } - out.append("*/\n"); + out.append("\n"); } out.append(" }\n"); } @@ -710,24 +714,24 @@ } private String findMethodName(Method m) { - StringBuilder tmp = new StringBuilder(); + StringBuilder name = new StringBuilder(); + String descr = m.getDescriptor(); if ("".equals(m.getName())) { // NOI18N - tmp.append("consV"); // NOI18N + name.append("cons"); // NOI18N } else if ("".equals(m.getName())) { // NOI18N - tmp.append("classV"); // NOI18N + name.append("class"); // NOI18N } else { - tmp.append(m.getName()); - outType(m.getReturnType(), tmp); + name.append(m.getName()); } - List args = m.getParameters(); - for (Parameter t : args) { - outType(t.getDescriptor(), tmp); - } - return tmp.toString(); + + boolean hasReturn[] = { false }; + countArgs(findDescriptor(m.getDescriptor()), hasReturn, name); + return name.toString(); } private String findMethodName(CPMethodInfo mi, int[] cnt, boolean[] hasReturn) { StringBuilder name = new StringBuilder(); + String descr = mi.getDescriptor(); if ("".equals(mi.getName())) { // NOI18N name.append("cons"); // NOI18N } else {