summaryrefslogtreecommitdiff
path: root/Python/compile.c
AgeCommit message (Collapse)AuthorLines
2001-09-07SF bug [#458941] Looks like a unary minus bug.Tim Peters-16/+49
com_factor(): when a unary minus is attached to a float or imaginary zero, don't optimize the UNARY_MINUS opcode away: the const dict can't distinguish between +0.0 and -0.0, so ended up treating both like the first one added to it. Optimizing UNARY_PLUS away isn't a problem. (BTW, I already uploaded the 2.2a3 Windows installer, and this isn't important enough to delay the release.)
2001-08-30When re-writing a factor containing a unary negation of a literal, onlyFred Drake-0/+3
affect nodes without another operator. This was causing negated exponentiations to drop the exponentiation. This closes SF bug #456756.
2001-08-30Removed unreachable goto statement to silence SGI compiler.Sjoerd Mullender-1/+0
2001-08-27If an integer constant can't be generated from an integer literalJeremy Hylton-5/+2
because of overflow, generate a long instead.
2001-08-17Patch #445762: Support --disable-unicodeMartin v. Löwis-13/+25
- Do not compile unicodeobject, unicodectype, and unicodedata if Unicode is disabled - check for Py_USING_UNICODE in all places that use Unicode functions - disables unicode literals, and the builtin functions - add the types.StringTypes list - remove Unicode literals from most tests.
2001-08-14Fix SF bug [ #450909 ] __future__.division fails at promptJeremy Hylton-2/+6
When code is compiled and compiler flags are passed in, be sure to update cf_flags with any features defined by future statements in the compiled code.
2001-08-12SF Patch [ 429024 ] deal with some unary ops at compile timeJeremy Hylton-3/+66
Revised version of Fred's patch, including support for ~ operator. If the unary +, -, or ~ operator is applied to a constant, don't generate a UNARY_xxx opcode. Just store the approriate value as a constant. If the value is negative, extend the string containing the constant and insert a negative in the 0th position. For ~, compute the inverse of int and longs and use them directly, but be prepared to generate code for all other possibilities (invalid numbers, floats, complex).
2001-08-11Remove st_nested_scopes from struct symtable,Jeremy Hylton-128/+44
because nested scopes are always enabled. (Accidentally checked in one small change along this path yesterday, wreaking havoc in the Windows build.)
2001-08-11st_nested_scopes was uninitialized trash. Jeremy should fix in a betterTim Peters-0/+6
way; see code comments.
2001-08-10Refactor future feature handlingJeremy Hylton-27/+4
Replace uses of PyCF_xxx with CO_xxx. Replace individual feature slots in PyFutureFeatures with single bitmask ff_features. When flags must be transfered among the three parts of the interpreter that care about them -- the pythonrun layer, the compiler, and the future feature parser -- can simply or (|) the definitions.
2001-08-08Implement PEP 238 in its (almost) full glory.Guido van Rossum-4/+25
This introduces: - A new operator // that means floor division (the kind of division where 1/2 is 0). - The "future division" statement ("from __future__ import division) which changes the meaning of the / operator to implement "true division" (where 1/2 is 0.5). - New overloadable operators __truediv__ and __floordiv__. - New slots in the PyNumberMethods struct for true and floor division, new abstract APIs for them, new opcodes, and so on. I emphasize that without the future division statement, the semantics of / will remain unchanged until Python 3.0. Not yet implemented are warnings (default off) when / is used with int or long arguments. This has been on display since 7/31 as SF patch #443474. Flames to /dev/null.
2001-08-06Another bug fix for recent import * warning (caught by Thomas Wouters)Jeremy Hylton-3/+3
Only return if symtable_warn() returns -1, indicating that the warning was turned into an error.
2001-08-06Fix error message for import * in function/class scopeJeremy Hylton-1/+1
2001-08-06Fix SF bug [ #445474 ] warn about import * inside functionsJeremy Hylton-0/+5
Reported by the Man himself.
2001-07-16jcompile(): inherit the CO_GENERATOR_ALLOWED flag from the 'base'Guido van Rossum-0/+1
compiling struct.
2001-07-16Part way to allowing "from __future__ import generators" to communicateTim Peters-4/+13
that info to code dynamically compiled *by* code compiled with generators enabled. Doesn't yet work because there's still no way to tell the parser that "yield" is OK (unlike nested_scopes, the parser has its fingers in this too). Replaced PyEval_GetNestedScopes by a more-general PyEval_MergeCompilerFlags. Perhaps I should not have? I doubted it was *intended* to be part of the public API, so just did.
2001-06-28Another "if 0:" hack, this time to complain about otherwise invisibleTim Peters-2/+61
"return expr" instances in generators (which latter may be generators due to otherwise invisible "yield" stmts hiding in "if 0" blocks). This was fun the first time, but this has gotten truly ugly now.
2001-06-26SF bug #436207: "if 0: yield x" is ignored.Tim Peters-1/+33
Not anymore <wink>. Pure hack. Doesn't fix any other "if 0:" glitches.
2001-06-23Change the semantics of "return" in generators, as discussed on theTim Peters-25/+10
Iterators list and Python-Dev; e.g., these all pass now: def g1(): try: return except: yield 1 assert list(g1()) == [] def g2(): try: return finally: yield 1 assert list(g2()) == [1] def g3(): for i in range(3): yield None yield None assert list(g3()) == [None] * 4 compile.c: compile_funcdef and com_return_stmt: Just van Rossum's patch to compile the same code for "return" regardless of function type (this goes back to the previous scheme of returning Py_None). ceval.c: gen_iternext: take a return (but not a yield) of Py_None as meaning the generator is exhausted.
2001-06-23Disallow 'yield' in a 'try' block when there's a 'finally' clause.Tim Peters-0/+10
Derived from Thomas Wouters's patch on the Iterators list, but doesn't try to read c->c_block[c->c_nblocks].
2001-06-18Merging the gen-branch into the main line, at Guido's direction. Yay!Tim Peters-9/+51
Bugfix candidate in inspect.py: it was referencing "self" outside of a method.
2001-06-09SF bug 430991: wrong co_lnotabTim Peters-10/+54
Armin Rigo pointed out that the way the line-# table got built didn't work for lines generating more than 255 bytes of bytecode. Fixed as he suggested, plus corresponding changes to pyassem.py, plus added some long overdue docs about this subtle table to compile.c. Bugfix candidate (line numbers may be off in tracebacks under -O).
2001-05-09SF patch #416249, from Mark Favas: 2.1c1 compile: unused vrbl cleanupTim Peters-2/+0
2001-05-08Several small changes. Mostly reformatting, adding parens.Jeremy Hylton-10/+11
Check for free in class and method only if nested scopes are enabled. Add assertion to verify that no free variables occur when nested scopes are disabled. XXX When should nested scopes by made non-optional on the trunk?
2001-04-27Fix 2.1 nested scopes crash reported by Evan SimpsonJeremy Hylton-6/+20
The new test case demonstrates the bug. Be more careful in symtable_resolve_free() to add a var to cells or frees only if it won't be added under some other rule. XXX Add new assertion that will catch this bug.
2001-04-20Iterators phase 1. This comprises:Guido van Rossum-18/+6
new slot tp_iter in type object, plus new flag Py_TPFLAGS_HAVE_ITER new C API PyObject_GetIter(), calls tp_iter new builtin iter(), with two forms: iter(obj), and iter(function, sentinel) new internal object types iterobject and calliterobject new exception StopIteration new opcodes for "for" loops, GET_ITER and FOR_ITER (also supported by dis.py) new magic number for .pyc files new special method for instances: __iter__() returns an iterator iteration over dictionaries: "for x in dict" iterates over the keys iteration over files: "for x in file" iterates over lines TODO: documentation test suite decide whether to use a different way to spell iter(function, sentinal) decide whether "for key in dict" is a good idea use iterators in map/filter/reduce, min/max, and elsewhere (in/not in?) speed tuning (make next() a slot tp_next???)
2001-04-14Make some private symbols static.Guido van Rossum-1/+2
2001-04-09Warn when assigning to __debug__ instead of raising an error.Jeremy Hylton-7/+2
2001-03-23Make it illegal to assign to __debug__ as per Guido's request.Jeremy Hylton-1/+12
2001-03-22Set the line number correctly for a nested function with an exec orJeremy Hylton-2/+5
import *. Mark the offending stmt rather than the function def line.
2001-03-22Make error messages clearer for illegal combinations of nestedJeremy Hylton-15/+36
functions and import */exec.
2001-03-22If a code object is compiled with nested scopes, define the CO_NESTED flag.Jeremy Hylton-0/+2
Add PyEval_GetNestedScopes() which returns a non-zero value if the code for the current interpreter frame has CO_NESTED defined.
2001-03-21Update PyNode_CompileSymtable() to understand future statementsJeremy Hylton-9/+15
2001-03-21Fix PyFrame_FastToLocals() and counterpart to deal with cells andJeremy Hylton-51/+69
frees. Note there doesn't seem to be any way to test LocalsToFast(), because the instructions that trigger it are illegal in nested scopes with free variables. Fix allocation strategy for cells that are also formal parameters. Instead of emitting LOAD_FAST / STORE_DEREF pairs for each parameter, have the argument handling code in eval_code2() do the right thing. A side-effect of this change is that cell variables that are also arguments are listed at the front of co_cellvars in the order they appear in the argument list.
2001-03-20Fixup handling of free variables in methods when the class scope alsoJeremy Hylton-3/+12
has a binding for the name. The fix is in two places: - in symtable_update_free_vars, ignore a global stmt in a class scope - in symtable_load_symbols, add extra handling for names that are defined at class scope and free in a method Closes SF bug 407800
2001-03-19Fix crashes in nested list comprehensionsJeremy Hylton-8/+10
SF bugs 409230 and 407800 Also remove bogus list comp code from symtable_assign().
2001-03-02Refactored the warning-issuing code more.Guido van Rossum-11/+17
Made sure that the warnings issued by symtable_check_unoptimized() (about import * and exec) contain the proper filename and line number, and are transformed into SyntaxError exceptions with -Werror.
2001-03-01Useful future statement support for the interactive interpreterJeremy Hylton-11/+27
(Also remove warning about module-level global decl, because we can't distinguish from code passed to exec.) Define PyCompilerFlags type contains a single element, cf_nested_scopes, that is true if a nested scopes future statement has been entered at the interactive prompt. New API functions: PyNode_CompileFlags() PyRun_InteractiveOneFlags() -- same as their non Flags counterparts except that the take an optional PyCompilerFlags pointer compile.c: In jcompile() use PyCompilerFlags argument. If cf_nested_scopes is true, compile code with nested scopes. If it is false, but the code has a valid future nested scopes statement, set it to true. pythonrun.c: Create a new PyCompilerFlags object in PyRun_InteractiveLoop() and thread it through to PyRun_InteractiveOneFlags().
2001-03-01Fix core dump in example from Samuele Pedroni:Jeremy Hylton-15/+31
from __future__ import nested_scopes x=7 def f(): x=1 def g(): global x def i(): def h(): return x return h() return i() return g() print f() print x This kind of code didn't work correctly because x was treated as free in i, leading to an attempt to load x in g to make a closure for i. Solution is to make global decl apply to nested scopes unless their is an assignment. Thus, x in h is global.
2001-03-01Don't add global names to st->st_global if we're already iteratingJeremy Hylton-6/+15
over the elements of st->st_global!
2001-02-28undo introduction of st_global_starJeremy Hylton-3/+0
2001-02-28Warn about global statement at the module level.Jeremy Hylton-2/+17
Do better accounting for global variables.
2001-02-28Add warning/error handlin for problematic nested scopes cases asJeremy Hylton-26/+119
described in PEP 227. symtable_check_unoptimized() warns about import * and exec with "in" when it is used in a function that contains a nested function with free variables. Warnings are issued unless nested scopes are in effect, in which case these are SyntaxErrors. symtable_check_shadow() warns about assignments in a function scope that shadow free variables defined in a nested scope. This will always generate a warning -- and will behave differently with nested scopes than without. Restore full checking for free vars in children, even when nested scopes are not enabled. This is needed to support warnings for shadowing. Change symtable_warn() to return an int-- the return value of PyErr_WarnExplicit. Sundry cleanup: Remove commented out code. Break long lines.
2001-02-28Let's have some sanity. Introduce a helper to issue a symbol tableGuido van Rossum-16/+17
warning.
2001-02-28Use the new PyErr_WarnExplicit() API to issue better warnings forGuido van Rossum-12/+21
global after assign / use. Note: I'm not updating the PyErr_Warn() call for import * / exec combined with a function, because I can't trigger it with an example. Jeremy, just follow the example of the call to PyErr_WarnExplicit() that I *did* include.
2001-02-28Improve SyntaxErrors for bad future statements. Set file and locationJeremy Hylton-84/+6
for errors raised in future.c. Move some helper functions from compile.c to errors.c and make them API functions: PyErr_SyntaxLocation() and PyErr_ProgramText().
2001-02-28Print the offending line of code in the traceback for SyntaxErrorsJeremy Hylton-30/+95
raised by the compiler. XXX For now, text entered into the interactive intepreter is not printed in the traceback. Inspired by a patch from Roman Sulzhyk compile.c: Add helper fetch_program_text() that opens a file and reads until it finds the specified line number. The code is a near duplicate of similar code in traceback.c. Modify com_error() to pass two arguments to SyntaxError constructor, where the second argument contains the offending text when possible. Modify set_error_location(), now used only by the symtable pass, to set the text attribute on existing exceptions. pythonrun.c: Change parse_syntax_error() to continue of the offset attribute of a SyntaxError is None. In this case, it sets offset to -1. Move code from PyErr_PrintEx() into helper function print_error_text(). In the helper, only print the caret for a SyntaxError if offset > 0.
2001-02-28Presumed correct compiler pass for future statementsJeremy Hylton-4/+30
XXX still need to integrate into symtable API compile.h: Remove ff_n_simple_stmt; obsolete. Add ff_found_docstring used internally to skip one and only one string at the beginning of a module. compile.c: Add check for from __future__ imports to far into the file. In symtable_global() check for -1 returned from symtable_lookup(), which signifies name not defined. Add missing DECERF in symtable_add_def. Free c->c_future. future.c: Add special handling for multiple statements joined on a single line using one or more semicolons; this form can include an illegal future statement that would otherwise be hard to detect. Add support for detecting and skipping doc strings.
2001-02-27Improved __future__ parser; still more to doJeremy Hylton-43/+5
Makefile.pre.in: add target future.o Include/compile.h: define PyFutureFeaters and PyNode_Future() add c_future slot to struct compiling Include/symtable.h: add st_future slot to struct symtable Python/future.c: implementation of PyNode_Future() Python/compile.c: use PyNode_Future() for nested_scopes support Python/symtable.c: include compile.h to pick up PyFutureFeatures decl
2001-02-27Add warnings about undefined "global"Jeremy Hylton-0/+29
SF bug #233532 XXX Can't figure out how to write test cases that work with warnings