summaryrefslogtreecommitdiffstats
path: root/Lib/compiler/pyassem.py
Commit message (Collapse)AuthorAgeFilesLines
* SF bug 1442442: LIST_APPEND optimization got lost in the AST merge.Neal Norwitz2006-03-031-0/+1
| | | | Add it back.
* Add support for absolute/relative imports and if/else expressions:Thomas Wouters2006-03-031-1/+1
| | | | | | | | | - regenerate ast.py - add future flags for absolute-import and with-statement so they (hopefully) properly get set in code-object flags - try out if/else expressions in actual code for the hell of it. Seems to generate the same kind of bytecode as the normal compiler.
* Forgot to explain the effect of the new opcode.Guido van Rossum2006-02-281-0/+1
| | | | Sigh -- we really should have one place for all opcode metadata.
* No need for types, use isinstanceNeal Norwitz2005-11-251-2/+1
|
* Merge ast-branch to headJeremy Hylton2005-10-201-10/+9
| | | | | | | | | | 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.
* SF patch [ 597919 ] compiler package and SET_LINENOJeremy Hylton2002-12-311-14/+9
| | | | | | | | | | | | | | | | | 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.
* Remove uses of string module and stat.ST_MODENeal Norwitz2002-06-061-4/+3
|
* Whitespace normalization.Tim Peters2001-10-181-13/+13
|
* Vastly improved stacksize calculation.Jeremy Hylton2001-10-171-18/+51
| | | | | | | | | | | | | | | | | | | | | There are now no known cases where the compiler package computes a stack depth lower than the one computed by the builtin compiler. (To achieve this state, we had to fix bugs in both compilers :-). The chief change is to do the depth calculations with respect to basic blocks. The stack effect of block is calculated. Then the flow graph is traversed using breadth-first search to find the max weight path through the graph. Had to fix the StackDepthTracker to calculate the right info for several opcodes: LOAD_ATTR, CALL_FUNCTION (and friends), MAKE_CLOSURE, and DUP_TOPX. XXX Still need to handle free variables in MAKE_CLOSURE. XXX There are still a lot of places where the computed stack depth is larger than for the builtin compiler. These won't cause the interpreter to overflow the frame, but they waste space.
* Various sundry changes for 2.2 compatibilityJeremy Hylton2001-09-141-4/+5
| | | | | | | | | | | | | | | Remove the option to have nested scopes or old LGB scopes. This has a large impact on the code base, by removing the need for two variants of each CodeGenerator. Add a get_module() method to CodeGenerator objects, used to get the future features for the current module. Set CO_GENERATOR, CO_GENERATOR_ALLOWED, and CO_FUTURE_DIVISION flags as appropriate. Attempt to fix the value of nlocals in newCodeObject(), assuming that nlocals is 0 if CO_NEWLOCALS is not defined.
* Fix _convert_NAME() so that it doesn't store locals for class bodies.Jeremy Hylton2001-08-301-8/+6
| | | | | | | | | Fix list comp code generation -- emit GET_ITER instead of Const(0) after the list. Add CO_GENERATOR flag to generators. Get CO_xxx flags from the new module
* Improve stack depth computation for try/except and try/finallyJeremy Hylton2001-08-291-1/+4
| | | | Add CONTINUE_LOOP to the list of unconditional transfers
* Fix off-by-one errors in code to find depth of stack.Jeremy Hylton2001-08-291-3/+3
| | | | | XXX The code is still widely inaccurate, but most (all?) of the time it's an overestimate.
* Undo change from list to dict for handling varnames, consts, etc.Jeremy Hylton2001-08-291-49/+22
| | | | | | | | | | As the doc string for _lookupName() explains: This routine uses a list instead of a dictionary, because a dictionary can't store two different keys if the keys have the same value but different types, e.g. 2 and 2L. The compiler must treat these two separately, so it does an explicit type comparison before comparing the values.
* Modify name conversion to be (hopefully) a bit more efficient.Jeremy Hylton2001-08-291-17/+52
| | | | | | | | Use a dictionary instead of a list to map objects to their offsets in a const/name tuple of a code object. XXX The conversion is perhaps incomplete, in that we shouldn't have to do the list2dict to start.
* XXX_NAME ops should affect varnamesJeremy Hylton2001-08-281-1/+4
| | | | | | varnames should list all the local variables (with arguments first). The XXX_NAME ops typically occur at the module level and assignment ops should create locals.
* SF bug 430991: wrong co_lnotabTim Peters2001-06-091-17/+14
| | | | | | | | | 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).
* pyassem.py:Jeremy Hylton2001-04-121-1/+100
| | | | | | | | | | | | | | | | Fix annoying bugs in flow graph layout code. In some cases the implicit control transfers weren't honored. In other cases, JUMP_FORWARD instructions jumped backwards. Remove unused arg from nextBlock(). pycodegen.py Add optional force kwarg to set_lineno() that will emit a SET_LINENO even if it is the same as the previous lineno. Use explicit LOAD_FAST and STORE_FAST to access list comp implicit variables. (The symbol table doesn't know about them.)
* Revise handling of tuple arguments so that the variables names matchJeremy Hylton2001-04-121-1/+1
| | | | those used by compile.c. (test_grammar now depends on the names)
* Preliminary support for nested scopesJeremy Hylton2001-04-121-7/+43
| | | | | XXX Still doesn't work right for classes XXX Still doesn't do sufficient error checking
* Make sure the docstring is always entered as the first element in theJeremy Hylton2001-04-111-11/+1
| | | | | | consts, even if it is None. Simplify _lookupName() by removing lots of redundant tests.
* move pruneNext method to correct object (doh!)Jeremy Hylton2000-11-061-24/+24
|
* Change the graph structure to contain the code generator object forJeremy Hylton2000-11-061-12/+108
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | embedded code objects (e.g. functions) rather than the generated code object. This change means that the compiler generates code for everything at the end, rather then generating code for each function as it finds it. Implementation note: _convert_LOAD_CONST in pyassem.py must be change to call getCode(). Other changes follow. Several changes creates extra edges between basic blocks to reflect control flow for loops and exceptions. These missing edges had gone unnoticed because they do not affect the current compilation process. pyassem.py: Add _enable_debug() and _disable_debug() methods that print instructions and blocks to stdout as they are generated. Add edges between blocks for instructions like SETUP_LOOP, FOR_LOOP, etc. Add pruneNext to get rid of bogus edges remaining after unconditional transfer ops (e.g. JUMP_FORWARD) Change repr of Block to omit block length. pycodegen.py: Make sure a new block is started after FOR_LOOP, etc. Change assert implementation to use RAISE_VARARGS 1 when there is no user-specified failure output. misc.py: Implement __contains__ and copy for Set.
* Now supports entire Python 2.0 language and still supports PythonJeremy Hylton2000-10-131-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 1.5.2. The compiler generates code for the version of the interpreter it is run under. ast.py: Print and Printnl add dest attr for extended print new node AugAssign for augmented assignments new nodes ListComp, ListCompFor, and ListCompIf for list comprehensions pyassem.py: add work around for string-Unicode comparison raising UnicodeError on comparison of two objects in code object's const table pycodegen.py: define VERSION, the Python major version number get magic number using imp.get_magic() instead of hard coding implement list comprehensions, extended print, and augmented assignment; augmented assignment uses Delegator classes (see doc string) fix import and tuple unpacking for 1.5.2 transformer.py: various changes to support new 2.0 grammar and old 1.5 grammar add debug_tree helper than converts and symbol and token numbers to their names
* Fix SF bug #116263: support for from .. import *Jeremy Hylton2000-10-121-1/+3
| | | | | | transformer.py: return '*', None from com_import_as_name pycodegen.py: special case for name == '*' pyassem.py: fix stack counting for IMPORT_ opcodes
* patch by Neil Schemenauer to improve (fix?) line number generationJeremy Hylton2000-09-011-15/+26
|
* Bring Tools/compiler almost up to date. Specifically:Thomas Wouters2000-08-121-130/+128
| | | | | | | | | | - fix tab space issues (SF patch #101167 by Neil Schemenauer) - fix co_flags for classes to include CO_NEWLOCALS (SF patch #101145 by Neil) - fix for merger of UNPACK_LIST and UNPACK_TUPLE into UNPACK_SEQUENCE, (SF patch #101168 by, well, Neil :) - Adjust bytecode MAGIC to current bytecode. TODO: teach compile.py about list comprehensions.
* patches from Mark HammondJeremy Hylton2000-05-021-7/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Attached is a set of diffs for the .py compiler that adds support for the new extended call syntax. compiler/ast.py: CallFunc node gets 2 new children to support extended call syntax - "star_args" (for "*args") and "dstar_args" (for "**args") compiler/pyassem.py It appear that self.lnotab is supposed to be responsible for tracking line numbers, but self.firstlineno was still hanging around. Removed self.firstlineno completely. NOTE - I didnt actually test that the generated code has the correct line numbers!! Stack depth tracking appeared a little broken - the checks never made it beyond the "self.patterns" check - thus, the custom methods were never called! Fixed this. (XXX Jeremy notes: I think this code is still broken because it doesn't track stack effects across block bounaries.) Added support for the new extended call syntax opcodes for depth calculations. compiler/pycodegen.py Added support for the new extended call syntax opcodes. compiler/transformer.py Added support for the new extended call syntax.
* complete rewriteJeremy Hylton2000-03-161-283/+341
| | | | | | | | | code generator uses flowgraph as intermediate representation. the old rep uses a list with explicit "StackRefs" to indicate the target of jumps. pyassem converts flowgraph to bytecode, breaks up individual steps of generating bytecode
* revise arguments for addCode method on lnotab. take several numbersJeremy Hylton2000-03-061-10/+13
| | | | that are internally converted to chars, rather than taking a string.
* satisfy the tabnanny (thanks to MH for noticing the problem)Jeremy Hylton2000-02-211-90/+90
|
* changes to _lookupNameJeremy Hylton2000-02-171-14/+13
| | | | | | - removed now (happily) unused second arg - need to verify results of [].index are correct; for building consts, need to have same value and same type, e.g. 2 not the same as 2L
* the previous quick hack to fix def foo((x,y)) failed on some casesJeremy Hylton2000-02-171-9/+23
| | | | | | | | | | | | | | | (big surprise). new solution is a little less hackish. Code gen adds a TupleArg instance in the argument slot. The tuple arg includes a copy of the names that it is responsble for binding. The PyAssembler uses this information to calculate the correct argcount. all fix this wacky case: del (a, ((b,), c)), d which is the same as: del a, b, c, d (Can't wait for Guido to tell me why.) solution uses findOp which walks a tree to find out whether it contains OP_ASSIGN or OP_DELETE or ...
* fix argcount generation for arg lists containing tuple unpacksJeremy Hylton2000-02-161-2/+13
| | | | this is sort of a hack
* add a little debugging support when new.code raises SystemErrorJeremy Hylton2000-02-151-5/+21
|
* split compile.py into two filesJeremy Hylton2000-02-141-0/+437
add StackDepthFinder (and remove push/pop from CodeGen) add several nodes, including Ellipsis, Bit&|^, Exec