From: <fwi...@us...> - 2008-08-09 13:52:16
|
Revision: 5119 http://jython.svn.sourceforge.net/jython/?rev=5119&view=rev Author: fwierzbicki Date: 2008-08-09 13:52:14 +0000 (Sat, 09 Aug 2008) Log Message: ----------- debug() is not really all that necessary now that these have been extracted from the .g files. Modified Paths: -------------- branches/asm/src/org/python/antlr/GrammarActions.java Modified: branches/asm/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/asm/src/org/python/antlr/GrammarActions.java 2008-08-09 12:36:39 UTC (rev 5118) +++ branches/asm/src/org/python/antlr/GrammarActions.java 2008-08-09 13:52:14 UTC (rev 5119) @@ -92,11 +92,6 @@ public void setErrorHandler(ErrorHandler eh) { this.errorHandler = eh; } - void debug(String x) { - if (false) { - System.out.println(x); - } - } void throwGenExpNotSoleArg(PythonTree t) { throw new ParseException("Generator expression must be parenthesized if not sole argument", t); @@ -144,7 +139,6 @@ return errorHandler.errorStmt(t); } argumentsType a; - debug("Matched FunctionDef"); if (args != null) { a = args; } else { @@ -162,7 +156,6 @@ argumentsType makeArgumentsType(Token t, List params, Token snameToken, Token knameToken, List defaults) { - debug("Matched Arguments"); exprType[] p = (exprType[])params.toArray(new exprType[params.size()]); exprType[] d = (exprType[])defaults.toArray(new exprType[defaults.size()]); @@ -184,7 +177,6 @@ Object makeFloat(Token t) { - debug("makeFloat matched " + t.getText()); return Py.newFloat(Double.valueOf(t.getText())); } @@ -195,7 +187,6 @@ } Object makeInt(Token t) { - debug("Num matched " + t.getText()); String s = t.getText(); int radix = 10; if (s.startsWith("0x") || s.startsWith("0X")) { @@ -335,7 +326,6 @@ argumentsType makeArgumentsType(PythonTree t, List params, PythonTree snameToken, PythonTree knameToken, List defaults) { - debug("Matched Arguments"); exprType[] p = (exprType[])params.toArray(new exprType[params.size()]); exprType[] d = (exprType[])defaults.toArray(new exprType[defaults.size()]); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-13 00:30:40
|
Revision: 5164 http://jython.svn.sourceforge.net/jython/?rev=5164&view=rev Author: fwierzbicki Date: 2008-08-13 00:30:38 +0000 (Wed, 13 Aug 2008) Log Message: ----------- Before this check-in there was an AST inconsistency with CPython. To pick one example, CPython's AST for --1 is (USub(-1)) and Jython is (Usub(Usub(1)). This fixes that inconsistency. Modified Paths: -------------- branches/asm/src/org/python/antlr/GrammarActions.java Modified: branches/asm/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/asm/src/org/python/antlr/GrammarActions.java 2008-08-12 22:58:47 UTC (rev 5163) +++ branches/asm/src/org/python/antlr/GrammarActions.java 2008-08-13 00:30:38 UTC (rev 5164) @@ -4,6 +4,10 @@ import org.antlr.runtime.Token; import org.python.core.Py; +import org.python.core.PyComplex; +import org.python.core.PyFloat; +import org.python.core.PyInteger; +import org.python.core.PyLong; import org.python.core.PyObject; import org.python.core.PyString; import org.python.core.PyUnicode; @@ -85,7 +89,6 @@ public class GrammarActions { private ErrorHandler errorHandler = null; - public GrammarActions() { } @@ -448,10 +451,31 @@ exprType negate(PythonTree t, exprType o) { if (o instanceof Num) { Num num = (Num)o; - if (num.n instanceof PyObject) { - num.n = ((PyObject)num.n).__neg__(); + if (num.n instanceof PyInteger) { + int v = ((PyInteger)num.n).getValue(); + if (v > 0) { + num.n = new PyInteger(-v); + return num; + } + } else if (num.n instanceof PyLong) { + BigInteger v = ((PyLong)num.n).getValue(); + if (v.compareTo(BigInteger.ZERO) == 1) { + num.n = new PyLong(v.negate()); + return num; + } + } else if (num.n instanceof PyFloat) { + double v = ((PyFloat)num.n).getValue(); + if (v > 0) { + num.n = new PyFloat(-v); + return num; + } + } else if (num.n instanceof PyComplex) { + double v = ((PyComplex)num.n).imag; + if (v > 0) { + num.n = new PyComplex(0,-v); + return num; + } } - return num; } return new UnaryOp(t, unaryopType.USub, o); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-13 16:21:21
|
Revision: 5169 http://jython.svn.sourceforge.net/jython/?rev=5169&view=rev Author: fwierzbicki Date: 2008-08-13 16:21:18 +0000 (Wed, 13 Aug 2008) Log Message: ----------- remove comment that is no longer True, thanks to Leo Soto for pointing this out. Modified Paths: -------------- branches/asm/src/org/python/antlr/GrammarActions.java Modified: branches/asm/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/asm/src/org/python/antlr/GrammarActions.java 2008-08-13 14:52:12 UTC (rev 5168) +++ branches/asm/src/org/python/antlr/GrammarActions.java 2008-08-13 16:21:18 UTC (rev 5169) @@ -446,8 +446,6 @@ return new Call(t, func, a, k, starargs, kwargs); } - //FIXME: just calling __neg__ for now - can be better. Also does not parse expressions like - // --2 correctly (should give ^(USub -2) but gives 2). exprType negate(PythonTree t, exprType o) { if (o instanceof Num) { Num num = (Num)o; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |