From: <fwi...@us...> - 2009-10-04 15:10:28
|
Revision: 6834 http://jython.svn.sourceforge.net/jython/?rev=6834&view=rev Author: fwierzbicki Date: 2009-10-04 15:10:21 +0000 (Sun, 04 Oct 2009) Log Message: ----------- Use sig for invokevirtual. Modified Paths: -------------- trunk/jython/src/org/python/compiler/Module.java Modified: trunk/jython/src/org/python/compiler/Module.java =================================================================== --- trunk/jython/src/org/python/compiler/Module.java 2009-10-04 14:39:40 UTC (rev 6833) +++ trunk/jython/src/org/python/compiler/Module.java 2009-10-04 15:10:21 UTC (rev 6834) @@ -16,7 +16,11 @@ import org.python.core.CodeFlag; import org.python.core.CodeLoader; import org.python.core.CompilerFlags; +import org.python.core.ThreadState; import org.python.core.Py; +import org.python.core.PyCode; +import org.python.core.PyFrame; +import org.python.core.PyObject; import org.python.core.PyException; import org.python.core.PyRunnableBootstrap; import org.objectweb.asm.Type; @@ -24,6 +28,7 @@ import org.python.antlr.PythonTree; import org.python.antlr.ast.Suite; import org.python.antlr.base.mod; +import static org.python.util.CodegenUtils.*; class PyIntegerConstant extends Constant implements ClassConstants, Opcodes { @@ -444,9 +449,11 @@ c.aload(1); c.ldc("__name__"); - c.invokevirtual("org/python/core/PyFrame", "getname", "(" + $str + ")" + $pyObj); + c.invokevirtual("org/python/core/PyFrame", "getname", sig(PyObject.class, + String.class)); - c.invokevirtual("org/python/core/PyFrame", "setlocal", "(" + $str + $pyObj + ")V"); + c.invokevirtual("org/python/core/PyFrame", "setlocal", sig(Void.TYPE, String.class, + PyObject.class)); } Label genswitch = new Label(); @@ -469,7 +476,8 @@ SymInfo syminf = tbl.get(paramcells.get(i)); c.iconst(syminf.locals_index); c.iconst(syminf.env_index); - c.invokevirtual("org/python/core/PyFrame", "to_cell", "(II)V"); + c.invokevirtual("org/python/core/PyFrame", "to_cell", sig(Void.TYPE, Integer.TYPE, + Integer.TYPE)); } } @@ -540,7 +548,7 @@ c.dup(); c.ldc(classfile.name); c.invokespecial(classfile.name, "<init>", "(" + $str + ")V"); - c.invokevirtual(classfile.name, "getMain", "()" + $pyCode); + c.invokevirtual(classfile.name, "getMain", sig(PyCode.class)); String bootstrap = Type.getDescriptor(CodeBootstrap.class); c.invokestatic(Type.getInternalName(CodeLoader.class), CodeLoader.SIMPLE_FACTORY_METHOD_NAME, @@ -601,7 +609,8 @@ code.tableswitch(0, labels.length - 1, def, labels); for(i=0; i<labels.length; i++) { code.label(labels[i]); - code.invokevirtual(classfile.name, (codes.get(i)).fname, "(" + $pyFrame + $threadState + ")" + $pyObj); + code.invokevirtual(classfile.name, (codes.get(i)).fname, sig(PyObject.class, + PyFrame.class, ThreadState.class)); code.areturn(); } code.label(def); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-10-04 17:03:29
|
Revision: 6835 http://jython.svn.sourceforge.net/jython/?rev=6835&view=rev Author: fwierzbicki Date: 2009-10-04 17:03:17 +0000 (Sun, 04 Oct 2009) Log Message: ----------- use sig for invokestatic. Modified Paths: -------------- trunk/jython/src/org/python/compiler/Module.java Modified: trunk/jython/src/org/python/compiler/Module.java =================================================================== --- trunk/jython/src/org/python/compiler/Module.java 2009-10-04 15:10:21 UTC (rev 6834) +++ trunk/jython/src/org/python/compiler/Module.java 2009-10-04 17:03:17 UTC (rev 6835) @@ -19,10 +19,17 @@ import org.python.core.ThreadState; import org.python.core.Py; import org.python.core.PyCode; +import org.python.core.PyComplex; +import org.python.core.PyException; +import org.python.core.PyFloat; import org.python.core.PyFrame; +import org.python.core.PyFunctionTable; +import org.python.core.PyInteger; +import org.python.core.PyLong; import org.python.core.PyObject; -import org.python.core.PyException; import org.python.core.PyRunnableBootstrap; +import org.python.core.PyString; +import org.python.core.PyUnicode; import org.objectweb.asm.Type; import org.python.antlr.ParseException; import org.python.antlr.PythonTree; @@ -45,7 +52,7 @@ public void put(Code c) throws IOException { module.classfile.addField(name, $pyInteger, access); c.iconst(value); - c.invokestatic("org/python/core/Py", "newInteger", "(I)" + $pyInteger); + c.invokestatic("org/python/core/Py", "newInteger", sig(PyInteger.class, Integer.TYPE)); c.putstatic(module.classfile.name, name, $pyInteger); } @@ -78,7 +85,7 @@ public void put(Code c) throws IOException { module.classfile.addField(name, $pyFloat, access); c.ldc(new Double(value)); - c.invokestatic("org/python/core/Py", "newFloat", "(D)" + $pyFloat); + c.invokestatic("org/python/core/Py", "newFloat", sig(PyFloat.class, Double.TYPE)); c.putstatic(module.classfile.name, name, $pyFloat); } @@ -111,7 +118,7 @@ public void put(Code c) throws IOException { module.classfile.addField(name, $pyComplex, access); c.ldc(new Double(value)); - c.invokestatic("org/python/core/Py", "newImaginary", "(D)" + $pyComplex); + c.invokestatic("org/python/core/Py", "newImaginary", sig(PyComplex.class, Double.TYPE)); c.putstatic(module.classfile.name, name, $pyComplex); } @@ -144,7 +151,8 @@ public void put(Code c) throws IOException { module.classfile.addField(name, $pyStr, access); c.ldc(value); - c.invokestatic("org/python/core/PyString", "fromInterned", "(" + $str + ")" + $pyStr); + c.invokestatic("org/python/core/PyString", "fromInterned", sig(PyString.class, + String.class)); c.putstatic(module.classfile.name, name, $pyStr); } @@ -177,7 +185,8 @@ public void put(Code c) throws IOException { module.classfile.addField(name, $pyUnicode, access); c.ldc(value); - c.invokestatic("org/python/core/PyUnicode", "fromInterned", "(" + $str + ")" + $pyUnicode); + c.invokestatic("org/python/core/PyUnicode", "fromInterned", sig(PyUnicode.class, + String.class)); c.putstatic(module.classfile.name, name, $pyUnicode); } @@ -210,7 +219,7 @@ public void put(Code c) throws IOException { module.classfile.addField(name, $pyLong, access); c.ldc(value); - c.invokestatic("org/python/core/Py", "newLong", "(" + $str + ")" + $pyLong); + c.invokestatic("org/python/core/Py", "newLong", sig(PyLong.class, String.class)); c.putstatic(module.classfile.name, name, $pyLong); } @@ -292,7 +301,10 @@ c.iconst(moreflags); - c.invokestatic("org/python/core/Py", "newCode", "(I" + $strArr + $str + $str + "IZZ" + $pyFuncTbl + "I" + $strArr + $strArr + "II)" + $pyCode); + c.invokestatic("org/python/core/Py", "newCode", sig(PyCode.class, Integer.TYPE, + String[].class, String.class, String.class, Integer.TYPE, Boolean.TYPE, + Boolean.TYPE, PyFunctionTable.class, Integer.TYPE, String[].class, + String[].class, Integer.TYPE, Integer.TYPE)); c.putstatic(module.classfile.name, name, $pyCode); } } @@ -550,11 +562,10 @@ c.invokespecial(classfile.name, "<init>", "(" + $str + ")V"); c.invokevirtual(classfile.name, "getMain", sig(PyCode.class)); String bootstrap = Type.getDescriptor(CodeBootstrap.class); - c.invokestatic(Type.getInternalName(CodeLoader.class), - CodeLoader.SIMPLE_FACTORY_METHOD_NAME, - "(" + $pyCode + ")" + bootstrap); + c.invokestatic(p(CodeLoader.class), CodeLoader.SIMPLE_FACTORY_METHOD_NAME, + sig(CodeBootstrap.class, PyCode.class)); c.aload(0); - c.invokestatic("org/python/core/Py", "runMain", "(" + bootstrap + $strArr + ")V"); + c.invokestatic(p(Py.class), "runMain", sig(Void.TYPE, CodeBootstrap.class, String[].class)); c.return_(); } @@ -563,9 +574,8 @@ "()" + Type.getDescriptor(CodeBootstrap.class), ACC_PUBLIC | ACC_STATIC); c.ldc(Type.getType("L" + classfile.name + ";")); - c.invokestatic(Type.getInternalName(PyRunnableBootstrap.class), - PyRunnableBootstrap.REFLECTION_METHOD_NAME, - "(" + $clss + ")" + Type.getDescriptor(CodeBootstrap.class)); + c.invokestatic(p(PyRunnableBootstrap.class), PyRunnableBootstrap.REFLECTION_METHOD_NAME, + sig(CodeBootstrap.class, Class.class)); c.areturn(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-10-04 20:16:23
|
Revision: 6836 http://jython.svn.sourceforge.net/jython/?rev=6836&view=rev Author: fwierzbicki Date: 2009-10-04 20:16:12 +0000 (Sun, 04 Oct 2009) Log Message: ----------- Use sig for invokespecial and addMethod. Modified Paths: -------------- trunk/jython/src/org/python/compiler/Module.java Modified: trunk/jython/src/org/python/compiler/Module.java =================================================================== --- trunk/jython/src/org/python/compiler/Module.java 2009-10-04 17:03:17 UTC (rev 6835) +++ trunk/jython/src/org/python/compiler/Module.java 2009-10-04 20:16:12 UTC (rev 6836) @@ -46,14 +46,14 @@ } public void get(Code c) throws IOException { - c.getstatic(module.classfile.name, name, $pyInteger); + c.getstatic(module.classfile.name, name, ci(PyInteger.class)); } public void put(Code c) throws IOException { - module.classfile.addField(name, $pyInteger, access); + module.classfile.addField(name, ci(PyInteger.class), access); c.iconst(value); c.invokestatic("org/python/core/Py", "newInteger", sig(PyInteger.class, Integer.TYPE)); - c.putstatic(module.classfile.name, name, $pyInteger); + c.putstatic(module.classfile.name, name, ci(PyInteger.class)); } @Override @@ -79,14 +79,14 @@ } public void get(Code c) throws IOException { - c.getstatic(module.classfile.name, name, $pyFloat); + c.getstatic(module.classfile.name, name, ci(PyFloat.class)); } public void put(Code c) throws IOException { - module.classfile.addField(name, $pyFloat, access); + module.classfile.addField(name, ci(PyFloat.class), access); c.ldc(new Double(value)); c.invokestatic("org/python/core/Py", "newFloat", sig(PyFloat.class, Double.TYPE)); - c.putstatic(module.classfile.name, name, $pyFloat); + c.putstatic(module.classfile.name, name, ci(PyFloat.class)); } @Override @@ -112,14 +112,14 @@ } public void get(Code c) throws IOException { - c.getstatic(module.classfile.name, name, $pyComplex); + c.getstatic(module.classfile.name, name, ci(PyComplex.class)); } public void put(Code c) throws IOException { - module.classfile.addField(name, $pyComplex, access); + module.classfile.addField(name, ci(PyComplex.class), access); c.ldc(new Double(value)); c.invokestatic("org/python/core/Py", "newImaginary", sig(PyComplex.class, Double.TYPE)); - c.putstatic(module.classfile.name, name, $pyComplex); + c.putstatic(module.classfile.name, name, ci(PyComplex.class)); } @Override @@ -145,15 +145,15 @@ } public void get(Code c) throws IOException { - c.getstatic(module.classfile.name, name, $pyStr); + c.getstatic(module.classfile.name, name, ci(PyString.class)); } public void put(Code c) throws IOException { - module.classfile.addField(name, $pyStr, access); + module.classfile.addField(name, ci(PyString.class), access); c.ldc(value); c.invokestatic("org/python/core/PyString", "fromInterned", sig(PyString.class, String.class)); - c.putstatic(module.classfile.name, name, $pyStr); + c.putstatic(module.classfile.name, name, ci(PyString.class)); } @Override @@ -179,15 +179,15 @@ } public void get(Code c) throws IOException { - c.getstatic(module.classfile.name, name, $pyUnicode); + c.getstatic(module.classfile.name, name, ci(PyUnicode.class)); } public void put(Code c) throws IOException { - module.classfile.addField(name, $pyUnicode, access); + module.classfile.addField(name, ci(PyUnicode.class), access); c.ldc(value); c.invokestatic("org/python/core/PyUnicode", "fromInterned", sig(PyUnicode.class, String.class)); - c.putstatic(module.classfile.name, name, $pyUnicode); + c.putstatic(module.classfile.name, name, ci(PyUnicode.class)); } @Override @@ -213,14 +213,14 @@ } public void get(Code c) throws IOException { - c.getstatic(module.classfile.name, name, $pyLong); + c.getstatic(module.classfile.name, name, ci(PyLong.class)); } public void put(Code c) throws IOException { - module.classfile.addField(name, $pyLong, access); + module.classfile.addField(name, ci(PyLong.class), access); c.ldc(value); c.invokestatic("org/python/core/Py", "newLong", sig(PyLong.class, String.class)); - c.putstatic(module.classfile.name, name, $pyLong); + c.putstatic(module.classfile.name, name, ci(PyLong.class)); } @Override @@ -257,11 +257,11 @@ } public void get(Code c) throws IOException { - c.getstatic(module.classfile.name, name, $pyCode); + c.getstatic(module.classfile.name, name, ci(PyCode.class)); } public void put(Code c) throws IOException { - module.classfile.addField(name, $pyCode, access); + module.classfile.addField(name, ci(PyCode.class), access); c.iconst(argcount); //Make all names @@ -305,7 +305,7 @@ String[].class, String.class, String.class, Integer.TYPE, Boolean.TYPE, Boolean.TYPE, PyFunctionTable.class, Integer.TYPE, String[].class, String[].class, Integer.TYPE, Integer.TYPE)); - c.putstatic(module.classfile.name, name, $pyCode); + c.putstatic(module.classfile.name, name, ci(PyCode.class)); } } @@ -449,7 +449,7 @@ Code c = classfile.addMethod( code.fname, - "(" + $pyFrame + $threadState + ")" + $pyObj, + sig(PyObject.class, PyFrame.class, ThreadState.class), ACC_PUBLIC); CodeCompiler compiler = new CodeCompiler(this, printResults); @@ -541,25 +541,25 @@ //This block of code writes out the various standard methods public void addInit() throws IOException { - Code c = classfile.addMethod("<init>", "(Ljava/lang/String;)V", ACC_PUBLIC); + Code c = classfile.addMethod("<init>", sig(Void.TYPE, String.class), ACC_PUBLIC); c.aload(0); - c.invokespecial("org/python/core/PyFunctionTable", "<init>", "()V"); + c.invokespecial("org/python/core/PyFunctionTable", "<init>", sig(Void.TYPE)); addConstants(c); } public void addRunnable() throws IOException { - Code c = classfile.addMethod("getMain", "()" + $pyCode, ACC_PUBLIC); + Code c = classfile.addMethod("getMain", sig(PyCode.class), ACC_PUBLIC); mainCode.get(c); c.areturn(); } public void addMain() throws IOException { - Code c = classfile.addMethod("main", "(" + $strArr + ")V", + Code c = classfile.addMethod("main", sig(Void.TYPE, String[].class), ACC_PUBLIC | ACC_STATIC); c.new_(classfile.name); c.dup(); c.ldc(classfile.name); - c.invokespecial(classfile.name, "<init>", "(" + $str + ")V"); + c.invokespecial(classfile.name, "<init>", sig(Void.TYPE, String.class)); c.invokevirtual(classfile.name, "getMain", sig(PyCode.class)); String bootstrap = Type.getDescriptor(CodeBootstrap.class); c.invokestatic(p(CodeLoader.class), CodeLoader.SIMPLE_FACTORY_METHOD_NAME, @@ -571,7 +571,7 @@ public void addBootstrap() throws IOException { Code c = classfile.addMethod(CodeLoader.GET_BOOTSTRAP_METHOD_NAME, - "()" + Type.getDescriptor(CodeBootstrap.class), + sig(CodeBootstrap.class), ACC_PUBLIC | ACC_STATIC); c.ldc(Type.getType("L" + classfile.name + ";")); c.invokestatic(p(PyRunnableBootstrap.class), PyRunnableBootstrap.REFLECTION_METHOD_NAME, @@ -602,7 +602,7 @@ public void addFunctions() throws IOException { Code code = classfile.addMethod( "call_function", - "(I" + $pyFrame + $threadState + ")" + $pyObj, + sig(PyObject.class, Integer.TYPE, PyFrame.class, ThreadState.class), ACC_PUBLIC); code.aload(0); // this This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-10-04 22:31:34
|
Revision: 6838 http://jython.svn.sourceforge.net/jython/?rev=6838&view=rev Author: fwierzbicki Date: 2009-10-04 22:31:22 +0000 (Sun, 04 Oct 2009) Log Message: ----------- switch to p() from raw path strings where possible, also some cleanup. Modified Paths: -------------- trunk/jython/src/org/python/compiler/Module.java Modified: trunk/jython/src/org/python/compiler/Module.java =================================================================== --- trunk/jython/src/org/python/compiler/Module.java 2009-10-04 21:25:41 UTC (rev 6837) +++ trunk/jython/src/org/python/compiler/Module.java 2009-10-04 22:31:22 UTC (rev 6838) @@ -27,6 +27,7 @@ import org.python.core.PyInteger; import org.python.core.PyLong; import org.python.core.PyObject; +import org.python.core.PyRunnable; import org.python.core.PyRunnableBootstrap; import org.python.core.PyString; import org.python.core.PyUnicode; @@ -52,7 +53,7 @@ public void put(Code c) throws IOException { module.classfile.addField(name, ci(PyInteger.class), access); c.iconst(value); - c.invokestatic("org/python/core/Py", "newInteger", sig(PyInteger.class, Integer.TYPE)); + c.invokestatic(p(Py.class), "newInteger", sig(PyInteger.class, Integer.TYPE)); c.putstatic(module.classfile.name, name, ci(PyInteger.class)); } @@ -63,10 +64,11 @@ @Override public boolean equals(Object o) { - if (o instanceof PyIntegerConstant) + if (o instanceof PyIntegerConstant) { return ((PyIntegerConstant)o).value == value; - else + } else { return false; + } } } @@ -85,7 +87,7 @@ public void put(Code c) throws IOException { module.classfile.addField(name, ci(PyFloat.class), access); c.ldc(new Double(value)); - c.invokestatic("org/python/core/Py", "newFloat", sig(PyFloat.class, Double.TYPE)); + c.invokestatic(p(Py.class), "newFloat", sig(PyFloat.class, Double.TYPE)); c.putstatic(module.classfile.name, name, ci(PyFloat.class)); } @@ -96,10 +98,11 @@ @Override public boolean equals(Object o) { - if (o instanceof PyFloatConstant) + if (o instanceof PyFloatConstant) { return ((PyFloatConstant)o).value == value; - else + } else { return false; + } } } @@ -118,7 +121,7 @@ public void put(Code c) throws IOException { module.classfile.addField(name, ci(PyComplex.class), access); c.ldc(new Double(value)); - c.invokestatic("org/python/core/Py", "newImaginary", sig(PyComplex.class, Double.TYPE)); + c.invokestatic(p(Py.class), "newImaginary", sig(PyComplex.class, Double.TYPE)); c.putstatic(module.classfile.name, name, ci(PyComplex.class)); } @@ -129,10 +132,11 @@ @Override public boolean equals(Object o) { - if (o instanceof PyComplexConstant) + if (o instanceof PyComplexConstant) { return ((PyComplexConstant)o).value == value; - else + } else { return false; + } } } @@ -151,8 +155,7 @@ public void put(Code c) throws IOException { module.classfile.addField(name, ci(PyString.class), access); c.ldc(value); - c.invokestatic("org/python/core/PyString", "fromInterned", sig(PyString.class, - String.class)); + c.invokestatic(p(PyString.class), "fromInterned", sig(PyString.class, String.class)); c.putstatic(module.classfile.name, name, ci(PyString.class)); } @@ -163,10 +166,11 @@ @Override public boolean equals(Object o) { - if (o instanceof PyStringConstant) + if (o instanceof PyStringConstant) { return ((PyStringConstant)o).value.equals(value); - else + } else { return false; + } } } @@ -185,8 +189,7 @@ public void put(Code c) throws IOException { module.classfile.addField(name, ci(PyUnicode.class), access); c.ldc(value); - c.invokestatic("org/python/core/PyUnicode", "fromInterned", sig(PyUnicode.class, - String.class)); + c.invokestatic(p(PyUnicode.class), "fromInterned", sig(PyUnicode.class, String.class)); c.putstatic(module.classfile.name, name, ci(PyUnicode.class)); } @@ -197,10 +200,11 @@ @Override public boolean equals(Object o) { - if (o instanceof PyUnicodeConstant) + if (o instanceof PyUnicodeConstant) { return ((PyUnicodeConstant)o).value.equals(value); - else + } else { return false; + } } } @@ -219,7 +223,7 @@ public void put(Code c) throws IOException { module.classfile.addField(name, ci(PyLong.class), access); c.ldc(value); - c.invokestatic("org/python/core/Py", "newLong", sig(PyLong.class, String.class)); + c.invokestatic(p(Py.class), "newLong", sig(PyLong.class, String.class)); c.putstatic(module.classfile.name, name, ci(PyLong.class)); } @@ -230,9 +234,11 @@ @Override public boolean equals(Object o) { - if (o instanceof PyLongConstant) + if (o instanceof PyLongConstant) { return ((PyLongConstant)o).value.equals(value); - else return false; + } else { + return false; + } } } @@ -301,7 +307,7 @@ c.iconst(moreflags); - c.invokestatic("org/python/core/Py", "newCode", sig(PyCode.class, Integer.TYPE, + c.invokestatic(p(Py.class), "newCode", sig(PyCode.class, Integer.TYPE, String[].class, String.class, String.class, Integer.TYPE, Boolean.TYPE, Boolean.TYPE, PyFunctionTable.class, Integer.TYPE, String[].class, String[].class, Integer.TYPE, Integer.TYPE)); @@ -327,14 +333,15 @@ public Module(String name, String filename, boolean linenumbers, long mtime) { this.linenumbers = linenumbers; this.mtime = mtime; - classfile = new ClassFile(name, "org/python/core/PyFunctionTable", + classfile = new ClassFile(name, p(PyFunctionTable.class), ACC_SYNCHRONIZED | ACC_PUBLIC, mtime); constants = new Hashtable<Constant,Constant>(); sfilename = filename; - if (filename != null) + if (filename != null) { this.filename = PyString(filename); - else + } else { this.filename = null; + } codes = new ArrayList<PyCodeConstant>(); futures = new Future(); scopes = new Hashtable<PythonTree,ScopeInfo>(); @@ -349,8 +356,9 @@ private Constant findConstant(Constant c) { Constant ret = constants.get(c); - if (ret != null) + if (ret != null) { return ret; + } ret = c; c.module = this; //More sophisticated name mappings might be nice @@ -374,9 +382,11 @@ public Constant PyString(String value) { return findConstant(new PyStringConstant(value)); } + public Constant PyUnicode(String value) { return findConstant(new PyUnicodeConstant(value)); } + public Constant PyLong(String value) { return findConstant(new PyLongConstant(value)); } @@ -384,14 +394,17 @@ List<PyCodeConstant> codes; private boolean isJavaIdentifier(String s) { char[] chars = s.toCharArray(); - if (chars.length == 0) + if (chars.length == 0) { return false; - if (!Character.isJavaIdentifierStart(chars[0])) + } + if (!Character.isJavaIdentifierStart(chars[0])) { return false; + } for(int i=1; i<chars.length; i++) { - if (!Character.isJavaIdentifierPart(chars[i])) + if (!Character.isJavaIdentifierPart(chars[i])) { return false; + } } return true; } @@ -399,7 +412,9 @@ //XXX: this can probably go away now that we can probably just copy the list. private List<String> toNameAr(List<String> names,boolean nullok) { int sz = names.size(); - if (sz == 0 && nullok) return null; + if (sz == 0 && nullok) { + return null; + } List<String> nameArray = new ArrayList<String>(); nameArray.addAll(names); return nameArray; @@ -461,10 +476,8 @@ c.aload(1); c.ldc("__name__"); - c.invokevirtual("org/python/core/PyFrame", "getname", sig(PyObject.class, - String.class)); - - c.invokevirtual("org/python/core/PyFrame", "setlocal", sig(Void.TYPE, String.class, + c.invokevirtual(p(PyFrame.class), "getname", sig(PyObject.class, String.class)); + c.invokevirtual(p(PyFrame.class), "setlocal", sig(Void.TYPE, String.class, PyObject.class)); } @@ -488,21 +501,19 @@ SymInfo syminf = tbl.get(paramcells.get(i)); c.iconst(syminf.locals_index); c.iconst(syminf.env_index); - c.invokevirtual("org/python/core/PyFrame", "to_cell", sig(Void.TYPE, Integer.TYPE, + c.invokevirtual(p(PyFrame.class), "to_cell", sig(Void.TYPE, Integer.TYPE, Integer.TYPE)); } } - compiler.parse(tree, c, fast_locals, className, classBody, - scope, cflags); + compiler.parse(tree, c, fast_locals, className, classBody, scope, cflags); - // similar to visitResume code in pyasm.py if (scope.generator) { c.label(genswitch); c.aload(1); - c.getfield("org/python/core/PyFrame", "f_lasti", "I"); + c.getfield(p(PyFrame.class), "f_lasti", "I"); Label[] yields = new Label[compiler.yields.size()+1]; yields[0] = start; @@ -543,7 +554,7 @@ public void addInit() throws IOException { Code c = classfile.addMethod("<init>", sig(Void.TYPE, String.class), ACC_PUBLIC); c.aload(0); - c.invokespecial("org/python/core/PyFunctionTable", "<init>", sig(Void.TYPE)); + c.invokespecial(p(PyFunctionTable.class), "<init>", sig(Void.TYPE)); addConstants(c); } @@ -570,8 +581,7 @@ } public void addBootstrap() throws IOException { - Code c = classfile.addMethod(CodeLoader.GET_BOOTSTRAP_METHOD_NAME, - sig(CodeBootstrap.class), + Code c = classfile.addMethod(CodeLoader.GET_BOOTSTRAP_METHOD_NAME, sig(CodeBootstrap.class), ACC_PUBLIC | ACC_STATIC); c.ldc(Type.getType("L" + classfile.name + ";")); c.invokestatic(p(PyRunnableBootstrap.class), PyRunnableBootstrap.REFLECTION_METHOD_NAME, @@ -580,8 +590,7 @@ } public void addConstants(Code c) throws IOException { - classfile.addField("self", "L"+classfile.name+";", - ACC_STATIC|ACC_FINAL); + classfile.addField("self", "L"+classfile.name+";", ACC_STATIC|ACC_FINAL); c.aload(0); c.putstatic(classfile.name, "self", "L"+classfile.name+";"); Enumeration e = constants.elements(); @@ -600,10 +609,8 @@ } public void addFunctions() throws IOException { - Code code = classfile.addMethod( - "call_function", - sig(PyObject.class, Integer.TYPE, PyFrame.class, ThreadState.class), - ACC_PUBLIC); + Code code = classfile.addMethod("call_function", + sig(PyObject.class, Integer.TYPE, PyFrame.class, ThreadState.class), ACC_PUBLIC); code.aload(0); // this code.aload(2); // frame @@ -638,7 +645,7 @@ addFunctions(); - classfile.addInterface("org/python/core/PyRunnable"); + classfile.addInterface(p(PyRunnable.class)); if (sfilename != null) { classfile.setSource(sfilename); } @@ -659,8 +666,7 @@ { if (!err) { try { - Py.warning(Py.SyntaxWarning, msg, - (sfilename != null) ? sfilename : "?", + Py.warning(Py.SyntaxWarning, msg, (sfilename != null) ? sfilename : "?", node.getLine() ,null, Py.None); return; } catch(PyException e) { @@ -676,7 +682,8 @@ CompilerFlags cflags) throws Exception { - compile(node, ostream, name, filename, linenumbers, printResults, cflags, org.python.core.imp.NO_MTIME); + compile(node, ostream, name, filename, linenumbers, printResults, cflags, + org.python.core.imp.NO_MTIME); } public static void compile(mod node, OutputStream ostream, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-10-08 02:33:28
|
Revision: 6847 http://jython.svn.sourceforge.net/jython/?rev=6847&view=rev Author: fwierzbicki Date: 2009-10-08 02:33:20 +0000 (Thu, 08 Oct 2009) Log Message: ----------- Coding standards / Cleanup. Modified Paths: -------------- trunk/jython/src/org/python/compiler/Module.java Modified: trunk/jython/src/org/python/compiler/Module.java =================================================================== --- trunk/jython/src/org/python/compiler/Module.java 2009-10-07 19:16:54 UTC (rev 6846) +++ trunk/jython/src/org/python/compiler/Module.java 2009-10-08 02:33:20 UTC (rev 6847) @@ -1,5 +1,4 @@ // Copyright (c) Corporation for National Research Initiatives - package org.python.compiler; import java.io.IOException; @@ -39,6 +38,7 @@ import static org.python.util.CodegenUtils.*; class PyIntegerConstant extends Constant implements ClassConstants, Opcodes { + final int value; PyIntegerConstant(int value) { @@ -64,15 +64,15 @@ @Override public boolean equals(Object o) { if (o instanceof PyIntegerConstant) { - return ((PyIntegerConstant)o).value == value; + return ((PyIntegerConstant) o).value == value; } else { return false; } } } -class PyFloatConstant extends Constant implements ClassConstants, Opcodes -{ +class PyFloatConstant extends Constant implements ClassConstants, Opcodes { + final double value; PyFloatConstant(double value) { @@ -92,21 +92,21 @@ @Override public int hashCode() { - return (int)value; + return (int) value; } @Override public boolean equals(Object o) { if (o instanceof PyFloatConstant) { - return ((PyFloatConstant)o).value == value; + return ((PyFloatConstant) o).value == value; } else { return false; } } } -class PyComplexConstant extends Constant implements ClassConstants, Opcodes -{ +class PyComplexConstant extends Constant implements ClassConstants, Opcodes { + final double value; PyComplexConstant(double value) { @@ -126,21 +126,21 @@ @Override public int hashCode() { - return (int)value; + return (int) value; } @Override public boolean equals(Object o) { if (o instanceof PyComplexConstant) { - return ((PyComplexConstant)o).value == value; + return ((PyComplexConstant) o).value == value; } else { return false; } } } -class PyStringConstant extends Constant implements ClassConstants, Opcodes -{ +class PyStringConstant extends Constant implements ClassConstants, Opcodes { + final String value; PyStringConstant(String value) { @@ -166,15 +166,15 @@ @Override public boolean equals(Object o) { if (o instanceof PyStringConstant) { - return ((PyStringConstant)o).value.equals(value); + return ((PyStringConstant) o).value.equals(value); } else { return false; } } } -class PyUnicodeConstant extends Constant implements ClassConstants, Opcodes -{ +class PyUnicodeConstant extends Constant implements ClassConstants, Opcodes { + final String value; PyUnicodeConstant(String value) { @@ -200,15 +200,15 @@ @Override public boolean equals(Object o) { if (o instanceof PyUnicodeConstant) { - return ((PyUnicodeConstant)o).value.equals(value); + return ((PyUnicodeConstant) o).value.equals(value); } else { return false; } } } -class PyLongConstant extends Constant implements ClassConstants, Opcodes -{ +class PyLongConstant extends Constant implements ClassConstants, Opcodes { + final String value; PyLongConstant(String value) { @@ -234,15 +234,15 @@ @Override public boolean equals(Object o) { if (o instanceof PyLongConstant) { - return ((PyLongConstant)o).value.equals(value); + return ((PyLongConstant) o).value.equals(value); } else { return false; } } } -class PyCodeConstant extends Constant implements ClassConstants, Opcodes -{ +class PyCodeConstant extends Constant implements ClassConstants, Opcodes { + final String co_name; final int argcount; final List<String> names; @@ -250,19 +250,16 @@ final int co_firstlineno; final boolean arglist, keywordlist; final String fname; - // for nested scopes final List<String> cellvars; final List<String> freevars; final int jy_npurecell; - final int moreflags; - PyCodeConstant(mod tree, String name, boolean fast_locals, String - className, boolean classBody, boolean printResults, int - firstlineno, ScopeInfo scope, org.python.core.CompilerFlags cflags, + PyCodeConstant(mod tree, String name, boolean fast_locals, String className, boolean classBody, + boolean printResults, int firstlineno, ScopeInfo scope, CompilerFlags cflags, Module module) - throws Exception { + throws Exception { this.co_name = name; this.co_firstlineno = firstlineno; @@ -275,7 +272,7 @@ arglist = scope.ac.arglist; keywordlist = scope.ac.keywordlist; argcount = scope.ac.names.size(); - + //Do something to add init_code to tree //XXX: not sure we should be modifying scope.ac in a PyCodeConstant //constructor. @@ -292,16 +289,16 @@ //Better names in the future? if (isJavaIdentifier(name)) { - fname = name+"$"+id; + fname = name + "$" + id; } else { - fname = "f$"+id; + fname = "f$" + id; } //XXX: is fname needed at all, or should we just use "name"? this.name = fname; // !classdef only if (!classBody) { - names = toNameAr(scope.names,false); + names = toNameAr(scope.names, false); } else { names = null; } @@ -328,7 +325,7 @@ } //XXX: this can probably go away now that we can probably just copy the list. - private List<String> toNameAr(List<String> names,boolean nullok) { + private List<String> toNameAr(List<String> names, boolean nullok) { int sz = names.size(); if (sz == 0 && nullok) { return null; @@ -347,7 +344,7 @@ return false; } - for(int i=1; i<chars.length; i++) { + for (int i = 1; i < chars.length; i++) { if (!Character.isJavaIdentifierPart(chars[i])) { return false; } @@ -379,7 +376,7 @@ c.iconst(arglist ? 1 : 0); c.iconst(keywordlist ? 1 : 0); - c.getstatic(module.classfile.name, "self", "L"+module.classfile.name+";"); + c.getstatic(module.classfile.name, "self", "L" + module.classfile.name + ";"); c.iconst(id); @@ -387,38 +384,44 @@ int strArray = CodeCompiler.makeStrings(c, cellvars); c.aload(strArray); c.freeLocal(strArray); - } else + } else { c.aconst_null(); + } if (freevars != null) { int strArray = CodeCompiler.makeStrings(c, freevars); c.aload(strArray); c.freeLocal(strArray); - } else + } else { c.aconst_null(); + } c.iconst(jy_npurecell); c.iconst(moreflags); - c.invokestatic(p(Py.class), "newCode", sig(PyCode.class, Integer.TYPE, - String[].class, String.class, String.class, Integer.TYPE, Boolean.TYPE, - Boolean.TYPE, PyFunctionTable.class, Integer.TYPE, String[].class, - String[].class, Integer.TYPE, Integer.TYPE)); + c.invokestatic(p(Py.class), "newCode", sig(PyCode.class, Integer.TYPE, + String[].class, String.class, String.class, Integer.TYPE, Boolean.TYPE, + Boolean.TYPE, PyFunctionTable.class, Integer.TYPE, String[].class, + String[].class, Integer.TYPE, Integer.TYPE)); c.putstatic(module.classfile.name, name, ci(PyCode.class)); } } -public class Module implements Opcodes, ClassConstants, CompilationContext -{ +public class Module implements Opcodes, ClassConstants, CompilationContext { + ClassFile classfile; Constant filename; String sfilename; Constant mainCode; boolean linenumbers; Future futures; - Hashtable<PythonTree,ScopeInfo> scopes; + Hashtable<PythonTree, ScopeInfo> scopes; + List<PyCodeConstant> codes; long mtime; + /** The pool of Python Constants */ + Hashtable<Constant, Constant> constants; + public Module(String name, String filename, boolean linenumbers) { this(name, filename, linenumbers, org.python.core.imp.NO_MTIME); } @@ -427,8 +430,8 @@ this.linenumbers = linenumbers; this.mtime = mtime; classfile = new ClassFile(name, p(PyFunctionTable.class), - ACC_SYNCHRONIZED | ACC_PUBLIC, mtime); - constants = new Hashtable<Constant,Constant>(); + ACC_SYNCHRONIZED | ACC_PUBLIC, mtime); + constants = new Hashtable<Constant, Constant>(); sfilename = filename; if (filename != null) { this.filename = stringConstant(filename); @@ -437,16 +440,13 @@ } codes = new ArrayList<PyCodeConstant>(); futures = new Future(); - scopes = new Hashtable<PythonTree,ScopeInfo>(); + scopes = new Hashtable<PythonTree, ScopeInfo>(); } public Module(String name) { - this(name, name+".py", true, org.python.core.imp.NO_MTIME); + this(name, name + ".py", true, org.python.core.imp.NO_MTIME); } - // This block of code handles the pool of Python Constants - Hashtable<Constant,Constant> constants; - private Constant findConstant(Constant c) { Constant ret = constants.get(c); if (ret != null) { @@ -455,7 +455,7 @@ ret = c; c.module = this; //More sophisticated name mappings might be nice - c.name = "_"+constants.size(); + c.name = "_" + constants.size(); constants.put(ret, ret); return ret; } @@ -484,25 +484,17 @@ return findConstant(new PyLongConstant(value)); } - List<PyCodeConstant> codes; - PyCodeConstant codeConstant(mod tree, String name, - boolean fast_locals, String className, - boolean classBody, boolean printResults, - int firstlineno, ScopeInfo scope) - throws Exception - { - return codeConstant(tree,name,fast_locals,className,classBody, - printResults,firstlineno,scope,null); + PyCodeConstant codeConstant(mod tree, String name, boolean fast_locals, String className, + boolean classBody, boolean printResults, int firstlineno, ScopeInfo scope) + throws Exception { + return codeConstant(tree, name, fast_locals, className, classBody, + printResults, firstlineno, scope, null); } - PyCodeConstant codeConstant(mod tree, String name, - boolean fast_locals, String className, - boolean classBody, boolean printResults, - int firstlineno, - ScopeInfo scope, - org.python.core.CompilerFlags cflags) - throws Exception - { + PyCodeConstant codeConstant(mod tree, String name, boolean fast_locals, String className, + boolean classBody, boolean printResults, int firstlineno, ScopeInfo scope, + CompilerFlags cflags) + throws Exception { PyCodeConstant code = new PyCodeConstant(tree, name, fast_locals, className, classBody, printResults, firstlineno, scope, cflags, this); @@ -511,9 +503,9 @@ CodeCompiler compiler = new CodeCompiler(this, printResults); Code c = classfile.addMethod( - code.fname, - sig(PyObject.class, PyFrame.class, ThreadState.class), - ACC_PUBLIC); + code.fname, + sig(PyObject.class, PyFrame.class, ThreadState.class), + ACC_PUBLIC); if (classBody) { // Set the class's __module__ to __name__. fails when there's no __name__ @@ -524,7 +516,7 @@ c.ldc("__name__"); c.invokevirtual(p(PyFrame.class), "getname", sig(PyObject.class, String.class)); c.invokevirtual(p(PyFrame.class), "setlocal", sig(Void.TYPE, String.class, - PyObject.class)); + PyObject.class)); } Label genswitch = new Label(); @@ -535,16 +527,16 @@ c.label(start); int nparamcell = scope.jy_paramcells.size(); - if(nparamcell > 0) { + if (nparamcell > 0) { Map<String, SymInfo> tbl = scope.tbl; List<String> paramcells = scope.jy_paramcells; - for(int i = 0; i < nparamcell; i++) { + for (int i = 0; i < nparamcell; i++) { c.aload(1); SymInfo syminf = tbl.get(paramcells.get(i)); c.iconst(syminf.locals_index); c.iconst(syminf.env_index); c.invokevirtual(p(PyFrame.class), "to_cell", sig(Void.TYPE, Integer.TYPE, - Integer.TYPE)); + Integer.TYPE)); } } @@ -555,11 +547,11 @@ c.aload(1); c.getfield(p(PyFrame.class), "f_lasti", "I"); - Label[] yields = new Label[compiler.yields.size()+1]; + Label[] yields = new Label[compiler.yields.size() + 1]; yields[0] = start; for (int i = 1; i < yields.length; i++) { - yields[i] = compiler.yields.get(i-1); + yields[i] = compiler.yields.get(i - 1); } c.tableswitch(0, yields.length - 1, start, yields); } @@ -567,7 +559,7 @@ return code; } - //This block of code writes out the various standard methods + /** This block of code writes out the various standard methods */ public void addInit() throws IOException { Code c = classfile.addMethod("<init>", sig(Void.TYPE, String.class), ACC_PUBLIC); c.aload(0); @@ -596,7 +588,7 @@ c.invokestatic(p(Py.class), "runMain", sig(Void.TYPE, CodeBootstrap.class, String[].class)); c.return_(); } - + public void addBootstrap() throws IOException { Code c = classfile.addMethod(CodeLoader.GET_BOOTSTRAP_METHOD_NAME, sig(CodeBootstrap.class), ACC_PUBLIC | ACC_STATIC); @@ -607,17 +599,17 @@ } void addConstants(Code c) throws IOException { - classfile.addField("self", "L"+classfile.name+";", ACC_STATIC|ACC_FINAL); + classfile.addField("self", "L" + classfile.name + ";", ACC_STATIC | ACC_FINAL); c.aload(0); - c.putstatic(classfile.name, "self", "L"+classfile.name+";"); + c.putstatic(classfile.name, "self", "L" + classfile.name + ";"); Enumeration e = constants.elements(); while (e.hasMoreElements()) { - Constant constant = (Constant)e.nextElement(); + Constant constant = (Constant) e.nextElement(); constant.put(c); } - for(int i=0; i<codes.size(); i++) { + for (int i = 0; i < codes.size(); i++) { PyCodeConstant pyc = codes.get(i); pyc.put(c); } @@ -627,7 +619,7 @@ public void addFunctions() throws IOException { Code code = classfile.addMethod("call_function", - sig(PyObject.class, Integer.TYPE, PyFrame.class, ThreadState.class), ACC_PUBLIC); + sig(PyObject.class, Integer.TYPE, PyFrame.class, ThreadState.class), ACC_PUBLIC); code.aload(0); // this code.aload(2); // frame @@ -635,16 +627,17 @@ Label def = new Label(); Label[] labels = new Label[codes.size()]; int i; - for(i=0; i<labels.length; i++) + for (i = 0; i < labels.length; i++) { labels[i] = new Label(); + } //Get index for function to call code.iload(1); code.tableswitch(0, labels.length - 1, def, labels); - for(i=0; i<labels.length; i++) { + for (i = 0; i < labels.length; i++) { code.label(labels[i]); code.invokevirtual(classfile.name, (codes.get(i)).fname, sig(PyObject.class, - PyFrame.class, ThreadState.class)); + PyFrame.class, ThreadState.class)); code.areturn(); } code.label(def); @@ -670,45 +663,44 @@ } // Implementation of CompilationContext - public Future getFutures() { return futures; } + public Future getFutures() { + return futures; + } - public String getFilename() { return sfilename; } + public String getFilename() { + return sfilename; + } public ScopeInfo getScopeInfo(PythonTree node) { return scopes.get(node); } - public void error(String msg,boolean err,PythonTree node) - throws Exception - { + public void error(String msg, boolean err, PythonTree node) + throws Exception { if (!err) { try { Py.warning(Py.SyntaxWarning, msg, (sfilename != null) ? sfilename : "?", - node.getLine() ,null, Py.None); + node.getLine(), null, Py.None); return; - } catch(PyException e) { - if (!e.match(Py.SyntaxWarning)) + } catch (PyException e) { + if (!e.match(Py.SyntaxWarning)) { throw e; + } } } - throw new ParseException(msg,node); + throw new ParseException(msg, node); } - public static void compile(mod node, OutputStream ostream, - String name, String filename, - boolean linenumbers, boolean printResults, - CompilerFlags cflags) - throws Exception - { + + public static void compile(mod node, OutputStream ostream, String name, String filename, + boolean linenumbers, boolean printResults, CompilerFlags cflags) + throws Exception { compile(node, ostream, name, filename, linenumbers, printResults, cflags, org.python.core.imp.NO_MTIME); } - public static void compile(mod node, OutputStream ostream, - String name, String filename, - boolean linenumbers, boolean printResults, - CompilerFlags cflags, long mtime) - throws Exception - { + public static void compile(mod node, OutputStream ostream, String name, String filename, + boolean linenumbers, boolean printResults, CompilerFlags cflags, long mtime) + throws Exception { Module module = new Module(name, filename, linenumbers, mtime); if (cflags == null) { cflags = new CompilerFlags(); @@ -719,9 +711,9 @@ //Add __doc__ if it exists Constant main = module.codeConstant(node, "<module>", false, null, false, - printResults, 0, - module.getScopeInfo(node), - cflags); + printResults, 0, + module.getScopeInfo(node), + cflags); module.mainCode = main; module.write(ostream); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-10-26 20:28:01
|
Revision: 6907 http://jython.svn.sourceforge.net/jython/?rev=6907&view=rev Author: fwierzbicki Date: 2009-10-26 20:11:44 +0000 (Mon, 26 Oct 2009) Log Message: ----------- Remove unused variable. Modified Paths: -------------- trunk/jython/src/org/python/compiler/Module.java Modified: trunk/jython/src/org/python/compiler/Module.java =================================================================== --- trunk/jython/src/org/python/compiler/Module.java 2009-10-26 19:51:10 UTC (rev 6906) +++ trunk/jython/src/org/python/compiler/Module.java 2009-10-26 20:11:44 UTC (rev 6907) @@ -581,7 +581,6 @@ c.ldc(classfile.name); c.invokespecial(classfile.name, "<init>", sig(Void.TYPE, String.class)); c.invokevirtual(classfile.name, "getMain", sig(PyCode.class)); - String bootstrap = Type.getDescriptor(CodeBootstrap.class); c.invokestatic(p(CodeLoader.class), CodeLoader.SIMPLE_FACTORY_METHOD_NAME, sig(CodeBootstrap.class, PyCode.class)); c.aload(0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |