From: <fwi...@us...> - 2007-10-09 02:31:34
|
Revision: 3585 http://jython.svn.sourceforge.net/jython/?rev=3585&view=rev Author: fwierzbicki Date: 2007-10-08 19:31:33 -0700 (Mon, 08 Oct 2007) Log Message: ----------- A first pass at replacing compiler with ASM. Barely compiles, certainly doesn't work. But it is a start. Modified Paths: -------------- branches/asm_compiler/src/org/python/compiler/APIVersion.java branches/asm_compiler/src/org/python/compiler/AdapterMaker.java branches/asm_compiler/src/org/python/compiler/ClassFile.java branches/asm_compiler/src/org/python/compiler/Code.java branches/asm_compiler/src/org/python/compiler/CodeCompiler.java branches/asm_compiler/src/org/python/compiler/Constant.java branches/asm_compiler/src/org/python/compiler/JavaMaker.java branches/asm_compiler/src/org/python/compiler/LineNumberTable.java branches/asm_compiler/src/org/python/compiler/Module.java branches/asm_compiler/src/org/python/compiler/ProxyMaker.java branches/asm_compiler/src/org/python/compiler/SourceFile.java Modified: branches/asm_compiler/src/org/python/compiler/APIVersion.java =================================================================== --- branches/asm_compiler/src/org/python/compiler/APIVersion.java 2007-10-09 02:25:18 UTC (rev 3584) +++ branches/asm_compiler/src/org/python/compiler/APIVersion.java 2007-10-09 02:31:33 UTC (rev 3585) @@ -1,20 +1,21 @@ // Copyright (c) Corporation for National Research Initiatives package org.python.compiler; -import java.io.*; +import java.io.DataOutputStream; +import java.io.IOException; public class APIVersion extends Attribute { int attName; int version; - public APIVersion(int version, ConstantPool pool) throws IOException { - attName = pool.UTF8("org.python.APIVersion"); - this.version = version; + public APIVersion(int version) throws IOException { + //FJW attName = pool.UTF8("org.python.APIVersion"); + //FJW this.version = version; } public void write(DataOutputStream stream) throws IOException { - stream.writeShort(attName); - stream.writeInt(4); - stream.writeInt(version); + //FJW stream.writeShort(attName); + //FJW stream.writeInt(4); + //FJW stream.writeInt(version); } } Modified: branches/asm_compiler/src/org/python/compiler/AdapterMaker.java =================================================================== --- branches/asm_compiler/src/org/python/compiler/AdapterMaker.java 2007-10-09 02:25:18 UTC (rev 3584) +++ branches/asm_compiler/src/org/python/compiler/AdapterMaker.java 2007-10-09 02:31:33 UTC (rev 3585) @@ -2,12 +2,14 @@ package org.python.compiler; +import java.io.OutputStream; +import java.lang.reflect.Method; +import java.util.Enumeration; import java.util.Hashtable; -import java.util.Enumeration; -import java.lang.reflect.Method; -import java.io.*; +import org.objectweb.asm.Opcodes; + public class AdapterMaker extends ProxyMaker { public AdapterMaker(Class interfac) { @@ -18,7 +20,7 @@ names = new Hashtable(); //Class superclass = org.python.core.PyAdapter.class; - int access = ClassFile.PUBLIC | ClassFile.SYNCHRONIZED; + int access = Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNCHRONIZED; classfile = new ClassFile(myClass, "java/lang/Object", access); classfile.addInterface(mapClass(interfaces[0])); @@ -42,7 +44,7 @@ for (Enumeration e=names.keys(); e.hasMoreElements();) { String name = (String)e.nextElement(); classfile.addField(name, "Lorg/python/core/PyObject;", - ClassFile.PUBLIC); + Opcodes.ACC_PUBLIC); } } @@ -55,12 +57,10 @@ //System.out.println(name+": "+sig); names.put(name, name); - Code code = classfile.addMethod(name, sig, ClassFile.PUBLIC); + Code code = classfile.addMethod(name, sig, Opcodes.ACC_PUBLIC); code.aload(0); - int pyfunc = code.pool.Fieldref(classfile.name, name, - "Lorg/python/core/PyObject;"); - code.getfield(pyfunc); + code.mv.visitFieldInsn(GETFIELD, classfile.name, name, "Lorg/python/core/PyObject;"); code.dup(); Label returnNull = code.getLabel(); code.ifnull(returnNull); Modified: branches/asm_compiler/src/org/python/compiler/ClassFile.java =================================================================== --- branches/asm_compiler/src/org/python/compiler/ClassFile.java 2007-10-09 02:25:18 UTC (rev 3584) +++ branches/asm_compiler/src/org/python/compiler/ClassFile.java 2007-10-09 02:31:33 UTC (rev 3585) @@ -1,41 +1,30 @@ // Copyright (c) Corporation for National Research Initiatives package org.python.compiler; -import java.util.*; -import java.io.*; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; -class Method -{ - int access, name, type; - Attribute[] atts; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.FieldVisitor; +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Opcodes; - public Method(int name, int type, int access, Attribute[] atts) { - this.name = name; - this.type = type; - this.access = access; - this.atts = atts; - } - - public void write(DataOutputStream stream) throws IOException { - stream.writeShort(access); - stream.writeShort(name); - stream.writeShort(type); - ClassFile.writeAttributes(stream, atts); - } - -} - public class ClassFile { - ConstantPool pool; + ClassWriter pool; int access; public String name; String superclass; - int[] interfaces; - Vector methods; - Vector fields; - Vector attributes; + String[] interfaces; + List methodVisitors; + List fieldVisitors; + List attributes; + /* public final static int PUBLIC = 0x1; public final static int PRIVATE = 0x2; public final static int PROTECTED = 0x4; @@ -44,7 +33,7 @@ public final static int SYNCHRONIZED = 0x20; public final static int NATIVE = 0x100; public final static int ABSTRACT = 0x400; - + */ public static String fixName(String n) { if (n.indexOf('.') == -1) return n; @@ -56,99 +45,96 @@ } public ClassFile(String name) { - this(name, "java/lang/Object", SYNCHRONIZED | PUBLIC); + this(name, "java/lang/Object", Opcodes.ACC_SYNCHRONIZED | Opcodes.ACC_PUBLIC); } public ClassFile(String name, String superclass, int access) { this.name = fixName(name); this.superclass = fixName(superclass); - this.interfaces = new int[0]; + this.interfaces = new String[0]; this.access = access; + + pool = new ClassWriter(0); - pool = new ConstantPool(); - methods = new Vector(); - fields = new Vector(); - attributes = new Vector(); + methodVisitors = Collections.synchronizedList(new ArrayList()); + fieldVisitors = Collections.synchronizedList(new ArrayList()); + attributes = Collections.synchronizedList(new ArrayList()); } public void addInterface(String name) throws IOException { - int[] new_interfaces = new int[interfaces.length+1]; + String[] new_interfaces = new String[interfaces.length+1]; System.arraycopy(interfaces, 0, new_interfaces, 0, interfaces.length); - new_interfaces[interfaces.length] = pool.Class(name); + new_interfaces[interfaces.length] = name; interfaces = new_interfaces; } + //FIXME: Should really return a MethodVisitor public Code addMethod(String name, String type, int access) throws IOException { - Code code = new Code(type, pool, (access & STATIC) == STATIC); - Method m = new Method(pool.UTF8(name), pool.UTF8(type), access, - new Attribute[] {code}); - methods.addElement(m); + Code code = new Code(type, pool, (access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC); + MethodVisitor mv = pool.visitMethod(access, "main", "([Ljava/lang/String;)V", null, null); + methodVisitors.add(mv); + code.mv = mv; return code; } public void addField(String name, String type, int access) throws IOException { - Method m = new Method(pool.UTF8(name), pool.UTF8(type), access, - new Attribute[0]); - fields.addElement(m); + FieldVisitor fv = pool.visitField(access, name, type, null, null); + fieldVisitors.add(fv); + //FJW Method m = new Method(pool.UTF8(name), pool.UTF8(type), access, + //FJW new Attribute[0]); + } public static void writeAttributes(DataOutputStream stream, Attribute[] atts) throws IOException { - stream.writeShort(atts.length); - for (int i=0; i<atts.length; i++) { - atts[i].write(stream); - } + //stream.writeShort(atts.length); + //for (int i=0; i<atts.length; i++) { + // atts[i].write(stream); + //} } - public void writeMethods(DataOutputStream stream, Vector methods) + public void writeFields(DataOutputStream stream, List methods) throws IOException { + //stream.writeShort(methods.size()); + for (int i=0; i<methods.size(); i++) { + FieldVisitor fv = (FieldVisitor)methods.get(i); + fv.visitEnd(); + } + } + + public void writeMethods(DataOutputStream stream, List methods) + throws IOException + { stream.writeShort(methods.size()); for (int i=0; i<methods.size(); i++) { - Method m = (Method)methods.elementAt(i); - m.write(stream); + MethodVisitor mv = (MethodVisitor)methods.get(i); + mv.visitEnd(); + //m.write(stream); } } public void addAttribute(Attribute attr) throws IOException { - attributes.addElement(attr); + attributes.add(attr); } public void write(DataOutputStream stream) throws IOException { - //Write Header - int thisclass = pool.Class(name); - int superclass = pool.Class(this.superclass); + pool.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, this.name, null, this.superclass, interfaces); + writeFields(stream, fieldVisitors); + writeMethods(stream, methodVisitors); - stream.writeInt(0xcafebabe); - stream.writeShort(0x3); - stream.writeShort(0x2d); - - pool.write(stream); - - stream.writeShort(access); - stream.writeShort(thisclass); - stream.writeShort(superclass); - - //write out interfaces - stream.writeShort(interfaces.length); - for (int i=0; i<interfaces.length; i++) - stream.writeShort(interfaces[i]); - - writeMethods(stream, fields); - writeMethods(stream, methods); - //write out class attributes int n = attributes.size(); stream.writeShort(n); for (int i=0; i<n; i++) { - ((Attribute)attributes.elementAt(i)).write(stream); + ((Attribute)attributes.get(i)).write(stream); } } Modified: branches/asm_compiler/src/org/python/compiler/Code.java =================================================================== --- branches/asm_compiler/src/org/python/compiler/Code.java 2007-10-09 02:25:18 UTC (rev 3584) +++ branches/asm_compiler/src/org/python/compiler/Code.java 2007-10-09 02:31:33 UTC (rev 3585) @@ -2,9 +2,15 @@ package org.python.compiler; -import java.io.*; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; import java.util.Vector; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Opcodes; + class ExceptionLabel { public Label start, end, handler; @@ -18,10 +24,10 @@ } } - -public class Code extends Attribute +public class Code extends Attribute implements Opcodes { - ConstantPool pool; + MethodVisitor mv; + ClassWriter pool; public int stack; int max_stack; public DataOutputStream code; @@ -30,7 +36,7 @@ String locals[]; int nlocals; int argcount; - int att_name; + //FJW int att_name; = "Code" Vector labels, exceptions; LineNumberTable linenumbers; int returnLocal; @@ -40,7 +46,7 @@ addLabel(l); return l; } - + public Label getLabelAtPosition() { Label l = getLabel(); l.setPosition(); @@ -55,24 +61,19 @@ return stream.size(); } - public Code(String sig, ConstantPool pool, boolean isStatic) { + public Code(String sig, ClassWriter pool, boolean isStatic) { this.sig = sig; max_stack = 2; stack = 0; this.pool = pool; stream = new ByteArrayOutputStream(); code = new DataOutputStream(stream); - nlocals = -ConstantPool.sigSize(sig, false); + //FJW nlocals = -ConstantPool.sigSize(sig, false); if (!isStatic) nlocals = nlocals+1; argcount = nlocals; locals = new String[nlocals+128]; labels = new Vector(); exceptions = new Vector(); - try { - att_name = pool.UTF8("Code"); - } catch (IOException e) { - att_name=0; - } } public int getLocal(String type) { @@ -169,7 +170,7 @@ int length = bytes.length+12+8*n;; if (linenumbers != null) length += linenumbers.length(); - stream.writeShort(att_name); + //FJW stream.writeShort(att_name); stream.writeInt(length); stream.writeShort(max_stack); stream.writeShort(nlocals); @@ -208,138 +209,73 @@ } public void print(String s) throws IOException { - getstatic("java/lang/System", "out", "Ljava/io/PrintStream;"); + mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); ldc(s); - invokevirtual("java/io/PrintStream", "println", - "(Ljava/lang/String;)V"); + mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V"); } public void aaload() throws IOException { - code.writeByte(50); + mv.visitInsn(AALOAD); push(-1); } public void aastore() throws IOException { - code.writeByte(83); + mv.visitInsn(AASTORE); push(-3); } public void aconst_null() throws IOException { - code.writeByte(1); + mv.visitInsn(ACONST_NULL); push(1); } public void aload(int i) throws IOException { - if (i >= 0 && i < 4) { - code.writeByte(42+i); - } else { - code.writeByte(25); - code.writeByte(i); - } + mv.visitVarInsn(ALOAD, i); push(1); } - public void anewarray(int c) throws IOException { - code.writeByte(189); - code.writeShort(c); - //push(-1); push(1); - } - public void areturn() throws IOException { - code.writeByte(176); + mv.visitInsn(ARETURN); push(-1); } - public void arraylength() throws IOException { - code.writeByte(190); - //push(-1); push(1); - } - public void astore(int i) throws IOException { - if (i >= 0 && i < 4) { - code.writeByte(75+i); - } else { - code.writeByte(58); - code.writeByte(i); - } + mv.visitVarInsn(ASTORE, i); push(-1); } public void athrow() throws IOException { - code.writeByte(191); + mv.visitInsn(ATHROW); push(-1); } - public void checkcast(int c) throws IOException { - code.writeByte(192); - code.writeShort(c); - } - + public void dload(int i) throws IOException { - if (i >= 0 && i < 4) { - code.writeByte(38+i); - } else { - code.writeByte(24); - code.writeByte(i); - } + mv.visitVarInsn(DLOAD, i); push(2); } public void dreturn() throws IOException { - code.writeByte(175); + mv.visitInsn(DRETURN); push(-2); } - + public void dup() throws IOException { - code.writeByte(89); + mv.visitInsn(DUP); push(1); } - public void dup_x1() throws IOException { - code.writeByte(90); - push(1); - } - public void fload(int i) throws IOException { - if (i >= 0 && i < 4) { - code.writeByte(34+i); - } else { - code.writeByte(23); - code.writeByte(i); - } + mv.visitVarInsn(FLOAD, i); push(1); } public void freturn() throws IOException { - code.writeByte(174); + mv.visitInsn(FRETURN); push(-1); } - public void getfield(int c) throws IOException { - code.writeByte(180); - code.writeShort(c); - push(pool.sizes[c]-1); - } - - public void getfield(String c, String name, String type) - throws IOException - { - getfield(pool.Fieldref(c, name, type)); - } - - public void getstatic(int c) throws IOException { - code.writeByte(178); - code.writeShort(c); - push(pool.sizes[c]); - } - - public void getstatic(String c, String name, String type) - throws IOException - { - getstatic(pool.Fieldref(c, name, type)); - } - public void goto_(Label label) throws IOException { branch(167, label); } @@ -358,17 +294,13 @@ if (i < 0) i = i+65536; code.writeShort(i); } else { - ldc(pool.Integer(i)); + //FJW ldc(pool.Integer(i)); } } } push(1); } - public void if_icmpne(Label label) throws IOException { - push(-2); - branch(160, label); - } public void ifeq(Label label) throws IOException { push(-1); @@ -390,158 +322,40 @@ branch(198, label); } - 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 i) throws IOException { - if (i >= 0 && i < 4) { - code.writeByte(26+i); - } else { - code.writeByte(21); - code.writeByte(i); - } + mv.visitVarInsn(ILOAD, i); push(1); } - public void invokespecial(int c) throws IOException { - code.writeByte(183); - code.writeShort(c); - push(pool.sizes[c]-1); - } - - public void invokestatic(int c) throws IOException { - code.writeByte(184); - code.writeShort(c); - push(pool.sizes[c]); - } - - public void invokevirtual(int c) throws IOException { - code.writeByte(182); - code.writeShort(c); - push(pool.sizes[c]-1); - } - - public void invokevirtual(String c, String name, String type) - throws IOException - { - invokevirtual(pool.Methodref(c, name, type)); - } - public void ireturn() throws IOException { code.writeByte(172); push(-1); } - - public void istore(int i) throws IOException { - if (i >= 0 && i < 4) { - code.writeByte(59+i); - } else { - code.writeByte(54); - code.writeByte(i); - } - push(-1); - } - - 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 ldc(int c) throws IOException { - int size = pool.sizes[c]; - if (size == 1) { - if (c < 256) { - code.writeByte(18); - code.writeByte(c); - } else { - code.writeByte(19); - code.writeShort(c); - } - } else { - code.writeByte(20); - code.writeShort(c); - } - - push(pool.sizes[c]); - } - + public void ldc(String s) throws IOException { - ldc(pool.String(s)); + mv.visitLdcInsn(s); } public void lload(int i) throws IOException { - if (i >= 0 && i < 4) { - code.writeByte(30+i); - } else { - code.writeByte(22); - code.writeByte(i); - } + mv.visitVarInsn(LLOAD, i); push(2); } public void lreturn() throws IOException { - code.writeByte(173); + mv.visitInsn(LRETURN); push(-2); } - public void new_(int c) throws IOException { - code.writeByte(187); - code.writeShort(c); - push(1); - } - public void pop() throws IOException { - code.writeByte(87); + mv.visitInsn(POP); push(-1); } - public void putfield(int c) throws IOException { - code.writeByte(181); - code.writeShort(c); - push(-pool.sizes[c]-1); - } - - public void putfield(String c, String name, String type) - throws IOException - { - putfield(pool.Fieldref(c, name, type)); - } - - public void putstatic(int c) throws IOException { - code.writeByte(179); - code.writeShort(c); - push(-pool.sizes[c]); - } - - public void putstatic(String c, String name, String type) - throws IOException - { - putstatic(pool.Fieldref(c, name, type)); - } - public void return_() throws IOException { - code.writeByte(177); + mv.visitInsn(RETURN); } - public void ret(int index) throws IOException { - code.writeByte(169); - code.writeByte(index); - } - - public void swap() throws IOException { - code.writeByte(95); - } - public void tableswitch(Label def, int low, Label[] labels) throws IOException { @@ -559,7 +373,7 @@ public void setline(int line) throws IOException { if (linenumbers == null) - linenumbers = new LineNumberTable(pool); + linenumbers = new LineNumberTable(); linenumbers.addLine(size(), line); } } Modified: branches/asm_compiler/src/org/python/compiler/CodeCompiler.java =================================================================== --- branches/asm_compiler/src/org/python/compiler/CodeCompiler.java 2007-10-09 02:25:18 UTC (rev 3584) +++ branches/asm_compiler/src/org/python/compiler/CodeCompiler.java 2007-10-09 02:31:33 UTC (rev 3585) @@ -7,6 +7,8 @@ import java.util.Stack; import java.util.Vector; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.Opcodes; import org.python.core.CompilerFlags; import org.python.core.PyComplex; import org.python.core.PyFloat; @@ -71,8 +73,7 @@ import org.python.parser.ast.modType; import org.python.parser.ast.stmtType; -public class CodeCompiler extends Visitor - implements ClassConstants //, PythonGrammarTreeConstants +public class CodeCompiler extends Visitor implements Opcodes, ClassConstants //, PythonGrammarTreeConstants { public static final Object Exit=new Integer(1); @@ -86,7 +87,7 @@ public Module module; public Code code; - public ConstantPool pool; + public ClassWriter pool; public CodeCompiler mrefs; public CompilerFlags cflags; @@ -134,38 +135,25 @@ public int PyNone; public void getNone() throws IOException { - if (mrefs.PyNone == 0) { - mrefs.PyNone = pool.Fieldref("org/python/core/Py", "None", - $pyObj); - } - code.getstatic(mrefs.PyNone); + code.mv.visitFieldInsn(Opcodes.GETSTATIC, "org/python/core/Py", "None", $pyObj); } public void loadFrame() throws Exception { code.aload(1); } - int f_lasti; public void setLastI(int idx) throws Exception { - if (mrefs.f_lasti == 0) { - mrefs.f_lasti = code.pool.Fieldref( - "org/python/core/PyFrame", "f_lasti", "I"); - } loadFrame(); code.iconst(idx); - code.putfield(mrefs.f_lasti); + code.mv.visitFieldInsn(PUTFIELD, "org/python/core/PyFrame", "f_lasti", "I"); } int f_back; private void loadf_back() throws Exception { - if (mrefs.f_back == 0) { - mrefs.f_back = code.pool.Fieldref( - "org/python/core/PyFrame", "f_back", $pyFrame); - } - code.getfield(f_back); + code.mv.visitFieldInsn(PUTFIELD, "org/python/core/PyFrame", "f_back", $pyFrame); } public int storeTop() throws Exception { @@ -181,11 +169,7 @@ code.setline(line); loadFrame(); code.iconst(line); - if (mrefs.setline == 0) { - mrefs.setline = pool.Methodref("org/python/core/PyFrame", - "setline", "(I)V"); - } - code.invokevirtual(mrefs.setline); + code.mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyFrame", "setline", "(I)V"); } } @@ -278,8 +262,7 @@ if (classBody) { loadFrame(); - code.invokevirtual("org/python/core/PyFrame", "getf_locals", - "()" + $pyObj); + code.mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyFrame", "getf_locals", "()" + $pyObj); code.areturn(); } else { if (exit == null) { @@ -300,12 +283,6 @@ public Object visitModule(org.python.parser.ast.Module suite) throws Exception { - if (mrefs.setglobal == 0) { - mrefs.setglobal = code.pool.Methodref( - "org/python/core/PyFrame", "setglobal", - "(" +$str + $pyObj + ")V"); - } - if (suite.body.length > 0 && suite.body[0] instanceof Expr && ((Expr)suite.body[0]).value instanceof Str) @@ -313,13 +290,13 @@ loadFrame(); code.ldc("__doc__"); visit(((Expr) suite.body[0]).value); - code.invokevirtual(mrefs.setglobal); + code.mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyFrame", "setglobal", "(" +$str + $pyObj + ")V"); } if (module.setFile) { loadFrame(); code.ldc("__file__"); module.filename.get(code); - code.invokevirtual(mrefs.setglobal); + code.mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyFrame", "setglobal", "(" +$str + $pyObj + ")V"); } traverse(suite); return null; @@ -343,15 +320,11 @@ n = nodes.length; if (n == 0) { - if (mrefs.EmptyObjects == 0) { - mrefs.EmptyObjects = code.pool.Fieldref( - "org/python/core/Py", "EmptyObjects", $pyObjArr); - } - code.getstatic(mrefs.EmptyObjects); + code.mv.visitFieldInsn(Opcodes.GETSTATIC, "org/python/core/Py", "EmptyObjects", $pyObjArr); } else { int tmp = code.getLocal("[org/python/core/PyObject"); code.iconst(n); - code.anewarray(code.pool.Class("org/python/core/PyObject")); + code.mv.visitTypeInsn(ANEWARRAY, "org/python/core/PyObject"); code.astore(tmp); for(int i=0; i<n; i++) { @@ -383,14 +356,9 @@ int n = scope.freevars.size(); if (n == 0) return false; - if (mrefs.getclosure == 0) { - mrefs.getclosure = code.pool.Methodref( - "org/python/core/PyFrame", "getclosure", "(I)" + $pyObj); - } - int tmp = code.getLocal("[org/python/core/PyObject"); code.iconst(n); - code.anewarray(code.pool.Class("org/python/core/PyObject")); + code.mv.visitTypeInsn(ANEWARRAY, "org/python/core/PyObject"); code.astore(tmp); Hashtable upTbl = scope.up.tbl; for(int i=0; i<n; i++) { @@ -402,7 +370,7 @@ } SymInfo symInfo = (SymInfo)upTbl.get(scope.freevars.elementAt(i)); code.iconst(symInfo.env_index); - code.invokevirtual(getclosure); + code.mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyFrame", "getclosure", "(I)" + $pyObj); code.aastore(); } @@ -421,14 +389,10 @@ setline(node); - code.new_(code.pool.Class("org/python/core/PyFunction")); + code.mv.visitTypeInsn(NEW, "org/python/core/PyFunction"); code.dup(); loadFrame(); - if (mrefs.f_globals == 0) { - mrefs.f_globals = code.pool.Fieldref( - "org/python/core/PyFrame", "f_globals", $pyObj); - } - code.getfield(mrefs.f_globals); + code.mv.visitFieldInsn(PUTFIELD, "org/python/core/PyFrame", "f_globals", $pyObj); ScopeInfo scope = module.getScopeInfo(node); @@ -443,21 +407,9 @@ getDocString(node.body); if (!makeClosure(scope)) { - if (mrefs.PyFunction_init == 0) { - mrefs.PyFunction_init = code.pool.Methodref( - "org/python/core/PyFunction", "<init>", - "(" + $pyObj + $pyObjArr + $pyCode + $pyObj + ")V"); - } - code.invokespecial(mrefs.PyFunction_init); + code.mv.visitMethodInsn(INVOKESPECIAL, "org/python/core/PyFunction", "<init>", "(" + $pyObj + $pyObjArr + $pyCode + $pyObj + ")V"); } else { - if (mrefs.PyFunction_closure_init == 0) { - mrefs.PyFunction_closure_init = code.pool.Methodref( - "org/python/core/PyFunction", "<init>", - "(" + $pyObj + $pyObjArr + $pyCode + $pyObj + $pyObjArr + - ")V"); - } - code.invokespecial(mrefs.PyFunction_closure_init); - + code.mv.visitMethodInsn(INVOKESPECIAL, "org/python/core/PyFunction", "<init>", "(" + $pyObj + $pyObjArr + $pyCode + $pyObj + $pyObjArr + ")V"); } set(new Name(node.name, Name.Store, node)); @@ -471,12 +423,7 @@ visit(node.value); if (print_results) { - if (mrefs.printResult == 0) { - mrefs.printResult = code.pool.Methodref( - "org/python/core/Py", - "printResult", "(" + $pyObj + ")V"); - } - code.invokestatic(mrefs.printResult); + code.mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "printResult", "(" + $pyObj + ")V"); } else { code.pop(); } @@ -498,74 +445,41 @@ return null; } - public int print1, print2, print3, print4, print5, print6; - public Object visitPrint(Print node) throws Exception { setline(node); int tmp = -1; - int printcomma, printlnv, println; - if (node.dest != null) { - visit(node.dest); - tmp = storeTop(); - if (mrefs.print4 == 0) { - mrefs.print4 = pool.Methodref( - "org/python/core/Py", "printComma", - "(" + $pyObj + $pyObj + ")V"); - } - printcomma = mrefs.print4; - if (mrefs.print5 == 0) { - mrefs.print5 = pool.Methodref( - "org/python/core/Py", "println", - "(" + $pyObj + $pyObj + ")V"); - } - println = mrefs.print5; - if (mrefs.print6 == 0) { - mrefs.print6 = pool.Methodref( - "org/python/core/Py", "printlnv", - "(" + $pyObj + ")V"); - } - printlnv = mrefs.print6; - } - else { - if (mrefs.print1 == 0) { - mrefs.print1 = pool.Methodref( - "org/python/core/Py", "printComma", - "(" + $pyObj + ")V"); - } - printcomma = mrefs.print1; - if (mrefs.print2 == 0) { - mrefs.print2 = pool.Methodref( - "org/python/core/Py", "println", - "(" + $pyObj + ")V"); - } - println = mrefs.print2; - if (mrefs.print3 == 0) { - mrefs.print3 = pool.Methodref( - "org/python/core/Py", - "println", "()V"); - } - printlnv = mrefs.print3; - } - if (node.values == null || node.values.length == 0) { - if (node.dest != null) + if (node.dest != null) { code.aload(tmp); - code.invokestatic(printlnv); + code.mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "printlnv", "(" + $pyObj + ")V"); + } else { + code.mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "println", "()V"); + } } else { for (int i = 0; i < node.values.length; i++) { - if (node.dest != null) + if (node.dest != null) { code.aload(tmp); - visit(node.values[i]); - if (node.nl && i == node.values.length - 1) { - code.invokestatic(println); + visit(node.values[i]); + if (node.nl && i == node.values.length - 1) { + code.mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "println", "(" + $pyObj + $pyObj + ")V"); + } else { + code.mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "printComma", "(" + $pyObj + $pyObj + ")V"); + } } else { - code.invokestatic(printcomma); + visit(node.values[i]); + if (node.nl && i == node.values.length - 1) { + code.mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "println", "(" + $pyObj + ")V"); + } else { + code.mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "printComma", "(" + $pyObj + ")V"); + } + } } } - if (node.dest != null) + if (node.dest != null) { code.freeLocal(tmp); + } return null; } @@ -648,12 +562,7 @@ Vector v = code.getActiveLocals(); loadFrame(); - if (mrefs.f_savedlocals == 0) { - mrefs.f_savedlocals = code.pool.Fieldref( - "org/python/core/PyFrame", "f_savedlocals", - "[Ljava/lang/Object;"); - } - code.getfield(mrefs.f_savedlocals); + code.mv.visitFieldInsn(PUTFIELD, "org/python/core/PyFrame", "f_savedlocals", "[Ljava/lang/Object;"); int locals = code.getLocal("[java/lang/Object"); code.astore(locals); @@ -665,7 +574,7 @@ code.aload(locals); code.iconst(i); code.aaload(); - code.checkcast(code.pool.Class(type)); + code.mv.visitTypeInsn(CHECKCAST, type); code.astore(i); } code.freeLocal(locals); @@ -702,10 +611,8 @@ private void saveLocals() throws Exception { Vector v = code.getActiveLocals(); -//System.out.println("bs:" + bs); code.iconst(v.size()); - //code.anewarray(code.pool.Class("org/python/core/PyObject")); - code.anewarray(code.pool.Class("java/lang/Object")); + code.mv.visitTypeInsn(ANEWARRAY, "java/lang/Object"); int locals = code.getLocal("[java/lang/Object"); code.astore(locals); @@ -723,15 +630,9 @@ code.aastore(); } - if (mrefs.f_savedlocals == 0) { - mrefs.f_savedlocals = code.pool.Fieldref( - "org/python/core/PyFrame", "f_savedlocals", - "[Ljava/lang/Object;"); - } - loadFrame(); code.aload(locals); - code.putfield(mrefs.f_savedlocals); + code.mv.visitFieldInsn(PUTFIELD, "org/python/core/PyFrame", "f_savedlocals", "[Ljava/lang/Object;"); code.freeLocal(locals); } @@ -773,33 +674,13 @@ setline(node); traverse(node); if (node.type == null) { - if (mrefs.makeException0 == 0) { - mrefs.makeException0 = code.pool.Methodref( - "org/python/core/Py", "makeException", - "()" + $pyExc); - } - code.invokestatic(mrefs.makeException0); + code.mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "makeException", "()" + $pyExc); } else if (node.inst == null) { - if (mrefs.makeException1 == 0) { - mrefs.makeException1 = code.pool.Methodref( - "org/python/core/Py", "makeException", - "(" + $pyObj + ")" + $pyExc); - } - code.invokestatic(mrefs.makeException1); + code.mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "makeException", "(" + $pyObj + ")" + $pyExc); } else if (node.tback == null) { - if (mrefs.makeException2 == 0) { - mrefs.makeException2 = code.pool.Methodref( - "org/python/core/Py", "makeException", - "(" + $pyObj + $pyObj + ")" + $pyExc); - } - code.invokestatic(mrefs.makeException2); + code.mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "makeException", "(" + $pyObj + $pyObj + ")" + $pyExc); } else { - if (mrefs.makeException3 == 0) { - mrefs.makeException3 = code.pool.Methodref( - "org/python/core/Py", "makeException", - "(" + $pyObj + $pyObj + $pyObj + ")" + $pyExc); - } - code.invokestatic(mrefs.makeException3); + code.mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "makeException", "(" + $pyObj + $pyObj + $pyObj + ")" + $pyExc); } code.athrow(); return Exit; @@ -816,12 +697,7 @@ asname = node.names[i].asname; code.ldc(name); loadFrame(); - if (mrefs.importOneAs == 0) { - mrefs.importOneAs = code.pool.Methodref( - "org/python/core/imp", "importOneAs", - "(" + $str + $pyFrame + ")" + $pyObj); - } - code.invokestatic(mrefs.importOneAs); + code.mv.visitMethodInsn(INVOKESTATIC, "org/python/core/imp", "importOneAs", "(" + $str + $pyFrame + ")" + $pyObj); } else { String name = node.names[i].name; asname = name; @@ -829,12 +705,7 @@ asname = asname.substring(0, asname.indexOf('.')); code.ldc(name); loadFrame(); - if (mrefs.importOne == 0) { - mrefs.importOne = code.pool.Methodref( - "org/python/core/imp", "importOne", - "(" + $str + $pyFrame + ")" + $pyObj); - } - code.invokestatic(mrefs.importOne); + code.mv.visitMethodInsn(INVOKESTATIC, "org/python/core/imp", "importOne", "(" + $str + $pyFrame + ")" + $pyObj); } set(new Name(asname, Name.Store, node)); } @@ -860,12 +731,7 @@ makeStrings(code, names, names.length); loadFrame(); - if (mrefs.importFrom == 0) { - mrefs.importFrom = code.pool.Methodref( - "org/python/core/imp", "importFrom", - "(" + $str + $strArr + $pyFrame + ")" + $pyObjArr); - } - code.invokestatic(mrefs.importFrom); + code.mv.visitMethodInsn(INVOKESTATIC, "org/python/core/imp", "importFrom", "(" + $str + $strArr + $pyFrame + ")" + $pyObjArr); int tmp = storeTop(); for (int i = 0; i < node.names.length; i++) { code.aload(tmp); @@ -876,12 +742,7 @@ code.freeLocal(tmp); } else { loadFrame(); - if (mrefs.importAll == 0) { - mrefs.importAll = code.pool.Methodref( - "org/python/core/imp", "importAll", - "(" + $str + $pyFrame + ")V"); - } - code.invokestatic(mrefs.importAll); + code.mv.visitMethodInsn(INVOKESTATIC, "org/python/core/imp", "importAll", "(" + $str + $pyFrame + ")V"); } return null; } @@ -908,12 +769,7 @@ } //do the real work here - if (mrefs.exec == 0) { - mrefs.exec = code.pool.Methodref( - "org/python/core/Py", "exec", - "(" + $pyObj + $pyObj + $pyObj + ")V"); - } - code.invokestatic(mrefs.exec); + code.mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "exec", "(" + $pyObj + $pyObj + $pyObj + ")V"); return null; } @@ -922,55 +778,39 @@ setline(node); Label end_of_assert = code.getLabel(); - /* First do an if __debug__: */ + /* First do an if __debug__: */ loadFrame(); emitGetGlobal("__debug__"); - if (mrefs.nonzero == 0) { - mrefs.nonzero = code.pool.Methodref("org/python/core/PyObject", - "__nonzero__", "()Z"); - } - code.invokevirtual(mrefs.nonzero); + code.mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyFrame", "__nonzero__", "()Z"); code.ifeq(end_of_assert); /* Now do the body of the assert. If PyObject.__nonzero__ is true, - then the assertion succeeded, the message portion should not be - processed. Otherwise, the message will be processed. */ + then the assertion succeeded, the message portion should not be + processed. Otherwise, the message will be processed. */ visit(node.test); - code.invokevirtual(mrefs.nonzero); + code.mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyFrame", "__nonzero__", "()Z"); - /* If evaluation is false, then branch to end of method */ - code.ifne(end_of_assert); - - /* Push exception type onto stack(Py.AssertionError) */ - if (mrefs.asserttype == 0) { - mrefs.asserttype = code.pool.Fieldref( - "org/python/core/Py", "AssertionError", - "Lorg/python/core/PyObject;"); - } + /* If evaluation is false, then branch to end of method */ + code.ifne(end_of_assert); + + /* Push exception type onto stack(Py.AssertionError) */ + code.mv.visitFieldInsn(Opcodes.GETSTATIC, "org/python/core/Py", "AssertionError", "Lorg/python/core/PyObject;"); - code.getstatic(mrefs.asserttype); - - /* Visit the message part of the assertion, or pass Py.None */ - if( node.msg != null ){ - visit(node.msg); - } else{ - getNone(); - } - - if (mrefs.makeException2 == 0) { - mrefs.makeException2 = code.pool.Methodref( - "org/python/core/Py", "makeException", - "(" + $pyObj + $pyObj + ")" + $pyExc); + /* Visit the message part of the assertion, or pass Py.None */ + if( node.msg != null ) { + visit(node.msg); + } else { + getNone(); } - code.invokestatic(mrefs.makeException2); - - /* Raise assertion error. Only executes this logic if assertion - failed */ + code.mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "makeException", "(" + $pyObj + $pyObj + ")" + $pyExc); + + /* Raise assertion error. Only executes this logic if assertion + failed */ code.athrow(); - /* And finally set the label for the end of it all */ + /* And finally set the label for the end of it all */ end_of_assert.setPosition(); return null; @@ -984,11 +824,8 @@ setline(node.test); visit(node.test); - if (mrefs.nonzero == 0) { - mrefs.nonzero = code.pool.Methodref("org/python/core/PyObject", - "__nonzero__", "()Z"); - } - code.invokevirtual(mrefs.nonzero); + code.mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyFrame", "__nonzero__", "()Z"); + code.ifeq(end_of_suite); Object exit = suite(node.body); @@ -1049,11 +886,7 @@ //Do test visit(node.test); - if (mrefs.nonzero == 0) { - mrefs.nonzero = code.pool.Methodref("org/python/core/PyObject", - "__nonzero__", "()Z"); - } - code.invokevirtual(mrefs.nonzero); + code.mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyFrame", "__nonzero__", "()Z"); code.ifne(start_loop); finishLoop(savebcf); @@ -1087,12 +920,7 @@ visit(node.iter); //set up the loop iterator - if (mrefs.iter == 0) { - mrefs.iter = code.pool.Methodref( - "org/python/core/PyObject", - "__iter__", "()" + $pyObj); - } - code.invokevirtual(mrefs.iter); + code.mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyObject", "__iter__", "()Lorg/python/core/PyObject;"); code.astore(iter_tmp); //do check at end of loop. Saves one opcode ;-) @@ -1111,12 +939,8 @@ setline(node); //get the next element from the list code.aload(iter_tmp); - if (mrefs.iternext == 0) { - mrefs.iternext = code.pool.Methodref( - "org/python/core/PyObject", - "__iternext__", "()" + $pyObj); - } - code.invokevirtual(mrefs.iternext); + code.mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyObject", "__iternext__", "()" + $pyObj); + code.astore(expr_tmp); code.aload(expr_tmp); //if no more elements then fall through @@ -1154,12 +978,7 @@ code.aload(exc); //get specific exception visit(handler.type); - if (mrefs.match_exception == 0) { - mrefs.match_exception = code.pool.Methodref( - "org/python/core/Py", "matchException", - "(" + $pyExc + $pyObj + ")Z"); - } - code.invokestatic(mrefs.match_exception); + code.mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "matchException", "(" + $pyExc + $pyObj + ")Z"); code.ifeq(end_of_self); } else { if (i != node.handlers.length-1) { @@ -1170,9 +989,7 @@ if (handler.name != null) { code.aload(exc); - code.getfield(code.pool.Fieldref("org/python/core/PyException", - "value", - "Lorg/python/core/PyObject;")); + code.mv.visitFieldInsn(PUTFIELD, "org/python/core/PyException", "value", "Lorg/python/core/PyObject;"); set(handler.name); } @@ -1228,16 +1045,11 @@ code.aload(excLocal); loadFrame(); - if (mrefs.add_traceback == 0) { - mrefs.add_traceback = code.pool.Methodref( - "org/python/core/Py", "addTraceback", - "(" + $throwable + $pyFrame + ")V"); - } - code.invokestatic(mrefs.add_traceback); + code.mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "addTraceback", "(" + $throwable + $pyFrame + ")V"); inlineFinally(inFinally); code.aload(excLocal); - code.checkcast(code.pool.Class("java/lang/Throwable")); + code.mv.visitTypeInsn(CHECKCAST, "java/lang/Throwable"); code.athrow(); finallyEnd.setPosition(); @@ -1315,12 +1127,7 @@ loadFrame(); - if (mrefs.set_exception == 0) { - mrefs.set_exception = code.pool.Methodref( - "org/python/core/Py", "setException", - "(" + $throwable + $pyFrame + ")" + $pyExc); - } - code.invokestatic(mrefs.set_exception); + code.mv.visitMethodInsn(INVOKESTATIC, "org/python/core/Py", "setException", "(" + $throwable + $pyFrame + ")" + $pyExc); int exc = code.getFinallyLocal("java/lang/Throwable"); code.astore(exc); @@ -1365,11 +1172,7 @@ visit(node.values[0]); for (int i = 1; i < node.values.length; i++) { code.dup(); - if (mrefs.nonzero == 0) { - mrefs.nonzero = code.pool.Methodref("org/python/core/PyObject", - "__nonzero__", "()Z"); - } - code.invokevirtual(mrefs.nonzero); + code.mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyObject", "__nonzero__", "()Z"); switch (node.op) { case BoolOp.Or : code.ifne(end); @@ -1389,12 +1192,6 @@ public Object visitCompare(Compare node) throws Exception { int tmp1 = code.getLocal("org/python/core/PyObject"); int tmp2 = code.getLocal("org/python/core/PyObject"); - - if (mrefs.nonzero == 0) { - mrefs.nonzero = code.pool.Methodref("org/python/core/PyObject", - "__nonzero__", "()Z"); - } - Label end = code.getLabel(); visit(node.left); @@ -1404,16 +1201,16 @@ visit(node.comparators[i]); code.dup(); code.astore(tmp1); - code.invokevirtual(make_cmpop(node.ops[i])); + visitCmpop(node.ops[i]); code.dup(); code.astore(tmp2); - code.invokevirtual(mrefs.nonzero); + code.mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyObject", "__nonzero__", "()Z"); code.ifeq(end); code.aload(tmp1); } visit(node.comparators[n-1]); - code.invokevirtual(make_cmpop(node.ops[n-1])); + visitCmpop(node.ops[n-1]); if (n > 1) { code.astore(tmp2); @@ -1425,27 +1222,21 @@ return null; } - int[] compare_ops = new int[11]; - public int make_cmpop(int op) throws Exception { - if (compare_ops[op] == 0) { - String name = null; - switch (op) { - case Compare.Eq: name = "_eq"; break; - case Compare.NotEq: name = "_ne"; break; - case Compare.Lt: name = "_lt"; break; - case Compare.LtE: name = "_le"; break; - case Compare.Gt: name = "_gt"; break; - case Compare.GtE: name = "_ge"; break; - case Compare.Is: name = "_is"; break; - case Compare.IsNot: name = "_isnot"; break; - case Compare.In: name = "_in"; break; - case Compare.NotIn: name = "_notin"; break; - } - compare_ops[op] = code.pool.Methodref( - "org/python/core/PyObject", name, - "(" + $pyObj + ")" + $pyObj); + public void visitCmpop(int op) throws Exception { + String name = null; + switch (op) { + case Compare.Eq: name = "_eq"; break; + case Compare.NotEq: name = "_ne"; break; + case Compare.Lt: name = "_lt"; break; + case Compare.LtE: name = "_le"; break; + case Compare.Gt: name = "_gt"; break; + case Compare.GtE: name = "_ge"; break; + case Compare.Is: name = "_is"; break; + case Compare.IsNot: name = "_isnot"; break; + case Compare.In: name = "_in"; break; + case Compare.NotIn: name = "_notin"; break; } - return compare_ops[op]; + code.mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyObject", name, "(" + $pyObj + ")" + $pyObj); } static String[] bin_methods = new String[] { @@ -1464,27 +1255,16 @@ "_floordiv", }; - int[] bin_ops = new int[13]; - public int make_binop(int op) throws Exception { - if (bin_ops[op] == 0) { - String name = bin_methods[op]; - if (op == BinOp.Div && module.getFutures().areDivisionOn()) { - name = "_truediv"; - } - bin_ops[op] = code.pool.Methodref( - "org/python/core/PyObject", name, - "(" + $pyObj + ")" + $pyObj); - } - return bin_ops[op]; - } - public Object visitBinOp(BinOp node) throws Exception { visit(node.left); visit(node.right); - code.invokevirtual(make_binop(node.op)); + String name = bin_methods[node.op]; + if (node.op == BinOp.Div && module.getFutures().areDivisionOn()) { + name = "_truediv"; + } + code.mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyObject", name, "(" + $pyObj + ")" + $pyObj); return null; } - static String[] unary_methods = new String[] { null, @@ -1494,19 +1274,11 @@ "__neg__", }; - int[] unary_ops = new int[unary_methods.length]; - public int make_unaryop(int op) throws Exception { - if (unary_ops[op] == 0) { - String name = unary_methods[op]; - unary_ops[op] = code.pool.Methodref( - "org/python/core/PyObject", name, "()" + $pyObj); - } - return unary_ops[op]; - } - public Object visitUnaryOp(UnaryOp node) throws Exception { visit(node.operand); - code.invokevirtual(make_unaryop(node.op)); + + String name = unary_methods[node.op]; + code.mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyObject", name, "()" + $pyObj); return null; } @@ -1527,20 +1299,6 @@ "__ifloordiv__", }; - int[] augbin_ops = new int[aug_methods.length]; - public int make_augbinop(int op) throws Exception { - if (augbin_ops[op] == 0) { - String name = aug_methods[op]; - if (op == BinOp.Div && module.getFutures().areDivisionOn()) { - name = "__itruediv__"; - } - augbin_ops[op] = code.pool.Methodref( - "org/python/core/PyObject", name, - "(" + $pyObj + ")" + $pyObj); - } - return augbin_ops[op]; - } - public Object visitAugAssign(AugAssign node) throws Exception { visit(node.value); int tmp = storeTop(); @@ -1549,7 +1307,12 @@ visit(node.target); code.aload(tmp); - code.invokevirtual(make_augbinop(node.op)); + + String name = aug_methods[node.op]; + if (node.op == BinOp.Div && module.getFutures().areDivisionOn()) { + name = "__itruediv__"; + } + code.mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyObject", name, "(" + $pyObj + ")" + $pyObj); code.freeLocal(tmp); temporary = storeTop(); @@ -1565,7 +1328,7 @@ throws IOException { c.iconst(n); - c.anewarray(c.pool.Class("java/lang/String")); + c.mv.visitTypeInsn(ANEWARRAY, "java/lang/String"); int strings = c.getLocal("[java/lang/String"); c.astore(strings); for (int i=0; i<n; i++) { @@ -1591,43 +1354,22 @@ switch (values.length) { case 0: - if (mrefs.invokea0 == 0) { - mrefs.invokea0 = code.pool.Methodref( - "org/python/core/PyObject", "invoke", - "(" + $str + ")" + $pyObj); - } - code.invokevirtual(mrefs.invokea0); + code.mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyObject", "invoke", "(" + $str + ")" + $pyObj); break; case 1: - if (mrefs.invokea1 == 0) { - mrefs.invokea1 = code.pool.Methodref( - "org/python/core/PyObject", "invoke", - "(" + $str + $pyObj + ")" + $pyObj); - } visit(values[0]); - code.invokevirtual(mrefs.invokea1); + code.mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyObject", "invoke", "(" + $str + $pyObj + ")" + $pyObj); break; case 2: - if (mrefs.invokea2 == 0) { - mrefs.invokea2 = code.pool.Methodref( - "org/python/core/PyObject", "invoke", - "(" + $str + $pyObj + $pyObj + ")" + $pyObj); - } visit(values[0]); visit(values[1]); - code.invokevirtual(mrefs.invokea2); + code.mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyObject", "invoke", "(" + $str + $pyObj + $pyObj + ")" + $pyObj); break; default: makeArray(values); - if (mrefs.invoke2 == 0) { - mrefs.invoke2 = code.pool.Methodref( - "org/python/core/PyObject", "invoke", - "(" + $str + $pyObjArr + ")" + $pyObj); - } - code.invokevirtual(mrefs.invoke2); + code.mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyObject", "invoke", "(" + $str + $pyObjArr + ")" + $pyObj); break; } - return null; } @@ -1667,84 +1409,41 @@ else visit(node.kwargs); - if (mrefs.callextra == 0) { - mrefs.callextra = code.pool.Methodref( - "org/python/core/PyObject", "_callextra", - "(" + $pyObjArr + $strArr + $pyObj + $pyObj + ")" + - $pyObj); - } - code.invokevirtual(mrefs.callextra); + code.mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyObject", "_callextra", "(" + $pyObjArr + $strArr + $pyObj + $pyObj + ")" + $pyObj); } else if (keys.length > 0) { makeArray(values); makeStrings(code, keys, keys.length); - - if (mrefs.call1 == 0) { - mrefs.call1 = code.pool.Methodref( - "org/python/core/PyObject", "__call__", - "(" + $pyObjArr + $strArr + ")" + $pyObj); - } - code.invokevirtual(mrefs.call1); + code.mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyObject", "__call__", "(" + $pyObjArr + $strArr + ")" + $pyObj); } else { switch (values.length) { case 0: - if (mrefs.calla0 == 0) { - mrefs.calla0 = code.pool.Methodref( - "org/python/core/PyObject", "__call__", - "()" + $pyObj); - } - code.invokevirtual(mrefs.calla0); + code.mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyObject", "__call__", "()" + $pyObj); break; case 1: - if (mrefs.calla1 == 0) { - mrefs.calla1 = code.pool.Methodref( - "org/python/core/PyObject", "__call__", - "(" + $pyObj + ")" + $pyObj); - } visit(values[0]); - code.invokevirtual(mrefs.calla1); + code.mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/core/PyObject", "__call__", "(" + $pyObj + ")" + $pyObj); break; case 2: - if (mrefs.calla2 == 0) { - mrefs.calla2 = code.pool.Methodref( - "org/python/core/PyObject", "__call__", - "(" + $pyObj + $pyObj + ")" + $pyObj); - } visit(values[0]); visit(values[1]); - code.invokevirtual(mrefs.calla2); + code.mv.visitMethodInsn(INVOKEVIRTUAL, "org/python/cor... [truncated message content] |