From: <fwi...@us...> - 2009-10-06 20:33:08
|
Revision: 6843 http://jython.svn.sourceforge.net/jython/?rev=6843&view=rev Author: fwierzbicki Date: 2009-10-06 20:32:55 +0000 (Tue, 06 Oct 2009) Log Message: ----------- Make constants more.... constant in the compiler package. Changed confusing method names of the form Py*() that return constants to *constant. For example PyInteger() -> integerConstant(). Also reduced public interface of compiler package, especially around compiler constants. Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java trunk/jython/src/org/python/compiler/Constant.java trunk/jython/src/org/python/compiler/Module.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-10-06 13:11:06 UTC (rev 6842) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-10-06 20:32:55 UTC (rev 6843) @@ -434,7 +434,7 @@ scope.setup_closure(); scope.dump(); - module.PyCode(new Suite(node,node.getInternalBody()), name, true, + module.codeConstant(new Suite(node,node.getInternalBody()), name, true, className, false, false, node.getLine(), scope, cflags).get(code); @@ -2029,7 +2029,7 @@ scope.setup_closure(); scope.dump(); - module.PyCode(retSuite, name, true, className, + module.codeConstant(retSuite, name, true, className, false, false, node.getLine(), scope, cflags).get(code); if (!makeClosure(scope)) { @@ -2087,7 +2087,7 @@ scope.setup_closure(); scope.dump(); //Make code object out of suite - module.PyCode(new Suite(node,node.getInternalBody()), name, false, name, + module.codeConstant(new Suite(node,node.getInternalBody()), name, false, name, true, false, node.getLine(), scope, cflags).get(code); //Get doc string (if there) @@ -2114,13 +2114,13 @@ @Override public Object visitNum(Num node) throws Exception { if (node.getInternalN() instanceof PyInteger) { - module.PyInteger(((PyInteger) node.getInternalN()).getValue()).get(code); + module.integerConstant(((PyInteger) node.getInternalN()).getValue()).get(code); } else if (node.getInternalN() instanceof PyLong) { - module.PyLong(((PyObject)node.getInternalN()).__str__().toString()).get(code); + module.longConstant(((PyObject)node.getInternalN()).__str__().toString()).get(code); } else if (node.getInternalN() instanceof PyFloat) { - module.PyFloat(((PyFloat) node.getInternalN()).getValue()).get(code); + module.floatConstant(((PyFloat) node.getInternalN()).getValue()).get(code); } else if (node.getInternalN() instanceof PyComplex) { - module.PyComplex(((PyComplex) node.getInternalN()).imag).get(code); + module.complexConstant(((PyComplex) node.getInternalN()).imag).get(code); } return null; } @@ -2257,9 +2257,9 @@ public Object visitStr(Str node) throws Exception { PyString s = (PyString)node.getInternalS(); if (s instanceof PyUnicode) { - module.PyUnicode(s.asString()).get(code); + module.unicodeConstant(s.asString()).get(code); } else { - module.PyString(s.asString()).get(code); + module.stringConstant(s.asString()).get(code); } return null; } @@ -2304,7 +2304,7 @@ java.util.List<stmt> bod = new ArrayList<stmt>(); bod.add(n); - module.PyCode(new Suite(node, bod), "<genexpr>", true, + module.codeConstant(new Suite(node, bod), "<genexpr>", true, className, false, false, node.getLine(), scope, cflags).get(code); Modified: trunk/jython/src/org/python/compiler/Constant.java =================================================================== --- trunk/jython/src/org/python/compiler/Constant.java 2009-10-06 13:11:06 UTC (rev 6842) +++ trunk/jython/src/org/python/compiler/Constant.java 2009-10-06 20:32:55 UTC (rev 6843) @@ -7,11 +7,11 @@ import org.objectweb.asm.Opcodes; abstract class Constant implements Opcodes{ - public Module module; - public static int access = ACC_STATIC | ACC_FINAL; - public String name; + Module module; + static int access = ACC_STATIC | ACC_FINAL; + String name; - public abstract void get(Code mv) throws IOException; + abstract void get(Code mv) throws IOException; - public abstract void put(Code mv) throws IOException; + abstract void put(Code mv) throws IOException; } Modified: trunk/jython/src/org/python/compiler/Module.java =================================================================== --- trunk/jython/src/org/python/compiler/Module.java 2009-10-06 13:11:06 UTC (rev 6842) +++ trunk/jython/src/org/python/compiler/Module.java 2009-10-06 20:32:55 UTC (rev 6843) @@ -38,19 +38,18 @@ import org.python.antlr.base.mod; import static org.python.util.CodegenUtils.*; -class PyIntegerConstant extends Constant implements ClassConstants, Opcodes -{ - int value; +class PyIntegerConstant extends Constant implements ClassConstants, Opcodes { + final int value; - public PyIntegerConstant(int value) { + PyIntegerConstant(int value) { this.value = value; } - public void get(Code c) throws IOException { + void get(Code c) throws IOException { c.getstatic(module.classfile.name, name, ci(PyInteger.class)); } - public void put(Code c) throws IOException { + void put(Code c) throws IOException { module.classfile.addField(name, ci(PyInteger.class), access); c.iconst(value); c.invokestatic(p(Py.class), "newInteger", sig(PyInteger.class, Integer.TYPE)); @@ -74,17 +73,17 @@ class PyFloatConstant extends Constant implements ClassConstants, Opcodes { - double value; + final double value; - public PyFloatConstant(double value) { + PyFloatConstant(double value) { this.value = value; } - public void get(Code c) throws IOException { + void get(Code c) throws IOException { c.getstatic(module.classfile.name, name, ci(PyFloat.class)); } - public void put(Code c) throws IOException { + void put(Code c) throws IOException { module.classfile.addField(name, ci(PyFloat.class), access); c.ldc(new Double(value)); c.invokestatic(p(Py.class), "newFloat", sig(PyFloat.class, Double.TYPE)); @@ -108,17 +107,17 @@ class PyComplexConstant extends Constant implements ClassConstants, Opcodes { - double value; + final double value; - public PyComplexConstant(double value) { + PyComplexConstant(double value) { this.value = value; } - public void get(Code c) throws IOException { + void get(Code c) throws IOException { c.getstatic(module.classfile.name, name, ci(PyComplex.class)); } - public void put(Code c) throws IOException { + void put(Code c) throws IOException { module.classfile.addField(name, ci(PyComplex.class), access); c.ldc(new Double(value)); c.invokestatic(p(Py.class), "newImaginary", sig(PyComplex.class, Double.TYPE)); @@ -142,17 +141,17 @@ class PyStringConstant extends Constant implements ClassConstants, Opcodes { - String value; + final String value; - public PyStringConstant(String value) { + PyStringConstant(String value) { this.value = value; } - public void get(Code c) throws IOException { + void get(Code c) throws IOException { c.getstatic(module.classfile.name, name, ci(PyString.class)); } - public void put(Code c) throws IOException { + void put(Code c) throws IOException { module.classfile.addField(name, ci(PyString.class), access); c.ldc(value); c.invokestatic(p(PyString.class), "fromInterned", sig(PyString.class, String.class)); @@ -176,17 +175,17 @@ class PyUnicodeConstant extends Constant implements ClassConstants, Opcodes { - String value; + final String value; - public PyUnicodeConstant(String value) { + PyUnicodeConstant(String value) { this.value = value; } - public void get(Code c) throws IOException { + void get(Code c) throws IOException { c.getstatic(module.classfile.name, name, ci(PyUnicode.class)); } - public void put(Code c) throws IOException { + void put(Code c) throws IOException { module.classfile.addField(name, ci(PyUnicode.class), access); c.ldc(value); c.invokestatic(p(PyUnicode.class), "fromInterned", sig(PyUnicode.class, String.class)); @@ -210,17 +209,17 @@ class PyLongConstant extends Constant implements ClassConstants, Opcodes { - String value; + final String value; - public PyLongConstant(String value) { + PyLongConstant(String value) { this.value = value; } - public void get(Code c) throws IOException { + void get(Code c) throws IOException { c.getstatic(module.classfile.name, name, ci(PyLong.class)); } - public void put(Code c) throws IOException { + void put(Code c) throws IOException { module.classfile.addField(name, ci(PyLong.class), access); c.ldc(value); c.invokestatic(p(Py.class), "newLong", sig(PyLong.class, String.class)); @@ -244,29 +243,29 @@ class PyCodeConstant extends Constant implements ClassConstants, Opcodes { - public String co_name; - public int argcount; - public List<String> names; - public int id; - public int co_firstlineno; - public boolean arglist, keywordlist; + String co_name; + int argcount; + List<String> names; + int id; + int co_firstlineno; + boolean arglist, keywordlist; String fname; // for nested scopes - public List<String> cellvars; - public List<String> freevars; - public int jy_npurecell; + List<String> cellvars; + List<String> freevars; + int jy_npurecell; - public int moreflags; + int moreflags; - public PyCodeConstant() { + PyCodeConstant() { } - public void get(Code c) throws IOException { + void get(Code c) throws IOException { c.getstatic(module.classfile.name, name, ci(PyCode.class)); } - public void put(Code c) throws IOException { + void put(Code c) throws IOException { module.classfile.addField(name, ci(PyCode.class), access); c.iconst(argcount); @@ -320,7 +319,7 @@ ClassFile classfile; Constant filename; String sfilename; - public Constant mainCode; + Constant mainCode; public boolean linenumbers; Future futures; Hashtable<PythonTree,ScopeInfo> scopes; @@ -338,7 +337,7 @@ constants = new Hashtable<Constant,Constant>(); sfilename = filename; if (filename != null) { - this.filename = PyString(filename); + this.filename = stringConstant(filename); } else { this.filename = null; } @@ -367,27 +366,27 @@ return ret; } - public Constant PyInteger(int value) { + Constant integerConstant(int value) { return findConstant(new PyIntegerConstant(value)); } - public Constant PyFloat(double value) { + Constant floatConstant(double value) { return findConstant(new PyFloatConstant(value)); } - public Constant PyComplex(double value) { + Constant complexConstant(double value) { return findConstant(new PyComplexConstant(value)); } - public Constant PyString(String value) { + Constant stringConstant(String value) { return findConstant(new PyStringConstant(value)); } - public Constant PyUnicode(String value) { + Constant unicodeConstant(String value) { return findConstant(new PyUnicodeConstant(value)); } - public Constant PyLong(String value) { + Constant longConstant(String value) { return findConstant(new PyLongConstant(value)); } @@ -420,20 +419,18 @@ return nameArray; } - private int to_cell; - - public PyCodeConstant PyCode(mod tree, String name, + PyCodeConstant codeConstant(mod tree, String name, boolean fast_locals, String className, boolean classBody, boolean printResults, int firstlineno, ScopeInfo scope) throws Exception { - return PyCode(tree,name,fast_locals,className,classBody, + return codeConstant(tree,name,fast_locals,className,classBody, printResults,firstlineno,scope,null); } - public PyCodeConstant PyCode(mod tree, String name, + PyCodeConstant codeConstant(mod tree, String name, boolean fast_locals, String className, boolean classBody, boolean printResults, int firstlineno, @@ -589,7 +586,7 @@ c.areturn(); } - public void addConstants(Code c) throws IOException { + void addConstants(Code c) throws IOException { classfile.addField("self", "L"+classfile.name+";", ACC_STATIC|ACC_FINAL); c.aload(0); c.putstatic(classfile.name, "self", "L"+classfile.name+";"); @@ -701,7 +698,7 @@ //Add __doc__ if it exists - Constant main = module.PyCode(node, "<module>", false, null, false, + Constant main = module.codeConstant(node, "<module>", false, null, false, printResults, 0, module.getScopeInfo(node), cflags); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |