Commit Graph

312 Commits

Author SHA1 Message Date
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
Martin v. Löwis 737ea82a5a Patch #774665: Make Python LC_NUMERIC agnostic. 2004-06-08 18:52:54 +00:00
Raymond Hettinger 354433a59d SF patch #872326: Generator expression implementation
(Code contributed by Jiwon Seo.)

The documentation portion of the patch is being re-worked and will be
checked-in soon.  Likewise, PEP 289 will be updated to reflect Guido's
rationale for the design decisions on binding behavior (as described in
in his patch comments and in discussions on python-dev).

The test file, test_genexps.py, is written in doctest format and is
meant to exercise all aspects of the the patch.  Further additions are
welcome from everyone.  Please stress test this new feature as much as
possible before the alpha release.
2004-05-19 08:20:33 +00:00
Armin Rigo 80d937e986 Fix for line events in the case:
def f(a):
    if a:
      print 5
    else:
      pass
2004-03-22 17:52:53 +00:00
Raymond Hettinger ff5bc50bb0 Improve byte coding for multiple assignments.
Gives 30% speedup on "a,b=1,2" and 25% on "a,b,c=1,2,3".
2004-03-21 15:12:00 +00:00
Raymond Hettinger dd80f76265 SF patch #910929: Optimize list comprehensions
Add a new opcode, LIST_APPEND, and apply it to the code generation for
list comprehensions.  Reduces the per-loop overhead by about a third.
2004-03-07 07:31:06 +00:00
Guido van Rossum 6c9e130524 - Removed FutureWarnings related to hex/oct literals and conversions
and left shifts.  (Thanks to Kalle Svensson for SF patch 849227.)
  This addresses most of the remaining semantic changes promised by
  PEP 237, except for repr() of a long, which still shows the trailing
  'L'.  The PEP appears to promise warnings for operations that
  changed semantics compared to Python 2.3, but this is not
  implemented; we've suffered through enough warnings related to
  hex/oct literals and I think it's best to be silent now.
2003-11-29 23:52:13 +00:00
Martin v. Löwis dd7eb146a8 Patch #792869: Clarify error message for parameters declared global,
rename LOCAL_GLOBAL to PARAM_GLOBAL.
2003-10-18 22:05:25 +00:00
Raymond Hettinger 8ae4689657 Simplify and speedup uses of Py_BuildValue():
* Py_BuildValue("(OOO)",a,b,c)  -->  PyTuple_Pack(3,a,b,c)
* Py_BuildValue("()",a)         -->  PyTuple_New(0)
* Py_BuildValue("O", a)         -->  Py_INCREF(a)
2003-10-12 19:09:37 +00:00
Jeremy Hylton 9832613beb Fix SF bug [ 808594 ] leak on lambda with duplicate arguments error.
Refactor code so that one helper routine sets error location and
increments st_errors.

Bug fix candidate.
2003-09-22 04:26:44 +00:00
Raymond Hettinger cc1798e0c0 Improve the leak fix so that PyTuple_New is only called when needed. 2003-09-16 04:27:52 +00:00
Raymond Hettinger 37a724d718 Fix leak discovered in test_new by Michael Hudson.
Will backport to 2.3.1
2003-09-15 21:43:16 +00:00
Jeremy Hylton 376e63d5cd Fix for SF bug [ 784075 ] Fatal Python error: unknown scope
Make sure the inner function is not compiled when there is a syntax
error in the default arguments.
2003-08-28 14:42:14 +00:00
Jeremy Hylton 1955fcf67a SF patch 763201: handling of SyntaxErrors in symbol table build
Fixes for three related bugs, including errors that caused a script to
be ignored without printing an error message.  The key problem was a bad
interaction between syntax warnings and syntax errors.  If an
exception was already set when a warning was issued, the warning could
clobber the exception.

The PyErr_Occurred() check in issue_warning() isn't entirely
satisfying (the caller should know whether there was already an
error), but a better solution isn't immediately obvious.

Bug fix candidate.
2003-07-15 20:23:26 +00:00
Raymond Hettinger b9572c3456 Removed bytecode transformation for sequence packing/unpacking.
It depended on the previously removed basic block checker to
prevent a jump into the middle of the transformed block.

Clears SF 757818: tuple assignment -- SystemError: unknown opcode
2003-06-20 16:13:17 +00:00
Neal Norwitz a1d654e13a SF bug #644345, Poor error message for augmented assign
Update error message.  Hopefully this is clearer to some people.
2003-05-22 22:00:04 +00:00
Jeremy Hylton f9415e6245 Use macro to get length of list.
Remove comment about how code used to work.
2003-05-22 16:22:33 +00:00
Jeremy Hylton 521482d84f Remove comment with very long lines that explained what the code used
to do.

XXX Please be careful when checking in patches to avoid checking in
junk that explains what the patched code used to do.
2003-05-22 15:47:02 +00:00
Jeremy Hylton 4d508adae3 Fix for SF [ 734869 ] Lambda functions in list comprehensions
The compiler was reseting the list comprehension tmpname counter for each function, but the symtable was using the same counter for the entire module.  Repair by move tmpname into the symtable entry.

Bugfix candidate.
2003-05-21 17:34:50 +00:00
Tim Peters 12d55a7caa cmp_type(): The grammar stopped allowing '=' as a comparison operator
about a decade ago.  Put the code still allowing for it in cmp_type()
out of its lonely misery.
2003-05-12 19:16:52 +00:00
Martin v. Löwis a94568a753 Patch #734231: Update RiscOS support. In particular, correct
riscospath.extsep, and use os.extsep throughout.
2003-05-10 07:36:56 +00:00
Martin v. Löwis cd12bfc142 Patch #708604: Check more function results. Will backport to 2.2. 2003-05-03 10:53:08 +00:00
Michael W. Hudson 26848a34d1 Use Tim's suggestion to fix
[ 708901 ] Lineno calculation sometimes broken

A one line patch to compile.c and a rather-more-than-one-line patch
to test_dis.  Hey ho.

Possibly a backport candidate -- tho' lnotab is less used in 2.2...
2003-04-29 17:07:36 +00:00
Raymond Hettinger f4cf76dd5e Revert the previous enhancement to the bytecode optimizer.
The additional code complexity and new NOP opcode were not worth it.
2003-04-24 05:45:23 +00:00
Raymond Hettinger 060641d511 Improved the bytecode optimizer.
* Can now test for basic blocks.
* Optimize inverted comparisions.
* Optimize unary_not followed by a conditional jump.
* Added a new opcode, NOP, to keep code size constant.
* Applied NOP to previous transformations where appropriate.

Note, the NOP would not be necessary if other functions were
added to re-target jump addresses and update the co_lnotab mapping.
That would yield slightly faster and cleaner bytecode at the
expense of optimizer simplicity and of keeping it decoupled
from the line-numbering structure.
2003-04-22 06:49:11 +00:00
Raymond Hettinger 255a3d08a1 Extend SF patch #707257: Improve code generation
to cover the case for:  "x,y,z=1,2,3".  Gives a 30% speed-up.

Also, added FOR_ITER to the list of opcodes that can jump.
2003-04-15 10:35:07 +00:00
Raymond Hettinger 5b75c38cc9 Factored out test for absolute jumps. 2003-03-28 12:05:00 +00:00
Raymond Hettinger f6f575ae6f SF patch #707257: Improve code generation
Adds a single function to improve generated bytecode.  Has a single line
attachment point, so it is completely de-coupled from both the compiler
and ceval.c.

Makes three simple transforms that do not require a basic block analysis
or re-ordering of code.  Gives improved timings on pystone, pybench,
and any code using either "while 1" or "x,y=y,x".
2003-03-26 01:07:54 +00:00
Tim Peters b39903b0a0 symtable_cellvar_offsets(): This leaked references to little integers
in normal cases, and also in error cases.

Bugfix candidate.
2003-03-24 17:22:24 +00:00
Guido van Rossum 66b1259dbc SF #660455 : patch by NNorwitz.
"Unsigned" (i.e., positive-looking, but really negative) hex/oct
constants with a leading minus sign are once again properly negated.
The micro-optimization for negated numeric constants did the wrong
thing for such hex/oct constants.  The patch avoids the optimization
for all hex/oct constants.

This needs to be backported to Python 2.2!
2003-02-12 16:57:47 +00:00
Just van Rossum 3aaf42c613 patch #683515: "Add unicode support to compile(), eval() and exec"
Incorporated nnorwitz's comment re. Py__USING_UNICODE.
2003-02-10 08:21:10 +00:00
Jeremy Hylton 985eba53f5 Small function call optimization and special build option for call stats.
-DCALL_PROFILE: Count the number of function calls executed.

When this symbol is defined, the ceval mainloop and helper functions
count the number of function calls made.  It keeps detailed statistics
about what kind of object was called and whether the call hit any of
the special fast paths in the code.

Optimization:

When we take the fast_function() path, which seems to be taken for
most function calls, and there is minimal frame setup to do, avoid
call PyEval_EvalCodeEx().  The eval code ex function does a lot of
work to handle keywords args and star args, free variables,
generators, etc.  The inlined version simply allocates the frame and
copies the arguments values into the frame.

The optimization gets a little help from compile.c which adds a
CO_NOFREE flag to code objects that don't have free variables or cell
variables.  This change allows fast_function() to get into the fast
path with fewer tests.

I measure a couple of percent speedup in pystone with this change, but
there's surely more that can be done.
2003-02-05 23:13:00 +00:00
Michael W. Hudson 976249be74 A. Lloyd Flanagan pointed out a spelling error on c.l.py. 2003-01-16 15:39:07 +00:00
Jeremy Hylton accb62b28e SF patch [ 597919 ] compiler package and SET_LINENO
A variety of changes from Michael Hudson to get the compiler working
with 2.3.  The primary change is the handling of SET_LINENO:

# The set_lineno() function and the explicit emit() calls for
# SET_LINENO below are only used to generate the line number table.
# As of Python 2.3, the interpreter does not have a SET_LINENO
# instruction.  pyassem treats SET_LINENO opcodes as a special case.

A few other small changes:
 - Remove unused code from pycodegen and pyassem.
 - Fix error handling in parsermodule.  When PyParser_SimplerParseString()
   fails, it sets an exception with detailed info.  The parsermodule
   was clobbering that exception and replacing it was a generic
   "could not parse string" exception.  Keep the original exception.
2002-12-31 18:17:44 +00:00
Guido van Rossum 633d90c7a3 Oops. Roll back that last change. It wasn't ready for release. :-( 2002-12-23 16:51:42 +00:00
Guido van Rossum 9c8a0866c9 Add warning for assignment to None, True and False. This is patch
549213 by Jeremy (checking in for him since he's away and busy).
2002-12-23 16:35:23 +00:00
Neal Norwitz 06982221bb SF # 654960, remove unnecessary static variable
The static variable (implicit) was not necessary.
The c_globals can be None or True now.
2002-12-18 01:18:44 +00:00
Gustavo Niemeyer 78429a6aa6 Fixing bug
[#448679] Left to right

* Python/compile.c
  (com_dictmaker): Reordered evaluation of dictionaries to follow strict
  LTR evaluation.

* Lib/compiler/pycodegen.py
  (CodeGenerator.visitDict): Reordered evaluation of dictionaries to
  follow strict LTR evaluation.

* Doc/ref/ref5.tex
  Documented the general LTR evaluation order idea.

* Misc/NEWS
  Documented change in evaluation order of dictionaries.
2002-12-16 13:54:02 +00:00
Martin v. Löwis 95292d6caa Constify filenames and scripts. Fixes #651362. 2002-12-11 14:04:59 +00:00
Walter Dörwald 4c6c76559d Move three variables that are only used inside an if block into the block,
so the --disable-unicode build doesn't complain about unused variables.
2002-11-21 20:13:40 +00:00
Michael W. Hudson 3ae3315f44 Clamp code objects' tp_compare result to [-1, 1].
Bugfix candidate.
2002-10-03 09:50:47 +00:00
Michael W. Hudson 53d58bb369 Further SET_LINENO reomval fixes. See comments in patch #587933.
Use a slightly different strategy to determine when not to call the line
trace function.  This removes the need for the RETURN_NONE opcode, so
that's gone again.  Update docs and comments to match.

Thanks to Neal and Armin!

Also add a test suite.  This should have come with the original patch...
2002-08-30 13:09:51 +00:00
Guido van Rossum b7164621fa Add warnings for arguments named None. All set. (I could add a
warning for 'global None', but that's either accompanied by an
assignment to None, which will trigger a warning, or not, in which
case it's harmless. :-)
2002-08-16 02:48:11 +00:00
Guido van Rossum 63dd79ac04 Add warning for None used as keyword argument name in function call.
Still to do: function definition arguments (including *None and
**None).
2002-08-16 02:24:56 +00:00
Guido van Rossum 3ac99d4910 Add warnings for assignment or deletion of variables and attributes
named 'None'.  Still to do: function definition parameter lists, and
function call keyword arguments.
2002-08-16 02:13:49 +00:00