From: <fwi...@us...> - 2008-08-20 15:51:12
|
Revision: 5222 http://jython.svn.sourceforge.net/jython/?rev=5222&view=rev Author: fwierzbicki Date: 2008-08-20 15:49:38 +0000 (Wed, 20 Aug 2008) Log Message: ----------- Added Ellipsis and merged with trunk. Modified Paths: -------------- branches/nowalker/Lib/pkgutil.py branches/nowalker/grammar/Python.g branches/nowalker/src/org/python/compiler/Module.java branches/nowalker/src/org/python/core/PyBaseException.java branches/nowalker/src/org/python/core/PyFrame.java branches/nowalker/src/org/python/core/PyObject.java branches/nowalker/src/org/python/core/__builtin__.java branches/nowalker/src/org/python/core/imp.java branches/nowalker/src/org/python/modules/zipimport/zipimporter.java branches/nowalker/src/shell/jython.bat Property Changed: ---------------- branches/nowalker/ Property changes on: branches/nowalker ___________________________________________________________________ Modified: svnmerge-integrated - /trunk/jython:1-5208 + /trunk/jython:1-5221 Modified: branches/nowalker/Lib/pkgutil.py =================================================================== --- branches/nowalker/Lib/pkgutil.py 2008-08-20 15:39:29 UTC (rev 5221) +++ branches/nowalker/Lib/pkgutil.py 2008-08-20 15:49:38 UTC (rev 5222) @@ -22,7 +22,7 @@ # accessed by _imp here def read_jython_code(fullname, file, filename): - data = _imp.unmarshalCode(filename, file, False) + data = _imp.readCode(filename, file, False) return BytecodeLoader.makeCode(fullname + "$py", data, filename) def simplegeneric(func): Modified: branches/nowalker/grammar/Python.g =================================================================== --- branches/nowalker/grammar/Python.g 2008-08-20 15:39:29 UTC (rev 5221) +++ branches/nowalker/grammar/Python.g 2008-08-20 15:49:38 UTC (rev 5222) @@ -117,6 +117,7 @@ import org.python.antlr.ast.Continue; import org.python.antlr.ast.Delete; import org.python.antlr.ast.Dict; +import org.python.antlr.ast.Ellipsis; import org.python.antlr.ast.excepthandlerType; import org.python.antlr.ast.Exec; import org.python.antlr.ast.Expr; @@ -1092,7 +1093,7 @@ $subscript.tree = $sltype; } } - : DOT DOT DOT -> Ellipsis + : d1=DOT DOT DOT -> DOT<Ellipsis>[$d1] | (test[expr_contextType.Load] COLON) => lower=test[expr_contextType.Load] (c1=COLON (upper1=test[expr_contextType.Load])? (sliceop)?)? { $sltype = actions.makeSubscript($lower.tree, $c1, $upper1.tree, $sliceop.tree); } Modified: branches/nowalker/src/org/python/compiler/Module.java =================================================================== --- branches/nowalker/src/org/python/compiler/Module.java 2008-08-20 15:39:29 UTC (rev 5221) +++ branches/nowalker/src/org/python/compiler/Module.java 2008-08-20 15:49:38 UTC (rev 5222) @@ -405,6 +405,29 @@ CodeCompiler compiler = new CodeCompiler(this, printResults); + if (classBody) { + Label label_got_name = new Label(); + int module_tmp = c.getLocal("org/python/core/PyObject"); + + c.aload(1); + c.ldc("__module__"); + c.invokevirtual("org/python/core/PyFrame", "getname_or_null", "(" + $str + ")" + $pyObj); + c.dup(); + c.ifnonnull(label_got_name); + + c.pop(); + c.aload(1); + c.ldc("__name__"); + c.invokevirtual("org/python/core/PyFrame", "getname_or_null", "(" + $str + ")" + $pyObj); + + c.label(label_got_name); + c.astore(module_tmp); + c.aload(1); + c.ldc("__module__"); + c.aload(module_tmp); + c.invokevirtual("org/python/core/PyFrame", "setlocal", "(" + $str + $pyObj + ")V"); + } + Label genswitch = new Label(); if (scope.generator) { c.goto_(genswitch); Modified: branches/nowalker/src/org/python/core/PyBaseException.java =================================================================== --- branches/nowalker/src/org/python/core/PyBaseException.java 2008-08-20 15:39:29 UTC (rev 5221) +++ branches/nowalker/src/org/python/core/PyBaseException.java 2008-08-20 15:49:38 UTC (rev 5222) @@ -166,23 +166,20 @@ } } + @Override public String toString() { - return __repr__().toString(); + return BaseException_toString(); } - - public PyString __repr__() { - return BaseException___repr__(); - } - @ExposedMethod - final PyString BaseException___repr__() { + @ExposedMethod(names = ("__repr__")) + final String BaseException_toString() { PyObject reprSuffix = args.__repr__(); String name = getType().fastGetName(); int lastDot = name.lastIndexOf('.'); if (lastDot != -1) { name = name.substring(lastDot + 1); } - return Py.newString(name + reprSuffix.toString()); + return name + reprSuffix.toString(); } @ExposedSet(name = "args") Modified: branches/nowalker/src/org/python/core/PyFrame.java =================================================================== --- branches/nowalker/src/org/python/core/PyFrame.java 2008-08-20 15:39:29 UTC (rev 5221) +++ branches/nowalker/src/org/python/core/PyFrame.java 2008-08-20 15:49:38 UTC (rev 5222) @@ -282,6 +282,20 @@ throw Py.NameError(String.format(NAME_ERROR_MSG, index)); } + public PyObject getname_or_null(String index) { + PyObject ret; + if (f_locals == null || f_locals == f_globals) { + ret = doGetglobal(index); + } else { + ret = f_locals.__finditem__(index); + if (ret != null) { + return ret; + } + ret = doGetglobal(index); + } + return ret; + } + public PyObject getglobal(String index) { PyObject ret = doGetglobal(index); if (ret != null) { Modified: branches/nowalker/src/org/python/core/PyObject.java =================================================================== --- branches/nowalker/src/org/python/core/PyObject.java 2008-08-20 15:39:29 UTC (rev 5221) +++ branches/nowalker/src/org/python/core/PyObject.java 2008-08-20 15:49:38 UTC (rev 5222) @@ -281,7 +281,7 @@ * * @param arg0 the first argument to the function. * @param arg1 the second argument to the function. -n **/ + **/ public PyObject __call__(PyObject arg0, PyObject arg1) { return __call__(new PyObject[] { arg0, arg1 }, Py.NoKeywords); } Modified: branches/nowalker/src/org/python/core/__builtin__.java =================================================================== --- branches/nowalker/src/org/python/core/__builtin__.java 2008-08-20 15:39:29 UTC (rev 5221) +++ branches/nowalker/src/org/python/core/__builtin__.java 2008-08-20 15:49:38 UTC (rev 5222) @@ -1410,7 +1410,7 @@ @Override public String toString() { - return "<built-in function min>"; + return "<built-in function max>"; } private static PyObject max(PyObject o, PyObject key) { Modified: branches/nowalker/src/org/python/core/imp.java =================================================================== --- branches/nowalker/src/org/python/core/imp.java 2008-08-20 15:39:29 UTC (rev 5221) +++ branches/nowalker/src/org/python/core/imp.java 2008-08-20 15:49:38 UTC (rev 5222) @@ -87,7 +87,7 @@ static PyObject createFromPyClass(String name, InputStream fp, boolean testing, String fileName) { - byte[] data = unmarshalCode(name, fp, testing); + byte[] data = readCode(name, fp, testing); if (testing && data == null) { return null; } @@ -107,8 +107,7 @@ return createFromCode(name, code, fileName); } - public static byte[] unmarshalCode(String name, InputStream fp, - boolean testing) { + public static byte[] readCode(String name, InputStream fp, boolean testing) { byte[] data = readBytes(fp); int n = data.length; Modified: branches/nowalker/src/org/python/modules/zipimport/zipimporter.java =================================================================== --- branches/nowalker/src/org/python/modules/zipimport/zipimporter.java 2008-08-20 15:39:29 UTC (rev 5221) +++ branches/nowalker/src/org/python/modules/zipimport/zipimporter.java 2008-08-20 15:49:38 UTC (rev 5222) @@ -6,6 +6,7 @@ import java.io.InputStream; import java.util.Date; import java.util.Enumeration; +import java.util.EnumSet; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -51,19 +52,22 @@ /** zip_searchorder defines how we search for a module in the Zip * archive */ - static final int IS_SOURCE = 0; - static final int IS_BYTECODE = 1; - static final int IS_PACKAGE = 2; + static enum EntryType { + IS_SOURCE, IS_BYTECODE, IS_PACKAGE + }; static final SearchOrderEntry[] zip_searchorder = new SearchOrderEntry[] { - new SearchOrderEntry(File.separator + "__init__$py.class", IS_PACKAGE | IS_BYTECODE), - new SearchOrderEntry(File.separator + "__init__.py", IS_PACKAGE | IS_SOURCE), - new SearchOrderEntry("$py.class", IS_BYTECODE), - new SearchOrderEntry(".py", IS_SOURCE), - new SearchOrderEntry("", 0) + new SearchOrderEntry(File.separator + "__init__$py.class", + EnumSet.of(EntryType.IS_PACKAGE, EntryType.IS_BYTECODE)), + new SearchOrderEntry(File.separator + "__init__.py", + EnumSet.of(EntryType.IS_PACKAGE, EntryType.IS_SOURCE)), + new SearchOrderEntry("$py.class", EnumSet.of(EntryType.IS_BYTECODE)), + new SearchOrderEntry(".py", EnumSet.of(EntryType.IS_SOURCE)), }; /** Module information */ - static enum ModuleInfo {ERROR, NOT_FOUND, MODULE, PACKAGE}; + static enum ModuleInfo { + ERROR, NOT_FOUND, MODULE, PACKAGE + }; /** Pathname of the Zip archive */ @ExposedGet @@ -366,7 +370,7 @@ if (tocEntry == null) continue; - if ((entry.type & IS_PACKAGE) == IS_PACKAGE) { + if (entry.type.contains(EntryType.IS_PACKAGE)) { return ModuleInfo.PACKAGE; } return ModuleInfo.MODULE; @@ -399,8 +403,8 @@ continue; } - boolean ispackage = (entry.type & IS_PACKAGE) == IS_PACKAGE; - boolean isbytecode = (entry.type & IS_BYTECODE) == IS_BYTECODE; + boolean ispackage = entry.type.contains(EntryType.IS_PACKAGE); + boolean isbytecode = entry.type.contains(EntryType.IS_BYTECODE); if (isbytecode && isOutdatedBytecode(searchPath, tocEntry)) { continue; @@ -410,7 +414,7 @@ ZipBundle zipBundle = getDataStream(searchPath); byte[] codeBytes; if (isbytecode) { - codeBytes = imp.unmarshalCode(fullname, zipBundle.inputStream, true); + codeBytes = imp.readCode(fullname, zipBundle.inputStream, true); } else { codeBytes = imp.compileSource(fullname, zipBundle.inputStream, pathToEntry); @@ -422,7 +426,6 @@ continue; } - imp.cacheCompiledSource(pathToEntry, null, codeBytes); PyCode code = BytecodeLoader.makeCode(fullname + "$py", codeBytes, pathToEntry); return new ModuleCodeData(code, ispackage, pathToEntry); } @@ -661,9 +664,9 @@ */ protected static class SearchOrderEntry { public String suffix; - public int type; + public EnumSet type; - public SearchOrderEntry(String suffix, int type) { + public SearchOrderEntry(String suffix, EnumSet type) { this.suffix = suffix; this.type = type; } Modified: branches/nowalker/src/shell/jython.bat =================================================================== --- branches/nowalker/src/shell/jython.bat 2008-08-20 15:39:29 UTC (rev 5221) +++ branches/nowalker/src/shell/jython.bat 2008-08-20 15:49:38 UTC (rev 5222) @@ -18,10 +18,10 @@ set _JAVA_CMD=java if not "%JAVA_HOME%" == "" ( - set _JAVA_CMD="%JAVA_HOME%\bin\java" + set _JAVA_CMD="%JAVA_HOME:"=%\bin\java" ) -set _JYTHON_HOME="%JYTHON_HOME%" +set _JYTHON_HOME=%JYTHON_HOME% if not "%JYTHON_HOME%" == "" goto gotHome pushd "%~dp0%\.." set _JYTHON_HOME="%CD%" @@ -32,7 +32,7 @@ rem prefer built version set _CP=%_JYTHON_HOME%\jython.jar for %%j in (%_JYTHON_HOME%\javalib\*.jar) do ( - set _CP=!_CP!;"%%j" + set _CP=!_CP!;"%%j" ) goto run @@ -48,13 +48,103 @@ rem ----- Execute the requested command ---------------------------------------- :run -%_JAVA_CMD% %JAVA_OPTS% -Xss512k -Xbootclasspath/a:%_CP% -Dpython.home=%_JYTHON_HOME% -Dpython.executable="%~f0" -classpath "%CLASSPATH%" org.python.util.jython %JYTHON_OPTS% %* +set _JAVA_STACK=-Xss512k + +rem Escape any quotes. Use _S for ', _D for ", and _U to escape _ itself. +rem We have to escape _ itself, otherwise file names with _S and _D +rem will be converted to to wrong ones, when we un-escape. See JRUBY-2821. +set _ARGS=%* +if not defined _ARGS goto argsDone +set _ARGS=%_ARGS:_=_U% +set _ARGS=%_ARGS:'=_S% +set _ARGS=%_ARGS:"=_D% + +set _ARGS="%_ARGS%" + +:scanArgs +rem split args by spaces into first and rest +for /f "tokens=1,*" %%i in (%_ARGS%) do call :getArg "%%i" "%%j" +goto procArg + +:getArg +rem remove quotes around first arg +for %%i in (%1) do set _CMP=%%~i +set _ARGS=%2 +goto :EOF + +:procArg +if ["%_CMP%"] == [""] ( + set _ARGS= + goto argsDone +) + +REM NOTE: If you'd like to use a parameter with underscore in its name, +REM NOTE: use the quoted value: --do_stuff -> --do_Ustuff + +if ["%_CMP%"] == ["--"] goto argsDone + +if ["%_CMP%"] == ["--jdb"] ( + if "%JAVA_HOME%" == "" ( + set _JAVA_CMD=jdb + ) else ( + set _JAVA_CMD="%_JAVA_HOME:"=%\bin\jdb" + ) + goto :nextArg +) + +if ["%_CMP%"] == ["--verify"] ( + set CLASSPATH=%_CP:"=%;%CLASSPATH:"=% + set _CP= + goto :nextArg +) + +rem now unescape _D, _S and _Q +set _CMP=%_CMP:_D="% +set _CMP=%_CMP:_S='% +set _CMP=%_CMP:_U=_% +set _CMP1=%_CMP:~0,1% +set _CMP2=%_CMP:~0,2% + +rem detect first character is a quote; skip directly to jythonArg +rem this avoids a batch syntax error +if "%_CMP1:"=\\%" == "\\" goto jythonArg + +rem removing quote avoids a batch syntax error +if "%_CMP2:"=\\%" == "-J" goto jvmArg + +:jythonArg +set JYTHON_OPTS=%JYTHON_OPTS% %_CMP% +goto nextArg + +:jvmArg +set _VAL=%_CMP:~2% + +if "%_VAL:~0,4%" == "-Xss" ( + set _JAVA_STACK=%_VAL% + echo %_VAL% + goto nextArg +) + +set _JAVA_OPTS=%_JAVA_OPTS% %_VAL% + +:nextArg +set _CMP= +goto scanArgs + +:argsDone +%_JAVA_CMD% %_JAVA_OPTS% %_JAVA_STACK% -Xbootclasspath/a:%_CP% -Dpython.home=%_JYTHON_HOME% -Dpython.executable="%~f0" -classpath "%CLASSPATH%" org.python.util.jython %JYTHON_OPTS% %_ARGS% set E=%ERRORLEVEL% :cleanup +set _ARGS= +set _CMP= +set _CMP1= +set _CMP2= +set _CP= +set _JAVA_CMD= +set _JAVA_OPTS= +set _JAVA_STACK= set _JYTHON_HOME= -set _JAVA_CMD= -set _CP= :finish exit /b %E% This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |