From accb62b28e1d592733b2f678d5737ca3e8c64fc2 Mon Sep 17 00:00:00 2001 From: Jeremy Hylton Date: Tue, 31 Dec 2002 18:17:44 +0000 Subject: 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. --- Lib/compiler/pycodegen.py | 55 ++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 27 deletions(-) (limited to 'Lib/compiler/pycodegen.py') diff --git a/Lib/compiler/pycodegen.py b/Lib/compiler/pycodegen.py index ac978c088e..a3518d292c 100644 --- a/Lib/compiler/pycodegen.py +++ b/Lib/compiler/pycodegen.py @@ -13,6 +13,7 @@ from compiler.consts import CO_VARARGS, CO_VARKEYWORDS, CO_NEWLOCALS,\ CO_NESTED, CO_GENERATOR, CO_GENERATOR_ALLOWED, CO_FUTURE_DIVISION from compiler.pyassem import TupleArg +# XXX The version-specific code can go, since this code only works with 2.x. # Do we have Python 1.x or Python 2.x? try: VERSION = sys.version_info[0] @@ -32,22 +33,14 @@ EXCEPT = 2 TRY_FINALLY = 3 END_FINALLY = 4 -# XXX this doesn't seem to be used -class BlockStack(misc.Stack): - __super_init = misc.Stack.__init__ - - def __init__(self): - self.__super_init(self) - self.loop = None - def compileFile(filename, display=0): - f = open(filename) + f = open(filename, 'U') buf = f.read() f.close() mod = Module(buf, filename) try: mod.compile(display) - except SyntaxError, err: + except SyntaxError: raise else: f = open(filename + "c", "wb") @@ -134,7 +127,7 @@ class Module(AbstractCompileMode): # to indicate the type of the value. simplest way to get the # same effect is to call marshal and then skip the code. mtime = os.path.getmtime(self.filename) - mtime = struct.pack('i', mtime) + mtime = struct.pack('