Commit Graph

456 Commits

Author SHA1 Message Date
Skip Montanaro 869bacd465 revert - breaks build of Python/ast.c w/ gcc 2006-04-13 09:48:28 +00:00
Skip Montanaro b940671186 Use union to discriminate pointer types from enum/int types. 2006-04-13 09:37:01 +00:00
Anthony Baxter d691f1a35f casting nastiness to make C++ compiler happy 2006-04-13 01:23:28 +00:00
Anthony Baxter 2c33fc77fe per Jeremy's email, remove the _WITH_CAST versions of macros. g++
still has errors from the casts of asdl_seq_GET to cmpop_ty, but
otherwise it's C++ clean.
2006-04-12 00:43:09 +00:00
Anthony Baxter 7b782b61c5 more low-hanging fruit to make code compile under a C++ compiler. Not
entirely happy with the two new VISIT macros in compile.c, but I
couldn't see a better approach.
2006-04-11 12:01:56 +00:00
Neal Norwitz 14bc4e4d89 Use PyObject_* allocator since FutureFeatures is small 2006-04-10 06:57:06 +00:00
Neal Norwitz b183a25c29 Fix some warnings on HP-UX when using cc/aCC 2006-04-10 01:03:32 +00:00
Jeremy Hylton ed40ea1159 Generate line number table entries for except handlers.
Re-enable all the tests in test_trace.py except one.  Still not sure that these tests test what they used to test, but they pass.  One failing test seems to be caused by undocumented line number table behavior in Python 2.4.
2006-04-04 14:26:39 +00:00
Neal Norwitz cbce280d4f Don't abbreviate ABS, use long name ABSOLUTE. 2006-04-03 06:26:32 +00:00
Jeremy Hylton 12603c41da Expand comments on line numbers and blocks.
Reorder compiler_set_lineno() call for consistency.
2006-04-01 16:18:02 +00:00
Georg Brandl 5c170fd4a9 Fix some missing checks after PyTuple_New, PyList_New, PyDict_New 2006-03-17 19:03:25 +00:00
Nick Coghlan eadee9a744 Fix SF bug #1448804 and ad a test to ensure that all subscript operations continue to be handled correctly 2006-03-13 12:31:58 +00:00
Guido van Rossum f669436189 Um, I thought I'd already checked this in.
Anyway, this is the changes to the with-statement
so that __exit__ must return a true value in order
for a pending exception to be ignored.
The PEP (343) is already updated.
2006-03-10 02:28:35 +00:00
Neal Norwitz 10be2ea85d SF bug 1442442: LIST_APPEND optimization got lost in the AST merge.
Add it back.
2006-03-03 20:29:11 +00:00
Neal Norwitz d9cf85f421 Fix refleak if from __future__ import was not first 2006-03-02 08:08:42 +00:00
Neal Norwitz 3a5468efb0 Update known issues to reflect reality 2006-03-02 04:06:10 +00:00
Martin v. Löwis 49c5da1d88 Patch #1440601: Add col_offset attribute to AST nodes. 2006-03-01 22:49:05 +00:00
Jeremy Hylton e9357b21c0 Tabify and reflow some long lines.
Much of the peephole optimizer is now indented badly, but it's about
to be revised anyway.
2006-03-01 15:47:05 +00:00
Thomas Wouters 5e9f1fa706 Generally inehrit codeflags that are in PyCF_MASK, instead of writing it out
in multiple places. This makes compile()/eval()/etc also inherit the
absolute-import codeflag, like division and with-statement already were.
2006-02-28 20:02:27 +00:00
Thomas Wouters 34aa7ba114 from __future__ import with_statement addon for 'with', mostly written by
Neal.
2006-02-28 19:02:24 +00:00
Thomas Wouters f7f438ba3b SF patch #1438387, PEP 328: relative and absolute imports.
- IMPORT_NAME takes an extra argument from the stack: the relativeness of
   the import. Only passed to __import__ when it's not -1.

 - __import__() takes an optional 5th argument for the same thing; it
   __defaults to -1 (old semantics: try relative, then absolute)

 - 'from . import name' imports name (be it module or regular attribute)
   from the current module's *package*. Likewise, 'from .module import name'
   will import name from a sibling to the current module.

 - Importing from outside a package is not allowed; 'from . import sys' in a
   toplevel module will not work, nor will 'from .. import sys' in a
   (single-level) package.

 - 'from __future__ import absolute_import' will turn on the new semantics
   for import and from-import: imports will be absolute, except for
   from-import with dots.

Includes tests for regular imports and importhooks, parser changes and a
NEWS item, but no compiler-package changes or documentation changes.
2006-02-28 16:09:29 +00:00
Thomas Wouters 1175c43a12 Clarify C-style exception handling with proper label name. 2006-02-27 22:49:54 +00:00
Thomas Wouters bfe51ea5c8 Fix assertions. 2006-02-27 22:48:55 +00:00
Guido van Rossum c2e20744b2 PEP 343 -- the with-statement.
This was started by Mike Bland and completed by Guido
(with help from Neal).

This still needs a __future__ statement added;
Thomas is working on Michael's patch for that aspect.

There's a small amount of code cleanup and refactoring
in ast.c, compile.c and ceval.c (I fixed the lltrace
behavior when EXT_POP is used -- however I had to make
lltrace a static global).
2006-02-27 22:32:47 +00:00
Thomas Wouters dca3b9c797 PEP 308 implementation, including minor refdocs and some testcases. It
breaks the parser module, because it adds the if/else construct as well as
two new grammar rules for backward compatibility. If no one else fixes
parsermodule, I guess I'll go ahead and fix it later this week.

The TeX code was checked with texcheck.py, but not rendered. There is
actually a slight incompatibility:

>>> (x for x in lambda:0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: iteration over non-sequence

changes into

>>> (x for x in lambda: 0)
  File "<stdin>", line 1
    (x for x in lambda: 0)
                     ^
SyntaxError: invalid syntax

Since there's no way the former version can be useful, it's probably a
bugfix ;)
2006-02-27 00:24:13 +00:00
Martin v. Löwis 18e165558b Merge ssize_t branch. 2006-02-15 17:27:45 +00:00
Neal Norwitz 08b401f67a Fix icc warnings: single bit fields should be unsigned, shadowing local variables 2006-01-07 21:24:09 +00:00
Martin v. Löwis 94962615b7 Adjust usage of compiler_use_new_block to its return type. 2006-01-02 21:15:05 +00:00
Fredrik Lundh 93d69a7948 fixed compilation with an ordinary C89 compiler 2005-12-18 15:44:21 +00:00
Neal Norwitz 51abbc7b4a Fix Armin's bug 1333982. He found it, he didn't created it :-)
This code generated a C assertion:
        assert 1, ([s for s in x] +
                   [s for s in x])
        pass

assert was completely broken, it needed to use the proper block.
compiler_use_block() is now no longer used, so remove it.
2005-12-18 07:06:23 +00:00
Neal Norwitz 4e6bf49a5e Handle more error conditions with SystemError 2005-12-18 05:32:41 +00:00
Neal Norwitz 87b801cc2d Set MemoryError when alloc fails 2005-12-18 04:42:47 +00:00
Neal Norwitz adb69fcdff Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
simplifies a lot of error handling code, and fixes many memory leaks.
2005-12-17 20:54:49 +00:00
Neal Norwitz 28b32ac6bc Simplify logic for handling import * 2005-12-06 07:41:30 +00:00
Neal Norwitz 3715c3e576 Fix a few more ref leaks. Backport candidate 2005-11-24 22:09:18 +00:00
Neal Norwitz 7bcabc60a3 Fix a few more memory leaks
Document more info about the benefits of configuring without
pymalloc when running valgrind
2005-11-20 23:58:38 +00:00
Neal Norwitz 4737b2348b Last batch of ref leaks in new AST code.
Also converted a bunch of assert(0) to SystemError's.

There are still printfs, etc that need to be cleaned up.
2005-11-19 23:58:29 +00:00
Nick Coghlan 944d3eb154 Correctly handle identifiers for anonymous scopes and align genexpr name with symtable.c 2005-11-16 12:46:55 +00:00
Neal Norwitz b6fc9df8fc Fix a lot of memory and ref leaks in error paths.
(Call symtable_exit_block or compiler_exit_scope as appropriate)

Use PyMem_Free on c_future since it was allocated with PyMem_Malloc
2005-11-13 18:50:34 +00:00
Neal Norwitz 2744c6cc35 make internal method static 2005-11-13 01:08:38 +00:00
Neil Schemenauer c396d9edd6 Ensure that compiler_exit_scope() is called as necessary to free memory
allocated by compiler_enter_scope().  Change return type for
compiler_exit_scope() to be void.
2005-10-25 06:30:14 +00:00
Neal Norwitz f1d50684c6 Fix problem handling EXTENDED_ARGs from SF bug # 1333982 2005-10-23 23:00:41 +00:00
Neal Norwitz 7d37f2ff40 cleanup a bit and reuse instrsize (instruction size). working towards fixing problems with EXTENDED_ARG 2005-10-23 22:40:47 +00:00
Neil Schemenauer dad06a159e Remove unnecessary local variable. 2005-10-23 18:52:36 +00:00
Neil Schemenauer 8b528b28f1 Fix private name mangling. The symtable also must do mangles so that
the scope of names can be correctly determined.
2005-10-23 18:37:42 +00:00
Neil Schemenauer 3a44aaa30f Use PyTuple_Pack instead of Py_BuildValue. 2005-10-23 17:21:54 +00:00
Neil Schemenauer d403c45386 Fix arigo's funky LOAD_NAME bug: implicit globals inside classes have
historically been looked up using LOAD_NAME, not LOAD_GLOBAL.
looked up by LOAD_NAME, not
2005-10-23 04:24:49 +00:00
Neil Schemenauer ac699efad8 Don't stop generating code for import statements after the first "import as"
part.  Fixes one bug from #1333982.
2005-10-23 03:45:42 +00:00
Neil Schemenauer ccd19218bc Use <lamba> as the function name for lambdas (matches old compiler). 2005-10-21 18:09:19 +00:00
Armin Rigo 3144130217 ANSI-C-ify the placement of local var declarations. 2005-10-21 12:57:31 +00:00
Jeremy Hylton 3e0055f8c6 Merge ast-branch to head
This change implements a new bytecode compiler, based on a
transformation of the parse tree to an abstract syntax defined in
Parser/Python.asdl.

The compiler implementation is not complete, but it is in stable
enough shape to run the entire test suite excepting two disabled
tests.
2005-10-20 19:59:25 +00:00
Tim Peters ea9dcdc062 com_yield_expr(): Squash new compiler wng about unreferenced local. 2005-08-03 18:33:05 +00:00
Phillip J. Eby 0d6615fd29 PEP 342 implementation. Per Guido's comments, the generator throw()
method still needs to support string exceptions, and allow None for the
third argument.  Documentation updates are needed, too.
2005-08-02 00:46:46 +00:00
Brett Cannon c9371d4a1b Fix signedness of various char variables to stop causing a warning under gcc 4. 2005-06-25 08:23:41 +00:00
Brett Cannon 409d8f2ebd Allow classes to be defined with empty parentheses. This means that
``class C(): pass`` is no longer a syntax error.
2005-03-05 06:47:57 +00:00
Brett Cannon 5dc8ced4a8 Silence a gcc warning about putting in parentheses around && expressions mixed
with || expressions.  Also clarifies intend of 'if' conditional.
2005-03-03 07:01:48 +00:00
Raymond Hettinger e63a078635 Preserve sign of -0.0 when result is run through marshal. 2005-02-23 13:37:55 +00:00
Raymond Hettinger 07359a7fed Document how the pattern recognizer keeps all of its references in bounds.
Add a test in case the underlying assumptions ever change (i.e. the
compiler starts generating code blocks that are not punctuated by
RETURN_VALUE).
2005-02-21 20:03:14 +00:00
Raymond Hettinger 80121491e0 Teach the peepholer to fold unary operations on constants.
Afterwards, -0.5 loads in a single step and no longer requires a runtime
UNARY_NEGATIVE operation.
2005-02-20 12:41:32 +00:00
Raymond Hettinger b615bf0681 Remove the set conversion which didn't work with: [] in (0,) 2005-02-10 01:42:32 +00:00
Raymond Hettinger 5e547969f8 Have set conversion replace existing constant if not used elsewhere. 2005-02-09 21:24:51 +00:00
Raymond Hettinger 7fcb7869ba Adopt Skip's idea to optimize lists of constants in the context
of a "in" or "not in" test.
2005-02-07 19:32:38 +00:00
Raymond Hettinger a164574937 Transform "x in (1,2,3)" to "x in frozenset([1,2,3])".
Inspired by Skip's idea to recognize the throw-away nature of sequences
in this context and to transform their type to one with better performance.
2005-02-06 22:05:42 +00:00
Raymond Hettinger 9feb267caf Do not fold a constant if a large sequence will result.
Saves space in the presence of code like: (None,)*10000
2005-01-26 12:50:05 +00:00
Armin Rigo 664b43b3f4 Re-running python with/without the -Qnew flag uses incorrectly optimized
bytecodes from the previously saved .pyc files.  Fixed by disabling the static
optimization of BINARY_DIVIDE between two constants.
2005-01-07 18:10:51 +00:00
Raymond Hettinger c34f8673a1 Teach the peephole optimizer to fold simple constant expressions. 2005-01-02 06:17:33 +00:00
Jeremy Hylton 16b047904c SF patch 1025636: Check for NULL returns in compile.c:com_import_stmt
There is no test for this change, because there is no way to provoke memory errors on demand.  Test suite passes, though.
2004-11-07 14:04:00 +00:00
Raymond Hettinger 5dec096e6a Maintain peepholer's cumlc invariant by updating the running total
everytime a LOAD_CONSTANT is encountered, created, or overwritten.

Added two tests to cover cases affected by the patch.
2004-11-02 04:20:10 +00:00
Raymond Hettinger 099ecfbec9 Simplify and future proof NOP counting in the peepholer.
No longer assumes that the input is NOP free.
2004-11-01 15:19:11 +00:00
Armin Rigo d7bcf4deb1 Fixed a comment and added another one. 2004-10-30 21:08:59 +00:00
Raymond Hettinger effb3931ea Adopt some peepholer suggestions from Armin Rigo:
* Use simpler, faster two pass algorithm for markblocks().
* Free the blocks variable if not NULL and exiting without change.
* Verify that the rest of the compiler has not set an exception.
* Make the test for tuple of constants less restrictive.
* Embellish the comment for chained conditional jumps.
2004-10-30 08:55:08 +00:00
Raymond Hettinger 23109ef11e SF bug #1053819: Segfault in tuple_of_constants
Peepholer could be fooled into misidentifying a tuple_of_constants.
Added code to count consecutive occurrences of LOAD_CONST.
Use the count to weed out the misidentified cases.
Added a unittest.
2004-10-26 08:59:14 +00:00
Raymond Hettinger 9047c8f73d SF bug #1048870: call arg of lambda not updating 2004-10-24 00:10:06 +00:00
Raymond Hettinger fec0c466ad Improve error message for augmented assignments to genexps or listcomps.
Rather than introduce new logic, took the approach of making the message
itself more general.
2004-09-29 23:54:08 +00:00
Raymond Hettinger 8ffc1410e2 Fix two erroneous error messages. 2004-09-29 21:47:10 +00:00
Raymond Hettinger 06cc973d06 Replaced a test with an assertion.
(Suggested by Michael Hudson.)
2004-09-28 17:22:12 +00:00
Raymond Hettinger 2c31a058eb SF patch #1031667: Fold tuples of constants into a single constant
Example:
>>> import dis
>>> dis.dis(compile('1,2,3', '', 'eval'))
  0           0 LOAD_CONST               3 ((1, 2, 3))
              3 RETURN_VALUE
2004-09-22 18:44:21 +00:00
Anthony Baxter 1a4ddaecc7 SF patch #1007189, multi-line imports, for instance:
"from blah import (foo, bar
baz, bongo)"
2004-08-31 10:07:13 +00:00
Raymond Hettinger 1792bfbf90 Bypass peepholing of code with lineno tables having intervals >= 255.
Allows the lineno fixup code to remain simple and not have to deal with
multibyte codings.

* Add an assertion to that effect.
* Remove the XXX comment on the subject.
2004-08-25 17:19:38 +00:00
Raymond Hettinger 65d3c0537a Fix typo in comment and add clarification. 2004-08-25 15:15:56 +00:00
Raymond Hettinger ef0a82b682 Simplify chains of conditional jumps.
(Suggested by Neal Norwitz.)
2004-08-25 03:18:29 +00:00
Raymond Hettinger a12fa148d7 Incorporate review comments courtesy of Neal Norwitz:
* Perform the code length check earlier.
* Eliminate the extra PyMem_Free() upon hitting an EXTENDED_ARG.
* Assert that the NOP count used in jump retargeting matches the NOPs
  eliminated in the final step.
* Add an XXX note to indicate that more work is being to done to
  handle linenotab with intervals > 255.
2004-08-24 04:34:16 +00:00
Raymond Hettinger fd2d1f7870 SF Patch #1013667: Cleanup Peepholer Output
* Make a pass to eliminate NOPs.  Produce code that is more readable,
  more compact, and a tiny bit faster.  Makes the peepholer more flexible
  in the scope of allowable transformations.

* With Guido's okay, bumped up the magic number so that this patch gets
  widely exercised before the alpha goes out.
2004-08-23 23:37:48 +00:00
Raymond Hettinger 1a7892924f Move the bytecode optimizer upstream so that its results are saved in pyc
files and not re-optimized upon import.  Saves a bit of startup time while
still remaining decoupled from the rest of the compiler.

As a side benefit, handcoded bytecode is not run through the optimizer
when new code objects are created.  Hopefully, a handcoder has already
created exactly what they want to have run.

(Idea suggested by Armin Rigo and Michael Hudson.  Initially avoided
 because of worries about compiler coupling; however, only the nexus
 point needed to be moved so there won't be a conflict when the AST
 branch is loaded.)
2004-08-18 05:22:06 +00:00
Michael W. Hudson 0ccff074cd This is Mark Russell's patch:
[ 1009560 ] Fix @decorator evaluation order

From the description:

Changes in this patch:

- Change Grammar/Grammar to require
newlines between adjacent decorators.

- Fix order of evaluation of decorators
in the C (compile.c) and python
(Lib/compiler/pycodegen.py) compilers

- Add better order of evaluation check
to test_decorators.py (test_eval_order)

- Update the decorator documentation in
the reference manual (improve description
of evaluation order and update syntax
description)

and the comment:

Used Brett's evaluation order (see
http://mail.python.org/pipermail/python-dev/2004-August/047835.html)

(I'm checking this in for Anthony who was having problems getting SF to
talk to him)
2004-08-17 17:29:16 +00:00
Brett Cannon add33601c2 Correct the order of application for decorators. Meant to be bottom-up and not
top-down.  Now matches the PEP.
2004-08-15 07:21:25 +00:00
Brett Cannon 31f8350f43 Fix incorrect comment for (struct compiling)->c_cellvars 2004-08-15 01:15:01 +00:00
Tim Peters d459f536c5 code_new(): Wouldn't compile on Windows, because of gcc'ism. 2004-08-12 18:16:43 +00:00
Michael W. Hudson 6093462739 Fix bug
[ 1005248 ] new.code() not cleanly checking its arguments

using the result of new.code() can still destroy the sun, but merely
calling the function shouldn't any more.

I also rewrote the existing tests of new.code() to use vastly less
un-bogus arguments, and added tests for the previous insane behaviours.
2004-08-12 17:56:29 +00:00
Raymond Hettinger 98bd1814e2 SF bug #1004088: big code objects (>64K) may be optimized incorrectly
Will backport.
2004-08-06 19:46:34 +00:00
Michael W. Hudson e51c4f9a10 Revert 2.312; turns out interning the file name did do some good (reducing
.pyc size) after all.
2004-08-04 10:26:08 +00:00
Michael W. Hudson 782d8ffb42 Don't intern the filename of a file being compiled.
Hard to believe it ever helped anything, and it hurts finding reference
leaks.
2004-08-03 10:24:03 +00:00
Anthony Baxter 4e7785aa4f fix for @decorators under a debug build. 2004-08-02 11:08:15 +00:00
Anthony Baxter c2a5a63654 PEP-0318, @decorator-style. In Guido's words:
"@ seems the syntax that everybody can hate equally"
Implementation by Mark Russell, from SF #979728.
2004-08-02 06:10:11 +00:00
Raymond Hettinger 11a70c79b9 Upgrade None assignment SyntaxWarning to a SyntaxError. 2004-07-17 21:46:25 +00:00
Tim Peters db5860b7c7 optimize_code(): Repaired gross error in new special-casing for None.
The preceding case statement was missing a terminating "break" stmt,
so fell into the new code by mistake.  This caused uncaught out-of-bounds
accesses to the "names" tuple, leading to a variety of insane behaviors.
2004-07-17 05:00:52 +00:00
Raymond Hettinger 76d962d700 Treat None as a constant. 2004-07-16 12:16:48 +00:00
Neal Norwitz 93468eac72 Remove unused macros in .c files 2004-07-08 01:49:00 +00:00
Raymond Hettinger 43ea47ff06 Move NOP to end of code transformation. 2004-06-24 09:25:39 +00:00
Raymond Hettinger 9c18e81fb2 Install two code generation optimizations that depend on NOP.
Reduces the cost of "not" to almost zero.
2004-06-21 16:31:15 +00:00