summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
Commit message (Collapse)AuthorAgeFilesLines
* Remove trailing comma from 'why_code' enum, which was introduced by theThomas Wouters2001-02-161-1/+1
| | | | continue-inside-try patch. Partly fixes SF bug #132597.
* When calling a PyCFunction that has METH_KEYWORDS defined, don'tJeremy Hylton2001-02-091-10/+0
| | | | | | | | create an empty dictionary if it is called without keyword args. Just pass NULL. XXX I had believed that this caused weird errors, but the test suite runs cleanly.
* SF patch 103596 by Nick Mathewson: rause UnboundLocalError forJeremy Hylton2001-02-051-0/+16
| | | | uninitialized free variables
* Allow 'continue' inside 'try' clauseJeremy Hylton2001-02-011-4/+24
| | | | SF patch 102989 by Thomas Wouters
* Undo recent change that banned using import to bind a global, as perJeremy Hylton2001-02-011-5/+3
| | | | | | | | | | | discussion on python-dev. 'from mod import *' is still banned except at the module level. Fix value for special NOOPT entry in symtable. Initialze to 0 instead of None, so that later uses of PyInt_AS_LONG() are valid. (Bug reported by Donn Cave.) replace local REPR macros with PyObject_REPR in object.h
* SF bug #130532: newest CVS won't build on AIX.Tim Peters2001-01-311-2/+0
| | | | | Removed illegal redefinition of REPR macro; kept the one with the argument name that isn't too easy to confuse with zero <wink>.
* Remove f_closure slot of frameobject and use f_localsplus instead.Jeremy Hylton2001-01-291-4/+16
| | | | | | | | | | | | This change eliminates an extra malloc/free when a frame with free variables is created. Any cell vars or free vars are stored in f_localsplus after the locals and before the stack. eval_code2() fills in the appropriate values after handling initialization of locals. To track the size the frame has an f_size member that tracks the total size of f_localsplus. It used to be implicitly f_nlocals + f_stacksize.
* PEP 227 implementationJeremy Hylton2001-01-251-12/+77
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The majority of the changes are in the compiler. The mainloop changes primarily to implement the new opcodes and to pass a function's closure to eval_code2(). Frames and functions got new slots to hold the closure. Include/compile.h Add co_freevars and co_cellvars slots to code objects. Update PyCode_New() to take freevars and cellvars as arguments Include/funcobject.h Add func_closure slot to function objects. Add GetClosure()/SetClosure() functions (and corresponding macros) for getting at the closure. Include/frameobject.h PyFrame_New() now takes a closure. Include/opcode.h Add four new opcodes: MAKE_CLOSURE, LOAD_CLOSURE, LOAD_DEREF, STORE_DEREF. Remove comment about old requirement for opcodes to fit in 7 bits. compile.c Implement changes to code objects for co_freevars and co_cellvars. Modify symbol table to use st_cur_name (string object for the name of the current scope) and st_cur_children (list of nested blocks). Also define st_nested, which might more properly be called st_cur_nested. Add several DEF_XXX flags to track def-use information for free variables. New or modified functions of note: com_make_closure(struct compiling *, PyCodeObject *) Emit LOAD_CLOSURE opcodes as needed to pass cells for free variables into nested scope. com_addop_varname(struct compiling *, int, char *) Emits opcodes for LOAD_DEREF and STORE_DEREF. get_ref_type(struct compiling *, char *name) Return NAME_CLOSURE if ref type is FREE or CELL symtable_load_symbols(struct compiling *) Decides what variables are cell or free based on def-use info. Can now raise SyntaxError if nested scopes are mixed with exec or from blah import *. make_scope_info(PyObject *, PyObject *, int, int) Helper functions for symtable scope stack. symtable_update_free_vars(struct symtable *) After a code block has been analyzed, it must check each of its children for free variables that are not defined in the block. If a variable is free in a child and not defined in the parent, then it is defined by block the enclosing the current one or it is a global. This does the right logic. symtable_add_use() is now a macro for symtable_add_def() symtable_assign(struct symtable *, node *) Use goto instead of for (;;) Fixed bug in symtable where name of keyword argument in function call was treated as assignment in the scope of the call site. Ex: def f(): g(a=2) # a was considered a local of f ceval.c eval_code2() now take one more argument, a closure. Implement LOAD_CLOSURE, LOAD_DEREF, STORE_DEREF, MAKE_CLOSURE> Also: When name error occurs for global variable, report that the name was global in the error mesage. Objects/frameobject.c Initialize f_closure to be a tuple containing space for cellvars and freevars. f_closure is NULL if neither are present. Objects/funcobject.c Add support for func_closure. Python/import.c Change the magic number. Python/marshal.c Track changes to code objects.
* clearer error messages for apply() and "no locals"Jeremy Hylton2001-01-191-7/+12
|
* Rich comparisons fall-out:Guido van Rossum2001-01-171-148/+147
| | | | | | | | | | | | - Use PyObject_RichCompare*() where possible: when comparing keyword arguments, in _PyEval_SliceIndex(), and of course in cmp_outcome(). Unrelated stuff: - Removed all trailing whitespace. - Folded some long lines.
* This patch makes sure that the function name always appears in the errorKa-Ping Yee2001-01-151-29/+54
| | | | | | | message, and tries to make the messages more consistent and helpful when the wrong number of arguments or duplicate keyword arguments are supplied. Comes with more tests for test_extcall.py and and an update to an error message in test/output/test_pyexpat.
* Two changes to from...import:Guido van Rossum2001-01-121-30/+54
| | | | | | | | | | | 1) "from M import X" now works even if M is not a real module; it's basically a getattr() operation with AttributeError exceptions changed into ImportError. 2) "from M import *" now looks for M.__all__ to decide which names to import; if M.__all__ doesn't exist, it uses M.__dict__.keys() but filters out names starting with '_' as before. Whether or not __all__ exists, there's no restriction on the type of M.
* Fixed bugs noted by Greg SteinMoshe Zadka2001-01-111-0/+2
| | | | | * x wasn't initialized to NULL * Did not DECREF result from displayhook function
* Implementation of PEP-0217.Moshe Zadka2001-01-111-27/+17
| | | | This closes the PEP, and patch 103170
* Add missing Py_DECREF in fast_cfunction. Partial fix for SF bugCharles G. Waldman2001-01-101-3/+6
| | | | #127699.
* When a PyCFunction that takes only positional parameters is called withFred Drake2001-01-041-18/+19
| | | | | | | | | | an empty keywords dictionary (via apply() or the extended call syntax), the keywords dict should be ignored. If the keywords dict is not empty, TypeError should be raised. (Between the restructuring of the call machinery and this patch, an empty dict in this situation would trigger a SystemError via PyErr_BadInternalCall().) Added regression tests to detect errors for this.
* Revised implementation of CALL_FUNCTION and friends.Jeremy Hylton2001-01-031-296/+429
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | More revision still needed. Much of the code that was in the mainloop was moved to a series of helper functions. PyEval_CallObjectWithKeywords was split into two parts. The first part now only does argument handling. The second part is now named call_object and delegates the call to a call_(function,method,etc.) helper. XXX The call_XXX helper functions should be replaced with tp_call functions for the respective types. The CALL_FUNCTION implementation contains three kinds of optimization: 1. fast_cfunction and fast_function are called when the arguments on the stack can be passed directly to eval_code2() without copying them into a tuple. 2. PyCFunction objects are dispatched immediately, because they are presumed to occur more often than anything else. 3. Bound methods are dispatched inline. The method object contains a pointer to the function object that will be called. The function is called from within the mainloop, which may allow optimization #1 to be used, too. The extened call implementation -- f(*args) and f(**kw) -- are implemented as a separate case in the mainloop. This allows the common case of normal function calls to execute without wasting time on checks for extended calls, although it does introduce a small amount of code duplication. Also, the unused final argument of eval_code2() was removed. This is probably the last trace of the access statement :-).
* Fix for SF bug #117241Jeremy Hylton2000-10-301-1/+15
| | | | | | | | | When a method is called with no regular arguments and * args, defer the first arg is subclass check until after the * args have been expanded. N.B. The CALL_FUNCTION implementation is getting really hairy; should review it to see if it can be simplified.
* Ka-Ping Yee <ping@lfw.org>:Fred Drake2000-10-241-29/+48
| | | | | | Changes to error messages to increase consistency & clarity. This (mostly) closes SourceForge patch #101839.
* Do a better job at staying on-screen :P (Sorry, it's late here.) I'mThomas Wouters2000-10-111-1/+2
| | | | | assuming here that the ANSI-C adjacent-string-concatenation technique is allowable, now that Python requires an ANSI C compiler.
* Adjust debugging code in the implementation of the DUP_TOPX bytecode, useThomas Wouters2000-10-111-5/+1
| | | | | Py_FatalError() instead, and clarify the message somewhat. As discussed on python-dev.
* Remove the last gcc -Wall warning about possible use of an uninitializedFred Drake2000-10-111-0/+1
| | | | | | variable. w should be initialized before entering the bytecode interpretation loop since we only need one initialization to satisfy the compiler.
* Attempt to fix bogus gcc -Wall warnings reported by Marc-Andre Lemburg,Tim Peters2000-10-111-31/+61
| | | | | | by making the DUP_TOPX code utterly straightforward. This also gets rid of all normal-case internal DUP_TOPX if/branches, and allows replacing one POP() with TOP() in each case, so is a good idea regardless.
* Rationalize use of limits.h, moving the inclusion to Python.h.Fred Drake2000-09-261-6/+0
| | | | | | | | Add definitions of INT_MAX and LONG_MAX to pyport.h. Remove includes of limits.h and conditional definitions of INT_MAX and LONG_MAX elsewhere. This closes SourceForge patch #101659 and bug #115323.
* This patch adds a new Python C API called PyString_AsStringAndSize()Marc-André Lemburg2000-09-191-6/+4
| | | | | | | | | | | | | which implements the automatic conversion from Unicode to a string object using the default encoding. The new API is then put to use to have eval() and exec accept Unicode objects as code parameter. This closes bugs #110924 and #113890. As side-effect, the traditional C APIs PyString_Size() and PyString_AsString() will also accept Unicode objects as parameters.
* REMOVED all CWI, CNRI and BeOpen copyright markings.Guido van Rossum2000-09-011-9/+0
| | | | This should match the situation in the 1.6b1 tree.
* Cosmetics on Py_Get/SetRecursionLimit (for the style guide)Vladimir Marangozov2000-09-011-2/+4
|
* Revert removal of void from function definition. Guido sez I can take itTim Peters2000-09-011-1/+1
| | | | | out again after we complete switching to C++ <wink>. Thanks to Greg Stein for hitting me.
* Set the recursion limit to 1000 -- 2500 was not enough, let's beGuido van Rossum2000-09-011-1/+1
| | | | conservative.
* Supply missing prototypes for new Py_{Get,Set}RecursionLimit; fixes compiler ↵Tim Peters2000-09-011-1/+1
| | | | | | | wngs; un-analize Get's definition ("void" is needed only in declarations, not defns, & is generally considered bad style in the latter).
* add user-modifiable recursion_limitJeremy Hylton2000-08-311-5/+15
| | | | | | | | | | | ceval.c: define recurion_limit (static), default value is 2500 define Py_GetRecursionLimit and Py_SetRecursionLimit raise RuntimeError if limit is exceeded PC/config.h: remove plat-specific definition sysmodule.c: add sys.(get|set)recursionlimit
* Better error message with UnboundLocalErrorPaul Prescod2000-08-301-11/+39
|
* eval_code2(): Guido provides this patch for his suggested elaborationBarry Warsaw2000-08-291-2/+2
| | | | | of extended print. If the file object being printed to is None, then sys.stdout is used.
* Replace the run-time 'future-bytecode-stream-inspection' hack to find outThomas Wouters2000-08-271-55/+1
| | | | | | | how 'import' was called with a compiletime mechanism: create either a tuple of the import arguments, or None (in the case of a normal import), add it to the code-block constants, and load it onto the stack before calling IMPORT_NAME.
* Charles Waldman's patch to reinitialize the interpreter lock after aGuido van Rossum2000-08-271-0/+19
| | | | | | | fork. This solves the test_fork1 problem. (ceval.c, signalmodule.c, intrcheck.c) SourceForge: [ Patch #101226 ] make threading fork-safe
* Support for three-token characters (**=, >>=, <<=) which was written byThomas Wouters2000-08-241-4/+201
| | | | | Michael Hudson, and support in general for the augmented assignment syntax. The graminit.c patch is large!
* Charles G. Waldman <cgw@fnal.gov>:Fred Drake2000-08-241-0/+6
| | | | | | | | | Add the EXTENDED_ARG opcode to the virtual machine, allowing 32-bit arguments to opcodes instead of being forced to stick to the 16-bit limit. This is especially useful for machine-generated code, which can be too long for the SET_LINENO parameter to fit into 16 bits. This closes the implementation portion of SourceForge patch #100893.
* PEP 214, Extended print Statement, has been accepted by the BDFL.Barry Warsaw2000-08-211-16/+33
| | | | | | | eval_code2(): Implement new bytecodes PRINT_ITEM_TO and PRINT_NEWLINE_TO, as per accepted SF patch #100970. Also update graminit.c based on related Grammar/Grammar changes.
* Fix the bug Sjoerd Mullender discovered, where find_from_args() wasn'tThomas Wouters2000-08-201-1/+3
| | | | | | | | | | trying hard enough to find out what the arguments to an import were. There is no test-case for this bug, yet, but this is what it looked like: from encodings import cp1006, cp1026 ImportError: cannot import name cp1026 '__import__' was called with only the first name in the 'arguments' list.
* Remove a couple of warnings turned up by "gcc -Wall".Fred Drake2000-08-181-1/+2
|
* Apply SF patch #101135, adding 'import module as m' and 'from module importThomas Wouters2000-08-171-43/+70
| | | | | | | | name as n'. By doing some twists and turns, "as" is not a reserved word. There is a slight change in semantics for 'from module import name' (it will now honour the 'global' keyword) but only in cases that are explicitly undocumented.
* Merge UNPACK_LIST and UNPACK_TUPLE into a single UNPACK_SEQUENCE, since theyThomas Wouters2000-08-111-2/+1
| | | | | | | did the same anyway. I'm not sure what to do with Tools/compiler/compiler/* -- that isn't part of distutils, is it ? Should it try to be compatible with old bytecode version ?
* Initialized opcode and oparg to silence a gcc -Wall warning.Moshe Zadka2000-08-071-2/+2
|
* Use 'void' directly instead of the ANY #define, now that all code is ANSI C.Thomas Wouters2000-07-251-5/+5
| | | | Leave the actual #define in for API compatibility.
* Mass ANSIfication of function definitions. Doesn't cover all 'extern'Thomas Wouters2000-07-221-112/+49
| | | | declarations yet, those come later.
* Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in eitherThomas Wouters2000-07-161-1/+1
| | | | | | | | | | comments, docstrings or error messages. I fixed two minor things in test_winreg.py ("didn't" -> "Didn't" and "Didnt" -> "Didn't"). There is a minor style issue involved: Guido seems to have preferred English grammar (behaviour, honour) in a couple places. This patch changes that to American, which is the more prominent style in the source. I prefer English myself, so if English is preferred, I'd be happy to supply a patch myself ;)
* Include macglue.h for some function prototypes, and renamed a fewJack Jansen2000-07-111-0/+4
| | | | mac-specific functions to have a PyMac_ name.
* Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.Tim Peters2000-07-091-31/+29
|
* Change copyright notice - 2nd try.Guido van Rossum2000-06-301-6/+0
|
* Change copyright notice.Guido van Rossum2000-06-301-22/+7
|