You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(107) |
Dec
(67) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(76) |
Feb
(125) |
Mar
(72) |
Apr
(13) |
May
(18) |
Jun
(12) |
Jul
(129) |
Aug
(47) |
Sep
(1) |
Oct
(36) |
Nov
(128) |
Dec
(124) |
2002 |
Jan
(59) |
Feb
|
Mar
(14) |
Apr
(14) |
May
(72) |
Jun
(9) |
Jul
(3) |
Aug
(5) |
Sep
(18) |
Oct
(65) |
Nov
(28) |
Dec
(12) |
2003 |
Jan
(10) |
Feb
(2) |
Mar
(4) |
Apr
(33) |
May
(21) |
Jun
(9) |
Jul
(29) |
Aug
(34) |
Sep
(4) |
Oct
(8) |
Nov
(15) |
Dec
(4) |
2004 |
Jan
(26) |
Feb
(12) |
Mar
(11) |
Apr
(9) |
May
(7) |
Jun
|
Jul
(5) |
Aug
|
Sep
(3) |
Oct
(7) |
Nov
(1) |
Dec
(10) |
2005 |
Jan
(2) |
Feb
(72) |
Mar
(16) |
Apr
(39) |
May
(48) |
Jun
(97) |
Jul
(57) |
Aug
(13) |
Sep
(16) |
Oct
(24) |
Nov
(100) |
Dec
(24) |
2006 |
Jan
(15) |
Feb
(34) |
Mar
(33) |
Apr
(31) |
May
(79) |
Jun
(64) |
Jul
(41) |
Aug
(64) |
Sep
(31) |
Oct
(46) |
Nov
(55) |
Dec
(37) |
2007 |
Jan
(32) |
Feb
(61) |
Mar
(11) |
Apr
(58) |
May
(46) |
Jun
(30) |
Jul
(94) |
Aug
(93) |
Sep
(86) |
Oct
(69) |
Nov
(125) |
Dec
(177) |
2008 |
Jan
(169) |
Feb
(97) |
Mar
(74) |
Apr
(113) |
May
(120) |
Jun
(334) |
Jul
(215) |
Aug
(237) |
Sep
(72) |
Oct
(189) |
Nov
(126) |
Dec
(160) |
2009 |
Jan
(180) |
Feb
(45) |
Mar
(98) |
Apr
(140) |
May
(151) |
Jun
(71) |
Jul
(107) |
Aug
(119) |
Sep
(73) |
Oct
(121) |
Nov
(14) |
Dec
(6) |
2010 |
Jan
(13) |
Feb
(9) |
Mar
(10) |
Apr
(64) |
May
(3) |
Jun
(16) |
Jul
(7) |
Aug
(23) |
Sep
(17) |
Oct
(37) |
Nov
(5) |
Dec
(8) |
2011 |
Jan
(10) |
Feb
(11) |
Mar
(77) |
Apr
(11) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Finn B. <bc...@us...> - 2001-03-13 20:19:29
|
Update of /cvsroot/jython/jython/org/python/core In directory usw-pr-cvs1:/tmp/cvs-serv27939 Modified Files: PyFile.java Log Message: Fixed a bug that prevented the 'a' open mode flag from working. Index: PyFile.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyFile.java,v retrieving revision 2.17 retrieving revision 2.18 diff -C2 -r2.17 -r2.18 *** PyFile.java 2001/03/04 18:04:31 2.17 --- PyFile.java 2001/03/13 20:21:27 2.18 *************** *** 25,29 **** void setMode(String mode) { reading = mode.indexOf('r') >= 0; ! writing = mode.indexOf('w') >= 0 || mode.indexOf("+") >= 0; binary = mode.indexOf('b') >= 0; } --- 25,30 ---- void setMode(String mode) { reading = mode.indexOf('r') >= 0; ! writing = mode.indexOf('w') >= 0 || mode.indexOf("+") >= 0 || ! mode.indexOf('a') >= 0; binary = mode.indexOf('b') >= 0; } |
From: Finn B. <bc...@us...> - 2001-03-13 20:17:55
|
Update of /cvsroot/jython/jython/org/python/core In directory usw-pr-cvs1:/tmp/cvs-serv27688 Modified Files: PackageManager.java Log Message: Added abstract addDirectory() and addJarDir() to packagemanager base class. Index: PackageManager.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PackageManager.java,v retrieving revision 2.7 retrieving revision 2.8 diff -C2 -r2.7 -r2.8 *** PackageManager.java 2001/02/02 09:28:36 2.7 --- PackageManager.java 2001/03/13 20:19:53 2.8 *************** *** 43,46 **** --- 43,62 ---- boolean exclpkgs); + /** + * Append a directory to the list of directories searched for + * java packages and java classes. + * + * @param dir A directory. + */ + public abstract void addDirectory(java.io.File dir); + + /** + * Append a directory to the list of directories searched for + * java packages and java classes. + * + * @param dir A directory name. + */ + public abstract void addJarDir(String dir); + /** Basic helper implementation of {@link #doDir}. * It merges information from jpkg {@link PyJavaPackage#clsSet} |
From: Finn B. <bc...@us...> - 2001-03-13 20:17:12
|
Update of /cvsroot/jython/jython/org/python/compiler In directory usw-pr-cvs1:/tmp/cvs-serv27582 Modified Files: Module.java Log Message: Added Kent Johnson's patch to ensure jdk1.1 compilation. Index: Module.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/Module.java,v retrieving revision 2.4 retrieving revision 2.5 diff -C2 -r2.4 -r2.5 *** Module.java 2001/03/08 23:43:51 2.4 --- Module.java 2001/03/13 20:19:10 2.5 *************** *** 345,349 **** int sz = names.size(); if (sz ==0 && nullok) return null; ! return (String[])names.toArray(emptyStringAr); } --- 345,351 ---- int sz = names.size(); if (sz ==0 && nullok) return null; ! String[] nameArray = new String[sz]; ! names.copyInto(nameArray); ! return nameArray; } |
From: Finn B. <bc...@us...> - 2001-03-13 20:13:46
|
Update of /cvsroot/jython/jython/installer In directory usw-pr-cvs1:/tmp/cvs-serv27237 Modified Files: mklist.py Log Message: Added whichdb.py. Index: mklist.py =================================================================== RCS file: /cvsroot/jython/jython/installer/mklist.py,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -r1.11 -r1.12 *** mklist.py 2001/02/22 13:08:59 1.11 --- mklist.py 2001/03/13 20:15:44 1.12 *************** *** 135,138 **** --- 135,139 ---- 'urlparse.py', 'user.py', + 'whichdb.py', 'whrandom.py', 'xdrlib.py', |
From: Finn B. <bc...@us...> - 2001-03-13 20:13:08
|
Update of /cvsroot/jython/htdocs In directory usw-pr-cvs1:/tmp/cvs-serv27123 Modified Files: index.ht Log Message: Article written by Weiqi Gao added. Index: index.ht =================================================================== RCS file: /cvsroot/jython/htdocs/index.ht,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -r1.15 -r1.16 *** index.ht 2001/02/23 20:20:56 1.15 --- index.ht 2001/03/13 20:15:07 1.16 *************** *** 43,47 **** <dl> ! <dt><b>18-dec-2000</b> <dd>Jon Udell <a href="http://www.byte.com/column/BYT20001214S0009">talks</a> about using the JVM to implement other languages, among them JPython. --- 43,51 ---- <dl> ! <dt><b>12-mar-2001</b> ! <dd>Weiqi Gao <a href="http://www.ociweb.com/jnb/archive/jnbMar2001.html">shows</a> ! scripting examples using Jython and Rhino (javascript). ! ! <p><dt><b>18-dec-2000</b> <dd>Jon Udell <a href="http://www.byte.com/column/BYT20001214S0009">talks</a> about using the JVM to implement other languages, among them JPython. |
From: Finn B. <bc...@us...> - 2001-03-13 20:11:21
|
Update of /cvsroot/jython/jython/Lib/jxxload_help In directory usw-pr-cvs1:/tmp/cvs-serv26741 Modified Files: PackageManager.java Log Message: Added addJarDir(). Implementation is now required from the abstract base class. Index: PackageManager.java =================================================================== RCS file: /cvsroot/jython/jython/Lib/jxxload_help/PackageManager.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** PackageManager.java 2001/01/17 02:24:00 1.2 --- PackageManager.java 2001/03/13 20:13:19 1.3 *************** *** 48,51 **** } } ! } --- 48,54 ---- } } ! ! public void addJarDir(String jdir) { ! throw new RuntimeException("addJarDir not supported for reloadable packages"); ! } } |
From: Finn B. <bc...@us...> - 2001-03-13 20:09:05
|
Update of /cvsroot/jython/jython/Doc In directory usw-pr-cvs1:/tmp/cvs-serv26320 Modified Files: differences.ht Log Message: Added description of jython's acceptance of reserved words as identifier in some situations. Index: differences.ht =================================================================== RCS file: /cvsroot/jython/jython/Doc/differences.ht,v retrieving revision 2.8 retrieving revision 2.9 diff -C2 -r2.8 -r2.9 *** differences.ht 2000/11/12 22:22:06 2.8 --- differences.ht 2001/03/13 20:11:03 2.9 *************** *** 32,35 **** --- 32,40 ---- <p><LI>Jython supports continue in a try clause. <I>CPython should be fixed - but don't hold your breath.</I> + + <p><LI>Jython allows keywords to be used as identifier name + in some situations where there are no conflict. This allows + jython to call and override java methods with names like 'print' + and 'exec'. <I>Both behaviors are acceptable.</I> </UL> |
From: Samuele P. <ped...@us...> - 2001-03-11 16:27:39
|
Update of /cvsroot/jython/jython/org/python/compiler In directory usw-pr-cvs1:/tmp/cvs-serv25893 Modified Files: ScopeConstants.java ScopeInfo.java Log Message: nested scopes: consistent classdef&global handling Index: ScopeConstants.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/ScopeConstants.java,v retrieving revision 2.1 retrieving revision 2.2 diff -C2 -r2.1 -r2.2 *** ScopeConstants.java 2001/03/08 23:43:51 2.1 --- ScopeConstants.java 2001/03/11 16:29:31 2.2 *************** *** 4,12 **** public final static int BOUND = 1; ! public final static int GLOBAL = 2; public final static int PARAM = 4; public final static int FROM_PARAM = 8; public final static int CELL = 16; public final static int FREE = 32; public final static int TOPSCOPE = 0; --- 4,14 ---- public final static int BOUND = 1; ! public final static int NGLOBAL = 2; // func scope expl global public final static int PARAM = 4; public final static int FROM_PARAM = 8; public final static int CELL = 16; public final static int FREE = 32; + public final static int CLASS_GLOBAL = 64; // class scope expl global + public final static int GLOBAL = NGLOBAL|CLASS_GLOBAL; // all global public final static int TOPSCOPE = 0; Index: ScopeInfo.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/ScopeInfo.java,v retrieving revision 2.1 retrieving revision 2.2 diff -C2 -r2.1 -r2.2 *** ScopeInfo.java 2001/03/08 23:43:51 2.1 --- ScopeInfo.java 2001/03/11 16:29:31 2.2 *************** *** 23,27 **** System.err.print(name); if ((flags&BOUND) != 0) System.err.print('='); ! if ((flags&GLOBAL) != 0) System.err.print('G'); if ((flags&PARAM) != 0) System.err.print('P'); else if ((flags&FROM_PARAM) != 0) System.err.print('p'); --- 23,28 ---- System.err.print(name); if ((flags&BOUND) != 0) System.err.print('='); ! if ((flags&NGLOBAL) != 0) System.err.print('G'); else // func scope global (affect nested scopes) ! if ((flags&CLASS_GLOBAL) != 0) System.err.print('g'); // vs. class scope global if ((flags&PARAM) != 0) System.err.print('P'); else if ((flags&FROM_PARAM) != 0) System.err.print('p'); *************** *** 56,66 **** public int addGlobal(String name) { SymInfo info = (SymInfo)tbl.get(name); if (info == null) { ! tbl.put(name,new SymInfo(GLOBAL|BOUND)); return -1; } int prev = info.flags; ! info.flags |= GLOBAL|BOUND; return prev; } --- 57,68 ---- public int addGlobal(String name) { + int global = kind==CLASSSCOPE?CLASS_GLOBAL:NGLOBAL; // global kind = func vs. class SymInfo info = (SymInfo)tbl.get(name); if (info == null) { ! tbl.put(name,new SymInfo(global|BOUND)); return -1; } int prev = info.flags; ! info.flags |= global|BOUND; return prev; } *************** *** 126,130 **** int flags = info.flags; if (func) { ! if ((flags&GLOBAL) == 0 && (flags&BOUND) != 0) { if (nested_scopes) { info.flags |= CELL; --- 128,132 ---- int flags = info.flags; if (func) { ! if ((flags&NGLOBAL) == 0 && (flags&BOUND) != 0) { // not func global and bound ? if (nested_scopes) { info.flags |= CELL; *************** *** 209,214 **** continue; } ! if (nested && (up_flags&GLOBAL) != 0) { ! info.flags = GLOBAL|BOUND; continue; } --- 211,216 ---- continue; } ! if (nested && (up_flags&NGLOBAL) != 0) { // ! func global affect nested scopes ! info.flags = NGLOBAL|BOUND; continue; } |
From: Samuele P. <ped...@us...> - 2001-03-10 02:12:00
|
Update of /cvsroot/jython/jython/org/python/compiler In directory usw-pr-cvs1:/tmp/cvs-serv18403 Modified Files: CodeCompiler.java Future.java ScopesCompiler.java Removed Files: LocalsCompiler.java Log Message: fixed typo (in ScopesCompiler.java). fixed error msg passing node to ctr so correct line is reported (in Future.java). fixed long standing and fresh (of mine) spurious emitted getname instead of the correct getglobal (in CodeCompiler.java). Index: CodeCompiler.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/CodeCompiler.java,v retrieving revision 2.12 retrieving revision 2.13 diff -C2 -r2.12 -r2.13 *** CodeCompiler.java 2001/03/08 23:43:51 2.12 --- CodeCompiler.java 2001/03/10 02:13:48 2.13 *************** *** 2267,2282 **** loadFrame(); if (syminf != null) { ! if (fast_locals) { ! if ((syminf.flags&ScopeInfo.GLOBAL) !=0 && optimizeGlobals) { ! code.ldc(name); ! if (mrefs.getglobal == 0) { ! mrefs.getglobal = code.pool.Methodref( ! "org/python/core/PyFrame", "getglobal", ! "(Ljava/lang/String;)Lorg/python/core/PyObject;"); ! } ! code.invokevirtual(mrefs.getglobal); ! return null; } ! if ((syminf.flags&ScopeInfo.GLOBAL)==0 && (syminf.flags&ScopeInfo.CELL)!=0) { code.iconst(syminf.env_index); if (mrefs.getderef == 0) { --- 2267,2285 ---- loadFrame(); if (syminf != null) { ! int flags = syminf.flags; ! if (!my_scope.nested_scopes) flags &= ~ScopeInfo.FREE; ! if ((flags&ScopeInfo.GLOBAL) !=0 || ! optimizeGlobals&&fast_locals&&(flags&(ScopeInfo.BOUND|ScopeInfo.CELL|ScopeInfo.FREE))==0) { ! code.ldc(name); ! if (mrefs.getglobal == 0) { ! mrefs.getglobal = code.pool.Methodref( ! "org/python/core/PyFrame", "getglobal", ! "(Ljava/lang/String;)Lorg/python/core/PyObject;"); } ! code.invokevirtual(mrefs.getglobal); ! return null; ! } ! if (fast_locals) { ! if ((flags&ScopeInfo.CELL) != 0) { code.iconst(syminf.env_index); if (mrefs.getderef == 0) { *************** *** 2288,2292 **** return null; } ! if ((syminf.flags&ScopeInfo.GLOBAL)==0 && (syminf.flags&ScopeInfo.BOUND)!=0) { code.iconst(syminf.locals_index); if (mrefs.getlocal2 == 0) { --- 2291,2295 ---- return null; } ! if ((flags&ScopeInfo.BOUND) != 0) { code.iconst(syminf.locals_index); if (mrefs.getlocal2 == 0) { *************** *** 2299,2303 **** } } ! if (my_scope.nested_scopes && (syminf.flags&ScopeInfo.FREE) != 0) { code.iconst(syminf.env_index); if (mrefs.getderef == 0) { --- 2302,2306 ---- } } ! if ((flags&ScopeInfo.FREE) != 0) { code.iconst(syminf.env_index); if (mrefs.getderef == 0) { Index: Future.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/Future.java,v retrieving revision 2.1 retrieving revision 2.2 diff -C2 -r2.1 -r2.2 *** Future.java 2001/03/08 23:43:51 2.1 --- Future.java 2001/03/10 02:13:48 2.2 *************** *** 36,40 **** continue; } ! throw new ParseException("future feature "+feature+" is not defined"); } return true; --- 36,40 ---- continue; } ! throw new ParseException("future feature "+feature+" is not defined",cand); } return true; *************** *** 45,48 **** --- 45,49 ---- nested_scopes = cflags.nested_scopes; } + if ( node.id != PythonGrammarTreeConstants.JJTFILE_INPUT && node.id != PythonGrammarTreeConstants.JJTSINGLE_INPUT) return; Index: ScopesCompiler.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/ScopesCompiler.java,v retrieving revision 2.1 retrieving revision 2.2 diff -C2 -r2.1 -r2.2 *** ScopesCompiler.java 2001/03/08 23:43:51 2.1 --- ScopesCompiler.java 2001/03/10 02:13:48 2.2 *************** *** 237,241 **** if ((prev&GLOBAL) != 0) continue; String what; ! if ((prev&BOUND) != 0) what = "assignement"; else what = "use"; code_compiler.error("name '"+name+"' declared global after "+what,false,node); } --- 237,241 ---- if ((prev&GLOBAL) != 0) continue; String what; ! if ((prev&BOUND) != 0) what = "assignment"; else what = "use"; code_compiler.error("name '"+name+"' declared global after "+what,false,node); } --- LocalsCompiler.java DELETED --- |
From: Finn B. <bc...@us...> - 2001-03-09 15:31:44
|
Update of /cvsroot/jython/jython/org/python/core In directory usw-pr-cvs1:/tmp/cvs-serv10274 Modified Files: exceptions.java Log Message: Fixed several bugs in SyntaxError. - The class init was never run. - Typo in text attribute. - __str__ was defined wrongly and didn't return a CPython compatible value. Index: exceptions.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/exceptions.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -r1.7 -r1.8 *** exceptions.java 2001/03/04 18:09:29 1.7 --- exceptions.java 2001/03/09 15:33:30 1.8 *************** *** 110,114 **** "Base class for all standard Python exceptions."); ! buildClass(dict, "SyntaxError", "StandardError", "empty__init__", "Invalid syntax"); --- 110,114 ---- "Base class for all standard Python exceptions."); ! buildClass(dict, "SyntaxError", "StandardError", "SyntaxError", "Invalid syntax"); *************** *** 297,309 **** self.__setattr__("lineno", tmp[1]); self.__setattr__("offset", tmp[2]); ! self.__setattr__("texe", tmp[3]); } catch (PyException exc) { ; } } } ! public static PyString SyntaxError__str__(PyObject self) { ! return self.__getattr__("msg").__str__(); } - public static PyObject EnvironmentError(PyObject[] arg, String[] kws) { --- 297,329 ---- self.__setattr__("lineno", tmp[1]); self.__setattr__("offset", tmp[2]); ! self.__setattr__("text", tmp[3]); } catch (PyException exc) { ; } } } ! public static PyString SyntaxError__str__(PyObject[] arg, String[] kws) { ! ArgParser ap = new ArgParser("__init__", arg, kws, "self", "args"); ! PyObject self = ap.getPyObject(0); ! PyString str = self.__getattr__("msg").__str__(); ! PyObject filename = basename(self.__findattr__("filename")); ! PyObject lineno = self.__findattr__("lineno"); ! if (filename instanceof PyString && lineno instanceof PyInteger) ! return new PyString(str + " (" + filename + ", line " + lineno + ")"); ! else if (filename instanceof PyString) ! return new PyString(str + " (" + filename + ")"); ! else if (lineno instanceof PyInteger) ! return new PyString(str + " (line " + lineno + ")"); ! return str; ! } ! ! private static PyObject basename(PyObject filename) { ! if (filename instanceof PyString) { ! int i = ((PyString) filename).rfind(java.io.File.separator); ! if (i >= 0) ! return filename.__getslice__( ! new PyInteger(i+1), new PyInteger(Integer.MAX_VALUE)); ! } ! return filename; } public static PyObject EnvironmentError(PyObject[] arg, String[] kws) { |
From: Finn B. <bc...@us...> - 2001-03-09 08:29:51
|
Update of /cvsroot/jython/jython/org/python/modules In directory usw-pr-cvs1:/tmp/cvs-serv5427 Modified Files: newmodule.java Log Message: function(): Updated to nested scope. The ctor for PyFunction was changed. Index: newmodule.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/modules/newmodule.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** newmodule.java 2001/02/02 11:29:42 1.2 --- newmodule.java 2001/03/09 08:31:36 1.3 *************** *** 41,45 **** String name, PyObject[] argdefs) { ! PyFunction f = new PyFunction(globals, argdefs, code, null); if (name != null) f.__name__ = name; --- 41,45 ---- String name, PyObject[] argdefs) { ! PyFunction f = new PyFunction(globals, argdefs, code, null, null); if (name != null) f.__name__ = name; |
From: Samuele P. <ped...@us...> - 2001-03-08 23:42:07
|
Update of /cvsroot/jython/jython/org/python/compiler In directory usw-pr-cvs1:/tmp/cvs-serv850/compiler Modified Files: CodeCompiler.java Module.java Added Files: CompilerFlags.java Future.java ScopeConstants.java ScopeInfo.java ScopesCompiler.java SymInfo.java Log Message: nested scopes *future* support (as CPython 2.1) --- NEW FILE --- package org.python.compiler; public class CompilerFlags extends Object { public boolean nested_scopes; } --- NEW FILE --- // (C) Copyright 2001 Samuele Pedroni package org.python.compiler; import org.python.parser.*; public class Future extends Object { private boolean nested_scopes; private static final String FUTURE = "__future__"; private boolean check(SimpleNode cand) throws Exception { SimpleNode dotted_name = cand.getChild(0); if (dotted_name.getNumChildren() != 1 || !((String)dotted_name.getChild(0).getInfo()).equals(FUTURE)) return false; int n = cand.getNumChildren(); if (n == 1) { throw new ParseException("future statement does not support import *",cand); } for (int i = 1; i < n; i++) { SimpleNode imp = cand.getChild(i); String feature; switch(imp.id) { default: case PythonGrammarTreeConstants.JJTNAME: feature = (String)imp.getInfo(); break; case PythonGrammarTreeConstants.JJTIMPORT_AS_NAME: feature = (String)imp.getChild(0).getInfo(); break; } // *known* features if (feature.equals("nested_scopes")) { nested_scopes = true; continue; } throw new ParseException("future feature "+feature+" is not defined"); } return true; } public void preprocessFutures(SimpleNode node,CompilerFlags cflags) throws Exception { if (cflags != null) { nested_scopes = cflags.nested_scopes; } if ( node.id != PythonGrammarTreeConstants.JJTFILE_INPUT && node.id != PythonGrammarTreeConstants.JJTSINGLE_INPUT) return; int n = node.getNumChildren(); if (n == 0) return; int beg = 0; if (node.id == PythonGrammarTreeConstants.JJTFILE_INPUT && node.getChild(0).id == PythonGrammarTreeConstants.JJTEXPR_STMT && node.getChild(0).getChild(0).id == PythonGrammarTreeConstants.JJTSTRING) beg++; for (int i = beg; i < n; i++) { SimpleNode stmt = node.getChild(i); if (stmt.id != PythonGrammarTreeConstants.JJTIMPORTFROM) break; stmt.from_future_checked = true; if (!check(stmt)) break; } if (cflags != null) { cflags.nested_scopes = cflags.nested_scopes || nested_scopes; } } public static void checkFromFuture(SimpleNode node) throws Exception { if (node.from_future_checked) return; SimpleNode dotted_name = node.getChild(0); if (dotted_name.getNumChildren() == 1 && ((String)dotted_name.getChild(0).getInfo()).equals(FUTURE)) { throw new ParseException("from __future__ imports must occur at the beginning of the file",node); } node.from_future_checked = true; } public boolean areNestedScopesOn() { return nested_scopes; } } --- NEW FILE --- package org.python.compiler; public interface ScopeConstants { public final static int BOUND = 1; public final static int GLOBAL = 2; public final static int PARAM = 4; public final static int FROM_PARAM = 8; public final static int CELL = 16; public final static int FREE = 32; public final static int TOPSCOPE = 0; public final static int FUNCSCOPE = 1; public final static int CLASSSCOPE = 2; } --- NEW FILE --- // (C) Copyright 2001 Samuele Pedroni package org.python.compiler; import java.util.*; import org.python.parser.SimpleNode; public class ScopeInfo extends Object implements ScopeConstants { public SimpleNode scope_node; public String scope_name; public int level; public int func_level; public void dump() { // for debugging if (org.python.core.Options.verbose < org.python.core.Py.DEBUG) return; for(int i=0; i<level; i++) System.err.print(' '); System.err.print(((kind != CLASSSCOPE)?scope_name:"class "+scope_name)+": "); for (Enumeration e = tbl.keys(); e.hasMoreElements(); ) { String name = (String)e.nextElement(); SymInfo info = (SymInfo)tbl.get(name); int flags = info.flags; System.err.print(name); if ((flags&BOUND) != 0) System.err.print('='); if ((flags&GLOBAL) != 0) System.err.print('G'); if ((flags&PARAM) != 0) System.err.print('P'); else if ((flags&FROM_PARAM) != 0) System.err.print('p'); if ((flags&CELL) != 0) System.err.print('!'); if ((flags&FREE) != 0) System.err.print(",f"); System.err.print(" "); } System.err.println(); } public ScopeInfo(String name,SimpleNode node,int level,int kind,int func_level,ArgListCompiler ac,boolean nested_scopes) { scope_name = name; scope_node = node; this.level = level; this.kind = kind; this.func_level = func_level; this.ac = ac; this.nested_scopes = nested_scopes; } public int kind; public boolean nested_scopes; public boolean unqual_exec; public boolean exec; public boolean from_import_star; public ArgListCompiler ac; public Hashtable tbl = new Hashtable(); public Vector names = new Vector(); public int addGlobal(String name) { SymInfo info = (SymInfo)tbl.get(name); if (info == null) { tbl.put(name,new SymInfo(GLOBAL|BOUND)); return -1; } int prev = info.flags; info.flags |= GLOBAL|BOUND; return prev; } public int local = 0; public void addParam(String name) { tbl.put(name, new SymInfo(PARAM|BOUND,local++)); names.addElement(name); } public void markFromParam() { for (Enumeration e=tbl.elements(); e.hasMoreElements(); ) { SymInfo info = (SymInfo)e.nextElement(); info.flags |= FROM_PARAM; } } public void addBound(String name) { SymInfo info = (SymInfo)tbl.get(name); if (info == null) { tbl.put(name, new SymInfo(BOUND)); return; } info.flags |= BOUND; } public void addUsed(String name) { if (tbl.get(name) == null) { tbl.put(name, new SymInfo(0)); return; } } private final static Object PRESENT = new Object(); public Hashtable inner_free = new Hashtable(); public Vector cellvars = new Vector(); public Vector xxx_paramcells = new Vector(); public int xxx_npurecell; // ?? xxx public int cell; public void cook(ScopeInfo up,CodeCompiler ctxt) throws Exception { if (up == null) return; // top level => nop boolean nested_scopes = this.nested_scopes; boolean func = kind == FUNCSCOPE; Vector purecells = new Vector(); cell = 0; boolean some_inner_free = inner_free.size() > 0; for (Enumeration e = inner_free.keys(); e.hasMoreElements(); ) { String name = (String)e.nextElement(); SymInfo info = (SymInfo)tbl.get(name); if (info == null) { tbl.put(name,new SymInfo(FREE)); continue; } int flags = info.flags; if (func) { if ((flags&GLOBAL) == 0 && (flags&BOUND) != 0) { if (nested_scopes) { info.flags |= CELL; if ((info.flags&PARAM) != 0) xxx_paramcells.addElement(name); cellvars.addElement(name); info.env_index = cell++; if ((flags&PARAM) == 0) purecells.addElement(name); continue; } ctxt.error("local name '"+name+"' in '"+scope_name+"' shadows use as global in nested scopes",false,scope_node); } } else { info.flags |= FREE; } } boolean some_free = false; boolean nested = up.kind != TOPSCOPE; for (Enumeration e = tbl.keys(); e.hasMoreElements(); ) { String name = (String)e.nextElement(); SymInfo info = (SymInfo)tbl.get(name); int flags = info.flags; if (nested && (flags&FREE) != 0) up.inner_free.put(name,PRESENT); if ((flags&(GLOBAL|PARAM|CELL)) == 0) { if ((flags&BOUND) != 0) { // ?? only func // System.err.println("local: "+name); names.addElement(name); info.locals_index = local++; continue; } info.flags |= FREE; some_free = true; if (nested) up.inner_free.put(name,PRESENT); } } if ((xxx_npurecell = purecells.size()) > 0) { int sz = purecells.size(); for (int i = 0; i < sz; i++) { names.addElement(purecells.elementAt(i)); } } if ((unqual_exec || from_import_star)) { if(some_inner_free) dynastuff_trouble(true, ctxt); else if(func_level > 1 && some_free) dynastuff_trouble(false, ctxt); } } private void dynastuff_trouble(boolean inner_free,CodeCompiler ctxt) throws Exception { String illegal; if (unqual_exec && from_import_star) illegal = "function '"+scope_name+"' uses import * and bare exec, which are illegal"; else if (unqual_exec) illegal = "unqualified exec is not allowed in function '"+scope_name+"'"; else illegal = "import * is not allowed in function '"+scope_name+"'"; String why; if (inner_free) why = " because it contains a function with free variables"; else why = " because it contains free variables"; ctxt.error(illegal + why ,nested_scopes,scope_node); } public Vector freevars = new Vector(); public void setup_closure(ScopeInfo up) { if (!nested_scopes) return; int free = cell; // env = cell...,free... Hashtable up_tbl = up.tbl; boolean nested = up.kind != TOPSCOPE; for (Enumeration e = tbl.keys(); e.hasMoreElements(); ) { String name = (String)e.nextElement(); SymInfo info = (SymInfo)tbl.get(name); int flags = info.flags; if ((flags&FREE) != 0) { SymInfo up_info = (SymInfo)up_tbl.get(name); if (up_info != null) { // ?? differs from CPython -- what is the intended behaviour? int up_flags = up_info.flags; if ((up_flags&(CELL|FREE)) != 0) { info.env_index = free++; freevars.addElement(name); continue; } if (nested && (up_flags&GLOBAL) != 0) { info.flags = GLOBAL|BOUND; continue; } } info.flags &= ~FREE; } } } } --- NEW FILE --- // (C) Copyright 2001 Samuele Pedroni package org.python.compiler; import org.python.parser.*; import java.util.*; public class ScopesCompiler extends Visitor implements ScopeConstants { private CodeCompiler code_compiler; private boolean nested_scopes = false; private Stack scopes; private ScopeInfo cur = null; private int mode; private static final int GET=0; private static final int SET=1; private static final int DEL=2; private static final int AUGSET=4; private int level = 0; private int func_level = 0; public ScopesCompiler(CodeCompiler code_compiler) { // ?? polish this.code_compiler = code_compiler; scopes = new Stack(); mode = GET; String nested_scopes_opt = org.python.core.PySystemState.registry.getProperty("python.xfutures.nested_scopes"); if (nested_scopes_opt != null && nested_scopes_opt.equals("on")) nested_scopes = true; else nested_scopes = code_compiler.futures.areNestedScopesOn(); // System.err.println("nested-scopes: "+nested_scopes); } public Object set(SimpleNode node) throws Exception { return modal(node,SET); } public Object del(SimpleNode node) throws Exception { return modal(node,DEL); } public Object augset(SimpleNode node) throws Exception { return modal(node,AUGSET); } public Object modal(SimpleNode node, int newmode)throws Exception { mode = newmode; node.visit(this); mode = GET; return null; } public void beginScope(String name,int kind,SimpleNode node,ArgListCompiler ac) { if (cur != null) { scopes.push(cur); } if (kind == FUNCSCOPE) func_level++; node.scope = cur = new ScopeInfo(name,node,level++,kind,func_level,ac,nested_scopes); } public void endScope() throws Exception { if (cur.kind == FUNCSCOPE) func_level--; level--; ScopeInfo up = (!scopes.empty())?(ScopeInfo)scopes.pop():null; cur.cook(up,code_compiler); cur.dump(); // dbg cur = up; } public void parse(SimpleNode node) throws Exception { node.visit(this); } public Object single_input(SimpleNode node) throws Exception { beginScope("<single-top>",TOPSCOPE,node,null); suite(node); endScope(); return null; } public Object file_input(SimpleNode node) throws Exception { beginScope("<file-top>",TOPSCOPE,node,null); suite(node); endScope(); return null; } public Object eval_input(SimpleNode node) throws Exception { beginScope("<eval-top>",TOPSCOPE,node,null); return_stmt(node); endScope(); return null; } private String def(SimpleNode node) { String name = (String)node.getChild(0).getInfo(); cur.addBound(name); return name; } public Object funcdef(SimpleNode node) throws Exception { String my_name = def(node); ArgListCompiler ac = new ArgListCompiler(); SimpleNode suite; if (node.getNumChildren() == 3) { suite = node.getChild(2); //Parse arguments node.getChild(1).visit(ac); } else { suite = node.getChild(1); } SimpleNode[] defaults = ac.getDefaults(); int defc = defaults.length; for(int i=0; i<defc; i++) { defaults[i].visit(this); } beginScope(my_name,FUNCSCOPE,node,ac); int n = ac.names.size(); for (int i=0; i<n; i++) { cur.addParam((String)ac.names.elementAt(i)); } ac.init_code.visit(this); cur.markFromParam(); suite.visit(this); endScope(); return null; } public Object expr_stmt(SimpleNode node) throws Exception { int n = node.getNumChildren(); node.getChild(n-1).visit(this); for (int i=0; i<n-1; i++) { set(node.getChild(i)); } return null; } public Object print_ext(SimpleNode node) throws Exception { node.getChild(0).visit(this); return null; } public Object print_stmt(SimpleNode node) throws Exception { int n = node.getNumChildren(); if ( n > 0 ) { for (int i=0; i<n-1; i++) { node.getChild(i).visit(this); } if(node.getChild(n-1).id != PythonGrammarTreeConstants.JJTCOMMA) node.getChild(n-1).visit(this); } return null; } public Object del_stmt(SimpleNode node) throws Exception { int n = node.getNumChildren(); for (int i=0; i<n; i++) { del(node.getChild(i)); } return null; } public Object pass_stmt(SimpleNode n) throws Exception { return null; } public Object break_stmt(SimpleNode n) throws Exception { return null; } public Object continue_stmt(SimpleNode n) throws Exception { return null; } public Object return_stmt(SimpleNode node) throws Exception { if (node.getNumChildren() == 1) node.getChild(0).visit(this); return null; } public void stmt(SimpleNode node) throws Exception { int n = node.getNumChildren(); for (int i=0; i<n; i++) node.getChild(i).visit(this); } public Object raise_stmt(SimpleNode node) throws Exception { stmt(node); return null; } public Object Import(SimpleNode node) throws Exception { int n = node.getNumChildren(); for(int i = 0; i < n; i++) { SimpleNode imp = node.getChild(i); switch(imp.id) { case PythonGrammarTreeConstants.JJTDOTTED_NAME: cur.addBound((String)imp.getChild(0).getInfo()); break; case PythonGrammarTreeConstants.JJTDOTTED_AS_NAME: cur.addBound((String)imp.getChild(1).getInfo()); break; } } return null; } public Object ImportFrom(SimpleNode node) throws Exception { Future.checkFromFuture(node); // future stmt support int n = node.getNumChildren(); if (n == 1) { cur.from_import_star = true; return null; } for (int i = 1; i < n; i++) { SimpleNode imp = node.getChild(i); switch(imp.id) { case PythonGrammarTreeConstants.JJTNAME: cur.addBound((String)imp.getInfo()); break; case PythonGrammarTreeConstants.JJTIMPORT_AS_NAME: cur.addBound((String)imp.getChild(1).getInfo()); break; } } return null; } public Object global_stmt(SimpleNode node) throws Exception { int n = node.getNumChildren(); for(int i = 0; i < n; i++) { String name = (String)node.getChild(i).getInfo(); int prev = cur.addGlobal(name); if (prev >= 0) { if ((prev&FROM_PARAM) != 0) code_compiler.error("name '"+name+"' is local and global",true,node); if ((prev&GLOBAL) != 0) continue; String what; if ((prev&BOUND) != 0) what = "assignement"; else what = "use"; code_compiler.error("name '"+name+"' declared global after "+what,false,node); } } return null; } public Object exec_stmt(SimpleNode node) throws Exception { cur.exec = true; int n = node.getNumChildren(); if (n == 1) cur.unqual_exec = true; for (int i = 0; i < n; i++) node.getChild(i).visit(this); return null; } public Object assert_stmt(SimpleNode node) throws Exception { stmt(node); return null; } public Object if_stmt(SimpleNode node) throws Exception { stmt(node); return null; } public Object while_stmt(SimpleNode node) throws Exception { stmt(node); return null; } public Object for_stmt(SimpleNode node) throws Exception { if (mode != GET) illassign(node); set(node.getChild(0)); node.getChild(1).visit(this); node.getChild(2).visit(this); if (node.getNumChildren()>3) node.getChild(3).visit(this); return null; } public Object try_stmt(SimpleNode node) throws Exception { int n = node.getNumChildren(); for (int i=0; i<n; i++) { if (i%2 == 1 && i != n-1) { switch(node.getChild(i).getNumChildren()) { case 2: set(node.getChild(i).getChild(1)); case 1: node.getChild(i).getChild(0).visit(this); } continue; } node.getChild(i).visit(this); } return null; } public Object suite(SimpleNode node) throws Exception { stmt(node); return null; } private static void illassign(SimpleNode node) throws Exception { String target = "operator"; if (node.id == PythonGrammarTreeConstants.JJTCALL_OP) { target = "function call"; } else if ((node.id == PythonGrammarTreeConstants.JJTFOR_STMT)) { target = "list comprehension"; } throw new ParseException("can't assign to "+target,node); } public void binaryop(SimpleNode node) throws Exception { if (mode != GET) illassign(node); node.getChild(0).visit(this); node.getChild(1).visit(this); } public void unaryop(SimpleNode node) throws Exception { if (mode != GET) illassign(node); node.getChild(0).visit(this); } public Object or_boolean(SimpleNode node) throws Exception { binaryop(node); return null; } public Object and_boolean(SimpleNode node) throws Exception { binaryop(node); return null; } public Object not_1op(SimpleNode node) throws Exception { unaryop(node); return null; } public Object comparision(SimpleNode node) throws Exception { if (mode != GET) illassign(node); int n = node.getNumChildren(); for (int i=0; i<n; i++) { if (i%2 == 0) node.getChild(i).visit(this); } return null; } public Object or_2op(SimpleNode node) throws Exception { binaryop(node); return null; } public Object xor_2op(SimpleNode node) throws Exception { binaryop(node); return null; } public Object and_2op(SimpleNode node) throws Exception { binaryop(node); return null; } public Object lshift_2op(SimpleNode node) throws Exception { binaryop(node); return null; } public Object rshift_2op(SimpleNode node) throws Exception { binaryop(node); return null; } public Object add_2op(SimpleNode node) throws Exception { binaryop(node); return null; } public Object sub_2op(SimpleNode node) throws Exception { binaryop(node); return null; } public Object mul_2op(SimpleNode node) throws Exception { binaryop(node); return null; } public Object div_2op(SimpleNode node) throws Exception { binaryop(node); return null; } public Object mod_2op(SimpleNode node) throws Exception { binaryop(node); return null; } public Object pos_1op(SimpleNode node) throws Exception { unaryop(node); return null; } public Object neg_1op(SimpleNode node) throws Exception { unaryop(node); return null; } public Object invert_1op(SimpleNode node) throws Exception { unaryop(node); return null; } public Object pow_2op(SimpleNode node) throws Exception { binaryop(node); return null; } public Object str_1op(SimpleNode node) throws Exception { unaryop(node); return null; } public Object strjoin(SimpleNode node) throws Exception { binaryop(node); return null; } public Object Call_Op(SimpleNode node) throws Exception { if (mode != GET) illassign(node); node.getChild(0).visit(this); if (node.getNumChildren()>1) { SimpleNode args=node.getChild(1); int n = args.getNumChildren(); for (int i=0; i<n; i++) { SimpleNode arg = args.getChild(i); switch(arg.id) { case PythonGrammarTreeConstants.JJTKEYWORD: arg.getChild(1).visit(this); break; case PythonGrammarTreeConstants.JJTEXTRAARGVALUELIST: case PythonGrammarTreeConstants.JJTEXTRAKEYWORDVALUELIST: arg.getChild(0).visit(this); break; default: arg.visit(this); } } } return null; } public Object Index_Op(SimpleNode node) throws Exception { int prevmode= mode; mode = GET; node.getChild(0).visit(this); node.getChild(1).visit(this); mode = prevmode; return null; } public Object Dot_Op(SimpleNode node) throws Exception { int prevmode = mode; mode = GET; node.getChild(0).visit(this); mode = prevmode; return null; } public Object tuple(SimpleNode node) throws Exception { if (mode ==AUGSET) { throw new ParseException( "augmented assign to tuple not possible", node); } int n = node.getNumChildren(); if (n > 0) { for (int i=0; i<n-1; i++) node.getChild(i).visit(this); if (node.getChild(n-1).id != PythonGrammarTreeConstants.JJTCOMMA) node.getChild(n-1).visit(this); } return null; } public Object fplist(SimpleNode node) throws Exception { return list(node); } public Object list(SimpleNode node) throws Exception { if (mode ==AUGSET) { throw new ParseException( "augmented assign to list not possible", node); } int n = node.getNumChildren(); if (n > 0) { for (int i=0; i<n-1; i++) node.getChild(i).visit(this); if (node.getChild(n-1).id != PythonGrammarTreeConstants.JJTCOMMA) node.getChild(n-1).visit(this); } return null; } public Object list_iter(SimpleNode node) throws Exception { if (node.getNumChildren() == 1) node.getChild(0).visit(this); return null; } public Object dictionary(SimpleNode node) throws Exception { if (mode != GET) illassign(node); stmt(node); return null; } public Object lambdef(SimpleNode node) throws Exception { if (mode != GET) illassign(node); ArgListCompiler ac = new ArgListCompiler(); SimpleNode expr; if (node.getNumChildren() == 2) { expr = node.getChild(1); //Parse arguments node.getChild(0).visit(ac); } else { expr = node.getChild(0); } SimpleNode[] defaults = ac.getDefaults(); int defc = defaults.length; for(int i=0; i<defc; i++) { defaults[i].visit(this); } beginScope("<lambda>",FUNCSCOPE,node,ac); int n = ac.names.size(); for (int i=0; i<n; i++) { cur.addParam((String)ac.names.elementAt(i)); } ac.init_code.visit(this); cur.markFromParam(); expr.visit(this); endScope(); return null; } public Object Ellipses(SimpleNode n) throws Exception { return null; } public Object Slice(SimpleNode node) throws Exception { int n = node.getNumChildren(); for (int i=0; i<n; i++) { SimpleNode snode = node.getChild(i); if (snode.id != PythonGrammarTreeConstants.JJTCOLON) { snode.visit(this); } } return null; } public Object classdef(SimpleNode node) throws Exception { String cl_name = def(node); int n = node.getNumChildren(); SimpleNode suite = node.getChild(n-1); for (int i=1; i<n-1; i++) node.getChild(i).visit(this); beginScope(cl_name,CLASSSCOPE,node,null); suite.visit(this); endScope(); return null; } public Object Int(SimpleNode node) throws Exception { if (mode != GET) illassign(node); return null; } public Object Float(SimpleNode node) throws Exception { if (mode != GET) illassign(node); return null; } public Object Complex(SimpleNode node) throws Exception { if (mode != GET) illassign(node); return null; } public Object Name(SimpleNode node) throws Exception { String name = (String)node.getInfo(); if ( mode != GET) cur.addBound(name); else cur.addUsed(name); return null; } public Object String(SimpleNode node) throws Exception { if (mode != GET) illassign(node); return null; } public void aug_assign(SimpleNode node) throws Exception { augset(node.getChild(0)); node.getChild(1).visit(this); } public Object aug_plus(SimpleNode node) throws Exception { aug_assign(node); return null; } public Object aug_minus(SimpleNode node) throws Exception { aug_assign(node); return null; } public Object aug_multiply(SimpleNode node) throws Exception { aug_assign(node); return null; } public Object aug_divide(SimpleNode node) throws Exception { aug_assign(node); return null; } public Object aug_modulo(SimpleNode node) throws Exception { aug_assign(node); return null; } public Object aug_and(SimpleNode node) throws Exception { aug_assign(node); return null; } public Object aug_or(SimpleNode node) throws Exception { aug_assign(node); return null; } public Object aug_xor(SimpleNode node) throws Exception { aug_assign(node); return null; } public Object aug_lshift(SimpleNode node) throws Exception { aug_assign(node); return null; } public Object aug_rshift(SimpleNode node) throws Exception { aug_assign(node); return null; } public Object aug_power(SimpleNode node) throws Exception { aug_assign(node); return null; } } --- NEW FILE --- package org.python.compiler; public class SymInfo extends Object { public SymInfo(int flags) { this.flags = flags; } public SymInfo(int flags,int locals_index) { this.flags = flags; this.locals_index = locals_index; } public int flags; public int locals_index; public int env_index; } Index: CodeCompiler.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/CodeCompiler.java,v retrieving revision 2.11 retrieving revision 2.12 diff -C2 -r2.11 -r2.12 *** CodeCompiler.java 2001/02/07 09:21:23 2.11 --- CodeCompiler.java 2001/03/08 23:43:51 2.12 *************** *** 4,7 **** --- 4,10 ---- import org.python.parser.*; + import org.python.core.Py; + import org.python.core.PyObject; + import org.python.core.PyException; import java.io.IOException; import java.util.Stack; *************** *** 31,36 **** public boolean fast_locals, print_results; ! public Hashtable locals; ! public Hashtable globals; boolean optimizeGlobals = true; public Vector names; --- 34,42 ---- public boolean fast_locals, print_results; ! ! public Future futures; ! public Hashtable tbl; ! public ScopeInfo my_scope; ! boolean optimizeGlobals = true; public Vector names; *************** *** 161,167 **** public void parse(SimpleNode node, Code code, boolean fast_locals, String className, ! boolean classBody, ArgListCompiler ac) throws Exception { --- 167,186 ---- + public void error(String msg,boolean err,SimpleNode node) throws Exception { + if (!err) { + try { + Py.warning(Py.SyntaxWarning,msg,(module.sfilename!=null)?module.sfilename:"?", + node.beginLine,null,Py.None); + return; + } catch(PyException e) { + if (!Py.matchException(e,Py.SyntaxWarning)) throw e; + } + } + throw new ParseException(msg,node); + } + public void parse(SimpleNode node, Code code, boolean fast_locals, String className, ! boolean classBody, ScopeInfo scope) throws Exception { *************** *** 170,185 **** this.code = code; ! //Check out locals if fast_locals is on ! LocalsCompiler lc = new LocalsCompiler(); ! int n = ac.names.size(); ! for (int i=0; i<n; i++) { ! lc.addLocal((String)ac.names.elementAt(i)); } ! lc.parse(node); ! names = lc.names; ! locals = lc.locals; ! globals = lc.globals; ! optimizeGlobals = lc.optimizeGlobals; mode = GET; --- 189,204 ---- this.code = code; ! if (scope == null) { ! futures = new Future(); ! futures.preprocessFutures(node,null); ! new ScopesCompiler(this).parse(node); ! scope = node.scope; } ! ! my_scope = scope; ! names = scope.names; ! tbl = scope.tbl; ! optimizeGlobals = !scope.exec&&!scope.from_import_star; mode = GET; *************** *** 190,194 **** loadFrame(); code.invokevirtual("org/python/core/PyFrame", "getf_locals", ! "()Lorg/python/core/PyObject;"); code.areturn(); } else { --- 209,213 ---- loadFrame(); code.invokevirtual("org/python/core/PyFrame", "getf_locals", ! "()Lorg/python/core/PyObject;"); code.areturn(); } else { *************** *** 295,308 **** } ! int f_globals, PyFunction_init; public Object funcdef(SimpleNode node) throws Exception { String name = getName(node.getChild(0)); - ArgListCompiler ac = new ArgListCompiler(); SimpleNode suite; if (node.getNumChildren() == 3) { suite = node.getChild(2); //Parse arguments - node.getChild(1).visit(ac); } else { suite = node.getChild(1); --- 314,360 ---- } ! int getclosure; ! ! public boolean makeClosure(Vector freenames) throws Exception { ! if (freenames == null) return false; ! int n = freenames.size(); ! if (n == 0) return false; ! ! if (mrefs.getclosure == 0) { ! mrefs.getclosure = code.pool.Methodref( ! "org/python/core/PyFrame", "getclosure", ! "(I)Lorg/python/core/PyObject;"); ! } ! ! int tmp = code.getLocal(); ! code.iconst(n); ! code.anewarray(code.pool.Class("org/python/core/PyObject")); ! code.astore(tmp); + for(int i=0; i<n; i++) { + code.aload(tmp); + code.iconst(i); + code.aload(1); // get frame + code.iconst(((SymInfo)tbl.get(freenames.elementAt(i))).env_index); + code.invokevirtual(getclosure); + code.aastore(); + } + + code.aload(tmp); + code.freeLocal(tmp); + + return true; + } + + + + int f_globals, PyFunction_init, PyFunction_closure_init; + public Object funcdef(SimpleNode node) throws Exception { String name = getName(node.getChild(0)); SimpleNode suite; if (node.getNumChildren() == 3) { suite = node.getChild(2); //Parse arguments } else { suite = node.getChild(1); *************** *** 321,337 **** code.getfield(mrefs.f_globals); ! makeArray(ac.getDefaults()); ! ! module.PyCode(suite, name, ac, true, className, false, false, ! node.beginLine).get(code); ! getDocString(suite); ! if (mrefs.PyFunction_init == 0) { ! mrefs.PyFunction_init = code.pool.Methodref( "org/python/core/PyFunction", "<init>", "(Lorg/python/core/PyObject;[Lorg/python/core/PyObject;Lorg/python/core/PyCode;Lorg/python/core/PyObject;)V"); } - code.invokespecial(mrefs.PyFunction_init); set(node.getChild(0)); --- 373,403 ---- code.getfield(mrefs.f_globals); ! makeArray(node.scope.ac.getDefaults()); ! ! node.scope.setup_closure(my_scope); ! node.scope.dump(); ! module.PyCode(suite, name, true, className, false, false, ! node.beginLine, node.scope).get(code); ! Vector freenames = node.scope.freevars; ! node.scope = null; // release scope info ! getDocString(suite); ! if (!makeClosure(freenames)) { ! if (mrefs.PyFunction_init == 0) { ! mrefs.PyFunction_init = code.pool.Methodref( "org/python/core/PyFunction", "<init>", "(Lorg/python/core/PyObject;[Lorg/python/core/PyObject;Lorg/python/core/PyCode;Lorg/python/core/PyObject;)V"); + } + code.invokespecial(mrefs.PyFunction_init); + } else { + if (mrefs.PyFunction_closure_init == 0) { + mrefs.PyFunction_closure_init = code.pool.Methodref( + "org/python/core/PyFunction", "<init>", + "(Lorg/python/core/PyObject;[Lorg/python/core/PyObject;Lorg/python/core/PyCode;Lorg/python/core/PyObject;[Lorg/python/core/PyObject;)V"); + } + code.invokespecial(mrefs.PyFunction_closure_init); + } set(node.getChild(0)); *************** *** 628,631 **** --- 694,698 ---- public Object ImportFrom(SimpleNode node) throws Exception { + Future.checkFromFuture(node); // future stmt support setline(node); String name = (String)node.getChild(0).visit(this); *************** *** 677,685 **** public Object global_stmt(SimpleNode node) throws Exception { - int n = node.getNumChildren(); - for (int i=0; i<n; i++) { - Object name = node.getChild(i).getInfo(); - globals.put(name, name); - } return null; } --- 744,747 ---- *************** *** 716,720 **** public int assert1, assert2; ! public Object assert_stmt(SimpleNode node) throws Exception { setline(node); Label end_of_assert = code.getLabel(); --- 778,782 ---- public int assert1, assert2; ! public Object assert_stmt(SimpleNode node) throws Exception { // ?? pending __debug__ should be treated as temp global setline(node); Label end_of_assert = code.getLabel(); *************** *** 1875,1881 **** public int PyTuple_init, PyList_init, PyDictionary_init; public Object tuple(SimpleNode node) throws Exception { ! if (mode ==AUGSET) throw new ParseException( ! "augmented assign to tuple not possible", node); if (mode == SET) return seqSet(node); if (mode == DEL) return seqDel(node); --- 1937,1943 ---- public int PyTuple_init, PyList_init, PyDictionary_init; public Object tuple(SimpleNode node) throws Exception { ! /* if (mode ==AUGSET) throw new ParseException( ! "augmented assign to tuple not possible", node); */ if (mode == SET) return seqSet(node); if (mode == DEL) return seqDel(node); *************** *** 1899,1905 **** public Object list(SimpleNode node) throws Exception { ! if (mode ==AUGSET) throw new ParseException( ! "augmented assign to list not possible", node); if (node.getNumChildren() > 1 && node.getChild(1).id == --- 1961,1967 ---- public Object list(SimpleNode node) throws Exception { ! /* if (mode ==AUGSET) throw new ParseException( ! "augmented assign to list not possible", node); */ if (node.getNumChildren() > 1 && node.getChild(1).id == *************** *** 2004,2016 **** } ! public int PyFunction_init1; public Object lambdef(SimpleNode node) throws Exception { String name = "<lambda>"; - ArgListCompiler ac = new ArgListCompiler(); SimpleNode suite; if (node.getNumChildren() == 2) { suite = node.getChild(1); - //Parse arguments - node.getChild(0).visit(ac); } else { suite = node.getChild(0); --- 2066,2075 ---- } ! public int PyFunction_init1,PyFunction_closure_init1; public Object lambdef(SimpleNode node) throws Exception { String name = "<lambda>"; SimpleNode suite; if (node.getNumChildren() == 2) { suite = node.getChild(1); } else { suite = node.getChild(0); *************** *** 2034,2048 **** code.getfield(mrefs.f_globals); ! makeArray(ac.getDefaults()); ! ! module.PyCode(retSuite, name, ac, true, className, ! false, false, node.beginLine).get(code); ! ! if (mrefs.PyFunction_init1 == 0) { ! mrefs.PyFunction_init1 = code.pool.Methodref( "org/python/core/PyFunction", "<init>", "(Lorg/python/core/PyObject;[Lorg/python/core/PyObject;Lorg/python/core/PyCode;)V"); } ! code.invokespecial(mrefs.PyFunction_init1); return null; } --- 2093,2121 ---- code.getfield(mrefs.f_globals); ! makeArray(node.scope.ac.getDefaults()); ! ! node.scope.setup_closure(my_scope); ! node.scope.dump(); ! module.PyCode(retSuite, name, true, className, ! false, false, node.beginLine, node.scope).get(code); ! Vector freenames = node.scope.freevars; ! node.scope = null; // release scope info ! ! if (!makeClosure(freenames)) { ! if (mrefs.PyFunction_init1 == 0) { ! mrefs.PyFunction_init1 = code.pool.Methodref( "org/python/core/PyFunction", "<init>", "(Lorg/python/core/PyObject;[Lorg/python/core/PyObject;Lorg/python/core/PyCode;)V"); + } + code.invokespecial(mrefs.PyFunction_init1); + } else { + if (mrefs.PyFunction_closure_init1 == 0) { + mrefs.PyFunction_closure_init1 = code.pool.Methodref( + "org/python/core/PyFunction", "<init>", + "(Lorg/python/core/PyObject;[Lorg/python/core/PyObject;Lorg/python/core/PyCode;[Lorg/python/core/PyObject;)V"); + } + code.invokespecial(mrefs.PyFunction_closure_init1); } ! return null; } *************** *** 2091,2095 **** } ! public int makeClass; public Object classdef(SimpleNode node) throws Exception { setline(node); --- 2164,2168 ---- } ! public int makeClass,makeClass_closure; public Object classdef(SimpleNode node) throws Exception { setline(node); *************** *** 2107,2114 **** makeArray(bases); //Make code object out of suite ! module.PyCode(node.getChild(n-1), name, ! new ArgListCompiler(), false, name, true, false, ! node.beginLine).get(code); //Get doc string (if there) --- 2180,2190 ---- makeArray(bases); + node.scope.setup_closure(my_scope); + node.scope.dump(); //Make code object out of suite ! module.PyCode(node.getChild(n-1), name, false, name, true, false, ! node.beginLine, node.scope).get(code); ! Vector freenames = node.scope.freevars; ! node.scope = null; // release scope info //Get doc string (if there) *************** *** 2116,2126 **** //Make class out of name, bases, and code ! if (mrefs.makeClass == 0) { ! mrefs.makeClass = code.pool.Methodref( "org/python/core/Py", "makeClass", "(Ljava/lang/String;[Lorg/python/core/PyObject;Lorg/python/core/PyCode;Lorg/python/core/PyObject;)Lorg/python/core/PyObject;"); } ! code.invokestatic(mrefs.makeClass); ! //Assign this new class to the given name set(node.getChild(0)); --- 2192,2211 ---- //Make class out of name, bases, and code ! if (!makeClosure(freenames)) { ! if (mrefs.makeClass == 0) { ! mrefs.makeClass = code.pool.Methodref( "org/python/core/Py", "makeClass", "(Ljava/lang/String;[Lorg/python/core/PyObject;Lorg/python/core/PyCode;Lorg/python/core/PyObject;)Lorg/python/core/PyObject;"); + } + code.invokestatic(mrefs.makeClass); + } else { + if (mrefs.makeClass_closure == 0) { + mrefs.makeClass_closure = code.pool.Methodref( + "org/python/core/Py", "makeClass", + "(Ljava/lang/String;[Lorg/python/core/PyObject;Lorg/python/core/PyCode;Lorg/python/core/PyObject;[Lorg/python/core/PyObject;)Lorg/python/core/PyObject;"); + } + code.invokestatic(mrefs.makeClass_closure); } ! //Assign this new class to the given name set(node.getChild(0)); *************** *** 2162,2165 **** --- 2247,2251 ---- int setglobal, setlocal1, setlocal2; int delglobal, dellocal1, dellocal2; + int getderef,setderef; public Object Name(SimpleNode node) throws Exception { *************** *** 2175,2201 **** mode = SET; switch (mode) { case GET: loadFrame(); ! if (fast_locals) { ! Integer i = (Integer)locals.get(name); ! if (i == null && optimizeGlobals) { ! code.ldc(name); ! if (mrefs.getglobal == 0) { ! mrefs.getglobal = code.pool.Methodref( "org/python/core/PyFrame", "getglobal", "(Ljava/lang/String;)Lorg/python/core/PyObject;"); } ! code.invokevirtual(mrefs.getglobal); ! return null; ! } ! if (i != null) { ! code.iconst(i.intValue()); ! if (mrefs.getlocal2 == 0) { ! mrefs.getlocal2 = code.pool.Methodref( "org/python/core/PyFrame", "getlocal", "(I)Lorg/python/core/PyObject;"); } ! code.invokevirtual(mrefs.getlocal2); return null; } --- 2261,2310 ---- mode = SET; + SymInfo syminf = (SymInfo)tbl.get(name); + switch (mode) { case GET: loadFrame(); ! if (syminf != null) { ! if (fast_locals) { ! if ((syminf.flags&ScopeInfo.GLOBAL) !=0 && optimizeGlobals) { ! code.ldc(name); ! if (mrefs.getglobal == 0) { ! mrefs.getglobal = code.pool.Methodref( "org/python/core/PyFrame", "getglobal", "(Ljava/lang/String;)Lorg/python/core/PyObject;"); + } + code.invokevirtual(mrefs.getglobal); + return null; } ! if ((syminf.flags&ScopeInfo.GLOBAL)==0 && (syminf.flags&ScopeInfo.CELL)!=0) { ! code.iconst(syminf.env_index); ! if (mrefs.getderef == 0) { ! mrefs.getderef = code.pool.Methodref( ! "org/python/core/PyFrame", "getderef", ! "(I)Lorg/python/core/PyObject;"); ! } ! code.invokevirtual(mrefs.getderef); ! return null; ! } ! if ((syminf.flags&ScopeInfo.GLOBAL)==0 && (syminf.flags&ScopeInfo.BOUND)!=0) { ! code.iconst(syminf.locals_index); ! if (mrefs.getlocal2 == 0) { ! mrefs.getlocal2 = code.pool.Methodref( "org/python/core/PyFrame", "getlocal", "(I)Lorg/python/core/PyObject;"); + } + code.invokevirtual(mrefs.getlocal2); + return null; } ! } ! if (my_scope.nested_scopes && (syminf.flags&ScopeInfo.FREE) != 0) { ! code.iconst(syminf.env_index); ! if (mrefs.getderef == 0) { ! mrefs.getderef = code.pool.Methodref( ! "org/python/core/PyFrame", "getderef", ! "(I)Lorg/python/core/PyObject;"); ! } ! code.invokevirtual(mrefs.getderef); return null; } *************** *** 2212,2216 **** case SET: loadFrame(); ! if (globals.get(name) != null) { code.ldc(name); code.aload(temporary); --- 2321,2325 ---- case SET: loadFrame(); ! if (syminf != null && (syminf.flags&ScopeInfo.GLOBAL) != 0) { code.ldc(name); code.aload(temporary); *************** *** 2232,2253 **** code.invokevirtual(mrefs.setlocal1); } else { ! Integer i = (Integer)locals.get(name); ! if (i == null) { System.err.println("internal compiler error: "+node); } ! code.iconst(i.intValue()); ! code.aload(temporary); ! if (mrefs.setlocal2 == 0) { ! mrefs.setlocal2 = code.pool.Methodref( "org/python/core/PyFrame", "setlocal", "(ILorg/python/core/PyObject;)V"); } - code.invokevirtual(mrefs.setlocal2); } } return null; ! case DEL: loadFrame(); ! if (globals.get(name) != null) { code.ldc(name); if (mrefs.delglobal == 0) { --- 2341,2372 ---- code.invokevirtual(mrefs.setlocal1); } else { ! if (syminf == null) { System.err.println("internal compiler error: "+node); } ! if ((syminf.flags&ScopeInfo.CELL) != 0) { ! code.iconst(syminf.env_index); ! code.aload(temporary); ! if (mrefs.setderef == 0) { ! mrefs.setderef = code.pool.Methodref( ! "org/python/core/PyFrame", "setderef", ! "(ILorg/python/core/PyObject;)V"); ! } ! code.invokevirtual(mrefs.setderef); ! } else { ! code.iconst(syminf.locals_index); ! code.aload(temporary); ! if (mrefs.setlocal2 == 0) { ! mrefs.setlocal2 = code.pool.Methodref( "org/python/core/PyFrame", "setlocal", "(ILorg/python/core/PyObject;)V"); + } + code.invokevirtual(mrefs.setlocal2); } } } return null; ! case DEL: { loadFrame(); ! if (syminf != null && (syminf.flags&ScopeInfo.GLOBAL) != 0) { code.ldc(name); if (mrefs.delglobal == 0) { *************** *** 2267,2272 **** code.invokevirtual(mrefs.dellocal1); } else { ! Integer i = (Integer)locals.get(name); ! code.iconst(i.intValue()); if (mrefs.dellocal2 == 0) { mrefs.dellocal2 = code.pool.Methodref( --- 2386,2396 ---- code.invokevirtual(mrefs.dellocal1); } else { ! if (syminf == null) { ! System.err.println("internal compiler error: "+node); ! } ! if ((syminf.flags&ScopeInfo.CELL) != 0) { ! error("can not delete variable '"+name+"' referenced in nested scope",true,node); ! } ! code.iconst(syminf.locals_index); if (mrefs.dellocal2 == 0) { mrefs.dellocal2 = code.pool.Methodref( *************** *** 2277,2281 **** } } ! return null; } return null; --- 2401,2405 ---- } } ! return null; } } return null; Index: Module.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/compiler/Module.java,v retrieving revision 2.3 retrieving revision 2.4 diff -C2 -r2.3 -r2.4 *** Module.java 2000/01/11 20:38:48 2.3 --- Module.java 2001/03/08 23:43:51 2.4 *************** *** 193,196 **** --- 193,201 ---- public boolean arglist, keywordlist; String fname; + + // for nested scopes + public String[] cellvars; + public String[] freevars; + public int xxx_npurecell; public PyCodeConstant() { ; *************** *** 222,230 **** c.iconst(id); int mref_newCode = c.pool.Methodref( "org/python/core/Py", "newCode", ! "(I[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IZZLorg/python/core/PyFunctionTable;I)Lorg/python/core/PyCode;"); c.invokestatic(mref_newCode); --- 227,240 ---- c.iconst(id); + + if (cellvars != null) CodeCompiler.makeStrings(c, cellvars, cellvars.length); else c.aconst_null(); + if (freevars != null) CodeCompiler.makeStrings(c, freevars, freevars.length); else c.aconst_null(); + c.iconst(xxx_npurecell); + int mref_newCode = c.pool.Methodref( "org/python/core/Py", "newCode", ! "(I[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IZZLorg/python/core/PyFunctionTable;I[Ljava/lang/String;[Ljava/lang/String;I)Lorg/python/core/PyCode;"); c.invokestatic(mref_newCode); *************** *** 329,346 **** return true; } ! public PyCodeConstant PyCode(SimpleNode tree, String name, - ArgListCompiler ac, boolean fast_locals, String className, boolean classBody, boolean printResults, ! int firstlineno) throws Exception { PyCodeConstant code = new PyCodeConstant(); ! int i; ! code.arglist = ac.arglist; ! code.keywordlist = ac.keywordlist; ! code.argcount = ac.names.size(); ! code.co_name = name; code.co_firstlineno = firstlineno; --- 339,369 ---- return true; } ! ! private static final String[] emptyStringAr = new String[0]; ! ! private String[] toNameAr(Vector names,boolean nullok) { ! int sz = names.size(); ! if (sz ==0 && nullok) return null; ! return (String[])names.toArray(emptyStringAr); ! } ! ! ! private int to_cell; ! public PyCodeConstant PyCode(SimpleNode tree, String name, boolean fast_locals, String className, boolean classBody, boolean printResults, ! int firstlineno, ScopeInfo scope) throws Exception { PyCodeConstant code = new PyCodeConstant(); ! ArgListCompiler ac = (scope != null)?scope.ac:null; ! ! if (ac != null) { ! code.arglist = ac.arglist; ! code.keywordlist = ac.keywordlist; ! code.argcount = ac.names.size(); ! } ! code.co_name = name; code.co_firstlineno = firstlineno; *************** *** 363,378 **** CodeCompiler compiler = new CodeCompiler(this, printResults); ! if (ac.init_code.getNumChildren() > 0) { ac.init_code.jjtAddChild(tree, ac.init_code.getNumChildren()); tree = ac.init_code; } ! compiler.parse(tree, c, fast_locals, className, classBody, ac); ! code.names = new String[compiler.names.size()]; ! for(i=0; i<compiler.names.size(); i++) { ! code.names[i] = (String)compiler.names.elementAt(i); } ! code.module = this; code.name = code.fname; --- 386,422 ---- CodeCompiler compiler = new CodeCompiler(this, printResults); ! if (ac != null && ac.init_code.getNumChildren() > 0) { ac.init_code.jjtAddChild(tree, ac.init_code.getNumChildren()); tree = ac.init_code; } + + if (scope != null) { + int nparamcell = scope.xxx_paramcells.size(); + if (nparamcell > 0) { + if (to_cell == 0) { + to_cell = classfile.pool.Methodref("org/python/core/PyFrame","to_cell","(II)V"); + } + Hashtable tbl = scope.tbl; + Vector paramcells = scope.xxx_paramcells; + for (int i = 0; i < nparamcell; i++) { + c.aload(1); + SymInfo syminf = (SymInfo)tbl.get(paramcells.elementAt(i)); + c.iconst(syminf.locals_index); + c.iconst(syminf.env_index); + c.invokevirtual(to_cell); + } + } + } ! compiler.parse(tree, c, fast_locals, className, classBody, scope); ! code.names = toNameAr(compiler.names,false); ! ! if (scope != null) { ! code.cellvars = toNameAr(scope.cellvars,true); ! code.freevars = toNameAr(scope.freevars,true); ! code.xxx_npurecell = scope.xxx_npurecell; } ! code.module = this; code.name = code.fname; *************** *** 504,510 **** //Add __file__ for filename (if it exists?) ! Constant main = module.PyCode(node, "?", ! new ArgListCompiler(), ! false, null, false, printResults, 0); module.mainCode = main; module.write(ostream); --- 548,552 ---- //Add __file__ for filename (if it exists?) ! Constant main = module.PyCode(node, "?",false, null, false, printResults, 0,null); module.mainCode = main; module.write(ostream); |
From: Samuele P. <ped...@us...> - 2001-03-08 23:42:07
|
Update of /cvsroot/jython/jython/org/python/parser In directory usw-pr-cvs1:/tmp/cvs-serv850/parser Modified Files: SimpleNode.java Log Message: nested scopes *future* support (as CPython 2.1) Index: SimpleNode.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/parser/SimpleNode.java,v retrieving revision 2.12 retrieving revision 2.13 diff -C2 -r2.12 -r2.13 *** SimpleNode.java 2000/12/04 21:25:06 2.12 --- SimpleNode.java 2001/03/08 23:43:51 2.13 *************** *** 15,18 **** --- 15,21 ---- public int aug_tmp1, aug_tmp2, aug_tmp3, aug_tmp4; + public org.python.compiler.ScopeInfo scope; // for nested scopes + public boolean from_future_checked = false; // from __future__ support + public SimpleNode(int i) { id = i; *************** *** 358,360 **** } - --- 361,362 ---- |
From: Samuele P. <ped...@us...> - 2001-03-08 23:42:07
|
Update of /cvsroot/jython/jython/org/python/core In directory usw-pr-cvs1:/tmp/cvs-serv850/core Modified Files: Py.java PyCode.java PyFrame.java PyFunction.java PyTableCode.java Added Files: PyCell.java Log Message: nested scopes *future* support (as CPython 2.1) --- NEW FILE --- package org.python.core; public class PyCell extends PyObject { // ?? pending repr? public PyObject ob_ref; } Index: Py.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/Py.java,v retrieving revision 2.40 retrieving revision 2.41 diff -C2 -r2.40 -r2.41 *** Py.java 2001/03/04 18:08:02 2.40 --- Py.java 2001/03/08 23:43:51 2.41 *************** *** 240,251 **** warning(RuntimeWarning, message); } ! public static void warning(PyObject category, String message) { PyObject func = null; ! PyObject mod = __builtin__.__import__("warnings"); if (mod != null) func = mod.__getattr__("warn"); if (func == null) { ! System.err.println("warning: " + message); return; } else { --- 240,273 ---- warning(RuntimeWarning, message); } ! ! private static PyObject warnings_mod; ! private static PyObject importWarnings() { ! if (warnings_mod != null) return warnings_mod; ! PyObject mod; ! try { ! mod = __builtin__.__import__("warnings"); ! } catch(PyException e) { ! if (matchException(e,ImportError)) { ! return null; ! } ! throw e; ! } ! warnings_mod = mod; ! return mod; ! } ! ! private static String warn_hcategory(PyObject category) { ! PyObject name = category.__findattr__("__name__"); ! if (name != null) return "["+name+"]"; ! return "[warning]"; ! } ! public static void warning(PyObject category, String message) { PyObject func = null; ! PyObject mod = importWarnings(); if (mod != null) func = mod.__getattr__("warn"); if (func == null) { ! System.err.println(warn_hcategory(category) + ": " + message); return; } else { *************** *** 254,258 **** --- 276,295 ---- } + public static void warning(PyObject category, String message,String filename,int lineno, String module, PyObject registry) { + PyObject func = null; + PyObject mod = importWarnings(); + if (mod != null) + func = mod.__getattr__("warn_explicit"); + if (func == null) { + System.err.println(filename + ":" + lineno + ":" + warn_hcategory(category) + ": " + message); + return; + } else { + func.__call__(new PyObject[] {Py.newString(message), category, + Py.newString(filename), Py.newInteger(lineno), + (module == null)?Py.None:Py.newString(module), registry}, Py.NoKeywords); + } + } + public static PyObject JavaError; public static PyException JavaError(Throwable t) { *************** *** 396,399 **** --- 433,464 ---- } + // nested scopes: String[] cellvars,String[] freevars,int xxx_npurecell + + public static PyCode newCode(int argcount, String varnames[], + String filename, String name, + boolean args, boolean keywords, + PyFunctionTable funcs, int func_id, + String[] cellvars,String[] freevars,int xxx_npurecell) + { + return new PyTableCode(argcount, varnames, + filename, name, 0, args, keywords, funcs, + func_id, cellvars, freevars, xxx_npurecell); + } + + public static PyCode newCode(int argcount, String varnames[], + String filename, String name, + int firstlineno, + boolean args, boolean keywords, + PyFunctionTable funcs, int func_id, + String[] cellvars,String[] freevars,int xxx_npurecell) + + { + return new PyTableCode(argcount, varnames, + filename, name, firstlineno, args, keywords, + funcs, func_id, cellvars, freevars, xxx_npurecell); + } + + // -- + public static PyCode newCode(int argcount, String varnames[], String filename, String name, *************** *** 423,427 **** public static PyObject newJavaFunc(Class cls, String name) { try { ! java.lang.reflect.Method m = cls.getMethod(name, new Class[] { PyObject[].class, String[].class }); return new JavaFunc(m); --- 488,492 ---- public static PyObject newJavaFunc(Class cls, String name) { try { ! java.lang.reflect.Method m = cls.getMethod(name, new Class[] { PyObject[].class, String[].class }); return new JavaFunc(m); *************** *** 1303,1312 **** PyCode code, PyObject doc) { ! return makeClass(name, bases, code, doc, null); } public static PyObject makeClass(String name, PyObject[] bases, PyCode code, PyObject doc, ! Class proxyClass) { PyFrame frame = getFrame(); --- 1368,1391 ---- PyCode code, PyObject doc) { ! return makeClass(name, bases, code, doc, null, null); } + + public static PyObject makeClass(String name, PyObject[] bases, + PyCode code, PyObject doc,PyObject[] closure_cells) + { + return makeClass(name, bases, code, doc, null, closure_cells); + } + public static PyObject makeClass(String name, PyObject[] bases, PyCode code, PyObject doc, ! Class proxyClass) { ! return makeClass(name, bases, code, doc, proxyClass, null); ! } ! ! ! public static PyObject makeClass(String name, PyObject[] bases, ! PyCode code, PyObject doc, ! Class proxyClass,PyObject[] closure_cells) { PyFrame frame = getFrame(); *************** *** 1314,1318 **** PyObject dict = code.call(Py.EmptyObjects, Py.NoKeywords, ! globals, Py.EmptyObjects); if (doc != null) dict.__setitem__("__doc__", doc); --- 1393,1397 ---- PyObject dict = code.call(Py.EmptyObjects, Py.NoKeywords, ! globals, Py.EmptyObjects,new PyTuple(closure_cells)); if (doc != null) dict.__setitem__("__doc__", doc); *************** *** 1530,1534 **** } ! public PyObject call(PyFrame frame) { System.out.println("call #1"); return Py.None; --- 1609,1613 ---- } ! public PyObject call(PyFrame frame, PyObject closure) { System.out.println("call #1"); return Py.None; *************** *** 1536,1540 **** public PyObject call(PyObject args[], String keywords[], ! PyObject globals, PyObject[] defaults) { return func.__call__(args, keywords); --- 1615,1619 ---- public PyObject call(PyObject args[], String keywords[], ! PyObject globals, PyObject[] defaults, PyObject closure) { return func.__call__(args, keywords); *************** *** 1543,1552 **** public PyObject call(PyObject self, PyObject args[], String keywords[], ! PyObject globals, PyObject[] defaults) { return func.__call__(self, args, keywords); } ! public PyObject call(PyObject globals, PyObject[] defaults) { return func.__call__(); --- 1622,1631 ---- public PyObject call(PyObject self, PyObject args[], String keywords[], ! PyObject globals, PyObject[] defaults, PyObject closure) { return func.__call__(self, args, keywords); } ! public PyObject call(PyObject globals, PyObject[] defaults, PyObject closure) { return func.__call__(); *************** *** 1554,1558 **** public PyObject call(PyObject arg1, PyObject globals, ! PyObject[] defaults) { return func.__call__(arg1); --- 1633,1637 ---- public PyObject call(PyObject arg1, PyObject globals, ! PyObject[] defaults, PyObject closure) { return func.__call__(arg1); *************** *** 1560,1564 **** public PyObject call(PyObject arg1, PyObject arg2, ! PyObject globals, PyObject[] defaults) { return func.__call__(arg1, arg2); --- 1639,1643 ---- public PyObject call(PyObject arg1, PyObject arg2, ! PyObject globals, PyObject[] defaults, PyObject closure) { return func.__call__(arg1, arg2); *************** *** 1566,1570 **** public PyObject call(PyObject arg1, PyObject arg2, PyObject arg3, ! PyObject globals, PyObject[] defaults) { return func.__call__(arg1, arg2, arg3); --- 1645,1649 ---- public PyObject call(PyObject arg1, PyObject arg2, PyObject arg3, ! PyObject globals, PyObject[] defaults, PyObject closure) { return func.__call__(arg1, arg2, arg3); *************** *** 1573,1577 **** /** ! * A function object wrapper for a java method which comply with the * PyArgsKeywordsCall standard. */ --- 1652,1656 ---- /** ! * A function object wrapper for a java method which comply with the * PyArgsKeywordsCall standard. */ *************** *** 1605,1607 **** throw Py.TypeError("java function not settable: "+method.getName()); } ! } \ No newline at end of file --- 1684,1686 ---- throw Py.TypeError("java function not settable: "+method.getName()); } ! } Index: PyCode.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyCode.java,v retrieving revision 2.4 retrieving revision 2.5 diff -C2 -r2.4 -r2.5 *** PyCode.java 2001/02/25 16:43:19 2.4 --- PyCode.java 2001/03/08 23:43:51 2.5 *************** *** 8,30 **** { public String co_name; - abstract public PyObject call(PyFrame frame); - abstract public PyObject call(PyObject args[], String keywords[], ! PyObject globals, PyObject[] defaults); abstract public PyObject call(PyObject self, PyObject args[], String keywords[], ! PyObject globals, PyObject[] defaults); ! abstract public PyObject call(PyObject globals, PyObject[] defaults); abstract public PyObject call(PyObject arg1, PyObject globals, ! PyObject[] defaults); abstract public PyObject call(PyObject arg1, PyObject arg2, ! PyObject globals, PyObject[] defaults); abstract public PyObject call(PyObject arg1, PyObject arg2, PyObject arg3, ! PyObject globals, PyObject[] defaults); } --- 8,33 ---- { public String co_name; + + abstract public PyObject call(PyFrame frame, PyObject closure); + + public PyObject call(PyFrame frame) { return call(frame,null); } // commodity abstract public PyObject call(PyObject args[], String keywords[], ! PyObject globals, PyObject[] defaults, PyObject closure); abstract public PyObject call(PyObject self, PyObject args[], String keywords[], ! PyObject globals, PyObject[] defaults,PyObject closure); ! abstract public PyObject call(PyObject globals, PyObject[] defaults, PyObject closure); abstract public PyObject call(PyObject arg1, PyObject globals, ! PyObject[] defaults, PyObject closure); abstract public PyObject call(PyObject arg1, PyObject arg2, ! PyObject globals, PyObject[] defaults, PyObject closure); abstract public PyObject call(PyObject arg1, PyObject arg2, PyObject arg3, ! PyObject globals, PyObject[] defaults, PyObject closure); ! } Index: PyFrame.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyFrame.java,v retrieving revision 2.6 retrieving revision 2.7 diff -C2 -r2.6 -r2.7 *** PyFrame.java 2001/02/25 16:47:44 2.6 --- PyFrame.java 2001/03/08 23:43:51 2.7 *************** *** 16,20 **** public PyObject f_builtins; public PyObject[] f_fastlocals; ! // an interface to functions suitable for tracing, e.g. via sys.settrace() public TraceFunction tracefunc; --- 16,23 ---- public PyObject f_builtins; public PyObject[] f_fastlocals; ! public PyCell[] f_env; // nested scopes: cell + free env ! public int f_ncells; ! public int f_nfreevars; ! // an interface to functions suitable for tracing, e.g. via sys.settrace() public TraceFunction tracefunc; *************** *** 37,41 **** // This needs work to be efficient with multiple interpreter states if (locals == null && code != null && code.co_varnames.length > 0) { ! f_fastlocals = new PyObject[code.co_varnames.length]; } } --- 40,50 ---- // This needs work to be efficient with multiple interpreter states if (locals == null && code != null && code.co_varnames.length > 0) { ! f_fastlocals = new PyObject[code.co_varnames.length-code.xxx_npurecell]; // internal: may change ! } ! if (code != null) { // reserve space for env ! int env_sz = 0; ! if (code.co_freevars != null) env_sz += (f_nfreevars = code.co_freevars.length); ! if (code.co_cellvars != null) env_sz += (f_ncells = code.co_cellvars.length); ! if (env_sz > 0) f_env = new PyCell[env_sz]; } } *************** *** 136,140 **** public PyObject getlocal(String index) { ! //System.err.println("getlocal: "+index); if (f_locals == null) getf_locals(); --- 145,149 ---- public PyObject getlocal(String index) { ! // System.err.println("getlocal: "+index); if (f_locals == null) getf_locals(); *************** *** 143,147 **** return ret; ! throw Py.NameError("local: '"+index+"'"); //return getglobal(index); } --- 152,156 ---- return ret; ! throw Py.UnboundLocalError("local: '"+index+"'"); //return getglobal(index); } *************** *** 205,207 **** --- 214,240 ---- f_globals.__delitem__(index); } + + // nested scopes helpers + + public PyObject getclosure(int index) { + return f_env[index]; + } + + public PyObject getderef(int index) { + PyObject obj=f_env[index].ob_ref; + if (obj != null) return obj; + String name; + if (index >= f_ncells) name = f_code.co_freevars[index-f_ncells]; + else name = f_code.co_cellvars[index]; + throw Py.UnboundLocalError("local: '"+name+"'"); + } + + public void setderef(int index,PyObject value) { + f_env[index].ob_ref = value; + } + + public void to_cell(int parm_index,int env_index) { + f_env[env_index].ob_ref=f_fastlocals[parm_index]; + } + } Index: PyFunction.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyFunction.java,v retrieving revision 2.10 retrieving revision 2.11 diff -C2 -r2.10 -r2.11 *** PyFunction.java 2001/03/04 18:13:56 2.10 --- PyFunction.java 2001/03/08 23:43:51 2.11 *************** *** 14,20 **** public PyCode func_code; public PyObject __dict__; public PyFunction(PyObject globals, PyObject[] defaults, PyCode code, ! PyObject doc) { func_globals = globals; --- 14,21 ---- public PyCode func_code; public PyObject __dict__; + public PyObject func_closure; // nested scopes: closure public PyFunction(PyObject globals, PyObject[] defaults, PyCode code, ! PyObject doc,PyObject[] closure_cells) { func_globals = globals; *************** *** 26,39 **** func_defaults = defaults; func_code = code; } public PyFunction(PyObject globals, PyObject[] defaults, PyCode code) { ! this(globals, defaults, code, null); } private static final String[] __members__ = { "__doc__", "func_doc", "__name__", "func_name", "__dict__", ! "func_globals", "func_defaults", "func_code" }; --- 27,56 ---- func_defaults = defaults; func_code = code; + if (closure_cells != null) { + func_closure = new PyTuple(closure_cells); + } else { + func_closure = null; + } } + public PyFunction(PyObject globals, PyObject[] defaults, PyCode code, + PyObject doc) { + this(globals,defaults,code,doc,null); + } + public PyFunction(PyObject globals, PyObject[] defaults, PyCode code) { ! this(globals, defaults, code, null,null); } + + public PyFunction(PyObject globals, PyObject[] defaults, PyCode code, PyObject[] closure_cells) { + this(globals, defaults, code, null,closure_cells); + } + private static final String[] __members__ = { "__doc__", "func_doc", "__name__", "func_name", "__dict__", ! "func_globals", "func_defaults", "func_code", ! "func_closure" }; *************** *** 61,64 **** --- 78,87 ---- if (name == "func_doc" || name == "__doc__") __doc__ = value; + else if (name == "func_closure") { + if (!(value instanceof PyTuple)) { + throw Py.TypeError("func_closure must be set to a tuple"); + } + func_closure = value; + } // not yet implemented: // func_code *************** *** 111,114 **** --- 134,141 ---- if (name == "func_name") return new PyString(__name__); + if (name == "func_closure") { + if (func_closure != null) return func_closure; + return Py.None; + } if (name == "func_defaults") { if (func_defaults.length == 0) *************** *** 138,155 **** public PyObject __call__() { ! return func_code.call(func_globals, func_defaults); } public PyObject __call__(PyObject arg) { ! return func_code.call(arg, func_globals, func_defaults); } public PyObject __call__(PyObject arg1, PyObject arg2) { ! return func_code.call(arg1, arg2, func_globals, func_defaults); } public PyObject __call__(PyObject arg1, PyObject arg2, PyObject arg3) { ! return func_code.call(arg1, arg2, arg3, func_globals, func_defaults); } public PyObject __call__(PyObject[] args, String[] keywords) { ! return func_code.call(args, keywords, func_globals, func_defaults); } public PyObject __call__(PyObject arg1, PyObject[] args, --- 165,182 ---- public PyObject __call__() { ! return func_code.call(func_globals, func_defaults, func_closure); } public PyObject __call__(PyObject arg) { ! return func_code.call(arg, func_globals, func_defaults, func_closure); } public PyObject __call__(PyObject arg1, PyObject arg2) { ! return func_code.call(arg1, arg2, func_globals, func_defaults, func_closure); } public PyObject __call__(PyObject arg1, PyObject arg2, PyObject arg3) { ! return func_code.call(arg1, arg2, arg3, func_globals, func_defaults, func_closure); } public PyObject __call__(PyObject[] args, String[] keywords) { ! return func_code.call(args, keywords, func_globals, func_defaults, func_closure); } public PyObject __call__(PyObject arg1, PyObject[] args, *************** *** 157,161 **** { return func_code.call(arg1, args, keywords, func_globals, ! func_defaults); } public String toString() { --- 184,188 ---- { return func_code.call(arg1, args, keywords, func_globals, ! func_defaults, func_closure); } public String toString() { Index: PyTableCode.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyTableCode.java,v retrieving revision 2.11 retrieving revision 2.12 diff -C2 -r2.11 -r2.12 *** PyTableCode.java 2001/02/25 16:51:51 2.11 --- PyTableCode.java 2001/03/08 23:43:51 2.12 *************** *** 13,16 **** --- 13,19 ---- public int co_firstlineno = -1; public String co_varnames[]; + public String co_cellvars[]; + public int xxx_npurecell; // internal: may change + public String co_freevars[]; public String co_filename; public int co_flags; *************** *** 18,22 **** PyFunctionTable funcs; int func_id; ! public PyTableCode(int argcount, String varnames[], String filename, String name, --- 21,26 ---- PyFunctionTable funcs; int func_id; ! ! public PyTableCode(int argcount, String varnames[], String filename, String name, *************** *** 25,32 **** --- 29,49 ---- PyFunctionTable funcs, int func_id) { + this(argcount,varnames,filename,name,firstlineno,args,keywords,funcs,func_id,null,null,0); + } + + public PyTableCode(int argcount, String varnames[], + String filename, String name, + int firstlineno, + boolean args, boolean keywords, + PyFunctionTable funcs, int func_id, + String[] cellvars,String[] freevars,int xxx_npurecell) // may change + { co_argcount = nargs = argcount; co_varnames = varnames; co_filename = filename; co_firstlineno = firstlineno; + co_cellvars = cellvars; + co_freevars = freevars; + this.xxx_npurecell = xxx_npurecell; this.args = args; co_name = name; *************** *** 47,51 **** "co_name", "co_argcount", "co_varnames", "co_filename", "co_firstlineno", ! "co_flags" // not supported: co_nlocals, co_code, co_consts, co_names, // co_lnotab, co_stacksize --- 64,68 ---- "co_name", "co_argcount", "co_varnames", "co_filename", "co_firstlineno", ! "co_flags","co_cellvars","co_freevars" // not supported: co_nlocals, co_code, co_consts, co_names, // co_lnotab, co_stacksize *************** *** 75,90 **** } public PyObject __findattr__(String name) { // have to craft co_varnames specially ! if (name == "co_varnames") { ! PyString varnames[] = new PyString[co_varnames.length]; ! for (int i = 0; i < co_varnames.length; i++) ! varnames[i] = new PyString(co_varnames[i]); ! return new PyTuple(varnames); ! } return super.__findattr__(name); } ! public PyObject call(PyFrame frame) { // System.err.println("tablecode call: "+co_name); ThreadState ts = Py.getThreadState(); --- 92,114 ---- } + private static PyTuple toPyStringTuple(String[] ar) { + if (ar == null) return Py.EmptyTuple; + int sz = ar.length; + PyString[] pystr = new PyString[sz]; + for (int i = 0; i < sz; i++) { + pystr[i] = new PyString(ar[i]); + } + return new PyTuple(pystr); + } + public PyObject __findattr__(String name) { // have to craft co_varnames specially ! if (name == "co_varnames") return toPyStringTuple(co_varnames); ! if (name == "co_cellvars") return toPyStringTuple(co_cellvars); ! if (name == "co_freevars") return toPyStringTuple(co_freevars); return super.__findattr__(name); } ! public PyObject call(PyFrame frame, PyObject closure) { // System.err.println("tablecode call: "+co_name); ThreadState ts = Py.getThreadState(); *************** *** 108,111 **** --- 132,149 ---- } } + // nested scopes: setup env with closure + int env_j = 0; + int ncells = frame.f_ncells; + int nfreevars = frame.f_nfreevars; + PyCell[] env = frame.f_env; + PyTuple freevars = (PyTuple)closure; + for (int i = 0; i < ncells; i++,env_j++) { + env[env_j] = new PyCell(); + } + for (int i=0; i<nfreevars; i++,env_j++) { + env[env_j] = (PyCell)freevars.get(i); + } + + ts.frame = frame; *************** *** 199,252 **** } ! public PyObject call(PyObject globals, PyObject[] defaults) { if (co_argcount != 0 || args || keywords) ! return call(Py.EmptyObjects, Py.NoKeywords, globals, defaults); PyFrame frame = new PyFrame(this, globals); ! return call(frame); } ! public PyObject call(PyObject arg1, PyObject globals, PyObject[] defaults) { if (co_argcount != 1 || args || keywords) return call(new PyObject[] {arg1}, ! Py.NoKeywords, globals, defaults); PyFrame frame = new PyFrame(this, globals); frame.f_fastlocals[0] = arg1; ! return call(frame); } public PyObject call(PyObject arg1, PyObject arg2, PyObject globals, ! PyObject[] defaults) { if (co_argcount != 2 || args || keywords) return call(new PyObject[] {arg1, arg2}, ! Py.NoKeywords, globals, defaults); PyFrame frame = new PyFrame(this, globals); frame.f_fastlocals[0] = arg1; frame.f_fastlocals[1] = arg2; ! return call(frame); } public PyObject call(PyObject arg1, PyObject arg2, PyObject arg3, ! PyObject globals, PyObject[] defaults) { if (co_argcount != 2 || args || keywords) return call(new PyObject[] {arg1, arg2, arg3}, ! Py.NoKeywords, globals, defaults); PyFrame frame = new PyFrame(this, globals); frame.f_fastlocals[0] = arg1; frame.f_fastlocals[1] = arg2; frame.f_fastlocals[2] = arg3; ! return call(frame); } public PyObject call(PyObject self, PyObject call_args[], String call_keywords[], PyObject globals, ! PyObject[] defaults) { PyObject[] os = new PyObject[call_args.length+1]; os[0] = (PyObject)self; System.arraycopy(call_args, 0, os, 1, call_args.length); ! return call(os, call_keywords, globals, defaults); } --- 237,290 ---- } ! public PyObject call(PyObject globals, PyObject[] defaults, PyObject closure) { if (co_argcount != 0 || args || keywords) ! return call(Py.EmptyObjects, Py.NoKeywords, globals, defaults, closure); PyFrame frame = new PyFrame(this, globals); ! return call(frame, closure); } ! public PyObject call(PyObject arg1, PyObject globals, PyObject[] defaults, PyObject closure) { if (co_argcount != 1 || args || keywords) return call(new PyObject[] {arg1}, ! Py.NoKeywords, globals, defaults, closure); PyFrame frame = new PyFrame(this, globals); frame.f_fastlocals[0] = arg1; ! return call(frame, closure); } public PyObject call(PyObject arg1, PyObject arg2, PyObject globals, ! PyObject[] defaults, PyObject closure) { if (co_argcount != 2 || args || keywords) return call(new PyObject[] {arg1, arg2}, ! Py.NoKeywords, globals, defaults, closure); PyFrame frame = new PyFrame(this, globals); frame.f_fastlocals[0] = arg1; frame.f_fastlocals[1] = arg2; ! return call(frame, closure); } public PyObject call(PyObject arg1, PyObject arg2, PyObject arg3, ! PyObject globals, PyObject[] defaults, PyObject closure) { if (co_argcount != 2 || args || keywords) return call(new PyObject[] {arg1, arg2, arg3}, ! Py.NoKeywords, globals, defaults, closure); PyFrame frame = new PyFrame(this, globals); frame.f_fastlocals[0] = arg1; frame.f_fastlocals[1] = arg2; frame.f_fastlocals[2] = arg3; ! return call(frame, closure); } public PyObject call(PyObject self, PyObject call_args[], String call_keywords[], PyObject globals, ! PyObject[] defaults, PyObject closure) { PyObject[] os = new PyObject[call_args.length+1]; os[0] = (PyObject)self; System.arraycopy(call_args, 0, os, 1, call_args.length); ! return call(os, call_keywords, globals, defaults, closure); } *************** *** 256,260 **** public PyObject call(PyObject call_args[], String call_keywords[], ! PyObject globals, PyObject[] defaults) { //Needs try except finally blocks --- 294,298 ---- public PyObject call(PyObject call_args[], String call_keywords[], ! PyObject globals, PyObject[] defaults, PyObject closure) { //Needs try except finally blocks *************** *** 348,352 **** } } ! return call(my_frame); } --- 386,390 ---- } } ! return call(my_frame, closure); } |
From: Finn B. <bc...@us...> - 2001-03-05 19:57:16
|
Update of /cvsroot/jython/jython/org/python/core In directory usw-pr-cvs1:/tmp/cvs-serv3819 Modified Files: PyInstance.java Log Message: Experimental fix for #226677. Index: PyInstance.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyInstance.java,v retrieving revision 2.20 retrieving revision 2.21 diff -C2 -r2.20 -r2.21 *** PyInstance.java 2001/02/25 16:47:44 2.20 --- PyInstance.java 2001/03/05 19:58:51 2.21 *************** *** 544,547 **** --- 544,560 ---- } + public PyObject __getitem__(PyObject key) { + CollectionProxy proxy = getCollection(); + if (proxy != CollectionProxy.NoProxy) { + return proxy.__finditem__(key); + } + + PyObject ret = trySlice(key, "__getslice__", null); + if (ret != null) + return ret; + + return invoke("__getitem__", key); + } + public void __setitem__(PyObject key, PyObject value) { CollectionProxy proxy = getCollection(); |
From: Finn B. <bc...@us...> - 2001-03-05 19:54:43
|
Update of /cvsroot/jython/jython/org/python/core In directory usw-pr-cvs1:/tmp/cvs-serv3105 Modified Files: PyXRange.java Log Message: Make start, stop & step visible attribute on the xrange object. Index: PyXRange.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyXRange.java,v retrieving revision 2.2 retrieving revision 2.3 diff -C2 -r2.2 -r2.3 *** PyXRange.java 2001/02/01 16:41:11 2.2 --- PyXRange.java 2001/03/05 19:56:18 2.3 *************** *** 12,16 **** public class PyXRange extends PySequence { ! int start, stop, step; // directly from xrange(start, stop, step) int cycleLength; // The length of an uncopied xrange int copies; // The number of copies made (used to implement --- 12,16 ---- public class PyXRange extends PySequence { ! public int start, stop, step; // directly from xrange(start, stop, step) int cycleLength; // The length of an uncopied xrange int copies; // The number of copies made (used to implement |
From: Finn B. <bc...@us...> - 2001-03-05 19:53:59
|
Update of /cvsroot/jython/jython/org/python/core In directory usw-pr-cvs1:/tmp/cvs-serv2925 Modified Files: PyObject.java Log Message: _cmp(): Enable a 3way compare to use the rich-compare is available. _cmp_unsafe(): Make None compare less than everything else. Index: PyObject.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyObject.java,v retrieving revision 2.22 retrieving revision 2.23 diff -C2 -r2.22 -r2.23 *** PyObject.java 2001/03/04 18:04:31 2.22 --- PyObject.java 2001/03/05 19:55:34 2.23 *************** *** 918,941 **** * @return -1 if this < 0; 0 if this == o; +1 if this > o **/ ! public final int _cmp(PyObject o2_in) { ThreadState ts = Py.getThreadState(); try { if (++ts.compareStateNesting > 500) { ! PyDictionary stateDict = ts.getCompareStateDict(); ! ! PyObject pair = make_pair(o2_in); ! ! if (stateDict.__finditem__(pair) != null) { ! // already comparing these objects. assume ! // they're equal until shown otherwise */ return 0; - } - stateDict.__setitem__(pair, pair); - int res = _cmp_unsafe(o2_in); - stateDict.__delitem__(pair); - return res; } ! return _cmp_unsafe(o2_in); } finally { ts.compareStateNesting--; } --- 918,955 ---- * @return -1 if this < 0; 0 if this == o; +1 if this > o **/ ! public final int _cmp(PyObject o) { ! PyObject token = null; ThreadState ts = Py.getThreadState(); try { if (++ts.compareStateNesting > 500) { ! if ((token = check_recursion(ts, this, o)) == null) return 0; } ! ! PyObject r; ! r = __eq__(o); ! if (r != null && r.__nonzero__()) ! return 0; ! r = o.__eq__(this); ! if (r != null && r.__nonzero__()) ! return 0; ! ! r = __lt__(o); ! if (r != null && r.__nonzero__()) ! return -1; ! r = o.__gt__(this); ! if (r != null && r.__nonzero__()) ! return -1; ! ! r = __gt__(o); ! if (r != null && r.__nonzero__()) ! return 1; ! r = o.__lt__(this); ! if (r != null && r.__nonzero__()) ! return 1; ! ! return _cmp_unsafe(o); } finally { + delete_token(ts, token); ts.compareStateNesting--; } *************** *** 972,976 **** } else ctmp = null; - if (ctmp != Py.None && (itmp = o1.__cmp__(o2)) != -2) return itmp; --- 986,989 ---- *************** *** 995,998 **** --- 1008,1017 ---- if (this == o2_in) return 0; + + /* None is smaller than anything */ + if (this == Py.None) + return -1; + if (o2_in == Py.None) + return 1; // No rational way to compare these, so ask their classes to compare |
From: Finn B. <bc...@us...> - 2001-03-04 18:57:08
|
Update of /cvsroot/jython/jython/org/python/core In directory usw-pr-cvs1:/tmp/cvs-serv3790 Modified Files: PyString.java Log Message: StringFormatter.format(): Make exception text match CPython. Index: PyString.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyString.java,v retrieving revision 2.42 retrieving revision 2.43 diff -C2 -r2.42 -r2.43 *** PyString.java 2001/03/04 18:12:33 2.42 --- PyString.java 2001/03/04 18:58:40 2.43 *************** *** 2225,2229 **** default: ! throw Py.ValueError("unsupported format character '"+c+"'"); } int length = string.length(); --- 2225,2232 ---- default: ! throw Py.ValueError("unsupported format character '" + ! codecs.encode(Py.newString(c), null, "replace") + ! "' (0x" + Integer.toHexString(c) + ") at index " + ! (index-1)); } int length = string.length(); |
From: Finn B. <bc...@us...> - 2001-03-04 18:12:24
|
Update of /cvsroot/jython/jython/org/python/core In directory usw-pr-cvs1:/tmp/cvs-serv27792 Modified Files: PyFunction.java Log Message: __findattr__(): Make an unassigned __dict__ return None. Index: PyFunction.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyFunction.java,v retrieving revision 2.9 retrieving revision 2.10 diff -C2 -r2.9 -r2.10 *** PyFunction.java 2001/02/25 16:47:44 2.9 --- PyFunction.java 2001/03/04 18:13:56 2.10 *************** *** 118,122 **** if (name == "__dict__") { if (__dict__ == null) ! __dict__ = new PyStringMap(); return __dict__; } --- 118,122 ---- if (name == "__dict__") { if (__dict__ == null) ! return Py.None; return __dict__; } |
From: Finn B. <bc...@us...> - 2001-03-04 18:11:02
|
Update of /cvsroot/jython/jython/org/python/core In directory usw-pr-cvs1:/tmp/cvs-serv27548 Modified Files: PySequence.java PyString.java PyTuple.java __builtin__.java Log Message: Javadoc comments on classDictInit. Index: PySequence.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PySequence.java,v retrieving revision 2.16 retrieving revision 2.17 diff -C2 -r2.16 -r2.17 *** PySequence.java 2001/02/02 09:28:37 2.16 --- PySequence.java 2001/03/04 18:12:33 2.17 *************** *** 113,116 **** --- 113,117 ---- } + /** <i>Internal use only. Do not call this method explicit.</i> */ public static void classDictInit(PyObject dict) { dict.__setitem__("__nonzero__", new SeqFuncs("__nonzero__", 1, 0)); Index: PyString.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyString.java,v retrieving revision 2.41 retrieving revision 2.42 diff -C2 -r2.41 -r2.42 *** PyString.java 2001/02/25 16:51:51 2.41 --- PyString.java 2001/03/04 18:12:33 2.42 *************** *** 248,251 **** --- 248,252 ---- } + /** <i>Internal use only. Do not call this method explicit.</i> */ public static void classDictInit(PyObject dict) { dict.__setitem__("__str__", new StringFuncs("__str__", 1, 0)); Index: PyTuple.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyTuple.java,v retrieving revision 2.8 retrieving revision 2.9 diff -C2 -r2.8 -r2.9 *** PyTuple.java 2001/02/25 16:51:51 2.8 --- PyTuple.java 2001/03/04 18:12:33 2.9 *************** *** 44,47 **** --- 44,48 ---- public PyObject[] list; + /** <i>Internal use only. Do not call this method explicit.</i> */ public static void classDictInit(PyObject dict) { PySequence.classDictInit(dict); Index: __builtin__.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/__builtin__.java,v retrieving revision 2.30 retrieving revision 2.31 diff -C2 -r2.30 -r2.31 *** __builtin__.java 2001/02/25 16:51:51 2.30 --- __builtin__.java 2001/03/04 18:12:33 2.31 *************** *** 108,111 **** --- 108,112 ---- public class __builtin__ implements ClassDictInit { + /** <i>Internal use only. Do not call this method explicit.</i> */ public static void classDictInit(PyObject dict) { dict.__setitem__("None", Py.None); |
From: Finn B. <bc...@us...> - 2001-03-04 18:09:59
|
Update of /cvsroot/jython/jython/org/python/core In directory usw-pr-cvs1:/tmp/cvs-serv27207 Modified Files: PyJavaPackage.java Log Message: __setattr__(): Make the __file__ attribute writeable. site.py expect it to be. Index: PyJavaPackage.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyJavaPackage.java,v retrieving revision 2.10 retrieving revision 2.11 diff -C2 -r2.10 -r2.11 *** PyJavaPackage.java 2001/02/25 16:47:44 2.10 --- PyJavaPackage.java 2001/03/04 18:11:31 2.11 *************** *** 169,172 **** --- 169,177 ---- return; } + if (attr == "__file__") { + __file__ = value.__str__().toString(); + return; + } + super.__setattr__(attr,value); } |
From: Finn B. <bc...@us...> - 2001-03-04 18:07:57
|
Update of /cvsroot/jython/jython/org/python/core In directory usw-pr-cvs1:/tmp/cvs-serv26757 Modified Files: exceptions.java Log Message: Fixed formatting (long lines, trailing spaces). Index: exceptions.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/exceptions.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -r1.6 -r1.7 *** exceptions.java 2001/02/25 16:52:54 1.6 --- exceptions.java 2001/03/04 18:09:29 1.7 *************** *** 13,21 **** public class exceptions implements ClassDictInit { ! public static String __doc__ = "Python's standard exception class hierarchy.\n" + "\n" + "Here is a rundown of the class hierarchy. The classes found here are\n" + ! "inserted into both the exceptions module and the `built-in' module. It is\n" + "recommended that user defined class based exceptions be derived from the\n" + "`Exception' class, although this is currently not enforced.\n" + --- 13,22 ---- public class exceptions implements ClassDictInit { ! public static String __doc__ = "Python's standard exception class hierarchy.\n" + "\n" + "Here is a rundown of the class hierarchy. The classes found here are\n" + ! "inserted into both the exceptions module and the `built-in' module. "+ ! "It is\n" + "recommended that user defined class based exceptions be derived from the\n" + "`Exception' class, although this is currently not enforced.\n" + *************** *** 80,83 **** --- 81,85 ---- private exceptions() { ; } + /** <i>Internal use only. Do not call this method explicit.</i> */ public static void classDictInit(PyObject dict) { dict.invoke("clear"); *************** *** 117,121 **** "Improper mixture of spaces and tabs."); ! buildClass(dict, "EnvironmentError", "StandardError", "EnvironmentError", "Base class for I/O related errors."); --- 119,124 ---- "Improper mixture of spaces and tabs."); ! buildClass(dict, "EnvironmentError", "StandardError", ! "EnvironmentError", "Base class for I/O related errors."); *************** *** 129,133 **** "Unspecified run-time error."); ! buildClass(dict, "NotImplementedError", "RuntimeError", "empty__init__", "Method or function hasn't been implemented yet."); --- 132,137 ---- "Unspecified run-time error."); ! buildClass(dict, "NotImplementedError", "RuntimeError", ! "empty__init__", "Method or function hasn't been implemented yet."); *************** *** 154,158 **** "Unicode related error."); ! buildClass(dict, "KeyboardInterrupt", "StandardError", "empty__init__", "Program interrupted by user."); --- 158,163 ---- "Unicode related error."); ! buildClass(dict, "KeyboardInterrupt", "StandardError", ! "empty__init__", "Program interrupted by user."); *************** *** 166,174 **** "Result too large to be represented."); ! buildClass(dict, "FloatingPointError", "ArithmeticError", "empty__init__", "Floating point operation failed."); ! buildClass(dict, "ZeroDivisionError", "ArithmeticError", "empty__init__", ! "Second argument to a division or modulo operation was zero."); buildClass(dict, "LookupError", "StandardError", "empty__init__", --- 171,182 ---- "Result too large to be represented."); ! buildClass(dict, "FloatingPointError", "ArithmeticError", ! "empty__init__", "Floating point operation failed."); ! buildClass(dict, "ZeroDivisionError", "ArithmeticError", ! "empty__init__", ! "Second argument to a division or modulo operation "+ ! "was zero."); buildClass(dict, "LookupError", "StandardError", "empty__init__", *************** *** 213,217 **** - // An empty __init__ method public static PyObject empty__init__(PyObject[] arg, String[] kws) { --- 221,224 ---- *************** *** 221,225 **** } - public static PyObject Exception(PyObject[] arg, String[] kws) { --- 228,231 ---- *************** *** 252,256 **** } ! public static PyObject Exception__getitem__(PyObject[] arg, String[] kws) { ArgParser ap = new ArgParser("__getitem__", arg, kws, "self", "i"); PyObject self = ap.getPyObject(0); --- 258,264 ---- } ! public static PyObject Exception__getitem__(PyObject[] arg, ! String[] kws) ! { ArgParser ap = new ArgParser("__getitem__", arg, kws, "self", "i"); PyObject self = ap.getPyObject(0); *************** *** 306,310 **** } ! public static void EnvironmentError__init__(PyObject[] arg, String[] kws) { ArgParser ap = new ArgParser("__init__", arg, kws, "self", "args"); PyObject self = ap.getPyObject(0); --- 314,320 ---- } ! public static void EnvironmentError__init__(PyObject[] arg, ! String[] kws) ! { ArgParser ap = new ArgParser("__init__", arg, kws, "self", "args"); PyObject self = ap.getPyObject(0); *************** *** 328,332 **** self.__setattr__("strerror", tmp[1]); self.__setattr__("filename", tmp[2]); ! self.__setattr__("args", args.__getslice__(Py.Zero, Py.newInteger(2), Py.One)); } if (args.__len__() == 2) { --- 338,343 ---- self.__setattr__("strerror", tmp[1]); self.__setattr__("filename", tmp[2]); ! self.__setattr__("args", ! args.__getslice__(Py.Zero, Py.newInteger(2), Py.One)); } if (args.__len__() == 2) { *************** *** 338,342 **** } ! public static PyString EnvironmentError__str__(PyObject[] arg, String[] kws) { ArgParser ap = new ArgParser("__init__", arg, kws, "self"); PyObject self = ap.getPyObject(0); --- 349,355 ---- } ! public static PyString EnvironmentError__str__(PyObject[] arg, ! String[] kws) ! { ArgParser ap = new ArgParser("__init__", arg, kws, "self"); PyObject self = ap.getPyObject(0); *************** *** 344,348 **** if (self.__getattr__("filename") != Py.None) { return Py.newString("[Errno %s] %s: %s").__mod__( ! new PyTuple(new PyObject[] { self.__getattr__("errno"), self.__getattr__("strerror"), --- 357,361 ---- if (self.__getattr__("filename") != Py.None) { return Py.newString("[Errno %s] %s: %s").__mod__( ! new PyTuple(new PyObject[] { self.__getattr__("errno"), self.__getattr__("strerror"), *************** *** 387,395 **** private static PyObject buildClass(PyObject dict, String classname, ! String superclass, String classCodeName, String doc) { PyObject[] sclass = Py.EmptyObjects; if (superclass != null) ! sclass = new PyObject[] { dict.__getitem__(new PyString(superclass)) }; PyObject cls = Py.makeClass( classname, sclass, --- 400,410 ---- private static PyObject buildClass(PyObject dict, String classname, ! String superclass, ! String classCodeName, String doc) { PyObject[] sclass = Py.EmptyObjects; if (superclass != null) ! sclass = new PyObject[] { ! dict.__getitem__(new PyString(superclass)) }; PyObject cls = Py.makeClass( classname, sclass, |
From: Finn B. <bc...@us...> - 2001-03-04 18:07:28
|
Update of /cvsroot/jython/jython/org/python/core In directory usw-pr-cvs1:/tmp/cvs-serv26653 Modified Files: PyDictionary.java PyList.java PyStringMap.java Log Message: Added javadoc comments. Index: PyDictionary.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyDictionary.java,v retrieving revision 2.13 retrieving revision 2.14 diff -C2 -r2.13 -r2.14 *** PyDictionary.java 2001/02/25 16:55:14 2.13 --- PyDictionary.java 2001/03/04 18:08:59 2.14 *************** *** 97,109 **** } ! // Used by PyJavaClass.init() public PyDictionary() { this(new Hashtable()); } public PyDictionary(Hashtable t) { table = t; } public PyDictionary(PyObject elements[]) { this(); --- 97,122 ---- } ! /** ! * Create an empty dictionary. ! */ public PyDictionary() { this(new Hashtable()); } + /** + * Create an new dictionary which is based on the hashtable. + * @param t the hashtable used. The supplied hashtable is used as + * is and must only contain PyObject key:value pairs. + */ public PyDictionary(Hashtable t) { table = t; } + /** + * Create a new dictionary with the element as content. + * @param elements The initial elements that is inserted in the + * dictionary. Even numbered elements are keys, + * odd numbered elements are values. + */ public PyDictionary(PyObject elements[]) { this(); *************** *** 113,116 **** --- 126,130 ---- } + /** <i>Internal use only. Do not call this method explicit.</i> */ public static void classDictInit(PyObject dict) { dict.__setitem__("__len__", new DictFuncs("__len__", 1, 0)); *************** *** 232,239 **** --- 246,265 ---- } + /** + * Return true if the key exist in the dictionary. + */ public boolean has_key(PyObject key) { return table.containsKey(key); } + + /** + * Return this[key] if the key exists in the mapping, default_object + * is returned otherwise. + * + * @param key the key to lookup in the dictionary. + * @param default_object the value to return if the key does not + * exists in the mapping. + */ public PyObject get(PyObject key, PyObject default_object) { PyObject o = __finditem__(key); *************** *** 244,259 **** --- 270,301 ---- } + /** + * Return this[key] if the key exists in the mapping, None + * is returned otherwise. + * + * @param key the key to lookup in the dictionary. + */ public PyObject get(PyObject key) { return get(key, Py.None); } + /** + * Return a shallow copy of the dictionary. + */ public PyDictionary copy() { return new PyDictionary((Hashtable)table.clone()); } + /** + * Remove all items from the dictionary. + */ public void clear() { table.clear(); } + /** + * Insert all the key:value pairs from <code>d</code> into + * this dictionary. + */ public void update(PyDictionary d) { Hashtable otable = d.table; *************** *** 267,270 **** --- 309,316 ---- } + /** + * Insert all the key:value pairs from <code>d</code> into + * this dictionary. + */ public void update(PyStringMap d) { PyObject keys = d.keys(); *************** *** 274,281 **** --- 320,341 ---- } + /** + * Return this[key] if the key exist, otherwise insert key with + * a None value and return None. + * + * @param key the key to lookup in the dictionary. + */ public PyObject setdefault(PyObject key) { return setdefault(key, Py.None); } + /** + * Return this[key] if the key exist, otherwise insert key with + * the value of failobj and return failobj + * + * @param key the key to lookup in the dictionary. + * @param failobj the default value to insert in the dictionary + * if key does not already exist. + */ public PyObject setdefault(PyObject key, PyObject failobj) { PyObject o = __finditem__(key); *************** *** 285,288 **** --- 345,352 ---- } + /** + * Return a random (key, value) tuple pair and remove the pair + * from the dictionary. + */ public PyObject popitem() { java.util.Enumeration keys = table.keys(); *************** *** 295,298 **** --- 359,366 ---- } + /** + * Return a copy of the dictionarys list of (key, value) tuple + * pairs. + */ public PyList items() { java.util.Enumeration ek = table.keys(); *************** *** 308,311 **** --- 376,382 ---- } + /** + * Return a copy of the dictionarys list of keys. + */ public PyList keys() { java.util.Enumeration e = table.keys(); *************** *** 318,321 **** --- 389,395 ---- } + /** + * Return a copy of the dictionarys list of values. + */ public PyList values() { java.util.Enumeration e = table.elements(); Index: PyList.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyList.java,v retrieving revision 2.20 retrieving revision 2.21 diff -C2 -r2.20 -r2.21 *** PyList.java 2001/02/25 16:55:14 2.20 --- PyList.java 2001/03/04 18:08:59 2.21 *************** *** 99,102 **** --- 99,103 ---- } + /** <i>Internal use only. Do not call this method explicit.</i> */ public static void classDictInit(PyObject dict) { PySequence.classDictInit(dict); *************** *** 317,320 **** --- 318,326 ---- } + /** + * Add a single element to the end of list. + * + * @param o the element to add. + */ public void append(PyObject o) { resize(length+1); *************** *** 322,325 **** --- 328,337 ---- } + /** + * Return the number elements in the list that equals the argument. + * + * @param o the argument to test for. Testing is done with + * the <code>==</code> operator. + */ public int count(PyObject o) { int count = 0; *************** *** 333,336 **** --- 345,355 ---- } + /** + * return smallest index where an element in the list equals + * the argument. + * + * @param o the argument to test for. Testing is done with + * the <code>==</code> operator. + */ public int index(PyObject o) { int n = length; *************** *** 346,349 **** --- 365,377 ---- } + /** + * Insert the argument element into the list at the specified + * index. + * <br> + * Same as <code>s[index:index] = [o] if index >= 0</code>. + * + * @param index the position where the element will be inserted. + * @param o the element to insert. + */ public void insert(int index, PyObject o) { if (index < 0) *************** *** 356,363 **** --- 384,405 ---- } + /** + * Remove the first occurence of the argument from the list. + * The elements arecompared with the <code>==</code> operator. + * <br> + * Same as <code>del s[s.index(x)]</code> + * + * @param o the element to search for and remove. + */ public void remove(PyObject o) { del(index(o)); } + /** + * Reverses the items of s in place. + * The reverse() methods modify the list in place for economy + * of space when reversing a large list. It doesn't return the + * reversed list to remind you of this side effect. + */ public void reverse() { PyObject tmp; *************** *** 372,379 **** --- 414,430 ---- } + /** + * Removes and return the last element in the list. + */ public PyObject pop() { return pop(-1); } + /** + * Removes and return the <code>n</code> indexed element in the + * list. + * + * @param n the index of the element to remove and return. + */ public PyObject pop(int n) { if (length==0) { *************** *** 390,393 **** --- 441,452 ---- } + + /** + * Append the elements in the argument sequence to the end of the list. + * <br> + * Same as <code>s[len(s):len(s)] = o</code>. + * + * @param o the sequence of items to append to the list. + */ public void extend(PyObject o) { setslice(length, length, 1, o); *************** *** 600,609 **** } ! // Future PyLists will probably have their own PyObject[]. For now, we ! // must copy one out of and back into the vector public synchronized void sort(PyObject compare) { quicksort(list, 0, length, compare); } public void sort() { sort(null); --- 659,683 ---- } ! /** ! * Sort the items of the list in place. The compare argument is a ! * function of two arguments (list items) which should return ! * -1, 0 or 1 depending on whether the first argument is ! * considered smaller than, equal to, or larger than the second ! * argument. Note that this slows the sorting process down ! * considerably; e.g. to sort a list in reverse order it is much ! * faster to use calls to the methods sort() and reverse() than ! * to use the built-in function sort() with a comparison function ! * that reverses the ordering of the elements. ! * ! * @param compare the comparison function. ! */ public synchronized void sort(PyObject compare) { quicksort(list, 0, length, compare); } + /** + * Sort the items of the list in place. Items is compared with the + * normal relative comparison operators. + */ public void sort() { sort(null); Index: PyStringMap.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyStringMap.java,v retrieving revision 2.10 retrieving revision 2.11 diff -C2 -r2.10 -r2.11 *** PyStringMap.java 2001/02/25 16:51:51 2.10 --- PyStringMap.java 2001/03/04 18:08:59 2.11 *************** *** 238,241 **** --- 238,244 ---- } + /** + * Remove all items from the dictionary. + */ public synchronized void clear() { for (int i=0; i<keys.length; i++) { *************** *** 318,325 **** --- 321,339 ---- } + /** + * Return true if the key exist in the dictionary. + */ public boolean has_key(PyObject key) { return __finditem__(key) != null; } + /** + * Return this[key] if the key exists in the mapping, default_object + * is returned otherwise. + * + * @param key the key to lookup in the mapping. + * @param default_object the value to return if the key does not + * exists in the mapping. + */ public PyObject get(PyObject key, PyObject default_object) { PyObject o = __finditem__(key); *************** *** 330,337 **** --- 344,360 ---- } + /** + * Return this[key] if the key exists in the mapping, None + * is returned otherwise. + * + * @param key the key to lookup in the mapping. + */ public PyObject get(PyObject key) { return get(key, Py.None); } + /** + * Return a shallow copy of the dictionary. + */ public synchronized PyStringMap copy() { int n = keys.length; *************** *** 348,351 **** --- 371,378 ---- } + /** + * Insert all the key:value pairs from <code>map</code> into + * this mapping. + */ public synchronized void update(PyStringMap map) { String[] keyTable = map.keys; *************** *** 364,367 **** --- 391,398 ---- } + /** + * Insert all the key:value pairs from <code>dict</code> into + * this mapping. + */ public void update(PyDictionary dict) { java.util.Hashtable table = dict.table; *************** *** 377,384 **** --- 408,429 ---- } + /** + * Return this[key] if the key exist, otherwise insert key with + * a None value and return None. + * + * @param key the key to lookup in the mapping. + */ public PyObject setdefault(PyObject key) { return setdefault(key, Py.None); } + /** + * Return this[key] if the key exist, otherwise insert key with + * the value of failobj and return failobj + * + * @param key the key to lookup in the mapping. + * @param failobj the default value to insert in the mapping + * if key does not already exist. + */ public PyObject setdefault(PyObject key, PyObject failobj) { PyObject o = __finditem__(key); *************** *** 388,392 **** } ! public synchronized PyObject popitem() { if (size == 0) --- 433,440 ---- } ! /** ! * Return a random (key, value) tuple pair and remove the pair ! * from the mapping. ! */ public synchronized PyObject popitem() { if (size == 0) *************** *** 419,422 **** --- 467,474 ---- } + /** + * Return a copy of the mappings list of (key, value) tuple + * pairs. + */ public synchronized PyList items() { String[] keyTable = keys; *************** *** 455,458 **** --- 507,513 ---- + /** + * Return a copy of the mappings list of keys. + */ public synchronized PyList keys() { String[] keyTable = keys; *************** *** 470,473 **** --- 525,531 ---- } + /** + * Return a copy of the mappings list of values. + */ public synchronized PyList values() { PyObject[] valueTable = values; |
From: Finn B. <bc...@us...> - 2001-03-04 18:06:31
|
Update of /cvsroot/jython/jython/org/python/core In directory usw-pr-cvs1:/tmp/cvs-serv26430 Modified Files: Py.java PyClass.java Log Message: Cleaned the PyClass ctors and added comments. Index: Py.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/Py.java,v retrieving revision 2.39 retrieving revision 2.40 diff -C2 -r2.39 -r2.40 *** Py.java 2001/02/22 11:10:38 2.39 --- Py.java 2001/03/04 18:08:02 2.40 *************** *** 423,427 **** public static PyObject newJavaFunc(Class cls, String name) { try { ! java.lang.reflect.Method m = cls.getMethod(name, new Class[] { PyObject[].class, String[].class }); return new JavaFunc(m); --- 423,427 ---- public static PyObject newJavaFunc(Class cls, String name) { try { ! java.lang.reflect.Method m = cls.getMethod(name, new Class[] { PyObject[].class, String[].class }); return new JavaFunc(m); *************** *** 1335,1344 **** } ! PyClass pyclass = new PyClass(); ! if (proxyClass != null) ! pyclass.proxyClass = proxyClass; ! ! pyclass.init(name, new PyTuple(bases), dict); ! return pyclass; } --- 1335,1339 ---- } ! return new PyClass(name, new PyTuple(bases), dict, proxyClass); } *************** *** 1578,1582 **** /** ! * A function object wrapper for a java method which comply with the * PyArgsKeywordsCall standard. */ --- 1573,1577 ---- /** ! * A function object wrapper for a java method which comply with the * PyArgsKeywordsCall standard. */ Index: PyClass.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyClass.java,v retrieving revision 2.21 retrieving revision 2.22 diff -C2 -r2.21 -r2.22 *** PyClass.java 2001/02/25 16:57:01 2.21 --- PyClass.java 2001/03/04 18:08:02 2.22 *************** *** 41,49 **** } - public PyClass() { - super(__class__); - proxyClass = null; - } - protected PyClass(PyClass c) { super(c); --- 41,44 ---- *************** *** 51,56 **** } public PyClass(String name, PyTuple bases, PyObject dict) { ! this(); init(name, bases, dict); } --- 46,83 ---- } + + /** + * Create a python class. + * + * @param name name of the class. + * @param bases A list of base classes. + * @param dict The class dict. Normally this dict is returned by + * the class code object. + * + * @see org.python.core.Py#makeClass(String, PyObject[], PyCode, PyObject) + */ public PyClass(String name, PyTuple bases, PyObject dict) { ! this(name, bases, dict, null); ! } ! ! /** ! * Create a python class which inherit from a java class and where ! * we already have generated a proxyclass. If we do not have a ! * pre-generated proxyclass, the class initialization method will ! * create such a proxyclass if bases contain a java class. ! * ! * @param name name of the class. ! * @param bases A list of base classes. ! * @param dict The class dict. Normally this dict is returned by ! * the class code object. ! * ! * @see org.python.core.Py#makeClass(String, PyObject[], PyCode, ! * PyObject, Class) ! */ ! public PyClass(String name, PyTuple bases, PyObject dict, ! Class proxyClass) ! { ! super(__class__); ! this.proxyClass = proxyClass; init(name, bases, dict); } |
From: Finn B. <bc...@us...> - 2001-03-04 18:05:13
|
Update of /cvsroot/jython/jython/org/python/core In directory usw-pr-cvs1:/tmp/cvs-serv26220 Modified Files: CachedJarsPackageManager.java Log Message: Changed some comments links. The links was to protected methods and the javadoc generation with public option complained about missing methods. Index: CachedJarsPackageManager.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/CachedJarsPackageManager.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -r1.6 -r1.7 *** CachedJarsPackageManager.java 2001/02/02 09:28:36 1.6 --- CachedJarsPackageManager.java 2001/03/04 18:06:45 1.7 *************** *** 149,153 **** * Eventually updated info is not cached. * Persistent cache storage access goes through ! * {@link #inOpenCacheFile}, {@link #outCreateCacheFile}. */ public void addJarToPackages(java.net.URL jarurl) { --- 149,153 ---- * Eventually updated info is not cached. * Persistent cache storage access goes through ! * inOpenCacheFile() and outCreateCacheFile(). */ public void addJarToPackages(java.net.URL jarurl) { *************** *** 159,163 **** * Eventually updated info is (re-)cached if param cache is true. * Persistent cache storage access goes through ! * {@link #inOpenCacheFile}, {@link #outCreateCacheFile}. */ public void addJarToPackages(URL jarurl,boolean cache) { --- 159,163 ---- * Eventually updated info is (re-)cached if param cache is true. * Persistent cache storage access goes through ! * inOpenCacheFile() and outCreateCacheFile(). */ public void addJarToPackages(URL jarurl,boolean cache) { *************** *** 169,173 **** * Eventually updated info is not cached. * Persistent cache storage access goes through ! * {@link #inOpenCacheFile}, {@link #outCreateCacheFile}. */ public void addJarToPackages(File jarfile) { --- 169,173 ---- * Eventually updated info is not cached. * Persistent cache storage access goes through ! * inOpenCacheFile() and outCreateCacheFile(). */ public void addJarToPackages(File jarfile) { *************** *** 179,183 **** * Eventually updated info is (re-)cached if param cache is true. * Persistent cache storage access goes through ! * {@link #inOpenCacheFile}, {@link #outCreateCacheFile}. */ public void addJarToPackages(File jarfile,boolean cache) { --- 179,183 ---- * Eventually updated info is (re-)cached if param cache is true. * Persistent cache storage access goes through ! * inOpenCacheFile() and outCreateCacheFile(). */ public void addJarToPackages(File jarfile,boolean cache) { *************** *** 367,371 **** /** Initializes cache. Eventually reads back cache index. ! * Index persistent storage is accessed through {@link #inOpenIndex}. */ protected void initCache() { --- 367,371 ---- /** Initializes cache. Eventually reads back cache index. ! * Index persistent storage is accessed through inOpenIndex(). */ protected void initCache() { *************** *** 395,399 **** /** Write back cache index. ! * Index persistent storage is accessed through {@link #outOpenIndex}. */ public void saveCache() { --- 395,399 ---- /** Write back cache index. ! * Index persistent storage is accessed through outOpenIndex(). */ public void saveCache() { *************** *** 422,426 **** /** To pass a cachefile id by ref. And for internal use. ! * @see #outCreateCacheFile */ public static class JarXEntry extends Object { --- 422,426 ---- /** To pass a cachefile id by ref. And for internal use. ! * @see outCreateCacheFile */ public static class JarXEntry extends Object { |