From: <fwi...@us...> - 2009-10-27 03:00:27
|
Revision: 6912 http://jython.svn.sourceforge.net/jython/?rev=6912&view=rev Author: fwierzbicki Date: 2009-10-27 03:00:16 +0000 (Tue, 27 Oct 2009) Log Message: ----------- Code from Module reaching into internals of CodeCompiler moved to CodeCompiler Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.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-27 02:56:41 UTC (rev 6911) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2009-10-27 03:00:16 UTC (rev 6912) @@ -259,6 +259,41 @@ this.code = code; this.cflags = cflags; + //BEGIN preparse + if (classBody) { + // Set the class's __module__ to __name__. fails when there's no __name__ + code.aload(1); + code.ldc("__module__"); + + code.aload(1); + code.ldc("__name__"); + code.invokevirtual(p(PyFrame.class), "getname", sig(PyObject.class, String.class)); + code.invokevirtual(p(PyFrame.class), "setlocal", sig(Void.TYPE, String.class, + PyObject.class)); + } + + Label genswitch = new Label(); + if (scope.generator) { + code.goto_(genswitch); + } + Label start = new Label(); + code.label(start); + + int nparamcell = scope.jy_paramcells.size(); + if (nparamcell > 0) { + Map<String, SymInfo> tbl = scope.tbl; + java.util.List<String> paramcells = scope.jy_paramcells; + for (int i = 0; i < nparamcell; i++) { + code.aload(1); + SymInfo syminf = tbl.get(paramcells.get(i)); + code.iconst(syminf.locals_index); + code.iconst(syminf.env_index); + code.invokevirtual(p(PyFrame.class), "to_cell", sig(Void.TYPE, Integer.TYPE, + Integer.TYPE)); + } + } + //END preparse + my_scope = scope; tbl = scope.tbl; @@ -287,6 +322,24 @@ code.areturn(); } } + + //BEGIN postparse + + // similar to visitResume code in pyasm.py + if (scope.generator) { + code.label(genswitch); + + code.aload(1); + code.getfield(p(PyFrame.class), "f_lasti", "I"); + Label[] y = new Label[yields.size() + 1]; + + y[0] = start; + for (int i = 1; i < y.length; i++) { + y[i] = yields.get(i - 1); + } + code.tableswitch(0, y.length - 1, start, y); + } + //END postparse } @Override Modified: trunk/jython/src/org/python/compiler/Module.java =================================================================== --- trunk/jython/src/org/python/compiler/Module.java 2009-10-27 02:56:41 UTC (rev 6911) +++ trunk/jython/src/org/python/compiler/Module.java 2009-10-27 03:00:16 UTC (rev 6912) @@ -507,55 +507,7 @@ sig(PyObject.class, PyFrame.class, ThreadState.class), ACC_PUBLIC); - if (classBody) { - // Set the class's __module__ to __name__. fails when there's no __name__ - c.aload(1); - c.ldc("__module__"); - - c.aload(1); - 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)); - } - - Label genswitch = new Label(); - if (scope.generator) { - c.goto_(genswitch); - } - Label start = new Label(); - c.label(start); - - int nparamcell = scope.jy_paramcells.size(); - if (nparamcell > 0) { - Map<String, SymInfo> tbl = scope.tbl; - List<String> paramcells = scope.jy_paramcells; - 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)); - } - } - 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(p(PyFrame.class), "f_lasti", "I"); - 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); - } - c.tableswitch(0, yields.length - 1, start, yields); - } - return code; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |