summaryrefslogtreecommitdiffstats
path: root/Lib/compiler
Commit message (Collapse)AuthorAgeFilesLines
* a few small optimizations that seem to give a 5-10% speedup; theJeremy Hylton2000-11-061-76/+80
| | | | further optimization of com_node makes the most difference.
* 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-063-21/+133
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* If a function contains a doc string, remove the doc string node fromJeremy Hylton2000-11-061-1/+5
| | | | | | | the function's body. If assert is used without an error message, make the AST node None rather than Name('None').
* Many changes.Jeremy Hylton2000-10-251-220/+145
| | | | | | | | | | | | | | | | | | | | | Reformatting -- long lines, "[ ]" -> "[]", a few indentation nits. Replace calls to Node function (which constructed ast nodes) with calls to actual constructors imported from ast module. Optimize com_node (most frequently used method) for the common case -- the appropriate method is found in _dispatch. Fix com_augassign to use class object's rather than node names (rendered invalid by recent changes to ast) Remove expensive tests for sequence-ness in com_stmt and com_append_stmt. These tests should never fail; if they do, something is really broken and exception will be raised elsewhere. Fix com_stmt and com_append_stmt to use isinstance rather than testing's type slot of ast node (this slot disappeared with recent changes to ast).
* Generated from rev 1.1 of ast.txtJeremy Hylton2000-10-251-677/+606
|
* Small optimizations in dispatch method: 1) lookup node's __class__ onceJeremy Hylton2000-10-251-12/+14
| | | | | and store in local; 2) define _preorder to be dispatch (rather than method that called dispatch).
* Now supports entire Python 2.0 language and still supports PythonJeremy Hylton2000-10-134-93/+463
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-123-4/+13
| | | | | | transformer.py: return '*', None from com_import_as_name pycodegen.py: special case for name == '*' pyassem.py: fix stack counting for IMPORT_ opcodes
* change 2-space indent to 4-space indentJeremy Hylton2000-09-201-1081/+1079
|
* patch by Neil Schemenauer to improve (fix?) line number generationJeremy Hylton2000-09-012-17/+32
|
* Update magic number.Jeremy Hylton2000-09-012-15/+47
| | | | | | Fix import support to work with import as variant of Python 2.0. The grammar for import changed, requiring changes in transformer and code generator, even to handle compilation of imports with as.
* Bring Tools/compiler almost up to date. Specifically:Thomas Wouters2000-08-123-348/+349
| | | | | | | | | | - 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.
* replace most calls to emit 'SET_LINENO' will call to method set_linenoJeremy Hylton2000-08-041-31/+42
| | | | based on bug report by Neil Schemenauer
* update my email addressJeremy Hylton2000-08-041-1/+4
| | | | fix com_call_function to cope with trailing comma in "f(a, b,)"
* add a bit more legal junkGreg Stein2000-08-031-8/+16
| | | | (too lazy to paste in the whole BSD license tho; included by ref)
* patches from Mark HammondJeremy Hylton2000-05-024-14/+58
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-162-800/+831
| | | | | | | | | 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
* simplify visitor walker classJeremy Hylton2000-03-161-32/+22
| | | | | | - remove postorder - remove protocol for automatically walking children based on visitor method return value; now only walks if there is no method
* fix list.append problemsJeremy Hylton2000-03-161-3/+3
|
* change name of Set method: items -> elements (avoids confusion withJeremy Hylton2000-03-161-1/+1
| | | | dict)
* import compile function form pycodegenJeremy Hylton2000-03-061-0/+4
|
* rename compile.py to pycodegen.pyJeremy Hylton2000-03-061-176/+25
| | | | | | | | | | fix imports remove parse functions and visitor code track name change: Classdef to Class add some comments and tweak order of visitXXX methods get rid of if __name__ == "__main__ section
* add a doc stringJeremy Hylton2000-03-061-0/+20
| | | | import some useful functions from contained modules
* fix import to refer to compiler packageJeremy Hylton2000-03-061-1/+1
|
* 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.
* change node Classdef to ClassJeremy Hylton2000-03-062-24/+25
| | | | | | | add doc string to transformer module add two helper functions: parse(buf) -> AST parseFile(path) -> AST
* factor out the tree walking/visitor code that was in compile.pyJeremy Hylton2000-03-061-0/+127
|
* satisfy the tabnanny (thanks to MH for noticing the problem)Jeremy Hylton2000-02-212-98/+98
|
* 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-172-16/+48
| | | | | | | | | | | | | | | (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 ...
* add varargs and kwargs flags to Lambda nodesJeremy Hylton2000-02-171-0/+5
|
* satisfy the tabnannyJeremy Hylton2000-02-171-197/+199
| | | | fix broken references to filename var in generateXXX methods
* support for arglists with implicit tuple unpacksJeremy Hylton2000-02-161-15/+61
| | | | | | | | | | | | | | - added a number of support methods to generate code just before the body - hack protocol for communicating number of args to PyAssembler fix TryExcept generation for case where exception handler has no body fix visitAssAttr add comment about incomplete visitAssName stop using the ExampleASTVisitor change script invocation to accept a list of .py files (e.g. Lib/*.py)
* more robust assignment of lineno for keyword argsJeremy Hylton2000-02-161-3/+3
| | | | | | | | get the lineno from the name of the keyword arg example of case that didn't work-- def foo(x, y, a = None, b = None):
* fix argcount generation for arg lists containing tuple unpacksJeremy Hylton2000-02-161-2/+13
| | | | this is sort of a hack
* add flatten helper functionJeremy Hylton2000-02-161-0/+11
|
* finish first impl of code generatorJeremy Hylton2000-02-151-12/+70
| | | | | add support for nodes TryExcept, TryFinally, Sliceobj fix visitSubscript to properly handle x[a,b,c]
* fix creation of Ellipsis nodeJeremy Hylton2000-02-151-1/+1
|
* add a little debugging support when new.code raises SystemErrorJeremy Hylton2000-02-151-5/+21
|
* add line numbers to nodes in the except clause (when possible)Jeremy Hylton2000-02-151-1/+3
|
* tidy up tryexcept and tryfinally nodesJeremy Hylton2000-02-151-14/+20
|
* edit a doc stringJeremy Hylton2000-02-141-1/+6
| | | | (real intent is to test out rsync install)
* get rid of spurious printJeremy Hylton2000-02-141-1/+0
|
* looks like everything is working except for try/except (pystoneJeremy Hylton2000-02-141-6/+14
| | | | compiles correctly)
* LeftShift & RightShift: fix reprs, change attr names to left and rightJeremy Hylton2000-02-141-10/+10
| | | | (so they are common with other binary ops)
* rename several of the generic attribute names for nodes. new node attrs are:Jeremy Hylton2000-02-141-12/+12
| | | | | | Exec: expr, locals, globals Dict: items Assert: test, fail
* (), [], and {} should not be represented as constant expressions, theyJeremy Hylton2000-02-141-3/+3
| | | | should be calls to BUILD_ ops for these types with no arguments
* split compile.py into two filesJeremy Hylton2000-02-142-536/+623
| | | | | add StackDepthFinder (and remove push/pop from CodeGen) add several nodes, including Ellipsis, Bit&|^, Exec
* change MODULE_NAMESPACE/FUNCTION_NAMESPACE stuff to have a single flagJeremy Hylton2000-02-121-34/+87
| | | | | | | | | | | | | | | | | named OPTIMIZED, which matches compile.c and makes more sense for classes revamp call signature for PythonVMCode.__init__; doesn't really matter 'cuz this code is going to be refactored out of existence add generateClassCode and modify Func & Lambda generation add support for nodes Classdef, Keyword, fix CallFunc to generate right op arg when calling w/ keywords add ugly hack to properly compute offsets when the same stack ref is used multiple times