diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2010-06-30 10:34:53 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2010-06-30 10:34:53 (GMT) |
commit | ce5b6c43bfbd1e016463c92f43c9075f64fafaa6 (patch) | |
tree | bbb68b7c8d03d33a8f4681c37416fdd011cfff81 /Python | |
parent | 881c1b4c102e9404c10de159a7f01442c2d7224e (diff) | |
download | cpython-ce5b6c43bfbd1e016463c92f43c9075f64fafaa6.zip cpython-ce5b6c43bfbd1e016463c92f43c9075f64fafaa6.tar.gz cpython-ce5b6c43bfbd1e016463c92f43c9075f64fafaa6.tar.bz2 |
Revert r82044, since it changed the semantics of negated imaginary literals.
Before r82044, '-7j' became complex(0.0, -7.0); afterwards it was
complex(-0.0, -7.0). See issue 9011.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ast.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Python/ast.c b/Python/ast.c index ce9f211..b8cb565 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -1664,8 +1664,34 @@ ast_for_trailer(struct compiling *c, const node *n, expr_ty left_expr) static expr_ty ast_for_factor(struct compiling *c, const node *n) { + node *pfactor, *ppower, *patom, *pnum; expr_ty expression; + /* If the unary - operator is applied to a constant, don't generate + a UNARY_NEGATIVE opcode. Just store the approriate value as a + constant. The peephole optimizer already does something like + this but it doesn't handle the case where the constant is + (sys.maxint - 1). In that case, we want a PyIntObject, not a + PyLongObject. + */ + if (TYPE(CHILD(n, 0)) == MINUS + && NCH(n) == 2 + && TYPE((pfactor = CHILD(n, 1))) == factor + && NCH(pfactor) == 1 + && TYPE((ppower = CHILD(pfactor, 0))) == power + && NCH(ppower) == 1 + && TYPE((patom = CHILD(ppower, 0))) == atom + && TYPE((pnum = CHILD(patom, 0))) == NUMBER) { + char *s = PyObject_MALLOC(strlen(STR(pnum)) + 2); + if (s == NULL) + return NULL; + s[0] = '-'; + strcpy(s + 1, STR(pnum)); + PyObject_FREE(STR(pnum)); + STR(pnum) = s; + return ast_for_atom(c, patom); + } + expression = ast_for_expr(c, CHILD(n, 1)); if (!expression) return NULL; |