From: <fwi...@us...> - 2008-05-12 17:50:25
|
Revision: 4389 http://jython.svn.sourceforge.net/jython/?rev=4389&view=rev Author: fwierzbicki Date: 2008-05-12 10:48:35 -0700 (Mon, 12 May 2008) Log Message: ----------- Reworked Code.java back towards old API (so methods like code.dup() are back so it is not necessary to use code.visitInsn(DUP). This makes it easier to read the code and to compare with the old code base. Modified Paths: -------------- branches/asm/src/org/python/compiler/AdapterMaker.java branches/asm/src/org/python/compiler/Code.java branches/asm/src/org/python/compiler/JavaMaker.java branches/asm/src/org/python/compiler/ProxyMaker.java Modified: branches/asm/src/org/python/compiler/AdapterMaker.java =================================================================== --- branches/asm/src/org/python/compiler/AdapterMaker.java 2008-05-10 17:19:27 UTC (rev 4388) +++ branches/asm/src/org/python/compiler/AdapterMaker.java 2008-05-12 17:48:35 UTC (rev 4389) @@ -4,8 +4,8 @@ import java.io.OutputStream; import java.lang.reflect.Method; -import java.util.Enumeration; -import java.util.Hashtable; +import java.util.Set; +import java.util.HashSet; import org.python.objectweb.asm.Label; import org.python.objectweb.asm.MethodVisitor; @@ -14,20 +14,19 @@ public class AdapterMaker extends ProxyMaker { - public AdapterMaker(Class interfac) { + public AdapterMaker(Class<?> interfac) { super(interfac.getName()+"$Adapter", interfac); } public void build() throws Exception { - names = new Hashtable(); + names = new HashSet<String>(); - //Class superclass = org.python.core.PyAdapter.class; int access = Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNCHRONIZED; classfile = new ClassFile(myClass, "java/lang/Object", access); classfile.addInterface(mapClass(interfaces[0])); - addMethods(interfaces[0], new Hashtable()); + addMethods(interfaces[0], new HashSet<String>()); addConstructors(Object.class); doConstants(); } @@ -43,31 +42,28 @@ } public void doConstants() throws Exception { - for (Enumeration e=names.keys(); e.hasMoreElements();) { - String name = (String)e.nextElement(); - classfile.addField(name, "Lorg/python/core/PyObject;", - Opcodes.ACC_PUBLIC); + for (String name : names) { + classfile.addField(name, "Lorg/python/core/PyObject;", Opcodes.ACC_PUBLIC); } } public void addMethod(Method method, int access) throws Exception { - Class[] parameters = method.getParameterTypes(); - Class ret = method.getReturnType(); + Class<?>[] parameters = method.getParameterTypes(); + Class<?> ret = method.getReturnType(); String sig = makeSignature(parameters, ret); String name = method.getName(); - //System.out.println(name+": "+sig); - names.put(name, name); + names.add(name); - Code mv = classfile.addMethod(name, sig, Opcodes.ACC_PUBLIC); + Code code = classfile.addMethod(name, sig, Opcodes.ACC_PUBLIC); - mv.visitVarInsn(ALOAD, 0); - mv.visitFieldInsn(GETFIELD, classfile.name, name, "Lorg/python/core/PyObject;"); - mv.visitInsn(DUP); + code.aload(0); + code.getfield(classfile.name, name, "Lorg/python/core/PyObject;"); + code.dup(); Label returnNull = new Label(); - mv.visitJumpInsn(IFNULL, returnNull); - callMethod(mv, name, parameters, ret, method.getExceptionTypes()); - mv.visitLabel(returnNull); - doNullReturn(mv, ret); + code.ifnull(returnNull); + callMethod(code, name, parameters, ret, method.getExceptionTypes()); + code.label(returnNull); + doNullReturn(code, ret); } } Modified: branches/asm/src/org/python/compiler/Code.java =================================================================== --- branches/asm/src/org/python/compiler/Code.java 2008-05-10 17:19:27 UTC (rev 4388) +++ branches/asm/src/org/python/compiler/Code.java 2008-05-12 17:48:35 UTC (rev 4389) @@ -33,35 +33,6 @@ locals = new String[nlocals+128]; } - // XXX: So far I haven't found an ASM convenience for pushing constant - // integers, so for now I'm putting one here. This shouldn't except for - // variable i's (so if you know you are pushing a 0 just use ICONST_0 - // directly). - public void iconst(int i) { - if (i == -1) { - mv.visitInsn(ICONST_M1); - } else if (i == 0) { - mv.visitInsn(ICONST_0); - } else if (i == 1) { - mv.visitInsn(ICONST_1); - } else if (i == 2) { - mv.visitInsn(ICONST_2); - } else if (i == 3) { - mv.visitInsn(ICONST_3); - } else if (i == 4) { - mv.visitInsn(ICONST_4); - } else if (i == 5) { - mv.visitInsn(ICONST_5); - } else if (i > -127 && i < 128) { - mv.visitIntInsn(BIPUSH, i); - } else if (i > -32767 && i < 32768) { - mv.visitIntInsn(SIPUSH, i); - } else { - mv.visitLdcInsn(new Integer(i)); - } - } - - public int getLocal(String type) { //Could optimize this to skip arguments? for(int l = argcount; l<nlocals; l++) { @@ -254,5 +225,371 @@ return stack; } + public void aaload() { + mv.visitInsn(AALOAD); + } + + public void aastore() { + mv.visitInsn(AASTORE); + } + public void aconst_null() { + mv.visitInsn(ACONST_NULL); + } + + public void aload(int index) { + mv.visitVarInsn(ALOAD, index); + } + + public void anewarray(String index) { + mv.visitTypeInsn(ANEWARRAY, index); + } + + public void areturn() { + mv.visitInsn(ARETURN); + } + + public void arraylength() { + mv.visitInsn(ARRAYLENGTH); + } + + public void astore(int index) { + mv.visitVarInsn(ASTORE, index); + } + + public void athrow() { + mv.visitInsn(ATHROW); + } + + public void baload() { + mv.visitInsn(BALOAD); + } + + public void bastore() { + mv.visitInsn(BASTORE); + } + + public void bipush(int value) { + mv.visitIntInsn(BIPUSH, value); + } + + public void checkcast(String type) { + mv.visitTypeInsn(CHECKCAST, type); + } + + public void dconst_0() { + mv.visitInsn(DCONST_0); + } + + public void dload(int index) { + mv.visitVarInsn(DLOAD, index); + } + + public void dreturn() { + mv.visitInsn(DRETURN); + } + + public void dup() { + mv.visitInsn(DUP); + } + + public void dup2() { + mv.visitInsn(DUP2); + } + + public void dup_x1() { + mv.visitInsn(DUP_X1); + } + + public void dup_x2() { + mv.visitInsn(DUP_X2); + } + + public void dup2_x1() { + mv.visitInsn(DUP2_X1); + } + + public void dup2_x2() { + mv.visitInsn(DUP2_X2); + } + + public void fconst_0() { + mv.visitInsn(FCONST_0); + } + + public void fload(int index) { + mv.visitVarInsn(FLOAD, index); + } + + public void freturn() { + mv.visitInsn(FRETURN); + } + + public void getfield(String owner, String name, String type) { + mv.visitFieldInsn(GETFIELD, owner, name, type); + } + + public void getstatic(String owner, String name, String type) { + mv.visitFieldInsn(GETSTATIC, owner, name, type); + } + + public void goto_(Label label) { + mv.visitJumpInsn(GOTO, label); + } + + public void iconst(int value) { + if (value <= Byte.MAX_VALUE && value >= Byte.MIN_VALUE) { + switch (value) { + case -1: + iconst_m1(); + break; + case 0: + iconst_0(); + break; + case 1: + iconst_1(); + break; + case 2: + iconst_2(); + break; + case 3: + iconst_3(); + break; + case 4: + iconst_4(); + break; + case 5: + iconst_5(); + break; + default: + bipush(value); + break; + } + } else if (value <= Short.MAX_VALUE && value >= Short.MIN_VALUE) { + sipush(value); + } else { + ldc(value); + } + } + + public void iconst_m1() { + mv.visitInsn(ICONST_M1); + } + + public void iconst_0() { + mv.visitInsn(ICONST_0); + } + + public void iconst_1() { + mv.visitInsn(ICONST_1); + } + + public void iconst_2() { + mv.visitInsn(ICONST_2); + } + + public void iconst_3() { + mv.visitInsn(ICONST_3); + } + + public void iconst_4() { + mv.visitInsn(ICONST_4); + } + + public void iconst_5() { + mv.visitInsn(ICONST_5); + } + + public void ifeq(Label label) { + mv.visitJumpInsn(IFEQ, label); + } + + public void ifle(Label label) { + mv.visitJumpInsn(IFLE, label); + } + + public void ifne(Label label) { + mv.visitJumpInsn(IFNE, label); + } + + public void ifnull(Label label) { + mv.visitJumpInsn(IFNULL, label); + } + + public void ifnonnull(Label label) { + mv.visitJumpInsn(IFNONNULL, label); + } + + public void if_acmpne(Label label) { + mv.visitJumpInsn(IF_ACMPNE, label); + } + + public void if_acmpeq(Label label) { + mv.visitJumpInsn(IF_ACMPEQ, label); + } + + public void if_icmple(Label label) { + mv.visitJumpInsn(IF_ICMPLE, label); + } + + public void if_icmpgt(Label label) { + mv.visitJumpInsn(IF_ICMPGT, label); + } + + public void if_icmplt(Label label) { + mv.visitJumpInsn(IF_ICMPLT, label); + } + + public void if_icmpne(Label label) { + mv.visitJumpInsn(IF_ICMPNE, label); + } + + public void if_icmpeq(Label label) { + mv.visitJumpInsn(IF_ICMPEQ, label); + } + + public void iadd() { + mv.visitInsn(IADD); + } + + public void iaload() { + mv.visitInsn(IALOAD); + } + + /* XXX: different API from old iinc */ + public void iinc() { + mv.visitInsn(IINC); + } + + /* XXX: old API for iinc + public void iinc(int i, int increment) throws IOException { + code.writeByte(132); + code.writeByte(i); + code.writeByte(increment); + } + + public void iinc(int i) throws IOException { + iinc(i, 1); + } + */ + + public void iload(int index) { + mv.visitVarInsn(ILOAD, index); + } + + public void instanceof_(String type) { + mv.visitTypeInsn(INSTANCEOF, type); + } + + public void invokeinterface(String owner, String name, String type) { + mv.visitMethodInsn(INVOKEINTERFACE, owner, name, type); + } + + public void invokespecial(String owner, String name, String type) { + mv.visitMethodInsn(INVOKESPECIAL, owner, name, type); + } + + public void invokestatic(String owner, String name, String type) { + mv.visitMethodInsn(INVOKESTATIC, owner, name, type); + } + + public void invokevirtual(String owner, String name, String type) { + mv.visitMethodInsn(INVOKEVIRTUAL, owner, name, type); + } + + public void ireturn() { + mv.visitInsn(IRETURN); + } + + public void istore(int index) { + mv.visitVarInsn(ISTORE, index); + } + + public void isub() { + mv.visitInsn(ISUB); + } + + /* XXX: needed? + public void jsr(Label label) throws IOException { + //push(-1); + int offset = size(); + code.writeByte(168); + label.setBranch(offset, 2); + label.setStack(stack+1); + } + */ + + public void label(Label label) { + mv.visitLabel(label); + } + + public void lconst_0() { + mv.visitInsn(LCONST_0); + } + + public void ldc(Object cst) { + mv.visitLdcInsn(cst); + } + + public void lload(int index) { + mv.visitVarInsn(LLOAD, index); + } + + public void lreturn() { + mv.visitInsn(LRETURN); + } + + public void newarray(int atype) { + mv.visitIntInsn(NEWARRAY, atype); + } + + public void new_(String type) { + mv.visitTypeInsn(NEW, type); + } + + public void nop() { + mv.visitInsn(NOP); + } + + public void pop() { + mv.visitInsn(POP); + } + + public void pop2() { + mv.visitInsn(POP2); + } + + public void putstatic(String owner, String name, String type) { + mv.visitFieldInsn(PUTSTATIC, owner, name, type); + } + + public void putfield(String owner, String name, String type) { + mv.visitFieldInsn(PUTFIELD, owner, name, type); + } + + public void ret(int index) { + mv.visitVarInsn(RET, index); + } + + void return_() { + mv.visitInsn(RETURN); + } + + public void sipush(int value) { + mv.visitIntInsn(SIPUSH, value); + } + + public void swap() { + mv.visitInsn(SWAP); + } + + public void swap2() { + dup2_x2(); + pop2(); + } + + public void trycatch(Label start, Label end, Label handlerStart, String type) { + mv.visitTryCatchBlock(start, end, handlerStart, type); + } + } Modified: branches/asm/src/org/python/compiler/JavaMaker.java =================================================================== --- branches/asm/src/org/python/compiler/JavaMaker.java 2008-05-10 17:19:27 UTC (rev 4388) +++ branches/asm/src/org/python/compiler/JavaMaker.java 2008-05-12 17:48:35 UTC (rev 4389) @@ -53,7 +53,7 @@ code.visitLdcInsn(pythonClass); code.visitVarInsn(ALOAD, 1); - code.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "initProxy", "(" + $pyProxy + $str + $str + $objArr + $strArr + $strArr + "Z)V"); + code.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "initProxy", "(" + $pyProxy + $str + $str + $objArr + ")V"); code.visitInsn(RETURN); } Modified: branches/asm/src/org/python/compiler/ProxyMaker.java =================================================================== --- branches/asm/src/org/python/compiler/ProxyMaker.java 2008-05-10 17:19:27 UTC (rev 4388) +++ branches/asm/src/org/python/compiler/ProxyMaker.java 2008-05-12 17:48:35 UTC (rev 4389) @@ -73,7 +73,6 @@ } } - // Ctor used by javamaker. public ProxyMaker(String myClass, Class<?> superclass, Class<?>[] interfaces) { this.myClass = myClass; if (superclass == null) @@ -135,7 +134,7 @@ public void doConstants() throws Exception { Code code = classfile.addMethod("<clinit>", "()V", Modifier.STATIC); - code.visitInsn(RETURN); + code.return_(); } public static void doReturn(Code code, Class<?> type) throws Exception { @@ -147,22 +146,22 @@ case tByte: case tShort: case tInteger: - code.visitInsn(IRETURN); + code.ireturn(); break; case tLong: - code.visitInsn(LRETURN); + code.lreturn(); break; case tFloat: - code.visitInsn(FRETURN); + code.freturn(); break; case tDouble: - code.visitInsn(DRETURN); + code.dreturn(); break; case tVoid: - code.visitInsn(RETURN); + code.return_(); break; default: - code.visitInsn(ARETURN); + code.areturn(); break; } } @@ -176,37 +175,39 @@ case tByte: case tShort: case tInteger: - code.visitInsn(ICONST_0); - code.visitInsn(IRETURN); + code.iconst_0(); + code.ireturn(); break; case tLong: - code.visitInsn(LCONST_0); - code.visitInsn(LRETURN); + code.lconst_0(); + code.lreturn(); break; case tFloat: - code.visitInsn(FCONST_0); - code.visitInsn(FRETURN); + code.fconst_0(); + code.freturn(); break; case tDouble: - code.visitInsn(DCONST_0); - code.visitInsn(DRETURN); + code.dconst_0(); + code.dreturn(); break; case tVoid: - code.visitInsn(RETURN); + code.return_(); break; default: - code.visitInsn(ACONST_NULL); - code.visitInsn(ARETURN); + code.aconst_null(); + code.areturn(); break; } } - public void callSuper(Code code, String name, String superclass, - Class<?>[] parameters, Class<?> ret, - String sig) - throws Exception - { - code.visitVarInsn(ALOAD, 0); + public void callSuper(Code code, + String name, + String superclass, + Class<?>[] parameters, + Class<?> ret, + String sig) throws Exception { + + code.aload(0); int local_index; int i; for (i=0, local_index=1; i<parameters.length; i++) { @@ -216,28 +217,28 @@ case tByte: case tShort: case tInteger: - code.visitVarInsn(ILOAD, local_index); + code.iload(local_index); local_index += 1; break; case tLong: - code.visitVarInsn(LLOAD, local_index); + code.lload(local_index); local_index += 2; break; case tFloat: - code.visitVarInsn(FLOAD, local_index); + code.fload(local_index); local_index += 1; break; case tDouble: - code.visitVarInsn(DLOAD, local_index); + code.dload(local_index); local_index += 2; break; default: - code.visitVarInsn(ALOAD, local_index); + code.aload(local_index); local_index += 1; break; } } - code.visitMethodInsn(INVOKESPECIAL, superclass, name, sig); + code.invokespecial(superclass, name, sig); doReturn(code, ret); } @@ -246,26 +247,25 @@ String jcallName) throws Exception { - code.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyObject", jcallName, "(" + $objArr + ")" + $pyObj); - code.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "py2"+name, "(" + $pyObj + ")"+type); + code.invokevirtual("org/python/core/PyObject", jcallName, "(" + $objArr + ")" + $pyObj); + code.invokestatic("org/python/core/Py", "py2"+name, "(" + $pyObj + ")"+type); } public void getArgs(Code code, Class<?>[] parameters) throws Exception { if (parameters.length == 0) { - code.visitFieldInsn(Opcodes.GETSTATIC, "org/python/core/Py", "EmptyObjects", $pyObjArr); - } - else { + code.getstatic("org/python/core/Py", "EmptyObjects", $pyObjArr); + } else { code.iconst(parameters.length); - code.visitTypeInsn(ANEWARRAY, "java/lang/Object"); + code.anewarray("java/lang/Object"); int array = code.getLocal("[org/python/core/PyObject"); - code.visitVarInsn(ASTORE, array); + code.astore(array); int local_index; int i; for (i=0, local_index=1; i<parameters.length; i++) { - code.visitVarInsn(ALOAD, array); + code.aload(array); code.iconst(i); switch (getType(parameters[i])) { @@ -273,45 +273,46 @@ case tByte: case tShort: case tInteger: - code.visitVarInsn(ILOAD, local_index); + code.iload(local_index); local_index += 1; - code.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "newInteger", "(I)" + $pyInteger); + code.invokestatic("org/python/core/Py", "newInteger", "(I)" + $pyInteger); break; case tLong: - code.visitVarInsn(LLOAD, local_index); + code.lload(local_index); local_index += 2; - code.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "newInteger", "(J)" + $pyObj); + code.invokestatic("org/python/core/Py", "newInteger", "(J)" + $pyObj); break; case tFloat: - code.visitVarInsn(FLOAD, local_index); + code.fload(local_index); local_index += 1; - code.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "newFloat", "(F)" + $pyFloat); + code.invokestatic("org/python/core/Py", "newFloat", "(F)" + $pyFloat); break; case tDouble: - code.visitVarInsn(DLOAD, local_index); + code.dload(local_index); local_index += 2; - code.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "newFloat", "(D)" + $pyFloat); + code.invokestatic("org/python/core/Py", "newFloat", "(D)" + $pyFloat); break; case tCharacter: - code.visitVarInsn(ILOAD, local_index); + code.iload(local_index); local_index += 1; - code.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "newString", "(C)" + $pyStr); + code.invokestatic("org/python/core/Py", "newString", "(C)" + $pyStr); break; default: - code.visitVarInsn(ALOAD, local_index); + code.aload(local_index); local_index += 1; break; } - code.visitInsn(AASTORE); + code.aastore(); } - code.visitVarInsn(ALOAD, array); + code.aload(array); } } - public void callMethod(Code code, String name, Class<?>[] parameters, - Class<?> ret, Class<?>[] exceptions) - throws Exception - { + public void callMethod(Code code, + String name, + Class<?>[] parameters, + Class<?> ret, + Class<?>[] exceptions) throws Exception { Label start = null; Label end = null; @@ -323,9 +324,9 @@ end = new Label(); jcallName = "_jcallexc"; instLocal = code.getLocal("org/python/core/PyObject"); - code.visitVarInsn(ASTORE, instLocal); - code.visitLabel(start); - code.visitVarInsn(ALOAD, instLocal); + code.astore(instLocal); + code.label(start); + code.aload(instLocal); } getArgs(code, parameters); @@ -355,16 +356,16 @@ doJavaCall(code, "void", "V", jcallName); break; default: - code.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyObject", jcallName, "(" + $objArr + ")" + $pyObj); - code.visitLdcInsn(ret.getName()); - code.visitMethodInsn(INVOKESTATIC, "java/lang/Class","forName", "(" + $str + ")" + $clss); - code.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "tojava", "(" + $pyObj + $clss + ")" + $obj); + code.invokevirtual("org/python/core/PyObject", jcallName, "(" + $objArr + ")" + $pyObj); + code.ldc(ret.getName()); + code.invokestatic("java/lang/Class","forName", "(" + $str + ")" + $clss); + code.invokestatic("org/python/core/Py", "tojava", "(" + $pyObj + $clss + ")" + $obj); // I guess I need this checkcast to keep the verifier happy - code.visitTypeInsn(CHECKCAST,mapClass(ret)); + code.checkcast(mapClass(ret)); break; } if (end != null) { - code.visitLabel(end); + code.label(end); } doReturn(code, ret); @@ -375,12 +376,12 @@ Label handlerStart = null; for (int i = 0; i < exceptions.length; i++) { handlerStart = new Label(); - code.visitLabel(handlerStart); + code.label(handlerStart); int excLocal = code.getLocal("java/lang/Throwable"); - code.visitVarInsn(ASTORE, excLocal); + code.astore(excLocal); - code.visitVarInsn(ALOAD, excLocal); - code.visitInsn(ATHROW); + code.aload(excLocal); + code.athrow(); code.visitTryCatchBlock(start, end, handlerStart, mapClass(exceptions[i])); doNullReturn(code, ret); @@ -393,13 +394,13 @@ if (!throwableFound) { // The final catch (Throwable) handlerStart = new Label(); - code.visitLabel(handlerStart); + code.label(handlerStart); int excLocal = code.getLocal("java/lang/Throwable"); - code.visitVarInsn(ASTORE, excLocal); - code.visitVarInsn(ALOAD, instLocal); - code.visitVarInsn(ALOAD, excLocal); + code.astore(excLocal); + code.aload(instLocal); + code.aload(excLocal); - code.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyObject", "_jthrow", "(" + $throwable + ")V"); + code.invokevirtual("org/python/core/PyObject", "_jthrow", "(" + $throwable + ")V"); code.visitTryCatchBlock(start, end, handlerStart, "java/lang/Throwable"); code.freeLocal(excLocal); @@ -427,45 +428,40 @@ Code code = classfile.addMethod(name, sig, access); - code.visitVarInsn(ALOAD, 0); - code.visitLdcInsn(name); + code.aload(0); + code.ldc(name); if (!isAbstract) { int tmp = code.getLocal("org/python/core/PyObject"); - code.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "jfindattr", "(" + $pyProxy + $str + ")" + $pyObj); - code.visitVarInsn(ASTORE, tmp); - code.visitVarInsn(ALOAD, tmp); + code.invokestatic("org/python/core/Py", "jfindattr", "(" + $pyProxy + $str + ")" + $pyObj); + code.astore(tmp); + code.aload(tmp); Label callPython = new Label(); - code.visitJumpInsn(IFNONNULL, callPython); + code.ifnonnull(callPython); String superclass = mapClass(method.getDeclaringClass()); callSuper(code, name, superclass, parameters, ret, sig); - code.visitLabel(callPython); - code.visitVarInsn(ALOAD, tmp); - callMethod(code, name, parameters, ret, - method.getExceptionTypes()); + code.label(callPython); + code.aload(tmp); + callMethod(code, name, parameters, ret, method.getExceptionTypes()); addSuperMethod("super__"+name, name, superclass, parameters, ret, sig, access); - } - else { + } else { if (!isAdapter) { - code.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "jgetattr", "(" + $pyProxy + $str + ")" + $pyObj); - callMethod(code, name, parameters, ret, - method.getExceptionTypes()); - } - else { - code.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "jfindattr", "(" + $pyProxy + $str + ")" + $pyObj); - code.visitInsn(DUP); + code.invokestatic("org/python/core/Py", "jgetattr", "(" + $pyProxy + $str + ")" + $pyObj); + callMethod(code, name, parameters, ret, method.getExceptionTypes()); + } else { + code.invokestatic("org/python/core/Py", "jfindattr", "(" + $pyProxy + $str + ")" + $pyObj); + code.dup(); Label returnNull = new Label(); - code.visitJumpInsn(IFNULL, returnNull); + code.ifnull(returnNull); - callMethod(code, name, parameters, ret, - method.getExceptionTypes()); - code.visitLabel(returnNull); - code.visitInsn(POP); + callMethod(code, name, parameters, ret, method.getExceptionTypes()); + code.label(returnNull); + code.pop(); doNullReturn(code, ret); } } @@ -506,8 +502,7 @@ addSuperMethod(methods[i], access); continue; } - } - else if (Modifier.isFinal(access)) { + } else if (Modifier.isFinal(access)) { continue; } addMethod(methods[i], access); @@ -523,10 +518,11 @@ } } - public void addConstructor(String name, Class<?>[] parameters, Class<?> ret, - String sig, int access) - throws Exception - { + public void addConstructor(String name, + Class<?>[] parameters, + Class<?> ret, + String sig, + int access) throws Exception { Code code = classfile.addMethod("<init>", sig, access); callSuper(code, "<init>", name, parameters, Void.TYPE, sig); } @@ -577,11 +573,13 @@ ret, sig, access); } - public void addSuperMethod(String methodName, String superName, - String declClass, Class<?>[] parameters, - Class<?> ret, String sig, int access) - throws Exception - { + public void addSuperMethod(String methodName, + String superName, + String declClass, + Class<?>[] parameters, + Class<?> ret, + String sig, + int access) throws Exception { if (methodName.startsWith("super__")) { /* rationale: JC java-class, P proxy-class subclassing JC in order to avoid infinite recursion P should define super__foo @@ -610,18 +608,18 @@ Code code = classfile.addMethod("_setPyInstance", "(Lorg/python/core/PyInstance;)V", Modifier.PUBLIC); - code.visitVarInsn(ALOAD, 0); - code.visitVarInsn(ALOAD, 1); - code.visitFieldInsn(PUTFIELD, classfile.name, "__proxy", "Lorg/python/core/PyInstance;"); - code.visitInsn(RETURN); + code.aload(0); + code.aload(1); + code.putfield(classfile.name, "__proxy", "Lorg/python/core/PyInstance;"); + code.return_(); // getProxy method code = classfile.addMethod("_getPyInstance", "()Lorg/python/core/PyInstance;", Modifier.PUBLIC); - code.visitVarInsn(ALOAD, 0); - code.visitFieldInsn(GETFIELD, classfile.name, "__proxy", "Lorg/python/core/PyInstance;"); - code.visitInsn(ARETURN); + code.aload(0); + code.getfield(classfile.name, "__proxy", "Lorg/python/core/PyInstance;"); + code.areturn(); // implement PyProxy interface classfile.addField("__systemState", @@ -633,18 +631,18 @@ "(Lorg/python/core/PySystemState;)V", Modifier.PUBLIC); - code.visitVarInsn(ALOAD, 0); - code.visitVarInsn(ALOAD, 1); - code.visitFieldInsn(PUTFIELD, classfile.name, "__systemState", "Lorg/python/core/PySystemState;"); - code.visitInsn(RETURN); + code.aload(0); + code.aload(1); + code.putfield(classfile.name, "__systemState", "Lorg/python/core/PySystemState;"); + code.return_(); // getProxy method code = classfile.addMethod("_getPySystemState", "()Lorg/python/core/PySystemState;", Modifier.PUBLIC); - code.visitVarInsn(ALOAD, 0); - code.visitFieldInsn(GETFIELD, classfile.name, "__systemState", "Lorg/python/core/PySystemState;"); - code.visitInsn(ARETURN); + code.aload(0); + code.getfield(classfile.name, "__systemState", "Lorg/python/core/PySystemState;"); + code.areturn(); } public void addClassDictInit() throws Exception { @@ -655,14 +653,14 @@ Code code = classfile.addMethod("classDictInit", "(" + $pyObj + ")V", Modifier.PUBLIC | Modifier.STATIC); - code.visitVarInsn(ALOAD, 0); - code.visitLdcInsn("__supernames__"); + code.aload(0); + code.ldc("__supernames__"); String[] names = supernames.toArray(new String[n]); CodeCompiler.makeStrings(code, names, n); - code.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "java2py", "(" + $obj + ")" + $pyObj); - code.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyObject", "__setitem__", "(" + $str + $pyObj + ")V"); - code.visitInsn(RETURN); + code.invokestatic("org/python/core/Py", "java2py", "(" + $obj + ")" + $pyObj); + code.invokevirtual("org/python/core/PyObject", "__setitem__", "(" + $str + $pyObj + ")V"); + code.return_(); } public void build() throws Exception { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |